Skip to content

Commit

Permalink
more warden mixin cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Dec 3, 2023
1 parent 98a67fc commit 234ad19
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,43 +38,43 @@ public class LivingEntityMixin {

@Inject(method = "isAlive", at = @At("HEAD"), cancellable = true)
public void wilderWild$isAlive(CallbackInfoReturnable<Boolean> 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());
}

}
117 changes: 53 additions & 64 deletions src/main/java/net/frozenblock/wilderwild/mixin/warden/WardenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SoundEvent> 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<SpawnGroupData> 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);
Expand Down Expand Up @@ -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()) {
Expand All @@ -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))
Expand Down Expand Up @@ -267,15 +225,46 @@ public boolean isDiggingOrEmerging() {

@Inject(method = "getDimensions", at = @At("RETURN"), cancellable = true)
public void wilderWild$getDimensions(Pose pose, CallbackInfoReturnable<EntityDimensions> 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 {

Expand Down

0 comments on commit 234ad19

Please sign in to comment.