From da98bcfcde9b999746de6e20dd5b03ded40a75cb Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Sat, 4 Jan 2025 02:33:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AB=E6=AD=A3=E7=9B=B4=E5=8D=87=E6=9C=BA?= =?UTF-8?q?=E4=B9=98=E5=AE=A2=E5=9D=90=E5=A7=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/overlay/HelicopterHudOverlay.java | 8 +- .../superbwarfare/entity/Ah6Entity.java | 82 ++++++++++++++++--- .../superbwarfare/entity/SpeedboatEntity.java | 2 +- .../superbwarfare/entity/VehicleEntity.java | 47 ++++++++++- .../entity/WheelChairEntity.java | 2 +- .../mixins/MouseHandlerMixin.java | 2 +- 6 files changed, 123 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java index 793887818..b8d477d42 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java @@ -108,13 +108,13 @@ public class HelicopterHudOverlay { guiGraphics.drawString(Minecraft.getInstance().font, Component.literal(new DecimalFormat("##").format(length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y + 0.06, mobileVehicle.getDeltaMovement().z) * 72) + "KM/H"), w / 2 - 140, h / 2, 0x66FF00, false); - if (((lerpVy * 20 < -5 || (lerpVy * 20 < -1 && length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y + 0.06, mobileVehicle.getDeltaMovement().z) * 72 > 100)) && height < 36) + if (lerpVy * 20 < -20) { + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("SINK RATE,PULL UP!"), + w / 2 - 53, h / 2 + 24, -65536, false); + } else if (((lerpVy * 20 < -5 || (lerpVy * 20 < -1 && length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y + 0.06, mobileVehicle.getDeltaMovement().z) * 72 > 100)) && height < 36) || (length(mobileVehicle.getDeltaMovement().x, mobileVehicle.getDeltaMovement().y + 0.06, mobileVehicle.getDeltaMovement().z) * 72 > 40 && blockInWay < 72)) { guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("TERRAIN TERRAIN"), w / 2 - 42, h / 2 + 24, -65536, false); - } else if (lerpVy * 20 < -20) { - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("SINK RATE,PULL UP!"), - w / 2 - 53, h / 2 + 24, -65536, false); } Matrix4f transform = getVehicleTransform(mobileVehicle); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java index 917d7d5d0..be9cb9c6c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/Ah6Entity.java @@ -11,6 +11,8 @@ import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; +import com.google.common.collect.Lists; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; @@ -25,7 +27,10 @@ import net.minecraft.util.Mth; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Pose; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.vehicle.DismountHelper; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; @@ -44,6 +49,7 @@ import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; +import java.util.ArrayList; import java.util.Comparator; public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelicopterEntity, MultiWeaponVehicleEntity { @@ -143,14 +149,14 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot())); if (rightInputDown) { - this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 0.15f); + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) - 0.25f); } else if (this.leftInputDown) { - this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 0.15f); + this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) + 0.25f); } - this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 0.7f) * diffY * this.entityData.get(POWER) + 0.5f * this.entityData.get(DELTA_ROT), -5f, 5f)); - this.setXRot(Mth.clamp(this.getXRot() + (this.onGround() ? 0 : 0.6f) * diffX * this.entityData.get(POWER), -80, 80)); - this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.2f) * diffY * this.entityData.get(POWER), -50, 50)); + this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 2f) * diffY * this.entityData.get(POWER) - 0.5f * this.entityData.get(DELTA_ROT), -8f, 8f)); + this.setXRot(Mth.clamp(this.getXRot() + (this.onGround() ? 0 : 1.4f) * diffX * this.entityData.get(POWER), -80, 80)); + this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.2f) * diffY * this.entityData.get(POWER), -80, 80)); } if (this.level() instanceof ServerLevel) { @@ -243,7 +249,7 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico } entity.yRotO += f3 - f2; entity.setYRot(entity.getYRot() + f3 - f2); - entity.setYHeadRot(entity.getYRot()); + entity.setYBodyRot(this.getYRot()); } @Override @@ -265,25 +271,47 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico float z = 1f; y += (float) passenger.getMyRidingOffset(); + Vector4f worldPosition; + int i = this.getPassengers().indexOf(passenger); if (i == 0) { - Vector4f worldPosition = transformPosition(transform, x, y, z); + worldPosition = transformPosition(transform, x, y, z); passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } else if (i == 1) { - Vector4f worldPosition = transformPosition(transform, -x, y, z); + worldPosition = transformPosition(transform, -x, y, z); passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } else if (i == 2) { - Vector4f worldPosition = transformPosition(transform, x + 1.2f, y - 0.2f, z - 0.8f); + worldPosition = transformPosition(transform, x + 1.05f, y - 0.4f, z - 0.8f); passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } else { - Vector4f worldPosition = transformPosition(transform, -x - 1.2f, y - 0.2f, z - 0.8f); + worldPosition = transformPosition(transform, -x - 1.05f, y - 0.4f, z - 0.8f); passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } + + + if (passenger != this.getFirstPassenger()){ + passenger.setYRot(passenger.getYRot() + (getYRot() - yRotO)); + passenger.setYHeadRot(passenger.getYHeadRot() + (getYRot() - yRotO)); + passenger.setXRot(passenger.getXRot() + (getXRot() - xRotO)); + } + + callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); + copyEntityData(passenger); + } + + public void copyEntityData(Entity entity) { + entity.setYBodyRot(getYRot()); + float f = Mth.wrapDegrees(entity.getYRot() - getYRot()); + float g = Mth.clamp(f, -105.0f, 105.0f); + + entity.yRotO += g - f; + entity.setYRot(entity.getYRot() + g - f); + entity.setYHeadRot(entity.getYRot()); } @Override @@ -428,6 +456,40 @@ public class Ah6Entity extends MobileVehicleEntity implements GeoEntity, IHelico } } + @Override + public Vec3 getDismountLocationForPassenger(LivingEntity passenger) { + Vec3 vec3d = getDismountOffset(getBbWidth() * Mth.SQRT_OF_TWO, passenger.getBbWidth() * Mth.SQRT_OF_TWO); + double ox = getX() + vec3d.x;; + int i = this.getPassengers().indexOf(passenger); + if (i == 0 || i == 2) { + ox = getX() - vec3d.x; + } + + double oz = getZ() + vec3d.z; + BlockPos exitPos = new BlockPos((int) ox, (int) getY(), (int) oz); + BlockPos floorPos = exitPos.below(); + if (!level().isWaterAt(floorPos)) { + ArrayList list = Lists.newArrayList(); + double exitHeight = level().getBlockFloorHeight(exitPos); + if (DismountHelper.isBlockFloorValid(exitHeight)) { + list.add(new Vec3(ox, (double) exitPos.getY() + exitHeight, oz)); + } + double floorHeight = level().getBlockFloorHeight(floorPos); + if (DismountHelper.isBlockFloorValid(floorHeight)) { + list.add(new Vec3(ox, (double) floorPos.getY() + floorHeight, oz)); + } + for (Pose entityPose : passenger.getDismountPoses()) { + for (Vec3 vec3d2 : list) { + if (!DismountHelper.canDismountTo(level(), vec3d2, passenger, entityPose)) continue; + passenger.setPose(entityPose); + return vec3d2; + } + } + } + + return super.getDismountLocationForPassenger(passenger); + } + @Override public boolean isDriver(Player player) { return player == this.getFirstPassenger(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java index 70ef3b51b..50f150c54 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/SpeedboatEntity.java @@ -515,7 +515,7 @@ public class SpeedboatEntity extends MobileVehicleEntity implements GeoEntity, I float f3 = Mth.clamp(f2, -140.0F, 140.0F); entity.yRotO += f3 - f2; entity.setYRot(entity.getYRot() + f3 - f2); - entity.setYHeadRot(entity.getYRot()); + entity.setYBodyRot(this.getYRot()); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java index 57f05b42c..e0d2cb87d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/VehicleEntity.java @@ -2,7 +2,9 @@ package com.atsuishio.superbwarfare.entity; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.item.ContainerBlockItem; +import com.google.common.collect.Lists; import com.mojang.math.Axis; +import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; @@ -14,11 +16,10 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; -import net.minecraft.world.entity.AreaEffectCloud; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.projectile.ThrownPotion; +import net.minecraft.world.entity.vehicle.DismountHelper; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; @@ -28,6 +29,8 @@ import org.joml.Math; import org.joml.Matrix4f; import org.joml.Vector4f; +import java.util.ArrayList; + public class VehicleEntity extends Entity { public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT); @@ -314,4 +317,42 @@ public class VehicleEntity extends Entity { return 0.0D; } } + + protected Vec3 getDismountOffset(double vehicleWidth, double passengerWidth) { + double offset = (vehicleWidth + passengerWidth + (double) 1.0E-5f) / 2.0; + float yaw = getYRot() + 90.0f; + float x = -Mth.sin(yaw * ((float) java.lang.Math.PI / 180)); + float z = Mth.cos(yaw * ((float) java.lang.Math.PI / 180)); + float n = java.lang.Math.max(java.lang.Math.abs(x), java.lang.Math.abs(z)); + return new Vec3((double) x * offset / (double) n, 0.0, (double) z * offset / (double) n); + } + + @Override + public Vec3 getDismountLocationForPassenger(LivingEntity passenger) { + Vec3 vec3d = getDismountOffset(getBbWidth() * Mth.SQRT_OF_TWO, passenger.getBbWidth() * Mth.SQRT_OF_TWO); + double ox = getX() - vec3d.x; + double oz = getZ() + vec3d.z; + BlockPos exitPos = new BlockPos((int) ox, (int) getY(), (int) oz); + BlockPos floorPos = exitPos.below(); + if (!level().isWaterAt(floorPos)) { + ArrayList list = Lists.newArrayList(); + double exitHeight = level().getBlockFloorHeight(exitPos); + if (DismountHelper.isBlockFloorValid(exitHeight)) { + list.add(new Vec3(ox, (double) exitPos.getY() + exitHeight, oz)); + } + double floorHeight = level().getBlockFloorHeight(floorPos); + if (DismountHelper.isBlockFloorValid(floorHeight)) { + list.add(new Vec3(ox, (double) floorPos.getY() + floorHeight, oz)); + } + for (Pose entityPose : passenger.getDismountPoses()) { + for (Vec3 vec3d2 : list) { + if (!DismountHelper.canDismountTo(level(), vec3d2, passenger, entityPose)) continue; + passenger.setPose(entityPose); + return vec3d2; + } + } + } + + return super.getDismountLocationForPassenger(passenger); + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java index ea1286e7b..217ea27f4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/WheelChairEntity.java @@ -253,7 +253,7 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity { float f3 = Mth.clamp(f2, -90F, 90.0F); entity.yRotO += f3 - f2; entity.setYRot(entity.getYRot() + f3 - f2); - entity.setYHeadRot(entity.getYRot()); + entity.setYBodyRot(this.getYRot()); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java index 16249ccba..9b2d78d27 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/MouseHandlerMixin.java @@ -50,7 +50,7 @@ public class MouseHandlerMixin { } } - if (player.getVehicle() instanceof Ah6Entity ah6Entity && !ah6Entity.onGround()) { + if (player.getVehicle() instanceof Ah6Entity ah6Entity && !ah6Entity.onGround() && ah6Entity.getFirstPassenger() == player) { return 0.24; }