fixed tool aoe not applying enchantments

closes #340
This commit is contained in:
Ell 2023-12-17 18:07:09 +01:00
parent 5c40d29e23
commit 244ee2486e
5 changed files with 12 additions and 8 deletions

View file

@ -31,6 +31,7 @@ import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
@ -338,12 +339,14 @@ public final class Helper {
return pos;
}
public static void mineRecursively(Level level, BlockPos pos, BlockPos start, boolean drop, int horizontalRange, int verticalRange, Predicate<BlockState> filter) {
public static void mineRecursively(Level level, BlockPos pos, BlockPos start, ItemStack tool, int horizontalRange, int verticalRange, Predicate<BlockState> filter) {
if (Math.abs(pos.getX() - start.getX()) >= horizontalRange || Math.abs(pos.getZ() - start.getZ()) >= horizontalRange || Math.abs(pos.getY() - start.getY()) >= verticalRange)
return;
if (drop) {
level.destroyBlock(pos, true);
if (!tool.isEmpty()) {
var state = level.getBlockState(pos);
level.destroyBlock(pos, false);
Block.dropResources(state, level, pos, state.hasBlockEntity() ? level.getBlockEntity(pos) : null, null, tool);
} else {
// in this case we don't want the block breaking particles, so we can't use destroyBlock
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
@ -358,7 +361,7 @@ public final class Helper {
var offset = pos.offset(x, y, z);
var state = level.getBlockState(offset);
if (filter.test(state))
Helper.mineRecursively(level, offset, start, drop, horizontalRange, verticalRange, filter);
Helper.mineRecursively(level, offset, start, tool, horizontalRange, verticalRange, filter);
}
}
}

View file

@ -81,7 +81,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
return true;
});
Helper.mineRecursively(this.level, this.ritualPos, this.ritualPos, false, 6, 32, s -> s.is(BlockTags.LOGS) || s.getBlock() instanceof LeavesBlock);
Helper.mineRecursively(this.level, this.ritualPos, this.ritualPos, ItemStack.EMPTY, 6, 32, s -> s.is(BlockTags.LOGS) || s.getBlock() instanceof LeavesBlock);
var item = new ItemEntity(this.level,
this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5,
@ -190,4 +190,5 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
public IItemHandlerModifiable getItemHandler() {
return this.items;
}
}

View file

@ -49,7 +49,7 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
if ((stack.getItem() == ModItems.SKY_AXE || stack.getItem() == ModItems.DEPTH_AXE) && Helper.isToolEnabled(stack) && player.level().getBlockState(pos).is(BlockTags.LOGS)) {
var horRange = stack.getItem() == ModItems.DEPTH_AXE ? 6 : 1;
Helper.mineRecursively(player.level(), pos, pos, true, horRange, 32, s -> s.is(BlockTags.LOGS));
Helper.mineRecursively(player.level(), pos, pos, stack, horRange, 32, s -> s.is(BlockTags.LOGS));
return true;
}
return false;

View file

@ -91,7 +91,7 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
@Override
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
if (itemstack.getItem() == ModItems.DEPTH_PICKAXE && Helper.isToolEnabled(itemstack) && player.level().getBlockState(pos).is(Tags.Blocks.ORES)) {
Helper.mineRecursively(player.level(), pos, pos, true, 5, 5, s -> s.is(Tags.Blocks.ORES));
Helper.mineRecursively(player.level(), pos, pos, itemstack, 5, 5, s -> s.is(Tags.Blocks.ORES));
return true;
}
return false;

View file

@ -111,7 +111,7 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
return super.useOn(context);
level.removeBlock(pos, false);
var tile = state.hasBlockEntity() ? level.getBlockEntity(pos) : null;
Block.dropResources(state, level, pos, tile, null, ItemStack.EMPTY);
Block.dropResources(state, level, pos, tile, null, stack);
var newContext = new UseOnContext(player, otherHand, new BlockHitResult(context.getClickLocation(), context.getClickedFace(), context.getClickedPos(), context.isInside()));
other.useOn(newContext);
stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(context.getHand()));