From c827d01c1ad5af24576f71520aeb7f5ba78968aa Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Fri, 11 Apr 2025 21:16:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E9=80=A0=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=85=85=E7=94=B5=E7=AB=99=E7=9A=84=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E6=98=BE=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../block/CreativeChargingStationBlock.java | 5 +++-- .../CreativeChargingStationBlockEntity.java | 22 ++++++++++++++++--- ...iveChargingStationBlockEntityRenderer.java | 4 ++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/block/CreativeChargingStationBlock.java b/src/main/java/com/atsuishio/superbwarfare/block/CreativeChargingStationBlock.java index bc993b06b..93fff1373 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/CreativeChargingStationBlock.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/CreativeChargingStationBlock.java @@ -70,7 +70,7 @@ public class CreativeChargingStationBlock extends BaseEntityBlock { if (!pLevel.isClientSide) { return createTickerHelper( pBlockEntityType, ModBlockEntities.CREATIVE_CHARGING_STATION.get(), - (pLevel1, pPos, pState1, blockEntity) -> CreativeChargingStationBlockEntity.serverTick(blockEntity) + CreativeChargingStationBlockEntity::serverTick ); } return null; @@ -91,6 +91,8 @@ public class CreativeChargingStationBlock extends BaseEntityBlock { @Override @ParametersAreNonnullByDefault protected @NotNull ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hitResult) { + if (stack.isEmpty()) return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); if (cap == null) return ItemInteractionResult.FAIL; @@ -114,7 +116,6 @@ public class CreativeChargingStationBlock extends BaseEntityBlock { return ItemInteractionResult.SUCCESS; } - // TODO 如何交互? @Override @ParametersAreNonnullByDefault protected @NotNull InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) { diff --git a/src/main/java/com/atsuishio/superbwarfare/block/entity/CreativeChargingStationBlockEntity.java b/src/main/java/com/atsuishio/superbwarfare/block/entity/CreativeChargingStationBlockEntity.java index 4069f3a50..81f9f1e31 100644 --- a/src/main/java/com/atsuishio/superbwarfare/block/entity/CreativeChargingStationBlockEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/block/entity/CreativeChargingStationBlockEntity.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.block.entity; +import com.atsuishio.superbwarfare.block.CreativeChargingStationBlock; import com.atsuishio.superbwarfare.capability.energy.InfinityEnergyStorage; import com.atsuishio.superbwarfare.init.ModBlockEntities; import net.minecraft.core.BlockPos; @@ -11,6 +12,7 @@ import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.world.entity.Entity; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; @@ -35,7 +37,6 @@ public class CreativeChargingStationBlockEntity extends BlockEntity { public @NotNull CompoundTag getUpdateTag(HolderLookup.@NotNull Provider registries) { CompoundTag tag = new CompoundTag(); tag.putBoolean("ShowRange", this.showRange); - saveAdditional(tag, registries); return tag; } @@ -55,8 +56,11 @@ public class CreativeChargingStationBlockEntity extends BlockEntity { super(ModBlockEntities.CREATIVE_CHARGING_STATION.get(), pos, state); } - public static void serverTick(CreativeChargingStationBlockEntity blockEntity) { - if (blockEntity.level == null) return; + public static void serverTick(Level pLevel, BlockPos pPos, BlockState pState, CreativeChargingStationBlockEntity blockEntity) { + if (blockEntity.showRange != pState.getValue(CreativeChargingStationBlock.SHOW_RANGE)) { + pLevel.setBlockAndUpdate(pPos, pState.setValue(CreativeChargingStationBlock.SHOW_RANGE, blockEntity.showRange)); + setChanged(pLevel, pPos, pState); + } blockEntity.chargeEntity(); blockEntity.chargeBlock(); @@ -98,4 +102,16 @@ public class CreativeChargingStationBlockEntity extends BlockEntity { public IEnergyStorage getEnergyStorage(@Nullable Direction side) { return energyStorage; } + + @Override + protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) { + super.loadAdditional(tag, registries); + this.showRange = tag.getBoolean("ShowRange"); + } + + @Override + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) { + super.saveAdditional(tag, registries); + tag.putBoolean("ShowRange", this.showRange); + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/block/CreativeChargingStationBlockEntityRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/block/CreativeChargingStationBlockEntityRenderer.java index 5ac99009d..848d2379a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/block/CreativeChargingStationBlockEntityRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/block/CreativeChargingStationBlockEntityRenderer.java @@ -1,6 +1,6 @@ package com.atsuishio.superbwarfare.client.renderer.block; -import com.atsuishio.superbwarfare.block.ChargingStationBlock; +import com.atsuishio.superbwarfare.block.CreativeChargingStationBlock; import com.atsuishio.superbwarfare.block.entity.CreativeChargingStationBlockEntity; import com.atsuishio.superbwarfare.client.renderer.CustomRenderType; import com.mojang.blaze3d.vertex.PoseStack; @@ -19,7 +19,7 @@ public class CreativeChargingStationBlockEntityRenderer implements BlockEntityRe @Override public void render(CreativeChargingStationBlockEntity blockEntity, float partialTick, @NotNull PoseStack poseStack, @NotNull MultiBufferSource bufferSource, int packedLight, int packedOverlay) { - if (!blockEntity.getBlockState().hasProperty(ChargingStationBlock.SHOW_RANGE) || !blockEntity.getBlockState().getValue(ChargingStationBlock.SHOW_RANGE)) + if (!blockEntity.getBlockState().hasProperty(CreativeChargingStationBlock.SHOW_RANGE) || !blockEntity.getBlockState().getValue(CreativeChargingStationBlock.SHOW_RANGE)) return; poseStack.pushPose();