diff --git a/src/main/java/ru/betterend/blocks/EternalPedestal.java b/src/main/java/ru/betterend/blocks/EternalPedestal.java index b64b05be..ed2d1d69 100644 --- a/src/main/java/ru/betterend/blocks/EternalPedestal.java +++ b/src/main/java/ru/betterend/blocks/EternalPedestal.java @@ -38,39 +38,32 @@ public class EternalPedestal extends PedestalBlock { } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - ActionResult result = super.onUse(state, world, pos, player, hand, hit); - if (result.equals(ActionResult.SUCCESS)) { - BlockEntity blockEntity = world.getBlockEntity(pos); - if (blockEntity instanceof EternalPedestalEntity) { - EternalPedestalEntity pedestal = (EternalPedestalEntity) blockEntity; - BlockState updatedState = world.getBlockState(pos); - if (pedestal.isEmpty() && updatedState.get(ACTIVATED)) { + public void checkRitual(World world, BlockPos pos) { + BlockEntity blockEntity = world.getBlockEntity(pos); + if (blockEntity instanceof EternalPedestalEntity) { + EternalPedestalEntity pedestal = (EternalPedestalEntity) blockEntity; + BlockState updatedState = world.getBlockState(pos); + if (pedestal.isEmpty() && updatedState.get(ACTIVATED)) { + if (pedestal.hasRitual()) { + EternalRitual ritual = pedestal.getRitual(); + ritual.removePortal(); + } + world.setBlockState(pos, updatedState.with(ACTIVATED, false)); + } else { + ItemStack itemStack = pedestal.getStack(0); + if (itemStack.getItem() == EndItems.ETERNAL_CRYSTAL) { + world.setBlockState(pos, updatedState.with(ACTIVATED, true)); if (pedestal.hasRitual()) { - EternalRitual ritual = pedestal.getRitual(); - ritual.removePortal(); - } - world.setBlockState(pos, updatedState.with(ACTIVATED, false)); - } else { - ItemStack itemStack = pedestal.getStack(0); - if (itemStack.getItem() == EndItems.ETERNAL_CRYSTAL) { - world.setBlockState(pos, updatedState.with(ACTIVATED, true)); - if (pedestal.hasRitual()) { - pedestal.getRitual().checkStructure(); - } else { - EternalRitual ritual = new EternalRitual(world, pos); - ritual.checkStructure(); - } + pedestal.getRitual().checkStructure(); + } else { + EternalRitual ritual = new EternalRitual(world, pos); + ritual.checkStructure(); } } } } - return result; } - @Override - protected void activate(World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {} - @Override public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) { BlockState updated = super.getStateForNeighborUpdate(state, direction, newState, world, pos, posFrom); diff --git a/src/main/java/ru/betterend/blocks/InfusionPedestal.java b/src/main/java/ru/betterend/blocks/InfusionPedestal.java index 0e57bb94..65023821 100644 --- a/src/main/java/ru/betterend/blocks/InfusionPedestal.java +++ b/src/main/java/ru/betterend/blocks/InfusionPedestal.java @@ -28,42 +28,20 @@ public class InfusionPedestal extends PedestalBlock { } @Override - public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { - if (world.isClient || !state.isOf(this)) return ActionResult.CONSUME; + public void checkRitual(World world, BlockPos pos) { BlockEntity blockEntity = world.getBlockEntity(pos); - InfusionPedestalEntity pedestal = null; if (blockEntity instanceof InfusionPedestalEntity) { - pedestal = (InfusionPedestalEntity) blockEntity; - if (!pedestal.isEmpty() && pedestal.hasRitual()) { - if (pedestal.getRitual().hasRecipe()) { - pedestal.getRitual().stop(); - return ActionResult.SUCCESS; - } else if (pedestal.getRitual().checkRecipe()) { - return ActionResult.SUCCESS; - } + InfusionPedestalEntity pedestal = (InfusionPedestalEntity) blockEntity; + if (pedestal.hasRitual()) { + pedestal.getRitual().checkRecipe(); + } else { + InfusionRitual ritual = new InfusionRitual(world, pos); + pedestal.linkRitual(ritual); + ritual.checkRecipe(); } } - ActionResult result = ActionResult.FAIL; - if (hand != null) { - result = super.onUse(state, world, pos, player, hand, hit); - } - if (result == ActionResult.SUCCESS) { - if (pedestal != null) { - if (pedestal.hasRitual()) { - pedestal.getRitual().checkRecipe(); - } else { - InfusionRitual ritual = new InfusionRitual(world, pos); - pedestal.linkRitual(ritual); - ritual.checkRecipe(); - } - } - } - return result; } - @Override - protected void activate(World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {} - @Override public BlockEntity createBlockEntity(BlockView world) { return new InfusionPedestalEntity(); diff --git a/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java b/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java index 1cc317c9..9829e1fa 100644 --- a/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java +++ b/src/main/java/ru/betterend/blocks/basis/PedestalBlock.java @@ -114,7 +114,7 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid ItemStack itemStack = player.getStackInHand(hand); if (itemStack.isEmpty()) return ActionResult.CONSUME; pedestal.setStack(0, itemStack.split(1)); - activate(world, pos, player, hit); + this.checkRitual(world, pos); return ActionResult.SUCCESS; } else { ItemStack itemStack = pedestal.getStack(0); @@ -128,17 +128,13 @@ public class PedestalBlock extends BlockBaseNotFull implements BlockEntityProvid return ActionResult.PASS; } - protected void activate(World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { - Mutable mut = new Mutable(); - Point[] points = InfusionRitual.getMap(); - for (Point p: points) { - mut.set(pos).move(p.x, 0, p.y); - BlockState state = world.getBlockState(mut); + public void checkRitual(World world, BlockPos pos) { + Mutable posMutable = new Mutable(); + for (Point point: InfusionRitual.getMap()) { + posMutable.set(pos).move(point.x, 0, point.y); + BlockState state = world.getBlockState(posMutable); if (state.getBlock() instanceof InfusionPedestal) { - ActionResult result = state.getBlock().onUse(state, world, mut, player, null, hit); - if (result == ActionResult.SUCCESS) { - break; - } + ((InfusionPedestal) state.getBlock()).checkRitual(world, posMutable); } } }