From a33ec13136913dfce82f71408b4ee5fb21a2fc4e Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Sat, 14 Dec 2024 13:27:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E6=BB=91=E7=82=AE=E5=A1=94=E7=9A=84?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=9C=A8=E8=88=B9?= =?UTF-8?q?=E9=A9=BE=E9=A9=B6=E4=BD=8D=E7=A9=BA=E6=89=8B=E5=8F=B3=E9=94=AE?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=9E=84=E5=87=86=E8=A7=86=E8=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/client/ClickHandler.java | 7 ++- .../client/model/entity/SpeedboatModel.java | 6 --- .../renderer/entity/SpeedboatRenderer.java | 13 ++++++ .../superbwarfare/entity/SpeedboatEntity.java | 46 +++++++++++++------ .../event/ClientEventHandler.java | 5 ++ .../superbwarfare/mixins/CameraMixin.java | 18 +++++++- 6 files changed, 72 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index 4189abba4..690a5baa7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.config.client.ReloadConfig; import com.atsuishio.superbwarfare.entity.ICannonEntity; import com.atsuishio.superbwarfare.entity.IVehicleEntity; import com.atsuishio.superbwarfare.entity.MortarEntity; +import com.atsuishio.superbwarfare.entity.SpeedboatEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.ModVariables; @@ -103,7 +104,9 @@ public class ClickHandler { } if (button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) { - if (player.getMainHandItem().is(ModTags.Items.GUN) || (player.isPassenger() && player.getVehicle() instanceof ICannonEntity)) { + if (stack.is(ModTags.Items.GUN) + || (player.isPassenger() && player.getVehicle() instanceof ICannonEntity) + || (player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player && stack.is(ItemStack.EMPTY.getItem()))) { event.setCanceled(true); } } @@ -117,6 +120,7 @@ public class ClickHandler { if ((player.getMainHandItem().is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)) || stack.is(ModItems.MONITOR.get()) || (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity) + || (player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player) || (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) { if (button == ModKeyMappings.FIRE.getKey().getValue()) { handleWeaponFirePress(player, stack); @@ -238,6 +242,7 @@ public class ClickHandler { if ((player.getMainHandItem().is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)) || stack.is(ModItems.MONITOR.get()) || (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity) + || (player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player) || (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get()))) { if (key == ModKeyMappings.FIRE.getKey().getValue()) { handleWeaponFirePress(player, stack); 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 029210c22..7d1304661 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,7 +3,6 @@ package com.atsuishio.superbwarfare.client.model.entity; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.entity.SpeedboatEntity; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; import software.bernie.geckolib.core.animatable.model.CoreGeoBone; import software.bernie.geckolib.core.animation.AnimationState; import software.bernie.geckolib.model.GeoModel; @@ -35,10 +34,5 @@ public class SpeedboatModel extends GeoModel { rotor.setRotZ(5 * animatable.getEntityData().get(ROTOR)); duo.setRotY((animatable.getEntityData().get(POWER) > 0 ? -0.5f : 0.5f) * animatable.getEntityData().get(DELTA_ROT)); - - CoreGeoBone turret = getAnimationProcessor().getBone("paota"); - CoreGeoBone gun = getAnimationProcessor().getBone("gun"); - turret.setRotY(animatable.getEntityData().get(GUN_YAW) * Mth.DEG_TO_RAD); - gun.setRotX(-animatable.getEntityData().get(GUN_PITCH) * Mth.DEG_TO_RAD); } } 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 1d2d0249a..a50cd13e3 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 @@ -11,6 +11,7 @@ import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; import software.bernie.geckolib.cache.object.BakedGeoModel; +import software.bernie.geckolib.cache.object.GeoBone; import software.bernie.geckolib.renderer.GeoEntityRenderer; public class SpeedboatRenderer extends GeoEntityRenderer { @@ -41,6 +42,18 @@ public class SpeedboatRenderer extends GeoEntityRenderer { poseStack.popPose(); } + @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("paota")) { + bone.setRotY(Mth.lerp(partialTick, animatable.turretYRotO, animatable.getTurretYRot()) * Mth.DEG_TO_RAD); + } + if (name.equals("gun")) { + bone.setRotX(-Mth.lerp(partialTick, animatable.turretXRotO, animatable.getTurretXRot()) * Mth.DEG_TO_RAD); + } + super.renderRecursively(poseStack, animatable, bone, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha); + } + @Override protected float getDeathMaxRotation(SpeedboatEntity entityLivingBaseIn) { return 0.0F; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java index 2476ea693..d7aae894a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java @@ -7,7 +7,6 @@ import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.ContainerBlockItem; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.ParticleTool; -import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; @@ -57,8 +56,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, 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 GUN_YAW = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); - public static final EntityDataAccessor GUN_PITCH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final float MAX_HEALTH = CannonConfig.MK42_HP.get(); @@ -70,6 +67,14 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, private double lerpYRot; private double lerpXRot; + public float turretYRot; + public float turretXRot; + public float turretYRotO; + public float turretXRotO; + + public float rudderYRot; + public float rudderYRot0; + public SpeedboatEntity(PlayMessages.SpawnEntity packet, Level world) { this(ModEntities.SPEEDBOAT.get(), world); } @@ -86,8 +91,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, this.entityData.define(DELTA_ROT, 0f); this.entityData.define(POWER, 0f); this.entityData.define(ROTOR, 0f); - this.entityData.define(GUN_YAW, 0f); - this.entityData.define(GUN_PITCH, 0f); } @Override @@ -335,7 +338,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, // Vec3 driverAngleVec = driver.getLookAngle().normalize(); // double lookAngle = calculateAngle(driverAngleVec, rightVec); - double gunAngle = -Math.clamp(-105f, 105f, Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot())); + float gunAngle = -Math.clamp(-105f, 105f, Mth.wrapDegrees(driver.getYHeadRot() - this.getYRot())); // if (lookAngle < 90) { // gunAngle = calculateAngle(driver.getLookAngle(), this.getLookAngle()); // } else { @@ -348,17 +351,30 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, // gunAngle += 360; // } - this.entityData.set(GUN_YAW, (float) Mth.lerp(0.2, this.entityData.get(GUN_YAW), gunAngle)); +// this.entityData.set(GUN_YAW, gunAngle); +// this.entityData.set(GUN_YAW_O, this.entityData.get(GUN_YAW)); - float diffX = driver.getXRot() - this.getXRot(); - this.entityData.set(GUN_PITCH, (float) Mth.lerp(0.1, this.entityData.get(GUN_PITCH), diffX)); + turretYRotO = this.getTurretYRot(); + turretXRotO = this.getTurretXRot(); + + this.setTurretYRot(gunAngle); + this.setTurretXRot(driver.getXRot() - this.getXRot()); } - public double getRotY(EntityAnchorArgument.Anchor pAnchor, Vec3 pTarget) { - Vec3 vec3 = pAnchor.apply(this); - double d0 = (pTarget.x - vec3.x) * 0.2; - double d2 = (pTarget.z - vec3.z) * 0.2; - return Mth.wrapDegrees((float) (Mth.atan2(d2, d0) * 57.2957763671875) - 90.0F); + public float getTurretYRot() { + return this.turretYRot; + } + + public void setTurretYRot(float pTurretYRot) { + this.turretYRot = pTurretYRot; + } + + public float getTurretXRot() { + return this.turretXRot; + } + + public void setTurretXRot(float pTurretXRot) { + this.turretXRot = pTurretXRot; } private void handleSetDiffY(float diffY) { @@ -455,7 +471,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, protected void clampRotation(Entity entity) { float f = Mth.wrapDegrees(entity.getXRot()); - float f1 = Mth.clamp(f, -85.0F, 16.3F); + float f1 = Mth.clamp(f, -35.0F, 20F); entity.xRotO += f1 - f; entity.setXRot(entity.getXRot() + f1 - f); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index f0855870a..cdaeed8f5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.entity.DroneEntity; import com.atsuishio.superbwarfare.entity.ICannonEntity; +import com.atsuishio.superbwarfare.entity.SpeedboatEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.message.LaserShootMessage; @@ -694,6 +695,10 @@ public class ClientEventHandler { if (player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity) { event.setCanceled(true); } + + if ((player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player) && ClientEventHandler.zoom && stack.is(ItemStack.EMPTY.getItem())) { + event.setCanceled(true); + } } private static void handleWeaponSway(LivingEntity entity) { diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java index 2e14aab95..0c78f4d74 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/CameraMixin.java @@ -39,6 +39,22 @@ public abstract class CameraMixin { if (player != null) { ItemStack stack = player.getMainHandItem(); + if ((player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player) && ClientEventHandler.zoom && stack.is(ItemStack.EMPTY.getItem())) { + float yRot = boat.getYRot(); + if (yRot < 0) { + yRot += 360; + } + yRot = yRot + 90 % 360; + var CameraPos = new Vector3d(-0.6, 3.3, 0); + CameraPos.rotateZ(-boat.getXRot() * Mth.DEG_TO_RAD); + CameraPos.rotateY(-yRot * Mth.DEG_TO_RAD); + setRotation(player.getViewYRot(partialTicks), player.getViewXRot(partialTicks)); + setPosition(Mth.lerp(partialTicks, boat.xo + CameraPos.x, boat.getX() + CameraPos.x), Mth.lerp(partialTicks, boat.yo + CameraPos.y, boat.getY() + CameraPos.y), Mth.lerp(partialTicks, boat.zo + CameraPos.z, boat.getZ() + CameraPos.z)); + info.cancel(); + + return; + } + if (stack.is(ModItems.MONITOR.get()) && stack.getOrCreateTag().getBoolean("Using") && stack.getOrCreateTag().getBoolean("Linked")) { DroneEntity drone = EntityFindUtil.findDrone(player.level(), stack.getOrCreateTag().getString("LinkedDrone")); @@ -73,7 +89,7 @@ public abstract class CameraMixin { move(-getMaxZoom(16), 1.3, 0.0); return; } - if (thirdPerson && entity.getVehicle() instanceof SpeedboatEntity) { + if (thirdPerson && entity.getVehicle() instanceof SpeedboatEntity && !ClientEventHandler.zoom) { move(-getMaxZoom(3), 1, 0.0); return; }