直升机S键改为缓慢下降,添加载具防堆叠

This commit is contained in:
Atsuihsio 2025-01-20 16:40:04 +08:00
parent 27fbe9389f
commit c14b4a8cde
3 changed files with 46 additions and 14 deletions

View file

@ -18,6 +18,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.joml.Math;
import software.bernie.geckolib.animatable.GeoBlockEntity; import software.bernie.geckolib.animatable.GeoBlockEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.core.animation.AnimatableManager;
@ -54,12 +55,12 @@ public class ContainerBlockEntity extends BlockEntity implements GeoBlockEntity
} }
} else { } else {
if (blockEntity.entity != null) { 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); pLevel.addFreshEntity(blockEntity.entity);
} else if (blockEntity.entityType != null) { } else if (blockEntity.entityType != null) {
var entity = blockEntity.entityType.create(pLevel); var entity = blockEntity.entityType.create(pLevel);
if (entity != null) { 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); pLevel.addFreshEntity(entity);
} }
} }

View file

@ -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.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)); 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.level() instanceof ServerLevel) {
if (this.getEnergy() > 0) { if (this.getEnergy() > 0) {
boolean up = this.upInputDown || this.forwardInputDown; boolean up = upInputDown || forwardInputDown;
boolean down = this.downInputDown || this.backInputDown; boolean down = this.downInputDown;
if (!engineStart && up) { if (!engineStart && up) {
engineStart = true; 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)); this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.002f, 0.12f));
} }
if (down && engineStartOver) { if (engineStartOver) {
this.entityData.set(POWER, Math.max(this.entityData.get(POWER) - 0.0015f, this.onGround() ? 0 : 0.0375f)); 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) { if (engineStart && !engineStartOver) {
this.entityData.set(POWER, Math.min(this.entityData.get(POWER) + 0.0012f, 0.045f)); 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) { 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 { } 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 { } 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)); 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)); 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)); 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) { if (this.entityData.get(POWER) > 0.04f) {
engineStartOver = true; engineStartOver = true;

View file

@ -68,6 +68,7 @@ public class MobileVehicleEntity extends EnergyVehicleEntity {
collisionCoolDown--; collisionCoolDown--;
} }
super.baseTick(); super.baseTick();
preventStacking();
crushEntities(this.getDeltaMovement()); crushEntities(this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.06, 0.0)); this.setDeltaMovement(this.getDeltaMovement().add(0.0, -0.06, 0.0));
this.move(MoverType.SELF, this.getDeltaMovement()); 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 动量 * @param velocity 动量
*/ */
public void crushEntities(Vec3 velocity) { public void crushEntities(Vec3 velocity) {
if (this instanceof DroneEntity) return; if (this instanceof DroneEntity) return;
if (velocity.horizontalDistance() < 0.1) return; if (velocity.horizontalDistance() < 0.25) return;
if (isRemoved()) return; if (isRemoved()) return;
var frontBox = getBoundingBox().move(velocity.scale(0.5)); var frontBox = getBoundingBox().move(velocity.scale(0.5));
var velAdd = velocity.add(0, 0, 0).scale(0.9); 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 f = Math.min(entitySize / thisSize, 2);
double f1 = Math.min(thisSize / entitySize, 4); 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) { if (!this.level().isClientSide) {
this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1); this.level().playSound(null, this, ModSounds.VEHICLE_STRIKE.get(), this.getSoundSource(), 1, 1);
} }