优化部分代码

This commit is contained in:
17146 2024-10-31 20:45:00 +08:00
parent 042fe34b2b
commit 873fb69eb8
5 changed files with 39 additions and 60 deletions

View file

@ -38,6 +38,7 @@ import java.util.UUID;
import static net.mcreator.superbwarfare.tools.ParticleTool.sendParticle; import static net.mcreator.superbwarfare.tools.ParticleTool.sendParticle;
public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, OwnableEntity { public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, OwnableEntity {
protected static final EntityDataAccessor<Optional<UUID>> OWNER_UUID = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.OPTIONAL_UUID); protected static final EntityDataAccessor<Optional<UUID>> OWNER_UUID = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.OPTIONAL_UUID);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -210,7 +211,8 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity,
this.refreshDimensions(); this.refreshDimensions();
} }
public void destroy() {
public void destroy() {
if (level() instanceof ServerLevel) { if (level() instanceof ServerLevel) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeMineDamage(this.level().registryAccess(), this), 15.0f, ModDamageTypes.causeMineDamage(this.level().registryAccess(), this), 15.0f,
@ -242,10 +244,12 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity,
return true; return true;
} }
@Override
public String getSyncedAnimation() { public String getSyncedAnimation() {
return null; return null;
} }
@Override
public void setAnimation(String animation) { public void setAnimation(String animation) {
} }

View file

@ -42,13 +42,13 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import static net.mcreator.superbwarfare.tools.ParticleTool.sendParticle; import static net.mcreator.superbwarfare.tools.ParticleTool.sendParticle;
public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity { public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
protected int interpolationSteps; protected int interpolationSteps;
protected double serverYRot; protected double serverYRot;
protected double serverXRot; protected double serverXRot;
@ -69,15 +69,15 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
@Override @Override
public void addAdditionalSaveData(CompoundTag compound) { public void addAdditionalSaveData(CompoundTag compound) {
compound.putInt("cool_down", this.entityData.get(COOL_DOWN)); compound.putInt("CoolDown", this.entityData.get(COOL_DOWN));
compound.putInt("type", this.entityData.get(TYPE)); compound.putInt("Type", this.entityData.get(TYPE));
compound.putFloat("Health", this.entityData.get(HEALTH)); compound.putFloat("Health", this.entityData.get(HEALTH));
} }
@Override @Override
public void readAdditionalSaveData(CompoundTag compound) { public void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(COOL_DOWN, compound.getInt("cool_down")); this.entityData.set(COOL_DOWN, compound.getInt("CoolDown"));
this.entityData.set(TYPE, compound.getInt("type")); this.entityData.set(TYPE, compound.getInt("Type"));
this.entityData.set(HEALTH, compound.getFloat("Health")); this.entityData.set(HEALTH, compound.getFloat("Health"));
} }
@ -98,7 +98,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
@Override @Override
public boolean hurt(DamageSource source, float amount) { public boolean hurt(DamageSource source, float amount) {
if (this.level() instanceof ServerLevel serverLevel) { if (this.level() instanceof ServerLevel serverLevel) {
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
} }
@ -140,12 +139,10 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
public InteractionResult interact(Player player, InteractionHand hand) { public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown() && player.getMainHandItem().getItem() == ModItems.CROWBAR.get() && this.getFirstPassenger() == null) { if (player.isShiftKeyDown() && player.getMainHandItem().getItem() == ModItems.CROWBAR.get() && this.getFirstPassenger() == null) {
this.discard(); this.discard();
// ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MK_42_SPAWN_EGG.get()));
} else { } else {
player.setXRot(this.getXRot()); player.setXRot(this.getXRot());
player.setYRot(this.getYRot()); player.setYRot(this.getYRot());
player.startRiding(this); player.startRiding(this);
} }
return InteractionResult.sidedSuccess(this.level().isClientSide()); return InteractionResult.sidedSuccess(this.level().isClientSide());
@ -315,7 +312,7 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
this.getX() + i * this.getLookAngle().x, this.getX() + i * this.getLookAngle().x,
this.getEyeY() + i * this.getLookAngle().y, this.getEyeY() + i * this.getLookAngle().y,
this.getZ() + i * this.getLookAngle().z, this.getZ() + i * this.getLookAngle().z,
Mth.clamp(count--,1,5), 0.15, 0.15, 0.15, 0.0025); Mth.clamp(count--, 1, 5), 0.15, 0.15, 0.15, 0.0025);
} }
} }
} }
@ -350,11 +347,8 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
} }
} }
public static void init() {
}
protected void clampRotation(Entity entity) { protected void clampRotation(Entity entity) {
ItemStack stack = null; ItemStack stack = ItemStack.EMPTY;
if (entity instanceof Player player) { if (entity instanceof Player player) {
stack = player.getMainHandItem(); stack = player.getMainHandItem();
} }
@ -384,13 +378,6 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mk42.idle")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mk42.idle"));
} }
public String getSyncedAnimation() {
return null;
}
public void setAnimation(String animation) {
}
@Override @Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) { public void registerControllers(AnimatableManager.ControllerRegistrar data) {
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate)); data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));

View file

@ -44,6 +44,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import static net.mcreator.superbwarfare.tools.ParticleTool.sendParticle; import static net.mcreator.superbwarfare.tools.ParticleTool.sendParticle;
public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity { public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> TYPE = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.FLOAT);
@ -52,7 +53,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
public String animationprocedure = "empty"; public String animationprocedure = "empty";
protected int interpolationSteps; protected int interpolationSteps;
protected double serverYRot; protected double serverYRot;
protected double serverXRot; protected double serverXRot;
@ -73,15 +73,15 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
@Override @Override
public void addAdditionalSaveData(CompoundTag compound) { public void addAdditionalSaveData(CompoundTag compound) {
compound.putInt("cool_down", this.entityData.get(COOL_DOWN)); compound.putInt("CoolDown", this.entityData.get(COOL_DOWN));
compound.putInt("type", this.entityData.get(TYPE)); compound.putInt("Type", this.entityData.get(TYPE));
compound.putFloat("Health", this.entityData.get(HEALTH)); compound.putFloat("Health", this.entityData.get(HEALTH));
} }
@Override @Override
public void readAdditionalSaveData(CompoundTag compound) { public void readAdditionalSaveData(CompoundTag compound) {
this.entityData.set(COOL_DOWN, compound.getInt("cool_down")); this.entityData.set(COOL_DOWN, compound.getInt("CoolDown"));
this.entityData.set(TYPE, compound.getInt("type")); this.entityData.set(TYPE, compound.getInt("Type"));
this.entityData.set(HEALTH, compound.getFloat("Health")); this.entityData.set(HEALTH, compound.getFloat("Health"));
} }
@ -102,7 +102,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
@Override @Override
public boolean hurt(DamageSource source, float amount) { public boolean hurt(DamageSource source, float amount) {
if (this.level() instanceof ServerLevel serverLevel) { if (this.level() instanceof ServerLevel serverLevel) {
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false);
} }
@ -144,12 +143,10 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
public InteractionResult interact(Player player, InteractionHand hand) { public InteractionResult interact(Player player, InteractionHand hand) {
if (player.isShiftKeyDown() && player.getMainHandItem().getItem() == ModItems.CROWBAR.get() && this.getFirstPassenger() == null) { if (player.isShiftKeyDown() && player.getMainHandItem().getItem() == ModItems.CROWBAR.get() && this.getFirstPassenger() == null) {
this.discard(); this.discard();
// ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MK_42_SPAWN_EGG.get()));
} else { } else {
player.setXRot(this.getXRot()); player.setXRot(this.getXRot());
player.setYRot(this.getYRot()); player.setYRot(this.getYRot());
player.startRiding(this); player.startRiding(this);
} }
return InteractionResult.sidedSuccess(this.level().isClientSide()); return InteractionResult.sidedSuccess(this.level().isClientSide());
@ -288,7 +285,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
leftPos.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD); leftPos.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD);
leftPos.rotateY(-yRot * Mth.DEG_TO_RAD); leftPos.rotateY(-yRot * Mth.DEG_TO_RAD);
//左炮管 // 左炮管
CannonShellEntity entityToSpawnLeft = new CannonShellEntity(ModEntities.CANNON_SHELL.get(), CannonShellEntity entityToSpawnLeft = new CannonShellEntity(ModEntities.CANNON_SHELL.get(),
player, level, hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime).durability(durability); player, level, hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime).durability(durability);
@ -317,7 +314,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
int count = 5; int count = 5;
for (float i = 9.5f; i < 14; i += .5f) { for (float i = 9.5f; i < 14; i += .5f) {
var leftPosP = new Vector3d(i, 0, -0.45); var leftPosP = new Vector3d(i, 0, -0.45);
leftPosP.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD); leftPosP.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD);
leftPosP.rotateY(-yRot * Mth.DEG_TO_RAD); leftPosP.rotateY(-yRot * Mth.DEG_TO_RAD);
@ -326,10 +322,10 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
this.getX() + leftPosP.x, this.getX() + leftPosP.x,
this.getEyeY() - 0.2 + leftPosP.y, this.getEyeY() - 0.2 + leftPosP.y,
this.getZ() + leftPosP.z, this.getZ() + leftPosP.z,
Mth.clamp(count--,1,5), 0.1, 0.1, 0.1, 0.002); Mth.clamp(count--, 1, 5), 0.1, 0.1, 0.1, 0.002);
} }
//右炮管 // 右炮管
if (salvoShoot) { if (salvoShoot) {
var rightPos = new Vector3d(0, 0, 0.45); var rightPos = new Vector3d(0, 0, 0.45);
rightPos.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD); rightPos.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD);
@ -363,7 +359,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
int countR = 5; int countR = 5;
for (float i = 9.5f; i < 14; i += .5f) { for (float i = 9.5f; i < 14; i += .5f) {
var rightPosP = new Vector3d(i, 0, 0.45); var rightPosP = new Vector3d(i, 0, 0.45);
rightPosP.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD); rightPosP.rotateZ(-this.getXRot() * Mth.DEG_TO_RAD);
rightPosP.rotateY(-yRot * Mth.DEG_TO_RAD); rightPosP.rotateY(-yRot * Mth.DEG_TO_RAD);
@ -372,7 +367,7 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
this.getX() + rightPosP.x, this.getX() + rightPosP.x,
this.getEyeY() - 0.2 + rightPosP.y, this.getEyeY() - 0.2 + rightPosP.y,
this.getZ() + rightPosP.z, this.getZ() + rightPosP.z,
Mth.clamp(countR--,1,5), 0.1, 0.1, 0.1, 0.002); Mth.clamp(countR--, 1, 5), 0.1, 0.1, 0.1, 0.002);
} }
this.entityData.set(TYPE, 1); this.entityData.set(TYPE, 1);
@ -395,7 +390,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
this.getY(), this.getY(),
this.getZ() + 5 * this.getLookAngle().z, this.getZ() + 5 * this.getLookAngle().z,
100, 7, 0.02, 7, 0.005); 100, 7, 0.02, 7, 0.005);
} }
} }
@ -428,10 +422,8 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
} }
} }
public static void init() {
}
protected void clampRotation(Entity entity) { protected void clampRotation(Entity entity) {
ItemStack stack = null; ItemStack stack = ItemStack.EMPTY;
if (entity instanceof Player player) { if (entity instanceof Player player) {
stack = player.getMainHandItem(); stack = player.getMainHandItem();
} }
@ -460,13 +452,6 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mle1934.idle")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mle1934.idle"));
} }
public String getSyncedAnimation() {
return null;
}
public void setAnimation(String animation) {
}
@Override @Override
public void registerControllers(AnimatableManager.ControllerRegistrar data) { public void registerControllers(AnimatableManager.ControllerRegistrar data) {
data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate)); data.add(new AnimationController<>(this, "movement", 0, this::movementPredicate));

View file

@ -136,7 +136,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
public InteractionResult interact(Player player, InteractionHand hand) { public InteractionResult interact(Player player, InteractionHand hand) {
ItemStack mainHandItem = player.getMainHandItem(); ItemStack mainHandItem = player.getMainHandItem();
if (player.isShiftKeyDown()) { if (player.isShiftKeyDown()) {
if (mainHandItem.getItem() == ModItems.CROWBAR.get()){ if (mainHandItem.getItem() == ModItems.CROWBAR.get()) {
this.discard(); this.discard();
ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get())); ItemHandlerHelper.giveItemToPlayer(player, new ItemStack(ModItems.MORTAR_DEPLOYER.get()));
} }
@ -219,6 +219,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity {
} }
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mortar.idle")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.mortar.idle"));
} }
protected void destroy() { protected void destroy() {
if (this.level() instanceof ServerLevel level) { if (this.level() instanceof ServerLevel level) {
var x = this.getX(); var x = this.getX();

View file

@ -40,11 +40,10 @@ import software.bernie.geckolib.util.GeckoLibUtil;
@Mod.EventBusSubscriber @Mod.EventBusSubscriber
public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEntity { public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEntity {
public static final EntityDataAccessor<Integer> DOWN_TIME = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> DOWN_TIME = SynchedEntityData.defineId(TargetEntity.class, EntityDataSerializers.INT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
public String animationProcedure = "empty";
public TargetEntity(PlayMessages.SpawnEntity packet, Level world) { public TargetEntity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.TARGET.get(), world); this(ModEntities.TARGET.get(), world);
} }
@ -225,17 +224,6 @@ public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEnt
} }
} }
public String getSyncedAnimation() {
return null;
}
public void setAnimation(String animation) {
}
@Override
public void setAnimationProcedure(String procedure) {
}
private PlayState movementPredicate(AnimationState<TargetEntity> event) { private PlayState movementPredicate(AnimationState<TargetEntity> event) {
if (this.entityData.get(DOWN_TIME) > 0) { if (this.entityData.get(DOWN_TIME) > 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.target.down")); return event.setAndContinue(RawAnimation.begin().thenPlay("animation.target.down"));
@ -252,4 +240,18 @@ public class TargetEntity extends LivingEntity implements GeoEntity, AnimatedEnt
public AnimatableInstanceCache getAnimatableInstanceCache() { public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache; return this.cache;
} }
@Override
public String getSyncedAnimation() {
return null;
}
@Override
public void setAnimation(String animation) {
}
@Override
public void setAnimationProcedure(String procedure) {
}
} }