Skip to content

Commit

Permalink
Add mixin for MobType
Browse files Browse the repository at this point in the history
  • Loading branch information
maxanier committed Aug 5, 2023
1 parent 7a857f1 commit aa1928b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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 @@ -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,11 +1,13 @@
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;
Expand All @@ -14,7 +16,7 @@
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 {

private final VampirismPlayerAttributes vampirismPlayerAttributes = new VampirismPlayerAttributes();

Expand All @@ -31,4 +33,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;
}
}

0 comments on commit aa1928b

Please sign in to comment.