Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,7 +38,8 @@

public class PromethiumAxeItem extends AxeItem implements GeoItem {

public static final Deque<Tuple<Level, BlockPos>> pendingBlocks = new ArrayDeque<>();
public record PendingBlock(Level level, BlockPos pos, ItemStack tool) {};
public static final Deque<PendingBlock> pendingBlocks = new ArrayDeque<>();

private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);

Expand All @@ -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());
}
}

Expand All @@ -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;
}
Expand Down
Loading