From 8b69b280d58bb1108122129111cc3e259c5c5f13 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Sat, 19 Apr 2025 16:26:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E8=BE=88=E7=BB=86=E5=88=86=E4=B8=BA?= =?UTF-8?q?=E8=B7=91=E8=80=85=E5=92=8C=E6=92=85=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/entity/SenpaiEntity.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/SenpaiEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/SenpaiEntity.java index d1da26ed7..4922ed8d8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/SenpaiEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/SenpaiEntity.java @@ -3,9 +3,14 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.init.ModSounds; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.syncher.EntityDataAccessor; +import net.minecraft.network.syncher.EntityDataSerializers; +import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; @@ -33,7 +38,7 @@ import software.bernie.geckolib.util.GeckoLibUtil; import javax.annotation.ParametersAreNonnullByDefault; public class SenpaiEntity extends Monster implements GeoEntity { - + public static final EntityDataAccessor RUNNER = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.BOOLEAN); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public SenpaiEntity(EntityType type, Level world) { @@ -42,6 +47,24 @@ public class SenpaiEntity extends Monster implements GeoEntity { setNoAi(false); } + @Override + protected void defineSynchedData(SynchedEntityData.@NotNull Builder builder) { + super.defineSynchedData(builder); + builder.define(RUNNER, Math.random() < 0.5); + } + + @Override + public void addAdditionalSaveData(@NotNull CompoundTag compound) { + super.addAdditionalSaveData(compound); + compound.putBoolean("Runner", this.entityData.get(RUNNER)); + } + + @Override + public void readAdditionalSaveData(@NotNull CompoundTag compound) { + super.readAdditionalSaveData(compound); + this.entityData.set(RUNNER, compound.getBoolean("Runner")); + } + @Override public double getEyeY() { return 1.75F; @@ -94,19 +117,16 @@ public class SenpaiEntity extends Monster implements GeoEntity { return ModSounds.GROWL.get(); } - @Override - public void addAdditionalSaveData(@NotNull CompoundTag compound) { - super.addAdditionalSaveData(compound); - } - - @Override - public void readAdditionalSaveData(@NotNull CompoundTag compound) { - super.readAdditionalSaveData(compound); - } - @Override public void baseTick() { super.baseTick(); + + if (entityData.get(RUNNER)) { + addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 20, 0)); + } else { + addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 20, 0)); + } + this.refreshDimensions(); } @@ -139,7 +159,11 @@ public class SenpaiEntity extends Monster implements GeoEntity { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.senpai.die")); } if (this.isAggressive() && event.isMoving()) { - return event.setAndContinue(RawAnimation.begin().thenLoop("animation.senpai.run2")); + if (entityData.get(RUNNER)) { + return event.setAndContinue(RawAnimation.begin().thenLoop("animation.senpai.run2")); + } else { + return event.setAndContinue(RawAnimation.begin().thenLoop("animation.senpai.run")); + } } return event.setAndContinue(RawAnimation.begin().thenLoop("animation.senpai.idle")); }