mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-26 05:08:34 +01:00
parent
5c40d29e23
commit
244ee2486e
5 changed files with 12 additions and 8 deletions
|
@ -31,6 +31,7 @@ import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.level.ChunkPos;
|
import net.minecraft.world.level.ChunkPos;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.LevelAccessor;
|
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.Blocks;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
|
@ -338,12 +339,14 @@ public final class Helper {
|
||||||
return pos;
|
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)
|
if (Math.abs(pos.getX() - start.getX()) >= horizontalRange || Math.abs(pos.getZ() - start.getZ()) >= horizontalRange || Math.abs(pos.getY() - start.getY()) >= verticalRange)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (drop) {
|
if (!tool.isEmpty()) {
|
||||||
level.destroyBlock(pos, true);
|
var state = level.getBlockState(pos);
|
||||||
|
level.destroyBlock(pos, false);
|
||||||
|
Block.dropResources(state, level, pos, state.hasBlockEntity() ? level.getBlockEntity(pos) : null, null, tool);
|
||||||
} else {
|
} else {
|
||||||
// in this case we don't want the block breaking particles, so we can't use destroyBlock
|
// in this case we don't want the block breaking particles, so we can't use destroyBlock
|
||||||
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
||||||
|
@ -358,7 +361,7 @@ public final class Helper {
|
||||||
var offset = pos.offset(x, y, z);
|
var offset = pos.offset(x, y, z);
|
||||||
var state = level.getBlockState(offset);
|
var state = level.getBlockState(offset);
|
||||||
if (filter.test(state))
|
if (filter.test(state))
|
||||||
Helper.mineRecursively(level, offset, start, drop, horizontalRange, verticalRange, filter);
|
Helper.mineRecursively(level, offset, start, tool, horizontalRange, verticalRange, filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class BlockEntityWoodStand extends BlockEntityImpl implements ITickableBl
|
||||||
this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
this.level.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
|
||||||
return true;
|
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,
|
var item = new ItemEntity(this.level,
|
||||||
this.ritualPos.getX() + 0.5, this.ritualPos.getY() + 4.5, this.ritualPos.getZ() + 0.5,
|
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() {
|
public IItemHandlerModifiable getItemHandler() {
|
||||||
return this.items;
|
return this.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class ItemAxe extends AxeItem implements IModItem, ICustomItemModel {
|
||||||
public boolean onBlockStartBreak(ItemStack stack, BlockPos pos, Player player) {
|
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)) {
|
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;
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class ItemPickaxe extends PickaxeItem implements IModItem, ICustomItemMod
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, Player player) {
|
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)) {
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class ItemShovel extends ShovelItem implements IModItem, ICustomItemModel
|
||||||
return super.useOn(context);
|
return super.useOn(context);
|
||||||
level.removeBlock(pos, false);
|
level.removeBlock(pos, false);
|
||||||
var tile = state.hasBlockEntity() ? level.getBlockEntity(pos) : null;
|
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()));
|
var newContext = new UseOnContext(player, otherHand, new BlockHitResult(context.getClickLocation(), context.getClickedFace(), context.getClickedPos(), context.isInside()));
|
||||||
other.useOn(newContext);
|
other.useOn(newContext);
|
||||||
stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(context.getHand()));
|
stack.hurtAndBreak(1, player, p -> p.broadcastBreakEvent(context.getHand()));
|
||||||
|
|
Loading…
Reference in a new issue