Skip to content

Commit

Permalink
Better logic for SkySweeper - fixes #193
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Oct 19, 2024
1 parent 9e13278 commit 506c16c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ else if (tieredItem.getTier().equals(GooTier.CELESTIGEM))
else if (tieredItem.getTier().equals(GooTier.ECLIPSEALLOY))
maxBreak = 256;
}
Set<BlockPos> alsoBreakSet = findLikeBlocks(pLevel, pState, pPos, null, maxBreak, 2);
Set<BlockPos> alsoBreakSet = findLikeBlocks(pLevel, pState, pPos, maxBreak, 2);
BlockEvents.alreadyBreaking = true;
BlockEvents.spawnDropsAtPos = pPos;
for (BlockPos breakPos : alsoBreakSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,8 @@ public static void teleportDrops(List<ItemStack> drops, IItemHandler handler, It
drops.addAll(leftovers);
}

public static Set<BlockPos> 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<BlockPos> findLikeBlocks(Level pLevel, BlockState pState, BlockPos pPos, int maxBreak, int range) {
return findBlocks(pLevel, pState, pPos, maxBreak, range);
}

/**
Expand Down Expand Up @@ -424,14 +421,14 @@ private static Set<BlockPos> 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<BlockPos> findBlocks(Level pLevel, BlockState pState, BlockPos pPos, int maxBreak, Direction direction, int range) {
public static Set<BlockPos> findBlocksSkyfall(Level pLevel, BlockPos pPos, int maxBreak, Direction direction, int range) {
Set<BlockPos> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -167,9 +167,9 @@ else if (tieredItem.getTier().equals(GooTier.ECLIPSEALLOY))
if (canUseAbility(pStack, Ability.SKYSWEEPER) && pStack.isCorrectToolForDrops(pState)) {
Set<BlockPos> 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);
}
Expand Down

0 comments on commit 506c16c

Please sign in to comment.