正确缓存getAllWeapons
This commit is contained in:
parent
314ba3056a
commit
2cd30a58a5
10 changed files with 30 additions and 15 deletions
|
@ -90,7 +90,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
new ProjectileWeapon()
|
||||
|
|
|
@ -87,7 +87,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
new LaserWeapon()
|
||||
|
|
|
@ -77,7 +77,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
new SmallCannonShellWeapon()
|
||||
|
|
|
@ -71,7 +71,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
new SmallCannonShellWeapon()
|
||||
|
|
|
@ -79,7 +79,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
new CannonShellWeapon()
|
||||
|
|
|
@ -72,7 +72,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
new CannonShellWeapon()
|
||||
|
|
|
@ -66,7 +66,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
new ProjectileWeapon()
|
||||
|
|
|
@ -86,7 +86,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
|||
}
|
||||
|
||||
@Override
|
||||
public VehicleWeapon[][] getAllWeapons() {
|
||||
public VehicleWeapon[][] initWeapons() {
|
||||
return new VehicleWeapon[][]{
|
||||
new VehicleWeapon[]{
|
||||
// AP
|
||||
|
|
|
@ -252,12 +252,8 @@ public abstract class VehicleEntity extends Entity {
|
|||
}
|
||||
|
||||
private int[] initSelectedWeaponArray(WeaponVehicleEntity weaponVehicle) {
|
||||
this.availableWeapons = new VehicleWeapon[this.getMaxPassengers()][];
|
||||
|
||||
var weapons = weaponVehicle.getAllWeapons();
|
||||
for (int i = 0; i < weapons.length && i < this.getMaxPassengers(); i++) {
|
||||
this.availableWeapons[i] = weapons[i];
|
||||
}
|
||||
// 初始化武器数组
|
||||
weaponVehicle.getAllWeapons();
|
||||
|
||||
var selected = new int[this.getMaxPassengers()];
|
||||
for (int i = 0; i < this.getMaxPassengers(); i++) {
|
||||
|
@ -277,6 +273,7 @@ public abstract class VehicleEntity extends Entity {
|
|||
var selected = compound.getIntArray("SelectedWeapon");
|
||||
|
||||
if (selected.length != this.getMaxPassengers()) {
|
||||
// 数量不符时(可能是更新或遇到损坏数据),重新初始化已选择武器
|
||||
this.entityData.set(SELECTED_WEAPON, IntList.of(initSelectedWeaponArray(weaponVehicle)));
|
||||
} else {
|
||||
this.entityData.set(SELECTED_WEAPON, IntList.of(selected));
|
||||
|
|
|
@ -54,7 +54,25 @@ public interface WeaponVehicleEntity extends ArmedVehicleEntity {
|
|||
/**
|
||||
* 获取所有可用武器列表
|
||||
*/
|
||||
VehicleWeapon[][] getAllWeapons();
|
||||
default VehicleWeapon[][] getAllWeapons() {
|
||||
if (!(this instanceof VehicleEntity vehicle)) return new VehicleWeapon[][]{};
|
||||
|
||||
if (vehicle.availableWeapons == null) {
|
||||
vehicle.availableWeapons = new VehicleWeapon[vehicle.getMaxPassengers()][];
|
||||
|
||||
var weapons = this.initWeapons();
|
||||
for (int i = 0; i < weapons.length && i < vehicle.getMaxPassengers(); i++) {
|
||||
vehicle.availableWeapons[i] = weapons[i];
|
||||
}
|
||||
}
|
||||
|
||||
return vehicle.availableWeapons;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化所有可用武器列表
|
||||
*/
|
||||
VehicleWeapon[][] initWeapons();
|
||||
|
||||
/**
|
||||
* 获取该槽位可用的武器列表
|
||||
|
|
Loading…
Add table
Reference in a new issue