From 506c16c0ceff62e263561069a88736013509b472 Mon Sep 17 00:00:00 2001 From: direwolf20 <39863894+Direwolf20-MC@users.noreply.github.com> Date: Fri, 18 Oct 2024 22:42:44 -0400 Subject: [PATCH] Better logic for SkySweeper - fixes #193 --- .../common/items/interfaces/AbilityMethods.java | 2 +- .../common/items/interfaces/Helpers.java | 11 ++++------- .../common/items/interfaces/ToggleableTool.java | 8 ++++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/AbilityMethods.java b/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/AbilityMethods.java index 512a68cf..6bf09d98 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/AbilityMethods.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/AbilityMethods.java @@ -126,7 +126,7 @@ else if (tieredItem.getTier().equals(GooTier.CELESTIGEM)) else if (tieredItem.getTier().equals(GooTier.ECLIPSEALLOY)) maxBreak = 256; } - Set alsoBreakSet = findLikeBlocks(pLevel, pState, pPos, null, maxBreak, 2); + Set alsoBreakSet = findLikeBlocks(pLevel, pState, pPos, maxBreak, 2); BlockEvents.alreadyBreaking = true; BlockEvents.spawnDropsAtPos = pPos; for (BlockPos breakPos : alsoBreakSet) { diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/Helpers.java b/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/Helpers.java index cb3fe287..1b1690ca 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/Helpers.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/Helpers.java @@ -380,11 +380,8 @@ public static void teleportDrops(List drops, IItemHandler handler, It drops.addAll(leftovers); } - public static Set findLikeBlocks(Level pLevel, BlockState pState, BlockPos pPos, Direction direction, int maxBreak, int range) { - if (direction == null) - return findBlocks(pLevel, pState, pPos, maxBreak, range); - else - return findBlocks(pLevel, pState, pPos, maxBreak, direction, maxBreak); + public static Set findLikeBlocks(Level pLevel, BlockState pState, BlockPos pPos, int maxBreak, int range) { + return findBlocks(pLevel, pState, pPos, maxBreak, range); } /** @@ -424,14 +421,14 @@ private static Set findBlocks(Level pLevel, BlockState pState, BlockPo /** * Looks in a specified direction for similar blocks - used by shovels to clear all like blocks above them */ - private static Set findBlocks(Level pLevel, BlockState pState, BlockPos pPos, int maxBreak, Direction direction, int range) { + public static Set findBlocksSkyfall(Level pLevel, BlockPos pPos, int maxBreak, Direction direction, int range) { Set foundBlocks = new HashSet<>(); //The matching Blocks foundBlocks.add(pPos); //Obviously the block we broke is included in the return! for (int i = 1; i < range; i++) { BlockPos posToCheck = pPos.relative(direction, i); //The next blockPos to check BlockState blockState = pLevel.getBlockState(posToCheck); - if (blockState.is(pState.getBlock())) { + if (fallingBlockCondition.test(blockState)) { foundBlocks.add(posToCheck); } else { break; diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/ToggleableTool.java b/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/ToggleableTool.java index edcb6110..e87122d6 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/ToggleableTool.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/interfaces/ToggleableTool.java @@ -155,10 +155,10 @@ else if (tieredItem.getTier().equals(GooTier.ECLIPSEALLOY)) maxBreak = Config.TOOL_MAX_BREAK_ECLIPSEALLOY.get(); } if (canUseAbility(pStack, Ability.OREMINER) && oreCondition.test(pState) && pStack.isCorrectToolForDrops(pState)) { - breakBlockPositions.addAll(findLikeBlocks(pLevel, pState, pPos, null, maxBreak, 2)); + breakBlockPositions.addAll(findLikeBlocks(pLevel, pState, pPos, maxBreak, 2)); } if (canUseAbility(pStack, Ability.TREEFELLER) && logCondition.test(pState) && pStack.isCorrectToolForDrops(pState)) { - breakBlockPositions.addAll(findLikeBlocks(pLevel, pState, pPos, null, maxBreak, 2)); + breakBlockPositions.addAll(findLikeBlocks(pLevel, pState, pPos, maxBreak, 2)); } if (canUseAbility(pStack, Ability.HAMMER)) { breakBlockPositions.addAll(MiningCollect.collect(pEntityLiving, pPos, getTargetLookDirection(pEntityLiving), pLevel, getToolValue(pStack, Ability.HAMMER.getName()), MiningCollect.SizeMode.AUTO, pStack)); @@ -167,9 +167,9 @@ else if (tieredItem.getTier().equals(GooTier.ECLIPSEALLOY)) if (canUseAbility(pStack, Ability.SKYSWEEPER) && pStack.isCorrectToolForDrops(pState)) { Set newPos = new HashSet<>(); for (BlockPos blockPos : breakBlockPositions) { - BlockState blockState = pLevel.getBlockState(blockPos); + BlockState blockState = pLevel.getBlockState(blockPos.above()); if (fallingBlockCondition.test(blockState)) - newPos.addAll(findLikeBlocks(pLevel, blockState, blockPos, Direction.UP, maxBreak, 2)); + newPos.addAll(findBlocksSkyfall(pLevel, blockPos.above(), maxBreak, Direction.UP, maxBreak)); } breakBlockPositions.addAll(newPos); }