diff --git a/src/main/java/xyz/nearmisses/patience/mc_rebalance/mixin/WitherSkeletonRework.java b/src/main/java/xyz/nearmisses/patience/mc_rebalance/mixin/WitherSkeletonRework.java new file mode 100644 index 0000000..d395c92 --- /dev/null +++ b/src/main/java/xyz/nearmisses/patience/mc_rebalance/mixin/WitherSkeletonRework.java @@ -0,0 +1,57 @@ +package xyz.nearmisses.patience.mc_rebalance.mixin; + +import net.minecraft.core.Holder; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.monster.AbstractSkeleton; +import net.minecraft.world.entity.monster.WitherSkeleton; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Map; + +@Mixin(WitherSkeleton.class) +public abstract class WitherSkeletonRework extends AbstractSkeleton { + + protected WitherSkeletonRework(EntityType entityType, Level level) { + super(entityType, level); + } + + @Redirect(method = "doHurtTarget", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;addEffect(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)Z")) + public boolean doHurtTarget(LivingEntity instance, MobEffectInstance mobEffectInstance, Entity entity) { + Map, MobEffectInstance> effectsMap = instance.getActiveEffectsMap(); + + if (effectsMap.containsKey(MobEffects.WITHER)) { + int amp = effectsMap.get(MobEffects.WITHER).getAmplifier(); + if (this.getMainHandItem().is(Items.STONE_SWORD)) { + instance.addEffect(new MobEffectInstance(MobEffects.WITHER, 180, amp+1), this); + if(amp+1>2){ + this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.STONE_HOE)); + } + } else { // If on hoe, collapse wither effect + int duration = effectsMap.get(MobEffects.WITHER).getDuration(); + int dmgCount = 0; + int durationToDmg = 40 >> amp; + while(duration>0){ // There is definitely a better way to do this, I'll come back to it later + if(durationToDmg == 0 || duration % durationToDmg == 0) {dmgCount++;} + duration--; + } + instance.removeEffect(MobEffects.WITHER); + instance.hurt(instance.damageSources().wither(), dmgCount); + this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.STONE_SWORD)); + } + } else { // If enemy doesn't have wither, apply it + instance.addEffect(new MobEffectInstance(MobEffects.WITHER, 180), this); + } + return true; + } +} \ No newline at end of file diff --git a/src/main/resources/mc_rebalance.mixins.json b/src/main/resources/mc_rebalance.mixins.json index e105ccd..e1f0bd2 100644 --- a/src/main/resources/mc_rebalance.mixins.json +++ b/src/main/resources/mc_rebalance.mixins.json @@ -3,7 +3,8 @@ "package": "xyz.nearmisses.patience.mc_rebalance.mixin", "compatibilityLevel": "JAVA_21", "mixins": [ - "ExperienceOrbRework" + "ExperienceOrbRework", + "WitherSkeletonRework" ], "injectors": { "defaultRequire": 1