Skip to content

Commit

Permalink
fix tree felling helper memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
omergunr100 committed Dec 30, 2024
1 parent 22391bd commit c21c946
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class TreeFellingHelper {
private final Deque<BlockPos> orderedBlocks;
private int tick;

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

private TreeFellingHelper(ServerPlayer player, ItemStack tool, Deque<BlockPos> orderedBlocks) {
this.player = player;
Expand Down Expand Up @@ -83,12 +84,13 @@ 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) {
if (event.phase == TickEvent.Phase.START && event.side == LogicalSide.SERVER && !helpers.isEmpty()) {
for (var helper : helpers) {
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);
continue;
}
if (helper.tick % ConfigHolder.INSTANCE.tools.treeFellingDelay == 0)
Expand All @@ -97,6 +99,9 @@ public static void onWorldTick(TickEvent.LevelTickEvent event) {
helper.tick++;
}
}
if (!finished.isEmpty()) {
helpers.removeAll(finished);
}
}
}
}

0 comments on commit c21c946

Please sign in to comment.