mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-13 07:47:21 +01:00
fix sugarcane acting as logs with mechanical saws
- prevent trees adjacent to sugar cane or similar blocks from being cut by the mechanical saw unintentionally
This commit is contained in:
parent
c4098b31b2
commit
92975231d7
3 changed files with 24 additions and 13 deletions
|
@ -259,7 +259,7 @@ public class SawBlockEntity extends BlockBreakingKineticBlockEntity {
|
|||
super.invalidate();
|
||||
invProvider.invalidate();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
|
@ -351,8 +351,8 @@ public class SawBlockEntity extends BlockBreakingKineticBlockEntity {
|
|||
ItemHelper.addToList(stack, list);
|
||||
}
|
||||
}
|
||||
|
||||
for (int slot = 0; slot < list.size() && slot + 1 < inventory.getSlots(); slot++)
|
||||
|
||||
for (int slot = 0; slot < list.size() && slot + 1 < inventory.getSlots(); slot++)
|
||||
inventory.setStackInSlot(slot + 1, list.get(slot));
|
||||
|
||||
award(AllAdvancements.SAW_PROCESSING);
|
||||
|
@ -461,7 +461,7 @@ public class SawBlockEntity extends BlockBreakingKineticBlockEntity {
|
|||
}
|
||||
|
||||
super.onBlockBroken(stateToBreak);
|
||||
TreeCutter.findTree(level, breakingPos)
|
||||
TreeCutter.findTree(level, breakingPos, stateToBreak)
|
||||
.destroyBlocks(level, null, this::dropItemFromCutTree);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ public class SawMovementBehaviour extends BlockBreakingMovementBehaviour {
|
|||
return;
|
||||
}
|
||||
|
||||
TreeCutter.findTree(context.world, pos)
|
||||
TreeCutter.findTree(context.world, pos, brokenState)
|
||||
.destroyBlocks(context.world, null, (stack, dropPos) -> dropItemFromCutTree(context, stack, dropPos));
|
||||
}
|
||||
|
||||
|
|
|
@ -55,15 +55,20 @@ public class TreeCutter {
|
|||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public static Tree findTree(@Nullable BlockGetter reader, BlockPos pos) {
|
||||
return findTree(reader, pos, Blocks.AIR.defaultBlockState());
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a tree at the given pos. Block at the position should be air
|
||||
*
|
||||
* @param reader
|
||||
* @param pos
|
||||
* @return null if not found or not fully cut
|
||||
* @param reader the level that will be searched for a tree
|
||||
* @param pos position that the saw cut at
|
||||
* @param brokenState block state what was broken by the saw
|
||||
*/
|
||||
@Nonnull
|
||||
public static Tree findTree(@Nullable BlockGetter reader, BlockPos pos) {
|
||||
public static Tree findTree(@Nullable BlockGetter reader, BlockPos pos, BlockState brokenState) {
|
||||
if (reader == null)
|
||||
return NO_TREE;
|
||||
|
||||
|
@ -72,11 +77,14 @@ public class TreeCutter {
|
|||
Set<BlockPos> visited = new HashSet<>();
|
||||
List<BlockPos> frontier = new LinkedList<>();
|
||||
|
||||
// Bamboo, Sugar Cane, Cactus
|
||||
BlockState stateAbove = reader.getBlockState(pos.above());
|
||||
if (isVerticalPlant(stateAbove)) {
|
||||
// Bamboo, Sugar Cane, Cactus
|
||||
if (isVerticalPlant(brokenState)) {
|
||||
if (!isVerticalPlant(stateAbove))
|
||||
return NO_TREE;
|
||||
|
||||
logs.add(pos.above());
|
||||
for (int i = 1; i < 256; i++) {
|
||||
for (int i = 1; i < reader.getHeight(); i++) {
|
||||
BlockPos current = pos.above(i);
|
||||
if (!isVerticalPlant(reader.getBlockState(current)))
|
||||
break;
|
||||
|
@ -87,7 +95,10 @@ public class TreeCutter {
|
|||
}
|
||||
|
||||
// Chorus
|
||||
if (isChorus(stateAbove)) {
|
||||
if (isChorus(brokenState)) {
|
||||
if (!isChorus(stateAbove))
|
||||
return NO_TREE;
|
||||
|
||||
frontier.add(pos.above());
|
||||
while (!frontier.isEmpty()) {
|
||||
BlockPos current = frontier.remove(0);
|
||||
|
|
Loading…
Reference in a new issue