先辈细分为跑者和撅者

This commit is contained in:
Atsuishio 2025-04-19 16:26:10 +08:00 committed by Light_Quanta
parent 839632db8a
commit 8b69b280d5
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -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<Boolean> RUNNER = SynchedEntityData.defineId(SenpaiEntity.class, EntityDataSerializers.BOOLEAN);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public SenpaiEntity(EntityType<SenpaiEntity> 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"));
}