From 1ed15e06da4cc5a898b407be3a0b54893f1e145d Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Mon, 9 Dec 2024 22:37:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A0=E4=BA=BA=E6=9C=BA?= =?UTF-8?q?=E9=A3=9E=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/model/entity/DroneModel.java | 6 +- .../superbwarfare/entity/DroneEntity.java | 149 +++++------------- .../network/message/DroneMovementMessage.java | 7 + 3 files changed, 48 insertions(+), 114 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/DroneModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/DroneModel.java index 1becddd33..df6a77d2a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/DroneModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/DroneModel.java @@ -61,8 +61,8 @@ public class DroneModel extends GeoModel { float times = (float) (0.5f * Math.min(Minecraft.getInstance().getDeltaFrameTime(), 0.8)); - rotX = Mth.lerp(0.5f * times, rotX, animatable.getEntityData().get(ROT_X)); - rotZ = Mth.lerp(0.5f * times, rotZ, animatable.getEntityData().get(ROT_Z)); + rotX = Mth.lerp(0.2f * times, rotX, animatable.getEntityData().get(MOVE_X) * Mth.DEG_TO_RAD); + rotZ = Mth.lerp(0.2f * times, rotZ, animatable.getEntityData().get(MOVE_Z) * Mth.DEG_TO_RAD); main.setRotZ(rotX); main.setRotX(rotZ); @@ -76,7 +76,7 @@ public class DroneModel extends GeoModel { CoreGeoBone wingBL = getAnimationProcessor().getBone("wingBL"); CoreGeoBone wingBR = getAnimationProcessor().getBone("wingBR"); - rotation = (float) Mth.lerp(times, rotation, animatable.onGround() ? 0 : 0.08 - 0.1 * animatable.getEntityData().get(MOVE_Y)); + rotation = (float) Mth.lerp(times, rotation, animatable.onGround() ? 0 : 0.2); wingFL.setRotY(wingFL.getRotY() - rotation); wingFR.setRotY(wingFL.getRotY() - rotation); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java index f798bb32d..0016c7f27 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java @@ -44,6 +44,7 @@ import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.shapes.BooleanOp; import net.minecraft.world.phys.shapes.Shapes; +import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; @@ -66,13 +67,9 @@ public class DroneEntity extends LivingEntity implements GeoEntity { public static final EntityDataAccessor KAMIKAZE = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor MOVE_X = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor MOVE_Y = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor MOVE_Z = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor ROT_X = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor ROT_Z = SynchedEntityData.defineId(DroneEntity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); - private boolean move = false; public static double lastTickSpeed = 0; public DroneEntity(PlayMessages.SpawnEntity packet, Level world) { @@ -96,10 +93,7 @@ public class DroneEntity extends LivingEntity implements GeoEntity { this.entityData.define(AMMO, 0); this.entityData.define(KAMIKAZE, false); this.entityData.define(MOVE_X, 0f); - this.entityData.define(MOVE_Y, 0f); this.entityData.define(MOVE_Z, 0f); - this.entityData.define(ROT_X, 0f); - this.entityData.define(ROT_Z, 0f); } @Override @@ -144,11 +138,6 @@ public class DroneEntity extends LivingEntity implements GeoEntity { compound.putString("Controller", this.entityData.get(CONTROLLER)); compound.putInt("ammo", this.entityData.get(AMMO)); compound.putBoolean("Kamikaze", this.entityData.get(KAMIKAZE)); - compound.putFloat("moveX", this.entityData.get(MOVE_X)); - compound.putFloat("moveY", this.entityData.get(MOVE_Y)); - compound.putFloat("moveZ", this.entityData.get(MOVE_Z)); - compound.putFloat("rotX", this.entityData.get(ROT_X)); - compound.putFloat("rotZ", this.entityData.get(ROT_Z)); } @Override @@ -163,16 +152,6 @@ public class DroneEntity extends LivingEntity implements GeoEntity { this.entityData.set(AMMO, compound.getInt("ammo")); if (compound.contains("Kamikaze")) this.entityData.set(KAMIKAZE, compound.getBoolean("Kamikaze")); - if (compound.contains("moveX")) - this.entityData.set(MOVE_X, compound.getFloat("moveX")); - if (compound.contains("moveY")) - this.entityData.set(MOVE_Y, compound.getFloat("moveY")); - if (compound.contains("moveZ")) - this.entityData.set(MOVE_Z, compound.getFloat("moveZ")); - if (compound.contains("rotX")) - this.entityData.set(ROT_X, compound.getFloat("rotX")); - if (compound.contains("rotZ")) - this.entityData.set(ROT_Z, compound.getFloat("rotZ")); } public Vector3f getForwardDirection() { @@ -191,102 +170,61 @@ public class DroneEntity extends LivingEntity implements GeoEntity { ).normalize(); } -// if (this.level().isClientSide) { -// -// if (!this.onGround()) { -// // left and right -// float moveX = 0; -// if (Minecraft.getInstance().options.keyLeft.isDown()) { -// moveX = -1; -// } else if (Minecraft.getInstance().options.keyRight.isDown()) { -// moveX = 1; -// } -// -// Vector3f direction = getRightDirection().mul(moveX); -// setDeltaMovement(getDeltaMovement().add(direction.x, direction.y, direction.z)); -// -// // forward and backward -//// direction = getForwardDirection().mul(thrust * pressingInterpolatedZ.getSmooth()); -//// setDeltaMovement(getDeltaMovement().add(direction.x, direction.y, direction.z)); -// } else { -// // up and down -// -// float moveY = 0; -// if (Minecraft.getInstance().options.keyJump.isDown()) { -// moveY = -1; -// } else if (Minecraft.getInstance().options.keyShift.isDown()) { -// moveY = 1; -// } -// -// setDeltaMovement(getDeltaMovement().add(0.0f, moveY, 0.0f)); -// } -// } + @Override public void baseTick() { super.baseTick(); + double moveX; + double moveZ; if (!this.onGround()) { + // left and right + moveX = 0; if (this.getPersistentData().getBoolean("left")) { - this.entityData.set(MOVE_X, -1.5f); - this.entityData.set(ROT_X, Mth.lerp(0.1f, this.entityData.get(ROT_X), 0.3f)); - } - if (this.getPersistentData().getBoolean("right")) { - this.entityData.set(MOVE_X, 1.5f); - this.entityData.set(ROT_X, Mth.lerp(0.1f, this.entityData.get(ROT_X), -0.3f)); + moveX = Mth.clamp(moveX + 0.1f, 0, 1); + } else if (this.getPersistentData().getBoolean("right")) { + moveX = Mth.clamp(moveX - 0.1f, -1, 0); + } else { + moveX = Mth.lerp(0.9 * moveX, moveX, 0); } + + // forward and backward + moveZ = 0; if (this.getPersistentData().getBoolean("forward")) { - this.entityData.set(MOVE_Z, this.entityData.get(MOVE_Z) - 0.1f); - this.entityData.set(ROT_Z, Mth.lerp(0.05f, this.entityData.get(ROT_Z), -0.2f)); - } - if (this.getPersistentData().getBoolean("backward")) { - this.entityData.set(MOVE_Z, this.entityData.get(MOVE_Z) + 0.1f); - this.entityData.set(ROT_Z, Mth.lerp(0.05f, this.entityData.get(ROT_Z), 0.2f)); + moveZ = Mth.clamp(moveZ + 0.1f, 0, 1); + } else if (this.getPersistentData().getBoolean("backward")) { + moveZ= Mth.clamp(moveZ - 0.1f, -1, 0); + } else { + moveZ = Mth.lerp(0.9 * moveZ, moveZ, 0); } + } else { - this.entityData.set(ROT_X, 0f); - this.entityData.set(ROT_Z, 0f); + moveX = 0; + moveZ = 0; } - this.entityData.set(ROT_X, Mth.lerp(0.05f, this.entityData.get(ROT_X), 0)); - - if (!this.getPersistentData().getBoolean("left") && !this.getPersistentData().getBoolean("right")) { - this.entityData.set(MOVE_X, Mth.lerp(0.1f, this.entityData.get(MOVE_X), 0)); - } - - this.entityData.set(ROT_Z, Mth.lerp(0.05f, this.entityData.get(ROT_Z), 0)); - - this.entityData.set(MOVE_Z, Mth.lerp(0.05f, this.entityData.get(MOVE_Z), 0)); - + // up and down + double moveY = 0; if (this.getPersistentData().getBoolean("up")) { - this.entityData.set(MOVE_Y, -1.5f); - } - if (this.getPersistentData().getBoolean("down")) { - this.entityData.set(MOVE_Y, 1.5f); + moveY = Mth.clamp(moveY + 0.05f, 0, 1); + } else if (this.getPersistentData().getBoolean("down")) { + moveY = Mth.clamp(moveY - 0.05f, -1, 0); + } else { + moveY = Mth.lerp(0.99 * moveY, moveY, 0); } - this.entityData.set(MOVE_Y, Mth.lerp(0.5f, this.entityData.get(MOVE_Y), 0)); + setDeltaMovement(getDeltaMovement().add(0.0f, (this.onGround() ? 0.059 : 0) + moveY, 0.0f)); - this.setDeltaMovement(new Vec3( - this.getDeltaMovement().x + -this.entityData.get(MOVE_Z) * 0.07f * this.getLookAngle().x, - this.getDeltaMovement().y + (this.onGround() ? 0.059 : 0) + -this.entityData.get(MOVE_Y) * 0.05f, - this.getDeltaMovement().z + -this.entityData.get(MOVE_Z) * 0.07f * this.getLookAngle().z - )); + Vector3f direction = getRightDirection().mul((float) moveX); + setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(0.8))); - this.move = this.getPersistentData().getBoolean("left") - || this.getPersistentData().getBoolean("right") - || this.getPersistentData().getBoolean("forward") - || this.getPersistentData().getBoolean("backward") - || this.getPersistentData().getBoolean("up") - || this.getPersistentData().getBoolean("down"); + Vector3f directionZ = getForwardDirection().mul((float) moveZ); + setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(0.8))); Vec3 vec = this.getDeltaMovement(); - if (this.getDeltaMovement().horizontalDistanceSqr() < 0.75) { - if (this.move) { - this.setDeltaMovement(vec.multiply(1.035, 0.99, 1.035)); - } - } + this.setDeltaMovement(vec.multiply(1.055, 0.9, 1.055)); Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER)); @@ -299,7 +237,7 @@ public class DroneEntity extends LivingEntity implements GeoEntity { if (!controller.level().isClientSide) { this.level().playSound(null, this.getOnPos(), ModSounds.DRONE_SOUND.get(), SoundSource.AMBIENT, 3, 1); } - controller.setYRot(controller.getYRot() - 5 * this.entityData.get(ROT_X) * Mth.abs(this.entityData.get(MOVE_Z))); +// controller.setYRot((float) (controller.getYRot() - 50 * moveX)); } } @@ -434,18 +372,7 @@ public class DroneEntity extends LivingEntity implements GeoEntity { } } - this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED)); - float strafe = -this.entityData.get(MOVE_X); - super.travel(new Vec3(2 * strafe, -this.entityData.get(MOVE_Y), -this.entityData.get(MOVE_Z))); - Vec3 vec3 = this.getDeltaMovement(); - if (this.onGround()) { - this.setDeltaMovement(vec3.multiply(0.7, 0.98, 0.7)); - } else { - this.setDeltaMovement(vec3.multiply(1.04, 0.98, 1.04)); - } - if (!this.move) { - this.setDeltaMovement(vec3.multiply(0.9, 0.8, 0.9)); - } + super.travel(dir); lastTickSpeed = this.getDeltaMovement().length(); crash(controller); @@ -540,7 +467,7 @@ public class DroneEntity extends LivingEntity implements GeoEntity { ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), source, source), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(), this.getX(), this.getY(), this.getZ(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get(), ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); - net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); + ForgeEventFactory.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); ParticleTool.spawnMediumExplosionParticles(this.level(), this.position()); } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/DroneMovementMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/DroneMovementMessage.java index fd30fed41..98ce248ad 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/DroneMovementMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/DroneMovementMessage.java @@ -9,6 +9,9 @@ import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; +import static com.atsuishio.superbwarfare.entity.DroneEntity.MOVE_X; +import static com.atsuishio.superbwarfare.entity.DroneEntity.MOVE_Z; + public class DroneMovementMessage { private final int direction; private final boolean clicked; @@ -41,15 +44,19 @@ public class DroneMovementMessage { switch (message.direction) { case 0: drone.getPersistentData().putBoolean("left", message.clicked); + drone.getEntityData().set(MOVE_X, message.clicked ? 10f : 0); break; case 1: drone.getPersistentData().putBoolean("right", message.clicked); + drone.getEntityData().set(MOVE_X, message.clicked ? -10f : 0); break; case 2: drone.getPersistentData().putBoolean("forward", message.clicked); + drone.getEntityData().set(MOVE_Z, message.clicked ? -10f : 0); break; case 3: drone.getPersistentData().putBoolean("backward", message.clicked); + drone.getEntityData().set(MOVE_Z, message.clicked ? 10f : 0); break; case 4: drone.getPersistentData().putBoolean("up", message.clicked);