让船在无人情况下停止操作

This commit is contained in:
Atsuihsio 2024-12-14 14:48:44 +08:00
parent a33ec13136
commit 944faf99e3
2 changed files with 13 additions and 4 deletions

View file

@ -298,6 +298,10 @@ public class ClickHandler {
return; return;
} }
if ((player.getVehicle() != null && player.getVehicle() instanceof SpeedboatEntity boat && boat.getFirstPassenger() == player)) {
ModUtils.PACKET_HANDLER.sendToServer(new FireMessage(0));
}
if (stack.is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)) { if (stack.is(ModTags.Items.GUN) && !(player.getVehicle() != null && player.getVehicle() instanceof ICannonEntity)) {
if ((!(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading")) if ((!(stack.getOrCreateTag().getBoolean("is_normal_reloading") || stack.getOrCreateTag().getBoolean("is_empty_reloading"))
&& !stack.getOrCreateTag().getBoolean("reloading") && !stack.getOrCreateTag().getBoolean("reloading")

View file

@ -72,9 +72,6 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
public float turretYRotO; public float turretYRotO;
public float turretXRotO; public float turretXRotO;
public float rudderYRot;
public float rudderYRot0;
public SpeedboatEntity(PlayMessages.SpawnEntity packet, Level world) { public SpeedboatEntity(PlayMessages.SpawnEntity packet, Level world) {
this(ModEntities.SPEEDBOAT.get(), world); this(ModEntities.SPEEDBOAT.get(), world);
} }
@ -225,7 +222,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
if (this.onGround()) { if (this.onGround()) {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.2, 0.85, 0.2)); this.setDeltaMovement(this.getDeltaMovement().multiply(0.2, 0.85, 0.2));
} else if (this.isInWater()) { } else {
float f = 0.73f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90; float f = 0.73f + 0.09f * Mth.abs(90 - (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1))) / 90;
this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length()))); this.setDeltaMovement(this.getDeltaMovement().add(this.getViewVector(1).normalize().scale(0.04 * this.getDeltaMovement().length())));
this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f)); this.setDeltaMovement(this.getDeltaMovement().multiply(f, 0.85, f));
@ -250,6 +247,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
collideBlock(); collideBlock();
gunnerAngle(); gunnerAngle();
// gunnerFire();
this.refreshDimensions(); this.refreshDimensions();
} }
@ -291,6 +289,13 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
private void controlBoat() { private void controlBoat() {
Entity passenger0 = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0); Entity passenger0 = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
if (passenger0 == null) {
this.getPersistentData().putBoolean("left", false);
this.getPersistentData().putBoolean("right", false);
this.getPersistentData().putBoolean("forward", false);
this.getPersistentData().putBoolean("backward", false);
}
float diffY = 0; float diffY = 0;
if (this.getPersistentData().getBoolean("forward")) { if (this.getPersistentData().getBoolean("forward")) {
this.entityData.set(POWER, this.entityData.get(POWER) + 0.02f); this.entityData.set(POWER, this.entityData.get(POWER) + 0.02f);