Fix battery bank not marking chunks dirty
This commit is contained in:
parent
eadf061f15
commit
2d51a5e2c5
@ -68,7 +68,13 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public record BatteryBankEnergy(BlockEntityBatteryBank tile, BankMode mode) implements IMatteryEnergyStorage {
|
public class BatteryBankEnergy implements IMatteryEnergyStorage {
|
||||||
|
private final BankMode mode;
|
||||||
|
|
||||||
|
public BatteryBankEnergy(BankMode mode) {
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
public enum BankMode {
|
public enum BankMode {
|
||||||
RECEIVE,
|
RECEIVE,
|
||||||
EXTRACT,
|
EXTRACT,
|
||||||
@ -95,11 +101,11 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BatteryBankDistribution getDistribution(boolean mode) {
|
BatteryBankDistribution getDistribution(boolean mode) {
|
||||||
Fraction[] distribution = new Fraction[tile.battery_container.getContainerSize()];
|
Fraction[] distribution = new Fraction[battery_container.getContainerSize()];
|
||||||
Fraction summ = Fraction.ZERO;
|
Fraction summ = Fraction.ZERO;
|
||||||
|
|
||||||
for (int i = 0; i < tile.battery_container.getContainerSize(); i++) {
|
for (int i = 0; i < battery_container.getContainerSize(); i++) {
|
||||||
ItemStack stack = tile.battery_container.getItem(i);
|
ItemStack stack = battery_container.getItem(i);
|
||||||
|
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
||||||
@ -123,7 +129,7 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (summ.compareTo(Fraction.ZERO) != 0) {
|
if (summ.compareTo(Fraction.ZERO) != 0) {
|
||||||
for (int i = 0; i < tile.battery_container.getContainerSize(); i++) {
|
for (int i = 0; i < battery_container.getContainerSize(); i++) {
|
||||||
distribution[i] = distribution[i].div(summ);
|
distribution[i] = distribution[i].div(summ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,9 +146,9 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
Fraction[] distList = distribution.distribution;
|
Fraction[] distList = distribution.distribution;
|
||||||
Fraction summ = Fraction.ZERO;
|
Fraction summ = Fraction.ZERO;
|
||||||
|
|
||||||
for (int i = 0; i < tile.battery_container.getContainerSize(); i++) {
|
for (int i = 0; i < battery_container.getContainerSize(); i++) {
|
||||||
if (!distList[i].equals(Fraction.ZERO)) {
|
if (!distList[i].equals(Fraction.ZERO)) {
|
||||||
ItemStack stack = tile.battery_container.getItem(i);
|
ItemStack stack = battery_container.getItem(i);
|
||||||
|
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
||||||
@ -162,6 +168,10 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!simulate && !summ.isZero()) {
|
||||||
|
setChangedLight();
|
||||||
|
}
|
||||||
|
|
||||||
return summ;
|
return summ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +201,8 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
public Fraction getBatteryLevel() {
|
public Fraction getBatteryLevel() {
|
||||||
Fraction result = Fraction.ZERO;
|
Fraction result = Fraction.ZERO;
|
||||||
|
|
||||||
for (int i = 0; i < tile.battery_container.getContainerSize(); i++) {
|
for (int i = 0; i < battery_container.getContainerSize(); i++) {
|
||||||
ItemStack stack = tile.battery_container.getItem(i);
|
ItemStack stack = battery_container.getItem(i);
|
||||||
|
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
||||||
@ -217,8 +227,8 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
public Fraction getMaxBatteryLevel() {
|
public Fraction getMaxBatteryLevel() {
|
||||||
Fraction result = Fraction.ZERO;
|
Fraction result = Fraction.ZERO;
|
||||||
|
|
||||||
for (int i = 0; i < tile.battery_container.getContainerSize(); i++) {
|
for (int i = 0; i < battery_container.getContainerSize(); i++) {
|
||||||
ItemStack stack = tile.battery_container.getItem(i);
|
ItemStack stack = battery_container.getItem(i);
|
||||||
|
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
Optional<IMatteryEnergyStorage> cap = stack.getCapability(MatteryCapability.ENERGY).resolve();
|
||||||
@ -239,13 +249,13 @@ public class BlockEntityBatteryBank extends BlockEntityMattery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final BatteryBankEnergy energy_receiver = new BatteryBankEnergy(this, BatteryBankEnergy.BankMode.RECEIVE);
|
public final BatteryBankEnergy energy_receiver = new BatteryBankEnergy(BatteryBankEnergy.BankMode.RECEIVE);
|
||||||
private LazyOptional<BatteryBankEnergy> energy_receiver_resolver = LazyOptional.of(() -> energy_receiver);
|
private LazyOptional<BatteryBankEnergy> energy_receiver_resolver = LazyOptional.of(() -> energy_receiver);
|
||||||
|
|
||||||
public final BatteryBankEnergy energy_extractor = new BatteryBankEnergy(this, BatteryBankEnergy.BankMode.EXTRACT);
|
public final BatteryBankEnergy energy_extractor = new BatteryBankEnergy(BatteryBankEnergy.BankMode.EXTRACT);
|
||||||
private LazyOptional<BatteryBankEnergy> energy_extractor_resolver = LazyOptional.of(() -> energy_extractor);
|
private LazyOptional<BatteryBankEnergy> energy_extractor_resolver = LazyOptional.of(() -> energy_extractor);
|
||||||
|
|
||||||
public final BatteryBankEnergy energy = new BatteryBankEnergy(this, BatteryBankEnergy.BankMode.BIDIRECTIONAL);
|
public final BatteryBankEnergy energy = new BatteryBankEnergy(BatteryBankEnergy.BankMode.BIDIRECTIONAL);
|
||||||
private LazyOptional<BatteryBankEnergy> energy_resolver = LazyOptional.of(() -> energy);
|
private LazyOptional<BatteryBankEnergy> energy_resolver = LazyOptional.of(() -> energy);
|
||||||
|
|
||||||
protected boolean valid = true;
|
protected boolean valid = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user