为SmokeDecoyEntity添加NBT参数

This commit is contained in:
Light_Quanta 2025-05-20 01:48:47 +08:00
parent 409cf9271f
commit a75260754a
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -25,12 +25,23 @@ public class SmokeDecoyEntity extends Entity implements DecoyEntity {
super(ModEntities.SMOKE_DECOY.get(), level); super(ModEntities.SMOKE_DECOY.get(), level);
} }
public int life = 400;
public int igniteTime = 4;
@Override @Override
protected void readAdditionalSaveData(@NotNull CompoundTag compoundTag) { protected void readAdditionalSaveData(@NotNull CompoundTag compoundTag) {
if (compoundTag.contains("IgniteTime")) {
this.igniteTime = compoundTag.getInt("IgniteTime");
}
if (compoundTag.contains("Life")) {
this.life = compoundTag.getInt("Life");
}
} }
@Override @Override
protected void addAdditionalSaveData(@NotNull CompoundTag compoundTag) { protected void addAdditionalSaveData(@NotNull CompoundTag compoundTag) {
compoundTag.putInt("IgniteTime", igniteTime);
compoundTag.putInt("Life", life);
} }
@Override @Override
@ -41,7 +52,7 @@ public class SmokeDecoyEntity extends Entity implements DecoyEntity {
public void tick() { public void tick() {
super.tick(); super.tick();
this.move(MoverType.SELF, this.getDeltaMovement()); this.move(MoverType.SELF, this.getDeltaMovement());
if (tickCount == 4) { if (tickCount == this.igniteTime) {
if (this.level() instanceof ServerLevel serverLevel) { if (this.level() instanceof ServerLevel serverLevel) {
ParticleTool.sendParticle(serverLevel, ModParticleTypes.CUSTOM_SMOKE.get(), this.xo, this.yo, this.zo, ParticleTool.sendParticle(serverLevel, ModParticleTypes.CUSTOM_SMOKE.get(), this.xo, this.yo, this.zo,
100, 0, 0, 0, 0.07, true); 100, 0, 0, 0, 0.07, true);
@ -50,13 +61,13 @@ public class SmokeDecoyEntity extends Entity implements DecoyEntity {
this.setDeltaMovement(Vec3.ZERO); this.setDeltaMovement(Vec3.ZERO);
} }
if (this.tickCount > 400) { if (this.tickCount > this.life) {
this.discard(); this.discard();
} }
} }
public void decoyShoot(Entity entity, Vec3 shootVec, float pVelocity, float pInaccuracy) { public void decoyShoot(Entity entity, Vec3 shootVec, float pVelocity, float pInaccuracy) {
Vec3 vec3 = shootVec.normalize().add(this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy)).scale((double) pVelocity); Vec3 vec3 = shootVec.normalize().add(this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy), this.random.triangle(0.0, 0.0172275 * (double) pInaccuracy)).scale(pVelocity);
this.setDeltaMovement(entity.getDeltaMovement().scale(0.75).add(vec3)); this.setDeltaMovement(entity.getDeltaMovement().scale(0.75).add(vec3));
double d0 = vec3.horizontalDistance(); double d0 = vec3.horizontalDistance();
this.setYRot((float) (Mth.atan2(vec3.x, vec3.z) * 57.2957763671875)); this.setYRot((float) (Mth.atan2(vec3.x, vec3.z) * 57.2957763671875));