diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/ChargingStationBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/ChargingStationBlockEntity.java index 24fb72f46..f8146803e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/ChargingStationBlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/ChargingStationBlockEntity.java @@ -44,10 +44,6 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo protected static final int SLOT_FUEL = 0; protected static final int SLOT_CHARGE = 1; - private static final int[] SLOTS_FOR_UP = new int[]{0}; - private static final int[] SLOTS_FOR_SIDES = new int[]{0}; - private static final int[] SLOTS_FOR_DOWN = new int[]{0}; - public static final int MAX_ENERGY = 4000000; public static final int MAX_DATA_COUNT = 3; public static final int DEFAULT_FUEL_TIME = 1600; @@ -111,6 +107,9 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo if (handler.getEnergyStored() > 0) { blockEntity.chargeItemStack(handler); } + if (handler.getEnergyStored() > 0) { + blockEntity.chargeBlock(handler); + } }); if (blockEntity.fuelTick > 0) { @@ -184,6 +183,27 @@ public class ChargingStationBlockEntity extends BlockEntity implements WorldlyCo this.setChanged(); } + private void chargeBlock(EnergyStorage handler) { + if (this.level == null) return; + + for (Direction direction : Direction.values()) { + var blockEntity = this.level.getBlockEntity(this.getBlockPos().relative(direction)); + if (blockEntity == null || !blockEntity.getCapability(ForgeCapabilities.ENERGY).isPresent() || blockEntity instanceof ChargingStationBlockEntity) { + continue; + } + + blockEntity.getCapability(ForgeCapabilities.ENERGY).ifPresent(energy -> { + if (energy.canReceive() && energy.getEnergyStored() < energy.getMaxEnergyStored()) { + int receiveEnergy = energy.receiveEnergy(Math.min(handler.getEnergyStored(), CHARGE_OTHER_SPEED), false); + handler.extractEnergy(receiveEnergy, false); + + blockEntity.setChanged(); + this.setChanged(); + } + }); + } + } + public NonNullList getItems() { return this.items; }