Skip to content

Commit

Permalink
add crucifix action disable effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed Oct 3, 2024
1 parent 64f5727 commit 236532e
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"values": [
"#minecraft:disables_actions"
"#minecraft:disables_actions",
"vampirism:crucifix_suppression"
]
}
21 changes: 20 additions & 1 deletion src/lib/java/de/teamlapen/lib/lib/storage/UpdateParams.java
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
}

}
9 changes: 9 additions & 0 deletions src/lib/java/de/teamlapen/lib/lib/util/UtilLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
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 @@ -41,6 +41,7 @@ public class ModEffects {
);
public static final DeferredHolder<MobEffect, BleedingEffect> BLEEDING = EFFECTS.register("bleeding", () -> new BleedingEffect(MobEffectCategory.HARMFUL, 0x740000));
public static final DeferredHolder<MobEffect, MobEffect> RESURRECTION_FATIGUE = EFFECTS.register("resurrection_fatigue", () -> new VampirismEffect(MobEffectCategory.HARMFUL, 0x8B0000).disableDefaultCures());
public static final DeferredHolder<MobEffect, MobEffect> CRUCIFIX_SUPPRESSION = EFFECTS.register("crucifix_suppression", () -> new VampirismEffect(MobEffectCategory.HARMFUL, 0x8B0000).disableDefaultCures());

static void register(IEventBus bus) {
EFFECTS.register(bus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public ModEffectTypeProvider(PackOutput output, CompletableFuture<HolderLookup.P
protected void addTags(HolderLookup.@NotNull Provider pProvider) {
this.tag(ModEffectTags.HUNTER_POTION_RESISTANCE).add(MobEffects.BLINDNESS.unwrapKey().orElseThrow(), MobEffects.CONFUSION.unwrapKey().orElseThrow(), MobEffects.HUNGER.unwrapKey().orElseThrow(), MobEffects.POISON.unwrapKey().orElseThrow(), ModEffects.FREEZE.getKey());
this.tag(ModEffectTags.DISABLES_ACTIONS_HUNTER).addTag(ModEffectTags.DISABLES_ACTIONS);
this.tag(ModEffectTags.DISABLES_ACTIONS_VAMPIRE).addTag(ModEffectTags.DISABLES_ACTIONS);
this.tag(ModEffectTags.DISABLES_ACTIONS_VAMPIRE).addTag(ModEffectTags.DISABLES_ACTIONS).add(ModEffects.CRUCIFIX_SUPPRESSION.getKey());
this.tag(ModEffectTags.DISABLES_ACTIONS).add(ModEffects.RESURRECTION_FATIGUE.getKey());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public void deserializeUpdateNBT(HolderLookup.@NotNull Provider provider, @NotNu

@Override
public @NotNull CompoundTag serializeUpdateNBTInternal(HolderLookup.@NotNull Provider provider, UpdateParams params) {
params.markForAllPlayer();
CompoundTag nbt = new CompoundTag();
ListTag refinementItems = new ListTag();
for (int i = 0; i < this.refinementItems.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static double getNaturalArmorToughnessValue(int lvl) {
private Component dbnoMessage;
private final Disguise disguise;
private final RefinementHandler<IVampirePlayer> refinementHandler;
private int crucifixTicks;

public VampirePlayer(Player player) {
super(player);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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<IVampireVision> unlockedVisions = new TreeSet<>(Comparator.comparing(o -> VampirismAPI.vampireVisionRegistry().getVisionId(o)));
Expand Down
39 changes: 36 additions & 3 deletions src/main/java/de/teamlapen/vampirism/items/CrucifixItem.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EffectiveRefinementSet> CODEC = ModRegistries.REFINEMENT_SETS.byNameCodec().xmap(EffectiveRefinementSet::new, EffectiveRefinementSet::set);
Expand Down

0 comments on commit 236532e

Please sign in to comment.