From b199d275e31bdacd771d755ecc4df2c95e261524 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Thu, 19 Dec 2024 16:49:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=85=E7=94=B5=E7=AB=99?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=9D=97=E5=85=85=E8=83=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/ChargingStationBlockEntity.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) 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; }