mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-13 15:56:38 +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();
|
super.invalidate();
|
||||||
invProvider.invalidate();
|
invProvider.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
@ -351,8 +351,8 @@ public class SawBlockEntity extends BlockBreakingKineticBlockEntity {
|
||||||
ItemHelper.addToList(stack, list);
|
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));
|
inventory.setStackInSlot(slot + 1, list.get(slot));
|
||||||
|
|
||||||
award(AllAdvancements.SAW_PROCESSING);
|
award(AllAdvancements.SAW_PROCESSING);
|
||||||
|
@ -461,7 +461,7 @@ public class SawBlockEntity extends BlockBreakingKineticBlockEntity {
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onBlockBroken(stateToBreak);
|
super.onBlockBroken(stateToBreak);
|
||||||
TreeCutter.findTree(level, breakingPos)
|
TreeCutter.findTree(level, breakingPos, stateToBreak)
|
||||||
.destroyBlocks(level, null, this::dropItemFromCutTree);
|
.destroyBlocks(level, null, this::dropItemFromCutTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class SawMovementBehaviour extends BlockBreakingMovementBehaviour {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeCutter.findTree(context.world, pos)
|
TreeCutter.findTree(context.world, pos, brokenState)
|
||||||
.destroyBlocks(context.world, null, (stack, dropPos) -> dropItemFromCutTree(context, stack, dropPos));
|
.destroyBlocks(context.world, null, (stack, dropPos) -> dropItemFromCutTree(context, stack, dropPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,15 +55,20 @@ public class TreeCutter {
|
||||||
return Optional.empty();
|
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
|
* Finds a tree at the given pos. Block at the position should be air
|
||||||
*
|
*
|
||||||
* @param reader
|
* @param reader the level that will be searched for a tree
|
||||||
* @param pos
|
* @param pos position that the saw cut at
|
||||||
* @return null if not found or not fully cut
|
* @param brokenState block state what was broken by the saw
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static Tree findTree(@Nullable BlockGetter reader, BlockPos pos) {
|
public static Tree findTree(@Nullable BlockGetter reader, BlockPos pos, BlockState brokenState) {
|
||||||
if (reader == null)
|
if (reader == null)
|
||||||
return NO_TREE;
|
return NO_TREE;
|
||||||
|
|
||||||
|
@ -72,11 +77,14 @@ public class TreeCutter {
|
||||||
Set<BlockPos> visited = new HashSet<>();
|
Set<BlockPos> visited = new HashSet<>();
|
||||||
List<BlockPos> frontier = new LinkedList<>();
|
List<BlockPos> frontier = new LinkedList<>();
|
||||||
|
|
||||||
// Bamboo, Sugar Cane, Cactus
|
|
||||||
BlockState stateAbove = reader.getBlockState(pos.above());
|
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());
|
logs.add(pos.above());
|
||||||
for (int i = 1; i < 256; i++) {
|
for (int i = 1; i < reader.getHeight(); i++) {
|
||||||
BlockPos current = pos.above(i);
|
BlockPos current = pos.above(i);
|
||||||
if (!isVerticalPlant(reader.getBlockState(current)))
|
if (!isVerticalPlant(reader.getBlockState(current)))
|
||||||
break;
|
break;
|
||||||
|
@ -87,7 +95,10 @@ public class TreeCutter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chorus
|
// Chorus
|
||||||
if (isChorus(stateAbove)) {
|
if (isChorus(brokenState)) {
|
||||||
|
if (!isChorus(stateAbove))
|
||||||
|
return NO_TREE;
|
||||||
|
|
||||||
frontier.add(pos.above());
|
frontier.add(pos.above());
|
||||||
while (!frontier.isEmpty()) {
|
while (!frontier.isEmpty()) {
|
||||||
BlockPos current = frontier.remove(0);
|
BlockPos current = frontier.remove(0);
|
||||||
|
|
Loading…
Reference in a new issue