优化剩余载具弹药逻辑
This commit is contained in:
parent
23b225e56d
commit
c865f657e1
6 changed files with 126 additions and 116 deletions
|
@ -182,22 +182,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
if (decoyReloadCoolDown > 0) {
|
if (decoyReloadCoolDown > 0) {
|
||||||
decoyReloadCoolDown--;
|
decoyReloadCoolDown--;
|
||||||
}
|
}
|
||||||
if (this.getFirstPassenger() instanceof Player player) {
|
handleAmmo();
|
||||||
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);
|
|
||||||
reloadCoolDown = 25;
|
|
||||||
if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
|
||||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.ROCKET_70.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
|
||||||
}
|
|
||||||
this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getEntityData().get(WEAPON_TYPE) == 0) {
|
|
||||||
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum());
|
|
||||||
} else {
|
|
||||||
this.entityData.set(AMMO, this.getEntityData().get(LOADED_ROCKET));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.onGround()) {
|
if (this.onGround()) {
|
||||||
|
@ -221,6 +206,33 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleAmmo() {
|
||||||
|
if (!(this.getFirstPassenger() instanceof Player player)) return;
|
||||||
|
|
||||||
|
int ammoCount = this.getItemStacks().stream().filter(stack -> {
|
||||||
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
||||||
|
return stack.getOrCreateTag().getInt("HeavyAmmo") > 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).mapToInt(stack -> stack.getOrCreateTag().getInt("HeavyAmmo")).sum()
|
||||||
|
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum();
|
||||||
|
|
||||||
|
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);
|
||||||
|
reloadCoolDown = 25;
|
||||||
|
if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
||||||
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.ROCKET_70.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||||
|
}
|
||||||
|
this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getEntityData().get(WEAPON_TYPE) == 0) {
|
||||||
|
this.entityData.set(AMMO, ammoCount);
|
||||||
|
} else {
|
||||||
|
this.entityData.set(AMMO, this.getEntityData().get(LOADED_ROCKET));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void releaseDecoy() {
|
public void releaseDecoy() {
|
||||||
if (decoyInputDown) {
|
if (decoyInputDown) {
|
||||||
if (this.entityData.get(DECOY_COUNT) > 0 && this.level() instanceof ServerLevel) {
|
if (this.entityData.get(DECOY_COUNT) > 0 && this.level() instanceof ServerLevel) {
|
||||||
|
@ -520,6 +532,8 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void vehicleShoot(Player player) {
|
public void vehicleShoot(Player player) {
|
||||||
|
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||||
|
|
||||||
Matrix4f transform = getVehicleTransform();
|
Matrix4f transform = getVehicleTransform();
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
|
@ -538,7 +552,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
worldPositionRight = transformPosition(transform, -x, y, z);
|
worldPositionRight = transformPosition(transform, -x, y, z);
|
||||||
worldPositionLeft = transformPosition(transform, x, y, z);
|
worldPositionLeft = transformPosition(transform, x, y, z);
|
||||||
|
|
||||||
if (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
ProjectileEntity projectileRight = new ProjectileEntity(player.level())
|
ProjectileEntity projectileRight = new ProjectileEntity(player.level())
|
||||||
.shooter(player)
|
.shooter(player)
|
||||||
.damage(VehicleConfig.AH_6_CANNON_DAMAGE.get())
|
.damage(VehicleConfig.AH_6_CANNON_DAMAGE.get())
|
||||||
|
@ -557,7 +571,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
ProjectileEntity projectileLeft = new ProjectileEntity(player.level())
|
ProjectileEntity projectileLeft = new ProjectileEntity(player.level())
|
||||||
.shooter(player)
|
.shooter(player)
|
||||||
.damage(VehicleConfig.AH_6_CANNON_DAMAGE.get())
|
.damage(VehicleConfig.AH_6_CANNON_DAMAGE.get())
|
||||||
|
@ -571,9 +585,22 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
(float) 0.2);
|
(float) 0.2);
|
||||||
this.level().addFreshEntity(projectileLeft);
|
this.level().addFreshEntity(projectileLeft);
|
||||||
sendParticle((ServerLevel) this.level(), ParticleTypes.LARGE_SMOKE, worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z, 1, 0, 0, 0, 0, false);
|
sendParticle((ServerLevel) this.level(), ParticleTypes.LARGE_SMOKE, worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z, 1, 0, 0, 0, 0, false);
|
||||||
if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
|
||||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
if (!hasCreativeAmmo) {
|
||||||
|
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
|
||||||
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
||||||
|
return stack.getOrCreateTag().getInt("HeavyAmmo") > 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).findFirst().orElse(ItemStack.EMPTY);
|
||||||
|
|
||||||
|
if (!ammoBox.isEmpty()) {
|
||||||
|
ammoBox.getOrCreateTag().putInt("HeavyAmmo", java.lang.Math.max(0, ammoBox.getOrCreateTag().getInt("HeavyAmmo") - 1));
|
||||||
|
} else {
|
||||||
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!player.level().isClientSide) {
|
if (!player.level().isClientSide) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.WgMissileEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.WgMissileEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
|
||||||
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
|
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
|
||||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
|
@ -67,7 +66,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> COAX_HEAT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> COAX_HEAT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> LOADED_COAX_AMMO = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
|
||||||
public static final EntityDataAccessor<Integer> LOADED_MISSILE = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> LOADED_MISSILE = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> WEAPON_TYPE = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> WEAPON_TYPE = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Float> TRACK_L = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.FLOAT);
|
public static final EntityDataAccessor<Float> TRACK_L = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.FLOAT);
|
||||||
|
@ -107,7 +105,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
this.entityData.define(HEAT, 0);
|
this.entityData.define(HEAT, 0);
|
||||||
this.entityData.define(COAX_HEAT, 0);
|
this.entityData.define(COAX_HEAT, 0);
|
||||||
this.entityData.define(WEAPON_TYPE, 0);
|
this.entityData.define(WEAPON_TYPE, 0);
|
||||||
this.entityData.define(LOADED_COAX_AMMO, 0);
|
|
||||||
this.entityData.define(LOADED_MISSILE, 0);
|
this.entityData.define(LOADED_MISSILE, 0);
|
||||||
this.entityData.define(TRACK_L, 0f);
|
this.entityData.define(TRACK_L, 0f);
|
||||||
this.entityData.define(TRACK_R, 0f);
|
this.entityData.define(TRACK_R, 0f);
|
||||||
|
@ -116,14 +113,12 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
@Override
|
@Override
|
||||||
public void addAdditionalSaveData(CompoundTag compound) {
|
public void addAdditionalSaveData(CompoundTag compound) {
|
||||||
super.addAdditionalSaveData(compound);
|
super.addAdditionalSaveData(compound);
|
||||||
compound.putInt("LoadedCoaxAmmo", this.entityData.get(LOADED_COAX_AMMO));
|
|
||||||
compound.putInt("LoadedMissile", this.entityData.get(LOADED_MISSILE));
|
compound.putInt("LoadedMissile", this.entityData.get(LOADED_MISSILE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readAdditionalSaveData(CompoundTag compound) {
|
public void readAdditionalSaveData(CompoundTag compound) {
|
||||||
super.readAdditionalSaveData(compound);
|
super.readAdditionalSaveData(compound);
|
||||||
this.entityData.set(LOADED_COAX_AMMO, compound.getInt("LoadedCoaxAmmo"));
|
|
||||||
this.entityData.set(LOADED_MISSILE, compound.getInt("LoadedMissile"));
|
this.entityData.set(LOADED_MISSILE, compound.getInt("LoadedMissile"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,9 +277,8 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
return stack.getOrCreateTag().getInt("RifleAmmo") > 0;
|
return stack.getOrCreateTag().getInt("RifleAmmo") > 0;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}).mapToInt(stack -> stack.getOrCreateTag().getInt("RifleAmmo")).sum();
|
}).mapToInt(stack -> stack.getOrCreateTag().getInt("RifleAmmo")).sum()
|
||||||
|
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).mapToInt(ItemStack::getCount).sum();
|
||||||
this.entityData.set(LOADED_COAX_AMMO, ammoCount);
|
|
||||||
|
|
||||||
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.WIRE_GUIDE_MISSILE.get())).mapToInt(ItemStack::getCount).sum() > 0
|
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.WIRE_GUIDE_MISSILE.get())).mapToInt(ItemStack::getCount).sum() > 0
|
||||||
|| player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())))
|
|| player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())))
|
||||||
|
@ -300,7 +294,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
if (this.getEntityData().get(WEAPON_TYPE) == 0) {
|
if (this.getEntityData().get(WEAPON_TYPE) == 0) {
|
||||||
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).mapToInt(ItemStack::getCount).sum());
|
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).mapToInt(ItemStack::getCount).sum());
|
||||||
} else if (this.getEntityData().get(WEAPON_TYPE) == 1) {
|
} else if (this.getEntityData().get(WEAPON_TYPE) == 1) {
|
||||||
this.entityData.set(AMMO, this.getEntityData().get(LOADED_COAX_AMMO));
|
this.entityData.set(AMMO, ammoCount);
|
||||||
} else {
|
} else {
|
||||||
this.entityData.set(AMMO, this.getEntityData().get(LOADED_MISSILE));
|
this.entityData.set(AMMO, this.getEntityData().get(LOADED_MISSILE));
|
||||||
}
|
}
|
||||||
|
@ -314,15 +308,6 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean zooming() {
|
|
||||||
Entity driver = this.getFirstPassenger();
|
|
||||||
if (driver == null) return false;
|
|
||||||
if (driver instanceof Player player) {
|
|
||||||
return player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void vehicleShoot(Player player) {
|
public void vehicleShoot(Player player) {
|
||||||
Matrix4f transform = getBarrelTransform();
|
Matrix4f transform = getBarrelTransform();
|
||||||
|
@ -376,7 +361,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
||||||
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||||
|
|
||||||
if (this.entityData.get(LOADED_COAX_AMMO) > 0 || hasCreativeAmmo) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
ProjectileEntity projectileRight = new ProjectileEntity(player.level())
|
ProjectileEntity projectileRight = new ProjectileEntity(player.level())
|
||||||
.shooter(player)
|
.shooter(player)
|
||||||
.damage(9.5f)
|
.damage(9.5f)
|
||||||
|
@ -399,6 +384,8 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
|
|
||||||
if (!ammoBox.isEmpty()) {
|
if (!ammoBox.isEmpty()) {
|
||||||
ammoBox.getOrCreateTag().putInt("RifleAmmo", Math.max(0, ammoBox.getOrCreateTag().getInt("RifleAmmo") - 1));
|
ammoBox.getOrCreateTag().putInt("RifleAmmo", Math.max(0, ammoBox.getOrCreateTag().getInt("RifleAmmo") - 1));
|
||||||
|
} else {
|
||||||
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,7 +736,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
if (entityData.get(WEAPON_TYPE) == 0) {
|
if (entityData.get(WEAPON_TYPE) == 0) {
|
||||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
|
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
|
||||||
} else if (entityData.get(WEAPON_TYPE) == 1) {
|
} else if (entityData.get(WEAPON_TYPE) == 1) {
|
||||||
return (this.entityData.get(LOADED_COAX_AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
|
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
|
||||||
} else if (entityData.get(WEAPON_TYPE) == 2) {
|
} else if (entityData.get(WEAPON_TYPE) == 2) {
|
||||||
return (this.entityData.get(LOADED_MISSILE) > 0);
|
return (this.entityData.get(LOADED_MISSILE) > 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
|
import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity;
|
||||||
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier;
|
||||||
import com.atsuishio.superbwarfare.init.*;
|
import com.atsuishio.superbwarfare.init.*;
|
||||||
import com.atsuishio.superbwarfare.network.ModVariables;
|
|
||||||
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
|
import com.atsuishio.superbwarfare.network.message.ShakeClientMessage;
|
||||||
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
import com.atsuishio.superbwarfare.tools.CustomExplosion;
|
||||||
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
|
||||||
|
@ -69,7 +68,6 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> COAX_HEAT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> COAX_HEAT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
||||||
public static final EntityDataAccessor<Integer> LOADED_COAX_AMMO = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
|
||||||
public static final EntityDataAccessor<Integer> WEAPON_TYPE = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
public static final EntityDataAccessor<Integer> WEAPON_TYPE = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT);
|
||||||
|
|
||||||
public static final float MAX_HEALTH = VehicleConfig.LAV_150_HP.get();
|
public static final float MAX_HEALTH = VehicleConfig.LAV_150_HP.get();
|
||||||
|
@ -107,19 +105,16 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
this.entityData.define(HEAT, 0);
|
this.entityData.define(HEAT, 0);
|
||||||
this.entityData.define(COAX_HEAT, 0);
|
this.entityData.define(COAX_HEAT, 0);
|
||||||
this.entityData.define(WEAPON_TYPE, 0);
|
this.entityData.define(WEAPON_TYPE, 0);
|
||||||
this.entityData.define(LOADED_COAX_AMMO, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAdditionalSaveData(CompoundTag compound) {
|
public void addAdditionalSaveData(CompoundTag compound) {
|
||||||
super.addAdditionalSaveData(compound);
|
super.addAdditionalSaveData(compound);
|
||||||
compound.putInt("LoadedCoaxAmmo", this.entityData.get(LOADED_COAX_AMMO));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readAdditionalSaveData(CompoundTag compound) {
|
public void readAdditionalSaveData(CompoundTag compound) {
|
||||||
super.readAdditionalSaveData(compound);
|
super.readAdditionalSaveData(compound);
|
||||||
this.entityData.set(LOADED_COAX_AMMO, compound.getInt("LoadedCoaxAmmo"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -194,28 +189,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
if (this.getFirstPassenger() instanceof Player) {
|
this.handleAmmo();
|
||||||
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.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO_BOX.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
|
||||||
}
|
|
||||||
if ((this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.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) + 5);
|
|
||||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.getEntityData().get(WEAPON_TYPE) == 0) {
|
|
||||||
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).mapToInt(ItemStack::getCount).sum());
|
|
||||||
} else {
|
|
||||||
this.entityData.set(AMMO, this.getEntityData().get(LOADED_COAX_AMMO));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (this.level() instanceof ServerLevel) {
|
|
||||||
// this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum());
|
|
||||||
// }
|
|
||||||
|
|
||||||
Entity driver = this.getFirstPassenger();
|
Entity driver = this.getFirstPassenger();
|
||||||
if (driver instanceof Player player) {
|
if (driver instanceof Player player) {
|
||||||
if (this.entityData.get(HEAT) > 100) {
|
if (this.entityData.get(HEAT) > 100) {
|
||||||
|
@ -269,46 +245,31 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
collideHardBlock();
|
collideHardBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gunnerAngle();
|
gunnerAngle();
|
||||||
lowHealthWarning();
|
lowHealthWarning();
|
||||||
|
|
||||||
// Matrix4f transform = getVehicleTransform();
|
|
||||||
// 暂时屁用没有的点位计算
|
|
||||||
// Vector4f worldPosition1 = transformPosition(transform, 1.6f, 3f, 4);
|
|
||||||
// Vector4f worldPosition2 = transformPosition(transform, -1.6f, 3f, 4);
|
|
||||||
// Vector4f worldPosition3 = transformPosition(transform, 1.6f, 3f, -4);
|
|
||||||
// Vector4f worldPosition4 = transformPosition(transform, -1.6f, 3f, -4);
|
|
||||||
// Vector4f worldPosition5 = transformPosition(transform, 1.6f, 0.1f, 4);
|
|
||||||
// Vector4f worldPosition6 = transformPosition(transform, -1.6f, 0.1f, 4);
|
|
||||||
// Vector4f worldPosition7 = transformPosition(transform, 1.6f, 0.1f, -4);
|
|
||||||
// Vector4f worldPosition8 = transformPosition(transform, -1.6f, 0.1f, -4);
|
|
||||||
//
|
|
||||||
// Vec3 p1 = new Vec3(worldPosition1.x,worldPosition1.y,worldPosition1.z);
|
|
||||||
// Vec3 p2 = new Vec3(worldPosition2.x,worldPosition2.y,worldPosition2.z);
|
|
||||||
// Vec3 p3 = new Vec3(worldPosition3.x,worldPosition3.y,worldPosition3.z);
|
|
||||||
// Vec3 p4 = new Vec3(worldPosition4.x,worldPosition4.y,worldPosition4.z);
|
|
||||||
// Vec3 p5 = new Vec3(worldPosition5.x,worldPosition5.y,worldPosition5.z);
|
|
||||||
// Vec3 p6 = new Vec3(worldPosition6.x,worldPosition6.y,worldPosition6.z);
|
|
||||||
// Vec3 p7 = new Vec3(worldPosition7.x,worldPosition7.y,worldPosition7.z);
|
|
||||||
// Vec3 p8 = new Vec3(worldPosition8.x,worldPosition8.y,worldPosition8.z);
|
|
||||||
//
|
|
||||||
// if (player != null) {
|
|
||||||
// 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, p2.x, p2.y, p2.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
|
||||||
// sendParticle(serverLevel, ParticleTypes.END_ROD, p3.x, p3.y, p3.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
|
||||||
// sendParticle(serverLevel, ParticleTypes.END_ROD, p4.x, p4.y, p4.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
|
||||||
// sendParticle(serverLevel, ParticleTypes.END_ROD, p5.x, p5.y, p5.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
|
||||||
// sendParticle(serverLevel, ParticleTypes.END_ROD, p6.x, p6.y, p6.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
|
||||||
// sendParticle(serverLevel, ParticleTypes.END_ROD, p7.x, p7.y, p7.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
|
||||||
// sendParticle(serverLevel, ParticleTypes.END_ROD, p8.x, p8.y, p8.z, (int) (2 + 4 * this.getDeltaMovement().length()), 0, 0, 0, 0, true);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleAmmo() {
|
||||||
|
if (!(this.getFirstPassenger() instanceof Player player)) return;
|
||||||
|
|
||||||
|
int ammoCount = this.getItemStacks().stream().filter(stack -> {
|
||||||
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
||||||
|
return stack.getOrCreateTag().getInt("RifleAmmo") > 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).mapToInt(stack -> stack.getOrCreateTag().getInt("RifleAmmo")).sum()
|
||||||
|
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).mapToInt(ItemStack::getCount).sum();
|
||||||
|
|
||||||
|
|
||||||
|
if (this.getEntityData().get(WEAPON_TYPE) == 0) {
|
||||||
|
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).mapToInt(ItemStack::getCount).sum());
|
||||||
|
} else if (this.getEntityData().get(WEAPON_TYPE) == 1) {
|
||||||
|
this.entityData.set(AMMO, ammoCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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);
|
||||||
|
@ -317,17 +278,10 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean zooming() {
|
|
||||||
Entity driver = this.getFirstPassenger();
|
|
||||||
if (driver == null) return false;
|
|
||||||
if (driver instanceof Player player) {
|
|
||||||
return player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).zoom;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void vehicleShoot(Player player) {
|
public void vehicleShoot(Player player) {
|
||||||
|
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||||
|
|
||||||
Matrix4f transform = getBarrelTransform();
|
Matrix4f transform = getBarrelTransform();
|
||||||
if (entityData.get(WEAPON_TYPE) == 0) {
|
if (entityData.get(WEAPON_TYPE) == 0) {
|
||||||
if (this.cannotFire) return;
|
if (this.cannotFire) return;
|
||||||
|
@ -379,7 +333,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
|
|
||||||
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
||||||
|
|
||||||
if (this.entityData.get(LOADED_COAX_AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
ProjectileEntity projectileRight = new ProjectileEntity(player.level())
|
ProjectileEntity projectileRight = new ProjectileEntity(player.level())
|
||||||
.shooter(player)
|
.shooter(player)
|
||||||
.damage(9.5f)
|
.damage(9.5f)
|
||||||
|
@ -392,8 +346,19 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
0.25f);
|
0.25f);
|
||||||
this.level().addFreshEntity(projectileRight);
|
this.level().addFreshEntity(projectileRight);
|
||||||
|
|
||||||
if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) {
|
if (!hasCreativeAmmo) {
|
||||||
this.entityData.set(LOADED_COAX_AMMO, this.getEntityData().get(LOADED_COAX_AMMO) - 1);
|
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
|
||||||
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
||||||
|
return stack.getOrCreateTag().getInt("RifleAmmo") > 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).findFirst().orElse(ItemStack.EMPTY);
|
||||||
|
|
||||||
|
if (!ammoBox.isEmpty()) {
|
||||||
|
ammoBox.getOrCreateTag().putInt("RifleAmmo", java.lang.Math.max(0, ammoBox.getOrCreateTag().getInt("RifleAmmo") - 1));
|
||||||
|
} else {
|
||||||
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.RIFLE_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -718,7 +683,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
if (entityData.get(WEAPON_TYPE) == 0) {
|
if (entityData.get(WEAPON_TYPE) == 0) {
|
||||||
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
|
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire;
|
||||||
} else if (entityData.get(WEAPON_TYPE) == 1) {
|
} else if (entityData.get(WEAPON_TYPE) == 1) {
|
||||||
return (this.entityData.get(LOADED_COAX_AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
|
return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.level() instanceof ServerLevel) {
|
if (this.level() instanceof ServerLevel) {
|
||||||
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum());
|
this.handleAmmo();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity driver = this.getFirstPassenger();
|
Entity driver = this.getFirstPassenger();
|
||||||
|
@ -198,6 +198,21 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
|
||||||
this.refreshDimensions();
|
this.refreshDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleAmmo() {
|
||||||
|
if (!(this.getFirstPassenger() instanceof Player player)) return;
|
||||||
|
|
||||||
|
int ammoCount = this.getItemStacks().stream().filter(stack -> {
|
||||||
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
||||||
|
return stack.getOrCreateTag().getInt("HeavyAmmo") > 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).mapToInt(stack -> stack.getOrCreateTag().getInt("HeavyAmmo")).sum()
|
||||||
|
+ this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).mapToInt(ItemStack::getCount).sum();
|
||||||
|
|
||||||
|
|
||||||
|
this.entityData.set(AMMO, ammoCount);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean zooming() {
|
public boolean zooming() {
|
||||||
Entity driver = this.getFirstPassenger();
|
Entity driver = this.getFirstPassenger();
|
||||||
if (driver == null) return false;
|
if (driver == null) return false;
|
||||||
|
@ -247,7 +262,23 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
|
||||||
|
|
||||||
this.entityData.set(HEAT, this.entityData.get(HEAT) + 3);
|
this.entityData.set(HEAT, this.entityData.get(HEAT) + 3);
|
||||||
this.entityData.set(FIRE_ANIM, 3);
|
this.entityData.set(FIRE_ANIM, 3);
|
||||||
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
|
||||||
|
boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()));
|
||||||
|
|
||||||
|
if (!hasCreativeAmmo) {
|
||||||
|
ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> {
|
||||||
|
if (stack.is(ModItems.AMMO_BOX.get())) {
|
||||||
|
return stack.getOrCreateTag().getInt("HeavyAmmo") > 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).findFirst().orElse(ItemStack.EMPTY);
|
||||||
|
|
||||||
|
if (!ammoBox.isEmpty()) {
|
||||||
|
ammoBox.getOrCreateTag().putInt("HeavyAmmo", java.lang.Math.max(0, ammoBox.getOrCreateTag().getInt("HeavyAmmo") - 1));
|
||||||
|
} else {
|
||||||
|
this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -467,7 +467,7 @@
|
||||||
"tips.superbwarfare.shoot.rings": "Rings",
|
"tips.superbwarfare.shoot.rings": "Rings",
|
||||||
"tips.superbwarfare.annihilator.energy_not_enough": "Energy is Not Enough",
|
"tips.superbwarfare.annihilator.energy_not_enough": "Energy is Not Enough",
|
||||||
"tips.superbwarfare.target.down": "Target Down %1$s",
|
"tips.superbwarfare.target.down": "Target Down %1$s",
|
||||||
"tips.superbwarfare.target.damage": "Damage: %1$s Distance: %2$s",
|
"tips.superbwarfare.target.damage": "Damage: %1$s Distance: %2$sm",
|
||||||
"tips.superbwarfare.mortar.range": "Range: ",
|
"tips.superbwarfare.mortar.range": "Range: ",
|
||||||
"tips.superbwarfare.mortar.yaw": "Yaw:",
|
"tips.superbwarfare.mortar.yaw": "Yaw:",
|
||||||
"tips.superbwarfare.mortar.pitch": "Pitch:",
|
"tips.superbwarfare.mortar.pitch": "Pitch:",
|
||||||
|
|
|
@ -465,7 +465,7 @@
|
||||||
"tips.superbwarfare.shoot.rings": "环",
|
"tips.superbwarfare.shoot.rings": "环",
|
||||||
"tips.superbwarfare.annihilator.energy_not_enough": "能量不足",
|
"tips.superbwarfare.annihilator.energy_not_enough": "能量不足",
|
||||||
"tips.superbwarfare.target.down": "击倒目标 %1$s",
|
"tips.superbwarfare.target.down": "击倒目标 %1$s",
|
||||||
"tips.superbwarfare.target.damage": "伤害:%1$s 距离:%2$s M",
|
"tips.superbwarfare.target.damage": "伤害:%1$s 距离:%2$sm",
|
||||||
"tips.superbwarfare.mortar.range": "射程:",
|
"tips.superbwarfare.mortar.range": "射程:",
|
||||||
"tips.superbwarfare.mortar.yaw": "水平朝向:",
|
"tips.superbwarfare.mortar.yaw": "水平朝向:",
|
||||||
"tips.superbwarfare.mortar.pitch": "俯仰角度:",
|
"tips.superbwarfare.mortar.pitch": "俯仰角度:",
|
||||||
|
|
Loading…
Add table
Reference in a new issue