正确读取SELECTED_WEAPON,避免崩溃
This commit is contained in:
parent
6f9ecd0c51
commit
fd555460dd
1 changed files with 23 additions and 13 deletions
|
@ -235,6 +235,11 @@ public abstract class VehicleEntity extends Entity {
|
||||||
this.entityData.define(LAST_DRIVER_UUID, "undefined");
|
this.entityData.define(LAST_DRIVER_UUID, "undefined");
|
||||||
|
|
||||||
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
|
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
|
||||||
|
this.entityData.define(SELECTED_WEAPON, IntList.of(initSelectedWeaponArray(weaponVehicle)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int[] initSelectedWeaponArray(WeaponVehicleEntity weaponVehicle) {
|
||||||
this.availableWeapons = new VehicleWeapon[this.getMaxPassengers()][];
|
this.availableWeapons = new VehicleWeapon[this.getMaxPassengers()][];
|
||||||
|
|
||||||
var weapons = weaponVehicle.getAllWeapons();
|
var weapons = weaponVehicle.getAllWeapons();
|
||||||
|
@ -246,8 +251,8 @@ public abstract class VehicleEntity extends Entity {
|
||||||
for (int i = 0; i < this.getMaxPassengers(); i++) {
|
for (int i = 0; i < this.getMaxPassengers(); i++) {
|
||||||
selected[i] = weaponVehicle.hasWeapon(i) ? 0 : -1;
|
selected[i] = weaponVehicle.hasWeapon(i) ? 0 : -1;
|
||||||
}
|
}
|
||||||
this.entityData.define(SELECTED_WEAPON, IntList.of(selected));
|
|
||||||
}
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -258,9 +263,14 @@ public abstract class VehicleEntity extends Entity {
|
||||||
|
|
||||||
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
|
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
|
||||||
var selected = compound.getIntArray("SelectedWeapon");
|
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));
|
this.entityData.set(SELECTED_WEAPON, IntList.of(selected));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addAdditionalSaveData(CompoundTag compound) {
|
public void addAdditionalSaveData(CompoundTag compound) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue