Darkere / CrashUtilities

Minecraft Mod Utilities for Server Owner
MIT License
7 stars 5 forks source link

Forge FastUtils exception issue with world#Entity iterating #25

Closed X-Niter closed 2 years ago

X-Niter commented 2 years ago

For 1.18.2, I've noticed you're iterating through the world and then through the entities and as you are iterating through the entities you are clearing them which in 1.18.2 is causing a Fast Utilities stack strace in the console.

In my private project I've tested out some fix as I do the same exact thing, I'll share the code here, and let you implement the fix your way :) I do hope it helps.

Using your code for example, when iterating I add the entity to an array and then out side the loop I kill/remove those entities so long as the array is > 0. This did still work and did as intended while fixing the exception error.

private static int removeEntities(CommandContext<CommandSourceStack> context, ResourceLocation type) {
       counter = 0;
        List<Entity> entities= new ArrayList<>();
        List<ServerLevel> worlds = CommandUtils.getWorlds(context);
        worlds.forEach(world -> world.getEntities().getAll().forEach(e -> {
            if (type == null) {
                if(!entity.hasCustomName()) {
                    entities.add(e);
                }
            }
        }));
        if (entities.size() > 0) {
            entities.forEach(e -> {
                if(!entity.hasCustomName()) {
                    removeEntity(context, world, e);
                    counter++;
                }
            });
        }
}

Take it with a grain of salt, I'm handling it a bit different and just trying to use your code as an exmaple of what it may or may not look like on your end. Adding to an array and then handling the array outside for each loops works and fixes the FastUtil error from forge that currently is happening with CrashUtilities on 1.18.2.

Darkere commented 2 years ago

Can I get the stacktrace for that error?

X-Niter commented 2 years ago

Can I get the stacktrace for that error?

Here you go, Github gist of stack trace

Also if you saw, you're more then welcome to ping me over in discord if that shows to be more easier for you.

Darkere commented 2 years ago

Fixed in 4.1