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 mixin for MobType #1250

Open
wants to merge 2 commits into
base: 1.20
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/api/java/de/teamlapen/vampirism/api/VReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<? extends String>> sundamageDimensionsOverridePositive;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +100,7 @@ public EntityDataAccessor<Boolean> getConvertingDataParam() {
@NotNull
@Override
public MobType getMobType() {
return VReference.VAMPIRE_CREATURE_ATTRIBUTE;
return VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +95,7 @@ public EntityDataAccessor<Boolean> getConvertingDataParam() {
@NotNull
@Override
public MobType getMobType() {
return VReference.VAMPIRE_CREATURE_ATTRIBUTE;
return VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -93,7 +94,7 @@ public EntityDataAccessor<Boolean> getConvertingDataParam() {
@NotNull
@Override
public MobType getMobType() {
return VReference.VAMPIRE_CREATURE_ATTRIBUTE;
return VampirismConfig.SERVER.vampiresAreUndeadType.get() ? MobType.UNDEAD : VReference.VAMPIRE_CREATURE_ATTRIBUTE;
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,18 +19,35 @@

@Mixin(LivingEntity.class)
public abstract class MixinLivingEntity extends Entity {
private MixinLivingEntity(@NotNull EntityType<? extends LivingEntity> type, @NotNull Level worldIn) {
protected MixinLivingEntity(@NotNull EntityType<? extends LivingEntity> 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<Boolean> cir) {
if (cir.getReturnValue() && Helper.isVampire(this)) {
this.addEffect(new MobEffectInstance(ModEffects.FIRE_PROTECTION.get(), 800, 5));
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<MobType> cir) {
MobType t = vampirism$getMobType();
if (t != null) {
cir.setReturnValue(t);
cir.cancel();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<? extends LivingEntity> type, @NotNull Level worldIn) {
Expand All @@ -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;
}
}
Loading