From f441ca3dcfbeb83b1e7e245025e163395e2990ea Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 30 Dec 2024 17:16:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/atsuishio/superbwarfare/block/FuMO25Block.java | 8 +++++++- .../superbwarfare/block/entity/FuMO25BlockEntity.java | 9 ++++++++- .../superbwarfare/client/screens/FuMO25Screen.java | 3 +++ .../com/atsuishio/superbwarfare/menu/FuMO25Menu.java | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/block/FuMO25Block.java b/src/main/java/com/atsuishio/superbwarfare/block/FuMO25Block.java index 8d27c3e15..aaa2dc1d1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/FuMO25Block.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/FuMO25Block.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; +import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; @@ -50,7 +51,12 @@ public class FuMO25Block extends Block implements EntityBlock { @Override public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) { - return Shapes.or(box(1, 0, 1, 15, 1, 15), box(7, 1, 7, 9, 16, 9)); + return Shapes.or(box(1, 0, 1, 15, 6, 15), box(6, 6, 6, 10, 24, 10)); + } + + @Override + public RenderShape getRenderShape(BlockState pState) { + return RenderShape.MODEL; } @Nullable diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java index 7380aaa7e..d34f46b08 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/FuMO25BlockEntity.java @@ -45,12 +45,13 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider { public static final int DEFAULT_MIN_ENERGY = 64000; - public static final int MAX_DATA_COUNT = 3; + public static final int MAX_DATA_COUNT = 4; private LazyOptional energyHandler; public FuncType type = FuncType.NORMAL; public int time = 0; + public boolean powered = false; protected final ContainerEnergyData dataAccess = new ContainerEnergyData() { @@ -60,6 +61,7 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider { case 0 -> FuMO25BlockEntity.this.energyHandler.map(EnergyStorage::getEnergyStored).orElse(0); case 1 -> FuMO25BlockEntity.this.type.ordinal(); case 2 -> FuMO25BlockEntity.this.time; + case 3 -> FuMO25BlockEntity.this.powered ? 1 : 0; default -> 0; }; } @@ -71,6 +73,7 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider { FuMO25BlockEntity.this.energyHandler.ifPresent(handler -> handler.receiveEnergy((int) pValue, false)); case 1 -> FuMO25BlockEntity.this.type = FuncType.values()[(int) pValue]; case 2 -> FuMO25BlockEntity.this.time = (int) pValue; + case 3 -> FuMO25BlockEntity.this.powered = pValue == 1; } } @@ -99,6 +102,7 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider { if (energy < energyCost) { if (pState.getValue(FuMO25Block.POWERED)) { pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, false)); + blockEntity.powered = false; setChanged(pLevel, pPos, pState); } if (blockEntity.time > 0) { @@ -109,6 +113,7 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider { if (!pState.getValue(FuMO25Block.POWERED)) { if (energy >= DEFAULT_MIN_ENERGY) { pLevel.setBlockAndUpdate(pPos, pState.setValue(FuMO25Block.POWERED, true)); + blockEntity.powered = true; setChanged(pLevel, pPos, pState); } } else { @@ -156,6 +161,7 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider { } this.type = FuncType.values()[Mth.clamp(pTag.getInt("Type"), 0, 3)]; this.time = pTag.getInt("Time"); + this.powered = pTag.getBoolean("Powered"); } @Override @@ -165,6 +171,7 @@ public class FuMO25BlockEntity extends BlockEntity implements MenuProvider { getCapability(ForgeCapabilities.ENERGY).ifPresent(handler -> pTag.put("Energy", ((EnergyStorage) handler).serializeNBT())); pTag.putInt("Type", this.type.ordinal()); pTag.putInt("Time", this.time); + pTag.putBoolean("Powered", this.powered); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java b/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java index 7bcc7c1d0..375aa5224 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/screens/FuMO25Screen.java @@ -95,6 +95,7 @@ public class FuMO25Screen extends AbstractContainerScreen { if (entities == null || entities.isEmpty()) return; var pos = FuMO25ScreenHelper.pos; if (pos == null) return; + if (!FuMO25Screen.this.menu.isPowered()) return; int type = (int) FuMO25Screen.this.menu.getFuncType(); int range = type == 1 ? FuMO25BlockEntity.MAX_RANGE : FuMO25BlockEntity.DEFAULT_RANGE; @@ -121,6 +122,7 @@ public class FuMO25Screen extends AbstractContainerScreen { private void renderScan(GuiGraphics guiGraphics) { if (FuMO25Screen.this.menu.getEnergy() <= 0) return; + if (!FuMO25Screen.this.menu.isPowered()) return; var poseStack = guiGraphics.pose(); poseStack.pushPose(); @@ -179,6 +181,7 @@ public class FuMO25Screen extends AbstractContainerScreen { var pos = FuMO25ScreenHelper.pos; if (pos == null) return super.mouseClicked(pMouseX, pMouseY, pButton); if (pButton != 0) return super.mouseClicked(pMouseX, pMouseY, pButton); + if (!FuMO25Screen.this.menu.isPowered()) return super.mouseClicked(pMouseX, pMouseY, pButton); int type = (int) FuMO25Screen.this.menu.getFuncType(); int range = type == 1 ? FuMO25BlockEntity.MAX_RANGE : FuMO25BlockEntity.DEFAULT_RANGE; diff --git a/src/main/java/com/atsuishio/superbwarfare/menu/FuMO25Menu.java b/src/main/java/com/atsuishio/superbwarfare/menu/FuMO25Menu.java index d4d6ed1e9..7641f5808 100644 --- a/src/main/java/com/atsuishio/superbwarfare/menu/FuMO25Menu.java +++ b/src/main/java/com/atsuishio/superbwarfare/menu/FuMO25Menu.java @@ -185,6 +185,10 @@ public class FuMO25Menu extends EnergyMenu { return this.containerData.get(2); } + public boolean isPowered() { + return this.containerData.get(3) == 1; + } + static class ParaSlot extends Slot { public ParaSlot(Container pContainer, int pSlot, int pX, int pY) {