Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tree felling helper memory leak #2677

Merged
Merged
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 @@ -14,6 +14,7 @@
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.Mod;

import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;

import java.util.*;
Expand All @@ -29,7 +30,7 @@ public class TreeFellingHelper {
private final Deque<BlockPos> orderedBlocks;
private int tick;

public static Set<TreeFellingHelper> helpers = new HashSet<>();
public static final List<TreeFellingHelper> helpers = ObjectArrayList.of();

private TreeFellingHelper(ServerPlayer player, ItemStack tool, Deque<BlockPos> orderedBlocks) {
this.player = player;
Expand Down Expand Up @@ -83,12 +84,15 @@ 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) {
for (var helper : helpers) {
if (event.phase == TickEvent.Phase.START && event.side == LogicalSide.SERVER && !helpers.isEmpty()) {
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))) {
iterator.remove();
continue;
}
if (helper.tick % ConfigHolder.INSTANCE.tools.treeFellingDelay == 0)
Expand Down
Loading