diff --git a/src/main/java/blusunrize/immersiveengineering/client/ClientEventHandler.java b/src/main/java/blusunrize/immersiveengineering/client/ClientEventHandler.java index add526b5cd..1adb16ff16 100644 --- a/src/main/java/blusunrize/immersiveengineering/client/ClientEventHandler.java +++ b/src/main/java/blusunrize/immersiveengineering/client/ClientEventHandler.java @@ -85,6 +85,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.*; import net.minecraft.world.phys.HitResult.Type; import net.minecraft.world.phys.shapes.VoxelShape; @@ -104,7 +105,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.function.IntPredicate; import java.util.stream.IntStream; import static blusunrize.immersiveengineering.ImmersiveEngineering.rl; @@ -692,7 +692,7 @@ public void onMouseEvent(MouseScrollingEvent event) @SubscribeEvent() public void renderAdditionalBlockBounds(RenderHighlightEvent.Block event) { - if(event.getTarget().getType()==Type.BLOCK&&event.getCamera().getEntity() instanceof LivingEntity player) + if(event.getTarget().getType()==Type.BLOCK&&event.getCamera().getEntity() instanceof LivingEntity living) { PoseStack transform = event.getPoseStack(); MultiBufferSource buffer = event.getMultiBufferSource(); @@ -703,8 +703,8 @@ public void renderAdditionalBlockBounds(RenderHighlightEvent.Block event) transform.translate(-renderView.x, -renderView.y, -renderView.z); transform.translate(pos.getX(), pos.getY(), pos.getZ()); float eps = 0.002F; - BlockEntity tile = player.level.getBlockEntity(rtr.getBlockPos()); - ItemStack stack = player.getItemInHand(InteractionHand.MAIN_HAND); + BlockEntity tile = living.level.getBlockEntity(rtr.getBlockPos()); + ItemStack stack = living.getItemInHand(InteractionHand.MAIN_HAND); if(tile instanceof TurntableBlockEntity turntableTile&&Utils.isHammer(stack)) { @@ -714,15 +714,15 @@ public void renderAdditionalBlockBounds(RenderHighlightEvent.Block event) { transform.pushPose(); transform.translate(0.5, 0.5, 0.5); - ClientUtils.toModelRotation(side).getRotation().push(transform); + transform.pushTransformation(ClientUtils.toModelRotation(side).getRotation()); transform.mulPose(new Quaternion(-90, 0, 0, true)); Rotation rotation = turntableTile.getRotationFromSide(side); boolean cw180 = rotation==Rotation.CLOCKWISE_180; double angle; if(cw180) - angle = player.tickCount%40/20d; + angle = living.tickCount%40/20d; else - angle = player.tickCount%80/40d; + angle = living.tickCount%80/40d; double stepDistance = (cw180?2: 4)*Math.PI; angle = -(angle-Math.sin(angle*stepDistance)/stepDistance)*Math.PI; BlockOverlayUtils.drawCircularRotationArrows(buffer, transform, (float)angle, rotation==Rotation.COUNTERCLOCKWISE_90, cw180); @@ -731,7 +731,7 @@ public void renderAdditionalBlockBounds(RenderHighlightEvent.Block event) } } - Level world = player.level; + Level world = living.level; if(!stack.isEmpty()&&ConveyorHandler.isConveyorBlock(Block.byItem(stack.getItem()))&&rtr.getDirection().getAxis()==Axis.Y) { Direction side = rtr.getDirection(); @@ -773,15 +773,23 @@ public void renderAdditionalBlockBounds(RenderHighlightEvent.Block event) } transform.popPose(); - if(!stack.isEmpty()&&stack.getItem() instanceof DrillItem&& - ((DrillItem)stack.getItem()).isEffective(stack, world.getBlockState(rtr.getBlockPos()))) + BlockState targetBlock = world.getBlockState(rtr.getBlockPos()); + if(stack.getItem() instanceof DrillItem drillItem&&drillItem.isEffective(stack, targetBlock)) { - ItemStack head = ((DrillItem)stack.getItem()).getHead(stack); - if(!head.isEmpty()&&player instanceof Player&&!player.isShiftKeyDown()&&!DrillItem.isSingleBlockMode(stack)) + ItemStack head = drillItem.getHead(stack); + if(!head.isEmpty()&&living instanceof Player player&&!living.isShiftKeyDown()&&!DrillItem.isSingleBlockMode(stack)) { - ImmutableList blocks = ((IDrillHead)head.getItem()).getExtraBlocksDug(head, world, - (Player)player, event.getTarget()); - BlockOverlayUtils.drawAdditionalBlockbreak(event, (Player)player, blocks); + ImmutableList potentialBlocks = ((IDrillHead)head.getItem()).getExtraBlocksDug( + head, world, player, event.getTarget() + ); + List breakingBlocks = new ArrayList<>(); + for(BlockPos candidate : potentialBlocks) + { + BlockState targetState = world.getBlockState(candidate); + if(drillItem.canBreakExtraBlock(world, candidate, targetState, player, stack, head)) + breakingBlocks.add(candidate); + } + BlockOverlayUtils.drawAdditionalBlockbreak(event, player, breakingBlocks); } } } diff --git a/src/main/java/blusunrize/immersiveengineering/common/items/DrillItem.java b/src/main/java/blusunrize/immersiveengineering/common/items/DrillItem.java index 218c7d1d39..d78170f2e8 100644 --- a/src/main/java/blusunrize/immersiveengineering/common/items/DrillItem.java +++ b/src/main/java/blusunrize/immersiveengineering/common/items/DrillItem.java @@ -49,7 +49,6 @@ import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.event.entity.player.PlayerEvent.HarvestCheck; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; import net.minecraftforge.items.IItemHandler; @@ -273,16 +272,13 @@ public float getDestroySpeed(ItemStack stack, BlockState state) return super.getDestroySpeed(stack, state); } - public boolean canBreakExtraBlock(Level world, Block block, BlockPos pos, BlockState state, Player player, ItemStack drill, ItemStack head, boolean inWorld) + public boolean canBreakExtraBlock( + Level world, BlockPos pos, BlockState state, Player player, ItemStack drill, ItemStack head + ) { - if(block.canHarvestBlock(state, world, pos, player)&&isEffective(drill, state)&&canToolBeUsed(drill)) - { - if(inWorld) - return !((IDrillHead)head.getItem()).beforeBlockbreak(drill, head, player); - else - return true; - } - return false; + if(!state.canHarvestBlock(world, pos, player)||!isEffective(drill, state)||!canToolBeUsed(drill)) + return false; + return !((IDrillHead)head.getItem()).beforeBlockbreak(drill, head, player); } @Override @@ -309,7 +305,7 @@ public boolean onBlockStartBreak(ItemStack stack, BlockPos iPos, Player player) if(!state.isAir()&&state.getDestroyProgress(player, world, pos)!=0) { - if(!this.canBreakExtraBlock(world, block, pos, state, player, stack, head, true)) + if(!this.canBreakExtraBlock(world, pos, state, player, stack, head)) continue; int xpDropEvent = ForgeHooks.onBlockBreakEvent(world, ((ServerPlayer)player).gameMode.getGameModeForPlayer(), (ServerPlayer)player, pos); if(xpDropEvent < 0)