diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/warden/LivingEntityMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/warden/LivingEntityMixin.java index 85c60e8c92..e5f0a6d94c 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/warden/LivingEntityMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/warden/LivingEntityMixin.java @@ -27,6 +27,7 @@ import net.minecraft.world.entity.monster.warden.Warden; import net.minecraft.world.level.Level; 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.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -37,43 +38,43 @@ public class LivingEntityMixin { @Inject(method = "isAlive", at = @At("HEAD"), cancellable = true) public void wilderWild$isAlive(CallbackInfoReturnable info) { - if (LivingEntity.class.cast(this) instanceof Warden warden) { - if (EntityConfig.get().warden.wardenDyingAnimation || ((WilderWarden) warden).wilderWild$isStella()) { - info.setReturnValue(((WilderWarden) warden).wilderWild$getDeathTicks() < 70 && !warden.isRemoved()); - } + if (this.wilderWild$isWardenWithDeathAnimation()) { + info.setReturnValue(((WilderWarden) this).wilderWild$getDeathTicks() < 70 && !LivingEntity.class.cast(this).isRemoved()); } } @Inject(method = "tickDeath", at = @At("HEAD"), cancellable = true) public void wilderWild$tickDeath(CallbackInfo info) { - if (LivingEntity.class.cast(this) instanceof Warden warden) { - if (EntityConfig.get().warden.wardenDyingAnimation || ((WilderWarden) warden).wilderWild$isStella()) { - Level level = warden.level(); - int deathTicks = ((WilderWarden) warden).wilderWild$getDeathTicks() + 1; - ((WilderWarden) warden).wilderWild$setDeathTicks(deathTicks); - if (!level.isClientSide()) { - if (deathTicks == 35) { - warden.deathTime = 35; - } else if (deathTicks == 53) { - level.broadcastEntityEvent(warden, EntityEvent.POOF); - level.broadcastEntityEvent(warden, (byte) 69420); - } else if (deathTicks == 70) { - warden.remove(Entity.RemovalReason.KILLED); - } + if (this.wilderWild$isWardenWithDeathAnimation()) { + Warden warden = Warden.class.cast(this); + Level level = warden.level(); + int deathTicks = ((WilderWarden) this).wilderWild$getDeathTicks() + 1; + ((WilderWarden) this).wilderWild$setDeathTicks(deathTicks); + if (!level.isClientSide()) { + if (deathTicks == 35) { + warden.deathTime = 35; + } else if (deathTicks == 53) { + level.broadcastEntityEvent(warden, EntityEvent.POOF); + level.broadcastEntityEvent(warden, (byte) 69420); + } else if (deathTicks == 70) { + warden.remove(Entity.RemovalReason.KILLED); } - info.cancel(); } + info.cancel(); } } @Inject(method = "die", at = @At("TAIL")) public void wilderWild$die(DamageSource damageSource, CallbackInfo info) { - if (LivingEntity.class.cast(this) instanceof Warden warden) { - if (EntityConfig.get().warden.wardenDyingAnimation || ((WilderWarden) warden).wilderWild$isStella()) { - warden.getBrain().removeAllBehaviors(); - warden.setNoAi(true); - } + if (this.wilderWild$isWardenWithDeathAnimation()) { + Warden.class.cast(this).getBrain().removeAllBehaviors(); + Warden.class.cast(this).setNoAi(true); } } + @Unique + public boolean wilderWild$isWardenWithDeathAnimation() { + return LivingEntity.class.cast(this) instanceof Warden warden && (EntityConfig.get().warden.wardenDyingAnimation || ((WilderWarden) warden).wilderWild$isStella()); + } + } diff --git a/src/main/java/net/frozenblock/wilderwild/mixin/warden/WardenMixin.java b/src/main/java/net/frozenblock/wilderwild/mixin/warden/WardenMixin.java index ed6aa80543..62da515c79 100644 --- a/src/main/java/net/frozenblock/wilderwild/mixin/warden/WardenMixin.java +++ b/src/main/java/net/frozenblock/wilderwild/mixin/warden/WardenMixin.java @@ -18,6 +18,7 @@ package net.frozenblock.wilderwild.mixin.warden; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.frozenblock.wilderwild.config.EntityConfig; import net.frozenblock.wilderwild.entity.Tumbleweed; import net.frozenblock.wilderwild.entity.render.animations.WilderWarden; @@ -123,25 +124,19 @@ public boolean isDiggingOrEmerging() { return name != null && (name.equalsIgnoreCase("Stella") || name.equalsIgnoreCase("Osmiooo") || name.equalsIgnoreCase("Mossmio") || name.equalsIgnoreCase("Osmio")); } - @Inject(at = @At("RETURN"), method = "getDeathSound") - public void wilderWild$getDeathSound(CallbackInfoReturnable info) { - Warden warden = Warden.class.cast(this); - if (this.wilderWild$isStella()) { - warden.playSound(RegisterSounds.ENTITY_WARDEN_KIRBY_DEATH, 5.0F, 1.0F); - } else { - if (EntityConfig.get().warden.wardenDyingAnimation) { - if (warden instanceof SwimmingWardenInterface swim && swim.wilderWild$isSubmergedInWaterOrLava()) { - warden.playSound(RegisterSounds.ENTITY_WARDEN_UNDERWATER_DYING, 0.75F, 1.0F); - } else { - warden.playSound(RegisterSounds.ENTITY_WARDEN_DYING, 5.0F, 1.0F); - } - } - } + @ModifyReturnValue(at = @At("RETURN"), method = "getDeathSound") + public SoundEvent wilderWild$getDeathSound(SoundEvent soundEvent) { + return this.wilderWild$isStella() ? RegisterSounds.ENTITY_WARDEN_KIRBY_DEATH + : (Warden.class.cast(this) instanceof SwimmingWardenInterface swim && swim.wilderWild$isSubmergedInWaterOrLava()) ? RegisterSounds.ENTITY_WARDEN_UNDERWATER_DYING + : soundEvent; } - @Inject(at = @At("RETURN"), method = "finalizeSpawn") + @Inject(at = @At("TAIL"), method = "finalizeSpawn") public void wilderWild$finalizeSpawn(ServerLevelAccessor serverLevelAccess, DifficultyInstance localDifficulty, MobSpawnType spawnReason, @Nullable SpawnGroupData entityData, @Nullable CompoundTag nbtCompound, CallbackInfoReturnable info) { - if ((EntityConfig.get().warden.wardenEmergesFromEgg && spawnReason == MobSpawnType.SPAWN_EGG) || (EntityConfig.get().warden.wardenEmergesFromCommand && spawnReason == MobSpawnType.COMMAND)) { + if ( + (EntityConfig.get().warden.wardenEmergesFromEgg && spawnReason == MobSpawnType.SPAWN_EGG) + || (EntityConfig.get().warden.wardenEmergesFromCommand && spawnReason == MobSpawnType.COMMAND) + ) { this.setPose(Pose.EMERGING); this.getBrain().setMemoryWithExpiry(MemoryModuleType.IS_EMERGING, Unit.INSTANCE, WardenAi.EMERGE_DURATION); this.playSound(SoundEvents.WARDEN_AGITATED, 5.0f, 1.0f); @@ -179,47 +174,12 @@ public boolean isDiggingOrEmerging() { @Inject(method = "onSyncedDataUpdated", at = @At("HEAD"), cancellable = true) private void wilderWild$onSyncedDataUpdated(EntityDataAccessor data, CallbackInfo info) { Warden warden = Warden.class.cast(this); - if (EntityConfig.get().warden.wardenDyingAnimation || this.wilderWild$isStella()) { - if (DATA_POSE.equals(data)) { - if (warden.getPose() == Pose.DYING) { - if (this.wilderWild$isStella()) { - this.wilderWild$getKirbyDeathAnimationState().start(warden.tickCount); - } else { - if (warden instanceof SwimmingWardenInterface swim && swim.wilderWild$isSubmergedInWaterOrLava()) { - this.wilderWild$getSwimmingDyingAnimationState().start(warden.tickCount); - } else { - this.wilderWild$getDyingAnimationState().start(warden.tickCount); - } - } - info.cancel(); - } - } - } - } - - @Unique - private void wilderWild$addAdditionalDeathParticles() { - for (int i = 0; i < 20; ++i) { - double d = this.random.nextGaussian() * 0.02; - double e = this.random.nextGaussian() * 0.02; - double f = this.random.nextGaussian() * 0.02; - this.level().addParticle(ParticleTypes.SCULK_CHARGE_POP, this.getRandomX(1.0), this.getY(), this.getRandomZ(1.0), d, e, f); - this.level().addParticle(ParticleTypes.SCULK_SOUL, this.getRandomX(1.0), this.getY(), this.getRandomZ(1.0), d, e, f); + if (this.wilderWild$hasDeathAnimation() && DATA_POSE.equals(data) && warden.getPose() == Pose.DYING) { + this.wilderWild$getDeathAnimationForSituation().start(warden.tickCount); + info.cancel(); } } - @Unique - @Override - public int wilderWild$getDeathTicks() { - return this.wilderWild$deathTicks; - } - - @Unique - @Override - public void wilderWild$setDeathTicks(int i) { - this.wilderWild$deathTicks = i; - } - @ModifyArgs(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playLocalSound(DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FFZ)V", ordinal = 0)) private void wilderWild$stellaHeartbeat(Args args) { if (this.wilderWild$isStella()) { @@ -230,10 +190,8 @@ public boolean isDiggingOrEmerging() { @Inject(method = "tick", at = @At("TAIL")) private void wilderWild$tick(CallbackInfo info) { Warden warden = Warden.class.cast(this); - if (EntityConfig.get().warden.wardenDyingAnimation || this.wilderWild$isStella()) { - if (warden.getPose() == Pose.DYING) { - this.clientDiggingParticles(this.wilderWild$getDyingAnimationState()); - } + if (this.wilderWild$hasDeathAnimation() && warden.getPose() == Pose.DYING) { + this.clientDiggingParticles(this.wilderWild$getDyingAnimationState()); } if ((warden.isInWaterOrBubble() || warden.isInLava()) && (!warden.isEyeInFluid(FluidTags.WATER) || !warden.isEyeInFluid(FluidTags.LAVA)) @@ -267,15 +225,46 @@ public boolean isDiggingOrEmerging() { @Inject(method = "getDimensions", at = @At("RETURN"), cancellable = true) public void wilderWild$getDimensions(Pose pose, CallbackInfoReturnable info) { - if (!this.isDiggingOrEmerging()) { - if (EntityConfig.get().warden.wardenDyingAnimation || this.wilderWild$isStella()) { - if (wilderWild$deathTicks > 0) { - info.setReturnValue(EntityDimensions.fixed(this.getType().getWidth(), 0.35F)); - } - } + if (!this.isDiggingOrEmerging() && this.wilderWild$hasDeathAnimation() && this.wilderWild$deathTicks > 0) { + info.setReturnValue(EntityDimensions.fixed(this.getType().getWidth(), 0.35F)); } } + @Unique + public boolean wilderWild$hasDeathAnimation() { + return EntityConfig.get().warden.wardenDyingAnimation || this.wilderWild$isStella(); + } + + @Unique + private AnimationState wilderWild$getDeathAnimationForSituation() { + return this.wilderWild$isStella() ? this.wilderWild$getKirbyDeathAnimationState() + : (Warden.class.cast(this) instanceof SwimmingWardenInterface swim && swim.wilderWild$isSubmergedInWaterOrLava()) ? this.wilderWild$getSwimmingDyingAnimationState() + : this.wilderWild$getDyingAnimationState(); + } + + @Unique + private void wilderWild$addAdditionalDeathParticles() { + for (int i = 0; i < 20; ++i) { + double d = this.random.nextGaussian() * 0.02; + double e = this.random.nextGaussian() * 0.02; + double f = this.random.nextGaussian() * 0.02; + this.level().addParticle(ParticleTypes.SCULK_CHARGE_POP, this.getRandomX(1.0), this.getY(), this.getRandomZ(1.0), d, e, f); + this.level().addParticle(ParticleTypes.SCULK_SOUL, this.getRandomX(1.0), this.getY(), this.getRandomZ(1.0), d, e, f); + } + } + + @Unique + @Override + public int wilderWild$getDeathTicks() { + return this.wilderWild$deathTicks; + } + + @Unique + @Override + public void wilderWild$setDeathTicks(int i) { + this.wilderWild$deathTicks = i; + } + @Mixin(Warden.VibrationUser.class) public static class VibrationUserMixin {