diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java index a0999b882..d5e7eef0e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/SpeedboatModel.java @@ -3,12 +3,8 @@ package com.atsuishio.superbwarfare.client.model.entity; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.entity.SpeedboatEntity; import net.minecraft.resources.ResourceLocation; -import software.bernie.geckolib.core.animatable.model.CoreGeoBone; -import software.bernie.geckolib.core.animation.AnimationState; import software.bernie.geckolib.model.GeoModel; -import static com.atsuishio.superbwarfare.entity.SpeedboatEntity.*; - public class SpeedboatModel extends GeoModel { @Override @@ -25,13 +21,4 @@ public class SpeedboatModel extends GeoModel { public ResourceLocation getTextureResource(SpeedboatEntity entity) { return ModUtils.loc("textures/entity/speedboat.png"); } - - @Override - public void setCustomAnimations(SpeedboatEntity animatable, long instanceId, AnimationState animationState) { - CoreGeoBone rotor = getAnimationProcessor().getBone("Rotor"); - CoreGeoBone duo = getAnimationProcessor().getBone("duo"); - - rotor.setRotZ(5 * animatable.getEntityData().get(ROTOR)); - duo.setRotY((animatable.getEntityData().get(POWER) > 0 ? -0.5f : 0.5f) * animatable.getEntityData().get(DELTA_ROT)); - } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java index 1a06934fb..8352c6c62 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/entity/SpeedboatRenderer.java @@ -51,6 +51,12 @@ public class SpeedboatRenderer extends GeoEntityRenderer { @Override public void renderRecursively(PoseStack poseStack, SpeedboatEntity animatable, GeoBone bone, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { String name = bone.getName(); + if (name.equals("Rotor")) { + bone.setRotZ(Mth.lerp(partialTick, animatable.rotorRotO, animatable.getRotorRot())); + } + if (name.equals("duo")) { + bone.setRotY(Mth.lerp(partialTick, animatable.rudderRotO, animatable.getRudderRot())); + } if (name.equals("paota")) { bone.setRotY(Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * Mth.DEG_TO_RAD); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/MobileVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/MobileVehicleEntity.java index 4284e752e..503948f09 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/MobileVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/MobileVehicleEntity.java @@ -26,7 +26,7 @@ public class MobileVehicleEntity extends Entity { protected double serverXRot; public float roll; - + public float power; public boolean leftInputDown; public boolean rightInputDown; public boolean forwardInputDown; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java index df8786855..ab9ffe903 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java @@ -85,13 +85,11 @@ import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity { - + public static final EntityDataAccessor POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor POWER = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor HEAT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT); protected static final EntityDataAccessor LAST_ATTACKER_UUID = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor AMMO = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT); @@ -104,11 +102,14 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I private LazyOptional itemHandler = LazyOptional.of(() -> new InvWrapper(this)); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); - public float turretYRot; public float turretXRot; public float turretYRotO; public float turretXRotO; + public float rotorRot; + public float rudderRot; + public float rotorRotO; + public float rudderRotO; public boolean cannotFire; @@ -122,13 +123,12 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I @Override protected void defineSynchedData() { + this.entityData.define(POWER, 0f); this.entityData.define(AMMO, 0); this.entityData.define(FIRE_ANIM, 0); this.entityData.define(HEALTH, MAX_HEALTH); this.entityData.define(ENERGY, 0f); this.entityData.define(DELTA_ROT, 0f); - this.entityData.define(POWER, 0f); - this.entityData.define(ROTOR, 0f); this.entityData.define(HEAT, 0); this.entityData.define(LAST_ATTACKER_UUID, "undefined"); } @@ -281,6 +281,8 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I turretYRotO = this.getTurretYRot(); turretXRotO = this.getTurretXRot(); + rotorRotO = this.getRotorRot(); + rudderRotO = this.getRudderRot(); Entity driver = this.getFirstPassenger(); if (driver instanceof Player player) { @@ -314,9 +316,9 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I } if (this.level() instanceof ServerLevel serverLevel && this.isInWater() && this.getDeltaMovement().length() > 0.1) { - sendParticle(serverLevel, ParticleTypes.CLOUD, this.getX() + 1.2 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 1.2 * this.getDeltaMovement().z, (int)(2 + 4 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true); - sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 1.2 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 1.2 * this.getDeltaMovement().z, (int)(2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true); - sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() - 3.5 * this.getLookAngle().x, this.getY() - 0.25, this.getZ() - 3.5 * this.getLookAngle().z, (int)(40 * Mth.abs(this.entityData.get(POWER))), 0.15, 0.15, 0.15, 0.02, true); + sendParticle(serverLevel, ParticleTypes.CLOUD, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int)(2 + 4 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true); + sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int)(2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true); + sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() - 4.5 * this.getLookAngle().x, this.getY() - 0.25, this.getZ() - 4.5 * this.getLookAngle().z, (int)(40 * Mth.abs(power)), 0.15, 0.15, 0.15, 0.02, true); } controlBoat(); @@ -443,7 +445,6 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I this.backInputDown = false; } - float diffY = 0; if (forwardInputDown) { this.entityData.set(POWER, this.entityData.get(POWER) + 0.02f); } @@ -451,19 +452,15 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I if (backInputDown) { this.entityData.set(POWER, this.entityData.get(POWER) - 0.02f); if (rightInputDown) { - diffY = Mth.clamp(diffY + 1f, 0, 10); - handleSetDiffY(diffY); + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 0.2f); } else if (leftInputDown) { - diffY = Mth.clamp(diffY - 1f, -10, 0); - handleSetDiffY(diffY); + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 0.2f); } } else { if (rightInputDown) { - diffY = Mth.clamp(diffY - 1f, -10, 0); - handleSetDiffY(diffY); + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 0.1f); } else if (this.leftInputDown) { - diffY = Mth.clamp(diffY + 1f, 0, 10); - handleSetDiffY(diffY); + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 0.1f); } } @@ -476,12 +473,14 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I } this.entityData.set(POWER, this.entityData.get(POWER) * 0.87f); - this.entityData.set(ROTOR, this.entityData.get(ROTOR) + this.entityData.get(POWER)); this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.8f); + this.setRotorRot(this.getRotorRot() + 10 * this.entityData.get(POWER)); + this.setRudderRot(Mth.clamp(this.getRudderRot() - this.entityData.get(DELTA_ROT), -1.25f, 1.25f) * 0.7f * (this.entityData.get(POWER) > 0 ? 1 : -1)); + if (this.isInWater() || this.isUnderWater()) { - this.setYRot(this.getYRot() - this.entityData.get(DELTA_ROT)); - this.setDeltaMovement(this.getDeltaMovement().add((double)(Mth.sin(-this.getYRot() * 0.017453292F) * this.entityData.get(POWER)), 0.0, (double)(Mth.cos(this.getYRot() * 0.017453292F) * this.entityData.get(POWER)))); + this.setYRot((float) (this.getYRot() - Math.max(5 * this.getDeltaMovement().length(), 0.3) * this.entityData.get(DELTA_ROT))); + this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.getYRot() * 0.017453292F) * this.entityData.get(POWER), 0.0, Mth.cos(this.getYRot() * 0.017453292F) * this.entityData.get(POWER))); } } @@ -511,10 +510,21 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I this.turretXRot = pTurretXRot; } - private void handleSetDiffY(float diffY) { - this.entityData.set(DELTA_ROT, (float) Mth.clamp(diffY * 1.3 * Math.max(8 * this.getDeltaMovement().length(), 0.5), -2, 2)); + public float getRotorRot() { + return this.rotorRot; } + public void setRotorRot(float pRotorRot) { + this.rotorRot = pRotorRot; + } + + public float getRudderRot() { + return this.rudderRot; + } + + public void setRudderRot(float pRudderRot) { + this.rudderRot = pRudderRot; + } protected SoundEvent getEngineSound() { return ModSounds.BOAT_ENGINE.get(); @@ -526,8 +536,8 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I double posY = this.getY() + this.getPassengersRidingOffset() + pPassenger.getMyRidingOffset(); if (!zooming() && (this.isInWater() || this.isUnderWater())) { - pPassenger.setYRot(pPassenger.getYRot() - 1.27f * this.entityData.get(DELTA_ROT)); - pPassenger.setYHeadRot(pPassenger.getYHeadRot() - 1.27f * this.entityData.get(DELTA_ROT)); + pPassenger.setYRot((float) (pPassenger.getYRot() - Math.max(5 * this.getDeltaMovement().length(), 0.3) * this.entityData.get(DELTA_ROT))); + pPassenger.setYHeadRot((float) (pPassenger.getYHeadRot() - Math.max(5 * this.getDeltaMovement().length(), 0.3) * this.entityData.get(DELTA_ROT))); } if (this.getPassengers().size() > 1) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java index a29e80e78..26a80d4e1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java @@ -35,14 +35,11 @@ import software.bernie.geckolib.util.GeckoLibUtil; public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, IVehicleEntity, IChargeEntity { - public static final EntityDataAccessor POWER = SynchedEntityData.defineId(WheelChairEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(WheelChairEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor ENERGY = SynchedEntityData.defineId(WheelChairEntity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = 50; public static final float MAX_ENERGY = 24000; - public float leftWheelRot; public float rightWheelRot; public float leftWheelRotO; @@ -60,7 +57,6 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, @Override protected void defineSynchedData() { this.entityData.define(HEALTH, MAX_HEALTH); - this.entityData.define(POWER, 0f); this.entityData.define(ENERGY, 0f); } @@ -189,14 +185,14 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, this.setYRot(this.getYRot() + Mth.clamp(0.4f * diffY,-5f, 5f)); if (this.forwardInputDown) { - this.entityData.set(POWER, this.entityData.get(POWER) + 0.01f); + power += 0.01f; if (this.entityData.get(ENERGY) <= 0 && entity instanceof Player player) { moveWithOutPower(player, true); } } if (this.backInputDown) { - this.entityData.set(POWER, this.entityData.get(POWER) - 0.01f); + power -= 0.01f; if (this.entityData.get(ENERGY) <= 0 && entity instanceof Player player) { moveWithOutPower(player, false); } @@ -214,7 +210,7 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, this.entityData.set(ENERGY, Math.max(this.entityData.get(ENERGY) - 1, 0)); } - this.entityData.set(POWER, this.entityData.get(POWER) * 0.87f); + power *= 0.87f; float angle = (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1)); double s0; @@ -225,20 +221,20 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity, s0 = -this.getDeltaMovement().length(); } - this.setLeftWheelRot((float) (this.getLeftWheelRot() - 0.75 * s0) - 0.015f * Mth.clamp(0.4f * diffY,-5f, 5f)); - this.setRightWheelRot((float) (this.getRightWheelRot() - 0.75 * s0) + 0.015f * Mth.clamp(0.4f * diffY,-5f, 5f)); + this.setLeftWheelRot((float) (this.getLeftWheelRot() - 0.85 * s0) - 0.015f * Mth.clamp(0.4f * diffY,-5f, 5f)); + this.setRightWheelRot((float) (this.getRightWheelRot() - 0.85 * s0) + 0.015f * Mth.clamp(0.4f * diffY,-5f, 5f)); // if (entity instanceof Player player) { // player.displayClientMessage(Component.literal("Angle:" + new java.text.DecimalFormat("##.##").format(this.getRightWheelRot())), true); // } if (this.onGround()) { - this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.getYRot() * 0.017453292F) * this.entityData.get(POWER), 0.0, Mth.cos(this.getYRot() * 0.017453292F) * this.entityData.get(POWER))); + this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.getYRot() * 0.017453292F) * power, 0.0, Mth.cos(this.getYRot() * 0.017453292F) * power)); } } public void moveWithOutPower(Player player, boolean forward) { - this.entityData.set(POWER, this.entityData.get(POWER) + (forward ? 0.015f : -0.015f)); + power += (forward ? 0.015f : -0.015f); if (player instanceof ServerPlayer serverPlayer) { serverPlayer.level().playSound(null, serverPlayer.getOnPos(), SoundEvents.BOAT_PADDLE_LAND, SoundSource.PLAYERS, 1, 1); }