diff --git a/src/api/java/de/teamlapen/vampirism/api/VReference.java b/src/api/java/de/teamlapen/vampirism/api/VReference.java index 9bbb743112..78f4b57c96 100755 --- a/src/api/java/de/teamlapen/vampirism/api/VReference.java +++ b/src/api/java/de/teamlapen/vampirism/api/VReference.java @@ -43,8 +43,9 @@ public class VReference { */ public static MobCategory VAMPIRE_CREATURE_TYPE = MobCategory.create("vampirism_vampire", "vampirism_vampire", 30, false, false, 128); /** - * Vampire creatures have this creature attribute. + * Vampire creatures have this creature attribute. Note: There is a config option that makes Vampirism use UNDEAD type instead * Don't know why this exists alongside EnumCreatureType, but this is used by enchantments + * TODO 1.21 maybe replace with a getter method, if the config option still exists */ @SuppressWarnings("InstantiationOfUtilityClass") public static MobType VAMPIRE_CREATURE_ATTRIBUTE = new MobType(); diff --git a/src/main/java/de/teamlapen/vampirism/config/VampirismConfig.java b/src/main/java/de/teamlapen/vampirism/config/VampirismConfig.java index e283376d2a..ceaa1da5fc 100644 --- a/src/main/java/de/teamlapen/vampirism/config/VampirismConfig.java +++ b/src/main/java/de/teamlapen/vampirism/config/VampirismConfig.java @@ -142,6 +142,7 @@ public static class Server { public final ForgeConfigSpec.BooleanValue infectCreaturesSanguinare; public final ForgeConfigSpec.BooleanValue preventRenderingDebugBoundingBoxes; public final ForgeConfigSpec.BooleanValue allowVillageDestroyBlocks; + public final ForgeConfigSpec.BooleanValue vampiresAreUndeadType; public final ForgeConfigSpec.BooleanValue sundamageUnknownDimension; public final ForgeConfigSpec.ConfigValue> sundamageDimensionsOverridePositive; @@ -179,6 +180,7 @@ public static class Server { preventRenderingDebugBoundingBoxes = builder.comment("Prevent players from enabling the rendering of debug bounding boxes. This can allow them to see certain entities they are not supposed to see (e.g. disguised hunter").define("preventDebugBoundingBoxes", false); batDimensionBlacklist = builder.comment("Prevent vampire players to transform into a bat").defineList("batDimensionBlacklist", Collections.singletonList(Level.END.location().toString()), string -> string instanceof String && UtilLib.isValidResourceLocation(((String) string))); allowVillageDestroyBlocks = builder.comment("Allow players to destroy point of interest blocks in faction villages if they no not have the faction village").define("allowVillageDestroyBlocks", false); + vampiresAreUndeadType = builder.comment("Change vampire players mob type to UNDEAD. May cause issues with other mods").define("vampiresAreUndeadType", false); builder.push("sundamage"); sundamageUnknownDimension = builder.comment("Whether vampires should receive sundamage in unknown dimensions").define("sundamageUnknownDimension", false); diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedDonkeyEntity.java b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedDonkeyEntity.java index 89a92750a7..b002e6331a 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedDonkeyEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedDonkeyEntity.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.config.BalanceMobProps; +import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModAttributes; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -99,7 +100,7 @@ public EntityDataAccessor getConvertingDataParam() { @NotNull @Override public MobType getMobType() { - return VReference.VAMPIRE_CREATURE_ATTRIBUTE; + return VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE; } @Override diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedHorseEntity.java b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedHorseEntity.java index 2d09f9c0b2..7297fde1ee 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedHorseEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedHorseEntity.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.config.BalanceMobProps; +import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModAttributes; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -94,7 +95,7 @@ public EntityDataAccessor getConvertingDataParam() { @NotNull @Override public MobType getMobType() { - return VReference.VAMPIRE_CREATURE_ATTRIBUTE; + return VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE; } @NotNull diff --git a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedMuleEntity.java b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedMuleEntity.java index 51d3c1c0b9..09c637c5c1 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedMuleEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/converted/ConvertedMuleEntity.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.VReference; import de.teamlapen.vampirism.config.BalanceMobProps; +import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.core.ModAttributes; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -93,7 +94,7 @@ public EntityDataAccessor getConvertingDataParam() { @NotNull @Override public MobType getMobType() { - return VReference.VAMPIRE_CREATURE_ATTRIBUTE; + return VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE; } @NotNull diff --git a/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireBaseEntity.java b/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireBaseEntity.java index a5e9a7d1eb..22483fb8e0 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireBaseEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/vampire/VampireBaseEntity.java @@ -232,7 +232,7 @@ public EnumStrength isGettingGarlicDamage(LevelAccessor iWorld, boolean forceref @NotNull @Override public MobType getMobType() { - return VReference.VAMPIRE_CREATURE_ATTRIBUTE; + return VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE; } @Override diff --git a/src/main/java/de/teamlapen/vampirism/items/enchantment/EnchantmentVampireSlayer.java b/src/main/java/de/teamlapen/vampirism/items/enchantment/EnchantmentVampireSlayer.java index 2b24df4907..ce836d68ad 100755 --- a/src/main/java/de/teamlapen/vampirism/items/enchantment/EnchantmentVampireSlayer.java +++ b/src/main/java/de/teamlapen/vampirism/items/enchantment/EnchantmentVampireSlayer.java @@ -1,6 +1,7 @@ package de.teamlapen.vampirism.items.enchantment; import de.teamlapen.vampirism.api.VReference; +import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.items.PitchforkItem; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; @@ -36,7 +37,7 @@ public boolean canApplyAtEnchantingTable(@NotNull ItemStack stack) { @Override public float getDamageBonus(int level, @NotNull MobType creatureType) { - return creatureType == VReference.VAMPIRE_CREATURE_ATTRIBUTE ? 2f + Math.min(0, level - 1) * 1F : 0; + return creatureType == (VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE) ? 2f + Math.min(0, level - 1) * 1F : 0; } @Override diff --git a/src/main/java/de/teamlapen/vampirism/mixin/MixinLivingEntity.java b/src/main/java/de/teamlapen/vampirism/mixin/MixinLivingEntity.java index 281f8e2156..f7e98c5cf2 100644 --- a/src/main/java/de/teamlapen/vampirism/mixin/MixinLivingEntity.java +++ b/src/main/java/de/teamlapen/vampirism/mixin/MixinLivingEntity.java @@ -7,6 +7,8 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MobType; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; @@ -17,13 +19,17 @@ @Mixin(LivingEntity.class) public abstract class MixinLivingEntity extends Entity { - private MixinLivingEntity(@NotNull EntityType type, @NotNull Level worldIn) { + protected MixinLivingEntity(@NotNull EntityType type, @NotNull Level worldIn) { super(type, worldIn); } @Shadow public abstract boolean addEffect(MobEffectInstance effectInstanceIn); + @Shadow + public abstract ItemStack getMainHandItem(); // Needed in subclass + + @Inject(method = "checkTotemDeathProtection", at = @At("RETURN")) private void handleTotemOfUndying(DamageSource damageSourceIn, @NotNull CallbackInfoReturnable cir) { if (cir.getReturnValue() && Helper.isVampire(this)) { @@ -31,4 +37,17 @@ private void handleTotemOfUndying(DamageSource damageSourceIn, @NotNull Callback this.addEffect(new MobEffectInstance(ModEffects.SUNSCREEN.get(), 800, 4)); } } + + protected MobType vampirism$getMobType() { + return null; + } + + @Inject(method = "getMobType", at = @At("HEAD"), cancellable = true) + private void handleGetMobType(CallbackInfoReturnable cir) { + MobType t = vampirism$getMobType(); + if (t != null) { + cir.setReturnValue(t); + cir.cancel(); + } + } } diff --git a/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java b/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java index 593e030362..467fa4f477 100644 --- a/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java +++ b/src/main/java/de/teamlapen/vampirism/mixin/MixinPlayerEntity.java @@ -1,21 +1,25 @@ package de.teamlapen.vampirism.mixin; +import de.teamlapen.vampirism.config.VampirismConfig; import de.teamlapen.vampirism.entity.player.IVampirismPlayer; import de.teamlapen.vampirism.entity.player.VampirismPlayerAttributes; import de.teamlapen.vampirism.util.MixinHooks; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.MobType; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.Level; import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyVariable; @Mixin(Player.class) -public abstract class MixinPlayerEntity extends LivingEntity implements IVampirismPlayer { +public abstract class MixinPlayerEntity extends MixinLivingEntity implements IVampirismPlayer { + @Unique private final VampirismPlayerAttributes vampirismPlayerAttributes = new VampirismPlayerAttributes(); private MixinPlayerEntity(@NotNull EntityType type, @NotNull Level worldIn) { @@ -31,4 +35,12 @@ public VampirismPlayerAttributes getVampAtts() { public float vampireSlayerEnchantment(float damage, Entity target) { return damage + MixinHooks.calculateVampireSlayerEnchantments(target, this.getMainHandItem()); } + + @Override + protected MobType vampirism$getMobType() { + if (getVampAtts().vampireLevel > 0 && VampirismConfig.SERVER.vampiresAreUndeadType.get()) { + return MobType.UNDEAD; + } + return null; + } }