fixed bug on path creation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package de.jottyfan.minecraft.item;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@@ -26,7 +27,7 @@ public class QShovel extends ShovelItem implements ToolRangeable {
|
||||
this.range = properties.getHarvestRange();
|
||||
}
|
||||
|
||||
private void createPathOnGrass(Level level, BlockPos pos, Direction side) {
|
||||
private void createPath(Level level, BlockPos pos, Direction side, Set<Block> validBlocks) {
|
||||
BlockState blockState = level.getBlockState(pos);
|
||||
if (blockState.isAir()) {
|
||||
// try to find one underneath
|
||||
@@ -39,7 +40,9 @@ public class QShovel extends ShovelItem implements ToolRangeable {
|
||||
if (side != Direction.DOWN) {
|
||||
if (blockState != null && level.getBlockState(pos.above()).isAir()) {
|
||||
if (!level.isClientSide()) {
|
||||
level.setBlockAndUpdate(pos, Blocks.DIRT_PATH.defaultBlockState());
|
||||
if (validBlocks.contains(blockState.getBlock())) {
|
||||
level.setBlockAndUpdate(pos, Blocks.DIRT_PATH.defaultBlockState());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,10 +50,13 @@ public class QShovel extends ShovelItem implements ToolRangeable {
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
for (BlockPos pos : range.getRangeAsBlockPosArray(context.getClickedPos(), true, new BlockPos(1, 1, 1))) {
|
||||
createPathOnGrass(context.getLevel(), pos, context.getClickedFace());
|
||||
InteractionResult result = super.useOn(context);
|
||||
if (InteractionResult.SUCCESS.equals(result)) {
|
||||
for (BlockPos pos : range.getRangeAsBlockPosArray(context.getClickedPos(), true, new BlockPos(1, 1, 1))) {
|
||||
createPath(context.getLevel(), pos, context.getClickedFace(), FLATTENABLES.keySet());
|
||||
}
|
||||
}
|
||||
return super.useOn(context);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user