From c14b4a8cdeacb4cb89d52295dacf2bf6f4a451d6 Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Mon, 20 Jan 2025 16:40:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E5=8D=87=E6=9C=BAS=E9=94=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E7=BC=93=E6=85=A2=E4=B8=8B=E9=99=8D=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=85=B7=E9=98=B2=E5=A0=86=E5=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/entity/ContainerBlockEntity.java | 5 ++-- .../entity/vehicle/Ah6Entity.java | 27 +++++++++++------- .../entity/vehicle/MobileVehicleEntity.java | 28 +++++++++++++++++-- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java index 26d1bb49c..d4350fb60 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/ContainerBlockEntity.java @@ -18,6 +18,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import org.joml.Math; import software.bernie.geckolib.animatable.GeoBlockEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; @@ -54,12 +55,12 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity } } else { if (blockEntity.entity != null) { - blockEntity.entity.setPos(pPos.getX() + 0.5, pPos.getY() + 0.5, pPos.getZ() + 0.5); + blockEntity.entity.setPos(pPos.getX() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getY() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getZ() + 0.5 + (2 * Math.random() - 1) * 0.1f); pLevel.addFreshEntity(blockEntity.entity); } else if (blockEntity.entityType != null) { var entity = blockEntity.entityType.create(pLevel); if (entity != null) { - entity.setPos(pPos.getX() + 0.5, pPos.getY() + 0.5, pPos.getZ() + 0.5); + entity.setPos(pPos.getX() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getY() + 0.5 + (2 * Math.random() - 1) * 0.1f, pPos.getZ() + 0.5 + (2 * Math.random() - 1) * 0.1f); pLevel.addFreshEntity(entity); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index 3d7fa9b45..cac74ec7a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -275,14 +275,14 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli } this.setYRot(this.getYRot() + Mth.clamp((this.onGround() ? 0.1f : 2f) * diffY * this.entityData.get(PROPELLER_ROT) - 0.5f * this.entityData.get(DELTA_ROT), -8f, 8f)); - this.setXRot(Mth.clamp(this.getXRot() + (this.onGround() ? 0 : 1.4f) * diffX * this.entityData.get(PROPELLER_ROT), -80, 80)); + this.setXRot(Mth.clamp(this.getXRot() + ((this.onGround()) ? 0 : 1.4f) * diffX * this.entityData.get(PROPELLER_ROT), -80, 80)); this.setZRot(Mth.clamp(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.2f) * diffY * this.entityData.get(PROPELLER_ROT), -80, 80)); } if (this.level() instanceof ServerLevel) { if (this.getEnergy() > 0) { - boolean up = this.upInputDown || this.forwardInputDown; - boolean down = this.downInputDown || this.backInputDown; + boolean up = upInputDown || forwardInputDown; + boolean down = this.downInputDown; if (!engineStart && up) { engineStart = true; @@ -293,19 +293,26 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.002f, 0.12f)); } - if (down && engineStartOver) { - this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.0375f)); + if (engineStartOver) { + if (down) { + this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.0375f)); + } else if (backInputDown) { + this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.052f)); + if (passenger != null) { + passenger.setXRot(0.8f * passenger.getXRot()); + } + } } if (engineStart && !engineStartOver) { this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0012f, 0.045f)); } - if (!(up || down) && engineStartOver) { + if (!(up || down || backInputDown) && engineStartOver) { if (this.getDeltaMovement().y() < 0) { - this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0002f, 0.12f)); + this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0001f, 0.12f)); } else { - this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - (this.onGround() ? 0.00005f : 0.0002f), 0)); + this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - (this.onGround() ? 0.00005f : 0.0001f), 0)); } } } else { @@ -329,10 +336,10 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli setDeltaMovement(getDeltaMovement().add(0.0f, Math.min(Math.sin((90 - this.getXRot()) * Mth.DEG_TO_RAD), Math.sin((90 + this.getRoll()) * Mth.DEG_TO_RAD)) * this.entityData.get(PROPELLER_ROT), 0.0f)); Vector3f direction = getRightDirection().mul(Math.cos((this.getRoll() + 90) * Mth.DEG_TO_RAD) * this.entityData.get(PROPELLER_ROT)); - setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(0.85))); + setDeltaMovement(getDeltaMovement().add(new Vec3(direction.x, direction.y, direction.z).scale(backInputDown ? 0.45 : 0.85))); Vector3f directionZ = getForwardDirection().mul(-Math.cos((this.getXRot() + 90) * Mth.DEG_TO_RAD) * this.entityData.get(PROPELLER_ROT)); - setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(0.35))); + setDeltaMovement(getDeltaMovement().add(new Vec3(directionZ.x, directionZ.y, directionZ.z).scale(backInputDown ? 0.1 : 0.35))); if (this.entityData.get(POWER) > 0.04f) { engineStartOver = true; diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java index 4d7bee35a..8ef0d029e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MobileVehicleEntity.java @@ -68,6 +68,7 @@ public class MobileVehicleEntity extends EnergyVehicleEntity { collisionCoolDown--; } super.baseTick(); + preventStacking(); crushEntities(this.getDeltaMovement()); this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.06, 0.0)); this.move(MoverType.SELF, this.getDeltaMovement()); @@ -126,13 +127,36 @@ public class MobileVehicleEntity extends EnergyVehicleEntity { } } + /** + * 防止载具堆叠 + */ + public void preventStacking() { + var Box = getBoundingBox(); + + var entities = level().getEntities(EntityTypeTest.forClass(Entity.class), Box, entity -> entity != this && entity != getFirstPassenger() && entity.getVehicle() == null) + .stream().filter(entity -> entity instanceof VehicleEntity) + .toList(); + + for (var entity : entities) { + Vec3 toVec = this.position().add(new Vec3(1, 1 ,1).scale(random.nextFloat() * 0.01f + 1f)).vectorTo(entity.position()); + Vec3 velAdd = toVec.normalize().scale(Math.max((this.getBbWidth() + 2) - position().distanceTo(entity.position()), 0) * 0.002); + double entitySize = entity.getBbWidth() * entity.getBbHeight(); + double thisSize = this.getBbWidth() * this.getBbHeight(); + double f = Math.min(entitySize / thisSize, 2); + double f1 = Math.min(thisSize / entitySize, 2); + + this.push(-f * velAdd.x, -f * velAdd.y, -f * velAdd.z); + entity.push(f1 * velAdd.x, f1 * velAdd.y, f1 * velAdd.z); + } + } + /** * 撞击实体并造成伤害 * @param velocity 动量 */ public void crushEntities(Vec3 velocity) { if (this instanceof DroneEntity) return; - if (velocity.horizontalDistance() < 0.1) return; + if (velocity.horizontalDistance() < 0.25) return; if (isRemoved()) return; var frontBox = getBoundingBox().move(velocity.scale(0.5)); var velAdd = velocity.add(0, 0, 0).scale(0.9); @@ -150,7 +174,7 @@ public class MobileVehicleEntity extends EnergyVehicleEntity { double f = Math.min(entitySize / thisSize, 2); double f1 = Math.min(thisSize / entitySize, 4); - if (velocity.length() > 0.3) { + if (velocity.length() > 0.3 && getBoundingBox().distanceToSqr(entity.getBoundingBox().getCenter()) < 1) { if (!this.level().isClientSide) { this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1); }