Jump to content

[1.14.4] ConcurrentModificationException looping through potions


Flytre

Recommended Posts

Hello,

I have the following code as shown:

//potion effects?
if (player != null && event.phase == TickEvent.ClientTickEvent.Phase.START) {
    Collection<EffectInstance> effects = player.getActivePotionEffects();
    if (!effects.isEmpty()) {

        for (EffectInstance e : effects) {

            player.removePotionEffect(e.getPotion());

            player.addPotionEffect(new EffectInstance(e.getPotion(), e.getDuration(), e.getAmplifier(), true, false));
        }

    }

 

Now this throws a ConcurrentModificationException at the line of the for-loop, and I'm not sure why. Supposedly you cannot modify a list while using a for-loop, but I am not modifying the effects Collection as its already been assigned.

 

[14:03:03] [Client thread/ERROR] [ne.mi.ev.EventBus/EVENTBUS]: Exception caught during firing event: null
    Index: 1
    Listeners:
        0: NORMAL
        1: ASM: class flytre.cineroid.ForgeEvents tick(Lnet/minecraftforge/event/TickEvent$ClientTickEvent;)V
        2: ASM: net.minecraftforge.common.ForgeInternalHandler@1beb3b74 checkSettings(Lnet/minecraftforge/event/TickEvent$ClientTickEvent;)V
java.util.ConcurrentModificationException
    at java.base/java.util.HashMap$HashIterator.nextNode(HashMap.java:1498)
    at java.base/java.util.HashMap$ValueIterator.next(HashMap.java:1526)
    at flytre.cineroid.ForgeEvents.tick(ForgeEvents.java:66)
    at net.minecraftforge.eventbus.ASMEventHandler_1_ForgeEvents_tick_ClientTickEvent.invoke(.dynamic)
    at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
    at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
    at net.minecraftforge.fml.hooks.BasicEventHooks.onPreClientTick(BasicEventHooks.java:104)
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1330)
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:904)
    at net.minecraft.client.Minecraft.run(Minecraft.java:384)
    at net.minecraft.client.main.Main.main(Main.java:128)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
    at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)
    at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)
    at cpw.mods.modlauncher.Launcher.run(Launcher.java:81)
    at cpw.mods.modlauncher.Launcher.main(Launcher.java:65)
    at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:101)

 

 

I'm wondering how to fix this code! (My end goal is to remove potion particles from the player on the client-side, which I attempt to do by removing the effect and re-adding the effect without particles.)

Edited by Flytre
Error Detail
Link to comment
Share on other sites

8 minutes ago, Flytre said:

Looks like I'm going about it completely wrong. Can anyone point me in the direction of the right way to do this?

Use an Iterator and a while loop. Also you should check if the PotionEffect has the particles so you are not changing them every tick.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.