修复载具导致的崩溃问题
This commit is contained in:
parent
5abdadf0c9
commit
863f6a3cde
5 changed files with 17 additions and 26 deletions
|
@ -182,8 +182,7 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
|
||||||
if (decoyReloadCoolDown > 0) {
|
if (decoyReloadCoolDown > 0) {
|
||||||
decoyReloadCoolDown--;
|
decoyReloadCoolDown--;
|
||||||
}
|
}
|
||||||
Player player = (Player) this.getFirstPassenger();
|
if (this.getFirstPassenger() instanceof Player player) {
|
||||||
if (player != null) {
|
|
||||||
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.ROCKET_70.get())).mapToInt(ItemStack::getCount).sum() > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) {
|
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.ROCKET_70.get())).mapToInt(ItemStack::getCount).sum() > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) {
|
||||||
this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1);
|
this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1);
|
||||||
reloadCoolDown = 25;
|
reloadCoolDown = 25;
|
||||||
|
|
|
@ -211,8 +211,7 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ICha
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
Player player = (Player) this.getFirstPassenger();
|
if (this.getFirstPassenger() instanceof Player player) {
|
||||||
if (player != null) {
|
|
||||||
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).mapToInt(ItemStack::getCount).sum() > 0 && this.getEntityData().get(LOADED_COAX_AMMO) < 500)) {
|
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).mapToInt(ItemStack::getCount).sum() > 0 && this.getEntityData().get(LOADED_COAX_AMMO) < 500)) {
|
||||||
this.entityData.set(LOADED_COAX_AMMO, this.getEntityData().get(LOADED_COAX_AMMO) + 30);
|
this.entityData.set(LOADED_COAX_AMMO, this.getEntityData().get(LOADED_COAX_AMMO) + 30);
|
||||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||||
|
|
|
@ -194,8 +194,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
Player player = (Player) this.getFirstPassenger();
|
if (this.getFirstPassenger() instanceof Player player) {
|
||||||
if (player != null) {
|
|
||||||
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).mapToInt(ItemStack::getCount).sum() > 0 && this.getEntityData().get(LOADED_COAX_AMMO) < 500)) {
|
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).mapToInt(ItemStack::getCount).sum() > 0 && this.getEntityData().get(LOADED_COAX_AMMO) < 500)) {
|
||||||
this.entityData.set(LOADED_COAX_AMMO, this.getEntityData().get(LOADED_COAX_AMMO) + 30);
|
this.entityData.set(LOADED_COAX_AMMO, this.getEntityData().get(LOADED_COAX_AMMO) + 30);
|
||||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||||
|
@ -265,12 +264,6 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
||||||
turretYRotO = deltaT + getTurretYRot();
|
turretYRotO = deltaT + getTurretYRot();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player player = (Player) this.getFirstPassenger();
|
|
||||||
//
|
|
||||||
// if (player != null) {
|
|
||||||
// player.displayClientMessage(Component.literal( new DecimalFormat("##").format(getTurretYRot())), true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
collideBlock();
|
collideBlock();
|
||||||
gunnerAngle();
|
gunnerAngle();
|
||||||
lowHealthWarning();
|
lowHealthWarning();
|
||||||
|
@ -295,8 +288,6 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
||||||
// Vec3 p7 = new Vec3(worldPosition7.x,worldPosition7.y,worldPosition7.z);
|
// Vec3 p7 = new Vec3(worldPosition7.x,worldPosition7.y,worldPosition7.z);
|
||||||
// Vec3 p8 = new Vec3(worldPosition8.x,worldPosition8.y,worldPosition8.z);
|
// Vec3 p8 = new Vec3(worldPosition8.x,worldPosition8.y,worldPosition8.z);
|
||||||
//
|
//
|
||||||
// Player player = (Player) this.getFirstPassenger();
|
|
||||||
//
|
|
||||||
// if (player != null) {
|
// if (player != null) {
|
||||||
// if (player.level() instanceof ServerLevel serverLevel ) {
|
// if (player.level() instanceof ServerLevel serverLevel ) {
|
||||||
// sendParticle(serverLevel, ParticleTypes.END_ROD, p1.x, p1.y, p1.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
// sendParticle(serverLevel, ParticleTypes.END_ROD, p1.x, p1.y, p1.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
||||||
|
@ -317,7 +308,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
||||||
public void move(@NotNull MoverType movementType, @NotNull Vec3 movement) {
|
public void move(@NotNull MoverType movementType, @NotNull Vec3 movement) {
|
||||||
super.move(movementType, movement);
|
super.move(movementType, movement);
|
||||||
if (this.isInWater() && horizontalCollision) {
|
if (this.isInWater() && horizontalCollision) {
|
||||||
setDeltaMovement(this.getDeltaMovement().add(0,0.07,0));
|
setDeltaMovement(this.getDeltaMovement().add(0, 0.07, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +464,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entityData.set(POWER, this.entityData.get(POWER) * (upInputDown ? 0.5f : (rightInputDown || leftInputDown) ? 0.977f : 0.99f));
|
this.entityData.set(POWER, this.entityData.get(POWER) * (upInputDown ? 0.5f : (rightInputDown || leftInputDown) ? 0.977f : 0.99f));
|
||||||
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * (float)Math.max(0.76f - 0.1f * this.getDeltaMovement().horizontalDistance(), 0.3));
|
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * (float) Math.max(0.76f - 0.1f * this.getDeltaMovement().horizontalDistance(), 0.3));
|
||||||
|
|
||||||
float angle = (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1));
|
float angle = (float) calculateAngle(this.getDeltaMovement(), this.getViewVector(1));
|
||||||
double s0;
|
double s0;
|
||||||
|
@ -491,7 +482,7 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC
|
||||||
|
|
||||||
if (this.isInWater() || onGround()) {
|
if (this.isInWater() || onGround()) {
|
||||||
this.setYRot((float) (this.getYRot() - Math.max((isInWater() && !onGround() ? 5 : 10) * this.getDeltaMovement().horizontalDistance(), 0) * this.getRudderRot() * (this.entityData.get(POWER) > 0 ? 1 : -1)));
|
this.setYRot((float) (this.getYRot() - Math.max((isInWater() && !onGround() ? 5 : 10) * this.getDeltaMovement().horizontalDistance(), 0) * this.getRudderRot() * (this.entityData.get(POWER) > 0 ? 1 : -1)));
|
||||||
this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.getYRot() * 0.017453292F) * (!isInWater() && !onGround() ? 0.05f : (isInWater() && !onGround() ? 0.3f : 1)) * this.entityData.get(POWER), 0.0, Mth.cos(this.getYRot() * 0.017453292F) * (!isInWater() && !onGround() ? 0.05f : (isInWater() && !onGround() ? 0.3f : 1)) * this.entityData.get(POWER)));
|
this.setDeltaMovement(this.getDeltaMovement().add(Mth.sin(-this.getYRot() * 0.017453292F) * (!isInWater() && !onGround() ? 0.05f : (isInWater() && !onGround() ? 0.3f : 1)) * this.entityData.get(POWER), 0.0, Mth.cos(this.getYRot() * 0.017453292F) * (!isInWater() && !onGround() ? 0.05f : (isInWater() && !onGround() ? 0.3f : 1)) * this.entityData.get(POWER)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntity {
|
public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntity {
|
||||||
|
|
||||||
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT);
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
public static final float MAX_HEALTH = VehicleConfig.MK42_HP.get();
|
public static final float MAX_HEALTH = VehicleConfig.MK42_HP.get();
|
||||||
|
@ -287,12 +288,12 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntit
|
||||||
|
|
||||||
if (passenger instanceof Player player) {
|
if (passenger instanceof Player player) {
|
||||||
if (player.getOffhandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) {
|
if (player.getOffhandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) {
|
||||||
if (setTarget(player.getOffhandItem())) {
|
if (setTarget(player.getOffhandItem())) {
|
||||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(entityData.get(YAW) - this.getYRot()));
|
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(entityData.get(YAW) - this.getYRot()));
|
||||||
diffX = Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot());
|
diffX = Mth.wrapDegrees(entityData.get(PITCH) - this.getXRot());
|
||||||
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f));
|
this.setYRot(this.getYRot() + Mth.clamp(0.5f * diffY, -1.75f, 1.75f));
|
||||||
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.95f * diffX, -5, 5), -85, 15));
|
this.setXRot(Mth.clamp(this.getXRot() + Mth.clamp(0.95f * diffX, -5, 5), -85, 15));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
||||||
diffX = passenger.getXRot() - 1.3f - this.getXRot();
|
diffX = passenger.getXRot() - 1.3f - this.getXRot();
|
||||||
|
|
|
@ -45,6 +45,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
|
public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> DELTA_ROT = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.FLOAT);
|
||||||
public static final EntityDataAccessor<Boolean> MELON = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.BOOLEAN);
|
public static final EntityDataAccessor<Boolean> MELON = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.BOOLEAN);
|
||||||
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
|
||||||
|
@ -169,7 +170,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
|
||||||
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
diffY = Math.clamp(-90f, 90f, Mth.wrapDegrees(passenger.getYHeadRot() - this.getYRot()));
|
||||||
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
|
diffX = Math.clamp(-60f, 60f, Mth.wrapDegrees(passenger.getXRot() - this.getXRot()));
|
||||||
|
|
||||||
float roll = Mth.abs(Mth.clamp(getRoll() / 60 , -1.5f , 1.5f));
|
float roll = Mth.abs(Mth.clamp(getRoll() / 60, -1.5f, 1.5f));
|
||||||
|
|
||||||
float addY = Mth.clamp(Math.min((this.onGround() ? 1.5f : 0.9f) * (float) Math.max(getDeltaMovement().length() - 0.06, 0.1), 0.9f) * diffY - 0.5f * this.entityData.get(DELTA_ROT), (entityData.get(MELON) ? -2f : -3f) * (roll + 1), (entityData.get(MELON) ? 2f : 3f) * (roll + 1));
|
float addY = Mth.clamp(Math.min((this.onGround() ? 1.5f : 0.9f) * (float) Math.max(getDeltaMovement().length() - 0.06, 0.1), 0.9f) * diffY - 0.5f * this.entityData.get(DELTA_ROT), (entityData.get(MELON) ? -2f : -3f) * (roll + 1), (entityData.get(MELON) ? 2f : 3f) * (roll + 1));
|
||||||
float addX = Mth.clamp(Math.min((float) Math.max(getDeltaMovement().length() - 0.1, 0.01), 0.9f) * diffX, (entityData.get(MELON) ? -3f : -4f), (entityData.get(MELON) ? 3f : 4f));
|
float addX = Mth.clamp(Math.min((float) Math.max(getDeltaMovement().length() - 0.1, 0.01), 0.9f) * diffX, (entityData.get(MELON) ? -3f : -4f), (entityData.get(MELON) ? 3f : 4f));
|
||||||
|
@ -188,7 +189,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
|
||||||
|
|
||||||
MelonBombEntity melonBomb = new MelonBombEntity(player, player.level());
|
MelonBombEntity melonBomb = new MelonBombEntity(player, player.level());
|
||||||
melonBomb.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
melonBomb.setPos(worldPosition.x, worldPosition.y, worldPosition.z);
|
||||||
melonBomb.shoot(getDeltaMovement().x, getDeltaMovement().y, getDeltaMovement().z, (float)getDeltaMovement().length(), 0);
|
melonBomb.shoot(getDeltaMovement().x, getDeltaMovement().y, getDeltaMovement().z, (float) getDeltaMovement().length(), 0);
|
||||||
passenger.level().addFreshEntity(melonBomb);
|
passenger.level().addFreshEntity(melonBomb);
|
||||||
|
|
||||||
this.level().playSound(null, getOnPos(), SoundEvents.IRON_DOOR_OPEN, SoundSource.PLAYERS, 1, 1);
|
this.level().playSound(null, getOnPos(), SoundEvents.IRON_DOOR_OPEN, SoundSource.PLAYERS, 1, 1);
|
||||||
|
@ -203,7 +204,7 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
|
||||||
Mth.sin(-this.getYRot() * 0.017453292F) * (entityData.get(MELON) ? 0.16f : 0.19f) * this.entityData.get(POWER),
|
Mth.sin(-this.getYRot() * 0.017453292F) * (entityData.get(MELON) ? 0.16f : 0.19f) * this.entityData.get(POWER),
|
||||||
Mth.clamp(Math.sin((onGround() ? 45 : -(getXRot() - 30)) * Mth.DEG_TO_RAD) * getDeltaMovement().horizontalDistance() * (entityData.get(MELON) ? 0.047f : 0.067f), -0.04, 0.09),
|
Mth.clamp(Math.sin((onGround() ? 45 : -(getXRot() - 30)) * Mth.DEG_TO_RAD) * getDeltaMovement().horizontalDistance() * (entityData.get(MELON) ? 0.047f : 0.067f), -0.04, 0.09),
|
||||||
Mth.cos(this.getYRot() * 0.017453292F) * (entityData.get(MELON) ? 0.16f : 0.19f) * this.entityData.get(POWER)
|
Mth.cos(this.getYRot() * 0.017453292F) * (entityData.get(MELON) ? 0.16f : 0.19f) * this.entityData.get(POWER)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue