From 2c471d3a8b16f1096b585b36f79de6692b853448 Mon Sep 17 00:00:00 2001 From: "yrsegal@gmail.com" Date: Wed, 25 May 2022 18:50:19 -0400 Subject: [PATCH] fix #79 --- .../impetuses/BlockStoredPlayerImpetus.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java index 69fdb518..a25f2529 100644 --- a/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java +++ b/Common/src/main/java/at/petrak/hexcasting/common/blocks/circles/impetuses/BlockStoredPlayerImpetus.java @@ -17,10 +17,15 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.phys.BlockHitResult; import org.jetbrains.annotations.Nullable; public class BlockStoredPlayerImpetus extends BlockAbstractImpetus { + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; + public BlockStoredPlayerImpetus(Properties p_49795_) { super(p_49795_); } @@ -31,6 +36,12 @@ public class BlockStoredPlayerImpetus extends BlockAbstractImpetus { return new BlockEntityStoredPlayerImpetus(pPos, pState); } + @Override + protected void createBlockStateDefinition(StateDefinition.Builder builder) { + super.createBlockStateDefinition(builder); + builder.add(POWERED); + } + @Override public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) { @@ -64,14 +75,20 @@ public class BlockStoredPlayerImpetus extends BlockAbstractImpetus { boolean pIsMoving) { super.neighborChanged(pState, pLevel, pPos, pBlock, pFromPos, pIsMoving); - if (!pLevel.isClientSide() - && pLevel.hasNeighborSignal(pPos) - && !pState.getValue(ENERGIZED) - && pLevel.getBlockEntity(pPos) instanceof BlockEntityStoredPlayerImpetus tile) { - var player = tile.getStoredPlayer(); - if (player instanceof ServerPlayer splayer) { - // phew - tile.activateSpellCircle(splayer); + if (!pLevel.isClientSide()) { + boolean prevPowered = pState.getValue(POWERED); + boolean isPowered = pLevel.hasNeighborSignal(pPos); + + if (prevPowered != isPowered) { + pLevel.setBlockAndUpdate(pPos, pState.setValue(POWERED, isPowered)); + + if (isPowered && pLevel.getBlockEntity(pPos) instanceof BlockEntityStoredPlayerImpetus tile) { + var player = tile.getStoredPlayer(); + if (player instanceof ServerPlayer splayer) { + // phew + tile.activateSpellCircle(splayer); + } + } } } }