From 236532e11f07bd82631b4a2ba5311e6365bf79c3 Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Thu, 3 Oct 2024 15:52:16 +0200 Subject: [PATCH] add crucifix action disable effect --- .../mob_effect/disables_actions/vampire.json | 3 +- .../lib/lib/storage/UpdateParams.java | 21 +++++++++- .../de/teamlapen/lib/lib/util/UtilLib.java | 9 +++++ .../teamlapen/vampirism/core/ModEffects.java | 1 + .../provider/tags/ModEffectTypeProvider.java | 2 +- .../player/skills/RefinementHandler.java | 1 + .../entity/player/vampire/VampirePlayer.java | 11 ++++++ .../vampirism/items/CrucifixItem.java | 39 +++++++++++++++++-- .../component/EffectiveRefinementSet.java | 3 +- 9 files changed, 83 insertions(+), 7 deletions(-) diff --git a/src/generated/resources/data/minecraft/tags/mob_effect/disables_actions/vampire.json b/src/generated/resources/data/minecraft/tags/mob_effect/disables_actions/vampire.json index 07bef7126..6e9a460b7 100644 --- a/src/generated/resources/data/minecraft/tags/mob_effect/disables_actions/vampire.json +++ b/src/generated/resources/data/minecraft/tags/mob_effect/disables_actions/vampire.json @@ -1,5 +1,6 @@ { "values": [ - "#minecraft:disables_actions" + "#minecraft:disables_actions", + "vampirism:crucifix_suppression" ] } \ No newline at end of file diff --git a/src/lib/java/de/teamlapen/lib/lib/storage/UpdateParams.java b/src/lib/java/de/teamlapen/lib/lib/storage/UpdateParams.java index e406729a1..f4ef772d7 100644 --- a/src/lib/java/de/teamlapen/lib/lib/storage/UpdateParams.java +++ b/src/lib/java/de/teamlapen/lib/lib/storage/UpdateParams.java @@ -1,6 +1,13 @@ package de.teamlapen.lib.lib.storage; -public record UpdateParams(boolean isForAllPlayer, boolean ignoreChanges) { +public final class UpdateParams { + private boolean isForAllPlayer; + private final boolean ignoreChanges; + + private UpdateParams(boolean isForAllPlayer, boolean ignoreChanges) { + this.isForAllPlayer = isForAllPlayer; + this.ignoreChanges = ignoreChanges; + } public static UpdateParams defaults() { return new UpdateParams(false, false); @@ -18,4 +25,16 @@ public static UpdateParams all() { return new UpdateParams(true, true); } + public boolean isForAllPlayer() { + return isForAllPlayer; + } + + public boolean ignoreChanges() { + return ignoreChanges; + } + + public void markForAllPlayer() { + this.isForAllPlayer = true; + } + } diff --git a/src/lib/java/de/teamlapen/lib/lib/util/UtilLib.java b/src/lib/java/de/teamlapen/lib/lib/util/UtilLib.java index 8d40a701a..8b1e309ca 100644 --- a/src/lib/java/de/teamlapen/lib/lib/util/UtilLib.java +++ b/src/lib/java/de/teamlapen/lib/lib/util/UtilLib.java @@ -832,4 +832,13 @@ public static CompoundTag tagOf(String key, String value) { tag.putString(key, value); return tag; } + + public static int indexOf(Object[] array, Object obj) { + for (int i = 0; i < array.length; i++) { + if (array[i].equals(obj)) { + return i; + } + } + return -1; + } } diff --git a/src/main/java/de/teamlapen/vampirism/core/ModEffects.java b/src/main/java/de/teamlapen/vampirism/core/ModEffects.java index 6f72f13b9..f0c89d663 100644 --- a/src/main/java/de/teamlapen/vampirism/core/ModEffects.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModEffects.java @@ -41,6 +41,7 @@ public class ModEffects { ); public static final DeferredHolder BLEEDING = EFFECTS.register("bleeding", () -> new BleedingEffect(MobEffectCategory.HARMFUL, 0x740000)); public static final DeferredHolder RESURRECTION_FATIGUE = EFFECTS.register("resurrection_fatigue", () -> new VampirismEffect(MobEffectCategory.HARMFUL, 0x8B0000).disableDefaultCures()); + public static final DeferredHolder CRUCIFIX_SUPPRESSION = EFFECTS.register("crucifix_suppression", () -> new VampirismEffect(MobEffectCategory.HARMFUL, 0x8B0000).disableDefaultCures()); static void register(IEventBus bus) { EFFECTS.register(bus); diff --git a/src/main/java/de/teamlapen/vampirism/data/provider/tags/ModEffectTypeProvider.java b/src/main/java/de/teamlapen/vampirism/data/provider/tags/ModEffectTypeProvider.java index 5fb0383e1..0df4b1da5 100644 --- a/src/main/java/de/teamlapen/vampirism/data/provider/tags/ModEffectTypeProvider.java +++ b/src/main/java/de/teamlapen/vampirism/data/provider/tags/ModEffectTypeProvider.java @@ -26,7 +26,7 @@ public ModEffectTypeProvider(PackOutput output, CompletableFuture refinementHandler; + private int crucifixTicks; public VampirePlayer(Player player) { super(player); @@ -860,6 +861,12 @@ public void onUpdate() { if (remainingBarkTicks > 0) { --remainingBarkTicks; } + if (crucifixTicks > 0) { + --crucifixTicks; + if (this.player.tickCount % 10 == 8 && crucifixTicks > 30) { + this.player.addEffect(new MobEffectInstance(ModEffects.CRUCIFIX_SUPPRESSION, 30)); + } + } world.getProfiler().pop(); } @@ -1373,6 +1380,10 @@ public void updateMinionAttributes(boolean enabled) { })); } + public void effectCrucifixSuppression() { + this.crucifixTicks = Math.max(this.crucifixTicks + 25, 70); + } + private class VisionStatus implements ISyncableSaveData { private static final String KEY_VISION = "vision"; private final SortedSet unlockedVisions = new TreeSet<>(Comparator.comparing(o -> VampirismAPI.vampireVisionRegistry().getVisionId(o))); diff --git a/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java b/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java index 65560493b..adf52e0d0 100644 --- a/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java +++ b/src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java @@ -1,8 +1,10 @@ package de.teamlapen.vampirism.items; +import de.teamlapen.lib.lib.util.UtilLib; import de.teamlapen.vampirism.VampirismMod; import de.teamlapen.vampirism.api.entity.factions.IFaction; import de.teamlapen.vampirism.api.entity.player.hunter.IHunterPlayer; +import de.teamlapen.vampirism.api.entity.player.skills.IRefinementHandler; import de.teamlapen.vampirism.api.entity.player.skills.ISkill; import de.teamlapen.vampirism.api.items.IFactionExclusiveItem; import de.teamlapen.vampirism.api.items.IFactionLevelItem; @@ -34,6 +36,7 @@ import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.UseAnim; import net.minecraft.world.level.Level; +import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -103,14 +106,44 @@ public void appendHoverText(ItemStack stack, @Nullable TooltipContext context, L @Override public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean held) { - if (entity instanceof LivingEntity living && entity.tickCount % 16 == 8 && (living.getOffhandItem() == stack || living.getMainHandItem() == stack)) { - if (Helper.isVampire(entity)) { - ((LivingEntity) entity).addEffect(new MobEffectInstance(ModEffects.POISON, 20, 1)); + if (entity instanceof LivingEntity living && entity.tickCount % 16 == 8) { + if (Helper.isVampire(living) && (living.getOffhandItem() == stack || living.getMainHandItem() == stack)) { + living.addEffect(new MobEffectInstance(ModEffects.POISON, 20, 1)); if (entity instanceof Player player) { player.getInventory().removeItem(stack); player.drop(stack, true); } } + if (Helper.isHunter(living) && held && living instanceof Player player && all_crucifix.stream().noneMatch(s -> player.getCooldowns().isOnCooldown(s))) { + var nearbyVampires = living.level().getEntities(entity, new AABB(living.blockPosition()).inflate(6), Helper::isVampire); + var viewVector = living.getViewVector(1.0F).normalize(); + for (Entity e : nearbyVampires) { + if (e instanceof Player other && player.hasLineOfSight(other)) { + var targetVector = other.position().subtract(living.position()); + TIER tier = getVampirismTier(); + if (IRefinementHandler.get(other).filter(s -> s.isRefinementEquipped(ModRefinements.CRUCIFIX_RESISTANT)).isPresent()) { + int i = UtilLib.indexOf(TIER.values(), tier); + if (i > 0) { + tier = TIER.values()[i - 1]; + } else if(i == 0) { + continue; + } + } + + double distance = targetVector.lengthSqr(); + double degrees = Math.toDegrees(Math.cos(viewVector.dot(targetVector.normalize()))); + boolean effect = switch (tier) { + case ULTIMATE -> (distance < 100 && degrees < 20) || (distance < 56 && degrees < 55) || (distance < 25 && degrees < 70); + case ENHANCED -> (distance < 56 && degrees < 45) || (distance < 25 && degrees < 55); + case NORMAL -> (distance < 25 && degrees < 45); + }; + if (effect) { + VampirePlayer vampirePlayer = VampirePlayer.get(other); + vampirePlayer.effectCrucifixSuppression(); + } + } + } + } } } diff --git a/src/main/java/de/teamlapen/vampirism/items/component/EffectiveRefinementSet.java b/src/main/java/de/teamlapen/vampirism/items/component/EffectiveRefinementSet.java index 893813d29..5153b2c41 100644 --- a/src/main/java/de/teamlapen/vampirism/items/component/EffectiveRefinementSet.java +++ b/src/main/java/de/teamlapen/vampirism/items/component/EffectiveRefinementSet.java @@ -8,8 +8,9 @@ import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; +import org.jetbrains.annotations.Nullable; -public record EffectiveRefinementSet(IRefinementSet set) implements IEffectiveRefinementSet { +public record EffectiveRefinementSet(@Nullable IRefinementSet set) implements IEffectiveRefinementSet { public static final EffectiveRefinementSet EMPTY = new EffectiveRefinementSet(null); public static final Codec CODEC = ModRegistries.REFINEMENT_SETS.byNameCodec().xmap(EffectiveRefinementSet::new, EffectiveRefinementSet::set);