Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action disable effect #1251

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface IAction<T extends IFactionPlayer<T>> {
* Checks if the player can use this action
*
* @param player Must be an instance of class that belongs to {@link IAction#getFaction()}
* @implNote This only checks for action specific conditions. For a more general check use {@link de.teamlapen.vampirism.api.entity.player.actions.IActionHandler#canUseAction(IAction)}
*/
PERM canUse(T player);

Expand Down Expand Up @@ -95,7 +96,7 @@ enum PERM {
/**
* The player is not in the position to use the action.
* <p>
* This is the case if the player is in spectator mode or the action rejects the player
* This is different from {@link PERM#PLAYER_DISALLOWED} as it is returned by a specific action when it does not allow the player to use it
*/
DISALLOWED,
/**
Expand All @@ -107,7 +108,13 @@ enum PERM {
/**
* The user does not have the correct permission to use the action {@link de.teamlapen.vampirism.util.Permissions#ACTION}
*/
PERMISSION_DISALLOWED
PERMISSION_DISALLOWED,
/**
* The player is not in the position to use the action.
* <p>
* This is different from {@link PERM#DISALLOWED} as it is returned by the {@link IActionHandler} when the player is not able to use any action
*/
PLAYER_DISALLOWED;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public interface IActionHandler<T extends IFactionPlayer<T>> {
*/
IAction.PERM toggleAction(IAction<T> action, IAction.ActivationContext context);

/**
* Make a complete check if the player can use the action. This includes a general check and an action specific check ({@link IAction#canUse(IFactionPlayer)})
*/
IAction.PERM canUseAction(@NotNull IAction<T> action);

/**
* Deactivate a lasting action, if it was active.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ private static void drawActionPart(IAction<?> action, GuiGraphics graphics, int

@Override
public void drawSlice(IRadialMenuSlot<IAction<?>> slot, boolean highlighted, GuiGraphics buffer, float x, float y, float z, float radiusIn, float radiusOut, float startAngle, float endAngle, int r, int g, int b, int a) {
float actionPercentage = actionHandler.getPercentageForAction((IAction) slot.primarySlotIcon());
if (((IAction<T>)slot.primarySlotIcon()).canUse(this.player) != IAction.PERM.ALLOWED) {
actionPercentage = -1;
float actionPercentage = -1;
if (actionHandler.canUseAction((IAction)slot.primarySlotIcon()) == IAction.PERM.ALLOWED) {
actionPercentage = actionHandler.getPercentageForAction((IAction) slot.primarySlotIcon());
}
if (actionPercentage == 0) {
super.drawSlice(slot, highlighted, buffer, x, y, z, radiusIn, radiusOut, startAngle, endAngle, r, g, b, 100);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/de/teamlapen/vampirism/core/ModEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public IFaction<?> getFaction() {
.addAttributeModifier(ModAttributes.SUNDAMAGE.get(), "45ebd53a-14fa-4ede-b4e7-412e075a8b5f", 0.2, AttributeModifier.Operation.MULTIPLY_TOTAL)
.addAttributeModifier(Attributes.ARMOR_TOUGHNESS, "45ebd53a-14fa-4ede-b4e7-412e075a8b5f", -0.3, AttributeModifier.Operation.MULTIPLY_TOTAL)
);
public static final RegistryObject<MobEffect> ACTION_DISABLED = EFFECTS.register("action_disabled", () -> new VampirismEffect(MobEffectCategory.HARMFUL, 0x1919191));

private static final Logger LOGGER = LogManager.getLogger();
private static MobEffect modded_night_vision; //Substituted version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.teamlapen.vampirism.api.entity.player.actions.IAction;
import de.teamlapen.vampirism.config.VampirismConfig;
import de.teamlapen.vampirism.core.ModAdvancements;
import de.teamlapen.vampirism.core.ModEffects;
import de.teamlapen.vampirism.core.ModTags;
import de.teamlapen.vampirism.entity.minion.management.PlayerMinionController;
import de.teamlapen.vampirism.entity.player.IVampirismPlayer;
Expand All @@ -31,6 +32,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.capabilities.*;
import net.minecraftforge.common.util.LazyOptional;
Expand Down Expand Up @@ -571,4 +573,8 @@ private void writeBoundActions(@NotNull CompoundTag nbt) {
}
nbt.put("bound_actions", bounds);
}

public void onRespawn(boolean keepInventory) {
this.player.addEffect(new MobEffectInstance(ModEffects.ACTION_DISABLED.get(), 5 * 20));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public final void loadUpdateFromNBT(CompoundTag nbt) {
@Override
public void onDeath(DamageSource src) {
this.getSkillHandler().damageRefinements();
this.getActionHandler().resetTimers();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ public void onPlayerClone(PlayerEvent.@NotNull Clone event) {
}
}

@SubscribeEvent(priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
FactionPlayerHandler.get(event.getEntity()).onRespawn(event.isEndConquered());
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onPlayerInteract(PlayerInteractEvent.@NotNull RightClickBlock event) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.teamlapen.vampirism.api.entity.player.actions.IAction;
import de.teamlapen.vampirism.api.entity.player.actions.IActionHandler;
import de.teamlapen.vampirism.api.entity.player.actions.ILastingAction;
import de.teamlapen.vampirism.core.ModEffects;
import de.teamlapen.vampirism.util.Permissions;
import de.teamlapen.vampirism.util.RegUtil;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
Expand All @@ -17,7 +18,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.server.permission.PermissionAPI;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -268,19 +268,13 @@ public void saveToNbt(@NotNull CompoundTag nbt) {

@Override
public IAction.PERM toggleAction(@NotNull IAction<T> action, IAction.ActivationContext context) {
ResourceLocation id = RegUtil.id(action);
if (activeTimers.containsKey(id)) {
deactivateAction((ILastingAction<T>) action);
dirty = true;
return IAction.PERM.ALLOWED;
} else if (cooldownTimers.containsKey(id)) {
return IAction.PERM.COOLDOWN;
} else {
if (this.player.getRepresentingPlayer().isSpectator()) return IAction.PERM.DISALLOWED;
if (!isActionUnlocked(action)) return IAction.PERM.NOT_UNLOCKED;
if (!isActionAllowedPermission(action)) return IAction.PERM.PERMISSION_DISALLOWED;
IAction.PERM r = action.canUse(player);
if (r == IAction.PERM.ALLOWED) {
IAction.PERM perm = canUseAction(action);
if (perm == IAction.PERM.ALLOWED) {
ResourceLocation id = RegUtil.id(action);
if (activeTimers.containsKey(id)) {
deactivateAction((ILastingAction<T>) action);
dirty = true;
} else {
if (action.onActivated(player, context)) {
if (action instanceof ILastingAction) {
activeTimers.put(id, ((ILastingAction<T>) action).getDuration(player));
Expand All @@ -289,12 +283,26 @@ public IAction.PERM toggleAction(@NotNull IAction<T> action, IAction.ActivationC
}
dirty = true;
}

return IAction.PERM.ALLOWED;
} else {
return r;
}
}
return perm;
}

@Override
public IAction.PERM canUseAction(@NotNull IAction<T> action) {
ResourceLocation id = RegUtil.id(action);
if (this.player.getRepresentingPlayer().isSpectator() || player.getRepresentingPlayer().getEffect(ModEffects.ACTION_DISABLED.get()) != null) {
return IAction.PERM.PLAYER_DISALLOWED;
} else if (!isActionAllowedPermission(action)){
return IAction.PERM.PERMISSION_DISALLOWED;
} else if (!isActionUnlocked(action)) {
return IAction.PERM.NOT_UNLOCKED;
} else if (activeTimers.containsKey(id)) {
return IAction.PERM.ALLOWED;
} else if (cooldownTimers.containsKey(id)) {
return IAction.PERM.COOLDOWN;
}
return action.canUse(player);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ static void handle(@NotNull ServerboundToggleActionPacket msg, @NotNull Supplier
case COOLDOWN -> player.displayClientMessage(Component.translatable("text.vampirism.action.cooldown_not_over"), true);
case DISALLOWED -> player.displayClientMessage(Component.translatable("text.vampirism.action.disallowed"), true);
case PERMISSION_DISALLOWED -> player.displayClientMessage(Component.translatable("text.vampirism.action.permission_disallowed"), false);
case PLAYER_DISALLOWED -> player.displayClientMessage(Component.translatable("text.vampirism.action.temporary_disabled"), true);
default -> {
//Everything alright
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/vampirism/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"text.vampirism.action.not_bound": "No action is bound to this key. See %s.",
"text.vampirism.action.only_faction": "This action can only be used by players of %s faction",
"text.vampirism.action.permission_disallowed": "You do not have the permission to use this action",
"text.vampirism.action.temporary_disabled": "You are not able to use an action",
"__comment": "util",
"itemGroup.vampirism": "Vampirism",
"action.vampirism.cancel": "Cancel",
Expand Down
Loading