diff --git a/common/src/main/java/rearth/oritech/item/tools/harvesting/ChainsawItem.java b/common/src/main/java/rearth/oritech/item/tools/harvesting/ChainsawItem.java index ed9b9f932..074f3e9c8 100644 --- a/common/src/main/java/rearth/oritech/item/tools/harvesting/ChainsawItem.java +++ b/common/src/main/java/rearth/oritech/item/tools/harvesting/ChainsawItem.java @@ -77,7 +77,7 @@ public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPo var startState = world.getBlockState(startPos); if (startState.is(BlockTags.LOGS)) { var treeBlocks = TreefellerBlockEntity.getTreeBlocks(startPos, world); - PromethiumAxeItem.pendingBlocks.addAll(treeBlocks.stream().map(elem -> new Tuple<>(world, elem)).toList()); + PromethiumAxeItem.pendingBlocks.addAll(treeBlocks.stream().map(elem -> new PromethiumAxeItem.PendingBlock(world, elem, stack)).toList()); var extraEnergyUsed = treeBlocks.size() * getEnergyUsageMultiplier() / 2; this.tryUseEnergy(stack, (long) extraEnergyUsed, player); diff --git a/common/src/main/java/rearth/oritech/item/tools/harvesting/PromethiumAxeItem.java b/common/src/main/java/rearth/oritech/item/tools/harvesting/PromethiumAxeItem.java index 5313d5304..8dbadf3ce 100644 --- a/common/src/main/java/rearth/oritech/item/tools/harvesting/PromethiumAxeItem.java +++ b/common/src/main/java/rearth/oritech/item/tools/harvesting/PromethiumAxeItem.java @@ -8,7 +8,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundSource; import net.minecraft.tags.BlockTags; -import net.minecraft.util.Tuple; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.AxeItem; @@ -39,7 +38,8 @@ public class PromethiumAxeItem extends AxeItem implements GeoItem { - public static final Deque> pendingBlocks = new ArrayDeque<>(); + public record PendingBlock(Level level, BlockPos pos, ItemStack tool) {}; + public static final Deque pendingBlocks = new ArrayDeque<>(); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -65,7 +65,7 @@ public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPo var startState = world.getBlockState(startPos); if (startState.is(BlockTags.LOGS)) { var treeBlocks = TreefellerBlockEntity.getTreeBlocks(startPos, world); - pendingBlocks.addAll(treeBlocks.stream().map(elem -> new Tuple<>(world, elem)).toList()); + pendingBlocks.addAll(treeBlocks.stream().map(elem -> new PendingBlock(world, elem, stack)).toList()); } } @@ -75,23 +75,24 @@ public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPo public static void processPendingBlocks(Level world) { if (pendingBlocks.isEmpty()) return; - var topWorld = pendingBlocks.getFirst().getA(); + var topWorld = pendingBlocks.getFirst().level(); if (topWorld != world) return; for (int i = 0; i < 8 && !pendingBlocks.isEmpty(); i++) { - var candidate = pendingBlocks.pollFirst().getB(); - var candidateState = world.getBlockState(candidate); + var candidate = pendingBlocks.pollFirst(); + var candidatePos = candidate.pos(); + var candidateState = world.getBlockState(candidatePos); if (!candidateState.is(BlockTags.LOGS) && !candidateState.is(BlockTags.LEAVES)) return; - var dropped = Block.getDrops(candidateState, (ServerLevel) world, candidate, null); - world.setBlockAndUpdate(candidate, Blocks.AIR.defaultBlockState()); + var dropped = Block.getDrops(candidateState, (ServerLevel) world, candidatePos, null, null, candidate.tool()); + world.setBlockAndUpdate(candidatePos, Blocks.AIR.defaultBlockState()); - dropped.forEach(elem -> world.addFreshEntity(new ItemEntity(world, candidate.getX(), candidate.getY(), candidate.getZ(), elem))); + dropped.forEach(elem -> world.addFreshEntity(new ItemEntity(world, candidatePos.getX(), candidatePos.getY(), candidatePos.getZ(), elem))); - world.playSound(null, candidate, candidateState.getSoundType().getBreakSound(), SoundSource.BLOCKS, 0.5f, 1f); - world.addDestroyBlockEffect(candidate, candidateState); + world.playSound(null, candidatePos, candidateState.getSoundType().getBreakSound(), SoundSource.BLOCKS, 0.5f, 1f); + world.addDestroyBlockEffect(candidatePos, candidateState); - if (world instanceof ServerLevel sl) sl.sendParticles(ParticleTypes.SOUL_FIRE_FLAME, candidate.getX() + 0.5, candidate.getY() + 0.5, candidate.getZ() + 0.5, 4, 0.6, 0.6, 0.6, 0); + if (world instanceof ServerLevel sl) sl.sendParticles(ParticleTypes.SOUL_FIRE_FLAME, candidatePos.getX() + 0.5, candidatePos.getY() + 0.5, candidatePos.getZ() + 0.5, 4, 0.6, 0.6, 0.6, 0); if (candidateState.is(BlockTags.LOGS)) break; }