Skip to content

Commit

Permalink
switched to an iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
omergunr100 committed Dec 30, 2024
1 parent b50ad46 commit 55bb9bc
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class TreeFellingHelper {
private final Deque<BlockPos> orderedBlocks;
private int tick;

public static final Set<TreeFellingHelper> helpers = new HashSet<>();
public static final Set<TreeFellingHelper> finished = new HashSet<>();
public static final Set<TreeFellingHelper> helpers = new ObjectOpenHashSet<>();

private TreeFellingHelper(ServerPlayer player, ItemStack tool, Deque<BlockPos> orderedBlocks) {
this.player = player;
Expand Down Expand Up @@ -85,12 +84,14 @@ public static void fellTree(ItemStack stack, Level level, BlockState origin, Blo
@SubscribeEvent
public static void onWorldTick(TickEvent.LevelTickEvent event) {
if (event.phase == TickEvent.Phase.START && event.side == LogicalSide.SERVER && !helpers.isEmpty()) {
for (var helper : helpers) {
var iterator = helpers.iterator();
while (iterator.hasNext()) {
var helper = iterator.next();
if (event.level == helper.player.level()) {
if (helper.orderedBlocks.isEmpty() || helper.tool.isEmpty() ||
!(hasBehaviorsTag(helper.player.getMainHandItem()) &&
getBehaviorsTag(helper.player.getMainHandItem()).getBoolean(TREE_FELLING_KEY))) {
finished.add(helper);
iterator.remove();
continue;
}
if (helper.tick % ConfigHolder.INSTANCE.tools.treeFellingDelay == 0)
Expand All @@ -99,10 +100,6 @@ public static void onWorldTick(TickEvent.LevelTickEvent event) {
helper.tick++;
}
}
if (!finished.isEmpty()) {
helpers.removeAll(finished);
finished.clear();
}
}
}
}

0 comments on commit 55bb9bc

Please sign in to comment.