Posted May 14, 20205 yr So basically I am trying to make a Mug of Milk remove 30seconds(600ticks) off of every potion effect the player has. Though this causes a crash when I drink the item. (The code is located in the onItemUseFinish function) if (!worldIn.isRemote) { entityLiving.getActivePotionEffects().stream().map(EffectInstance::getEffectInstance).forEach(effect -> { int duration = effect.getDuration(); int amplifier = effect.getAmplifier(); duration -= 600; Effect effectPotion = effect.getPotion(); entityLiving.removeActivePotionEffect(effectPotion); entityLiving.addPotionEffect(new EffectInstance(effectPotion, duration, amplifier)); }); } I looked it up already and it is because in my code I remove the potion effect and then try to access it. Does anyone know a way around this? Edited May 14, 20205 yr by TheRedWaffle spelling
May 14, 20205 yr Author Here's the error if any of you need it. Spoiler ---- Minecraft Crash Report ---- // This doesn't make any sense! Time: 14/05/20 2:54 PM Description: Ticking player java.util.ConcurrentModificationException: null at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1633) ~[?:1.8.0_241] {} at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) ~[?:1.8.0_241] {} at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[?:1.8.0_241] {} at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) ~[?:1.8.0_241] {} at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) ~[?:1.8.0_241] {} at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_241] {} at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) ~[?:1.8.0_241] {} at com.theredwaffle.delicious_foods.items.MilkMugItem.onItemUseFinish(MilkMugItem.java:40) ~[?:?] {re:classloading} at net.minecraft.item.ItemStack.onItemUseFinish(ItemStack.java:213) ~[?:?] {re:classloading} at net.minecraft.entity.LivingEntity.onItemUseFinish(LivingEntity.java:2868) ~[?:?] {re:classloading} at net.minecraft.entity.player.ServerPlayerEntity.onItemUseFinish(ServerPlayerEntity.java:1025) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.entity.LivingEntity.updateActiveHand(LivingEntity.java:2746) ~[?:?] {re:classloading} at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2179) ~[?:?] {re:classloading} at net.minecraft.entity.player.PlayerEntity.tick(PlayerEntity.java:236) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.entity.player.ServerPlayerEntity.playerTick(ServerPlayerEntity.java:377) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.network.play.ServerPlayNetHandler.tick(ServerPlayNetHandler.java:183) ~[?:?] {re:classloading} at net.minecraft.network.NetworkManager.tick(NetworkManager.java:245) ~[?:?] {re:classloading} at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148) ~[?:?] {re:classloading} at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:900) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:818) ~[?:?] {re:classloading,pl:accesstransformer:B} at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) ~[?:?] {re:classloading,pl:runtimedistcleaner:A} at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:659) [?:?] {re:classloading,pl:accesstransformer:B} at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Server thread Stacktrace: at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1633) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418) at com.theredwaffle.delicious_foods.items.MilkMugItem.onItemUseFinish(MilkMugItem.java:40) at net.minecraft.item.ItemStack.onItemUseFinish(ItemStack.java:213) at net.minecraft.entity.LivingEntity.onItemUseFinish(LivingEntity.java:2868) at net.minecraft.entity.player.ServerPlayerEntity.onItemUseFinish(ServerPlayerEntity.java:1025) at net.minecraft.entity.LivingEntity.updateActiveHand(LivingEntity.java:2746) at net.minecraft.entity.LivingEntity.tick(LivingEntity.java:2179) at net.minecraft.entity.player.PlayerEntity.tick(PlayerEntity.java:236) -- Player being ticked -- Details: Entity Type: minecraft:player (net.minecraft.entity.player.ServerPlayerEntity) Entity ID: 272 Entity Name: Dev Entity's Exact location: 185.70, 67.00, 148.83 Entity's Block location: World: (185,67,148), Chunk: (at 9,4,4 in 11,9; contains blocks 176,0,144 to 191,255,159), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Entity's Momentum: 0.00, -0.08, 0.00 Entity's Passengers: [] Entity's Vehicle: ~~ERROR~~ NullPointerException: null Stacktrace: at net.minecraft.entity.player.ServerPlayerEntity.playerTick(ServerPlayerEntity.java:377) at net.minecraft.network.play.ServerPlayNetHandler.tick(ServerPlayNetHandler.java:183) at net.minecraft.network.NetworkManager.tick(NetworkManager.java:245) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@6d25cff6 Stacktrace: at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:148) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:900) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:818) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:659) at java.lang.Thread.run(Thread.java:748) -- System Details -- Details: Minecraft Version: 1.15.2 Minecraft Version ID: 1.15.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_241, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 957315352 bytes (912 MB) / 1887436800 bytes (1800 MB) up to 3782737920 bytes (3607 MB) CPUs: 12 JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump ModLauncher: 5.0.0-milestone.4+67+b1a340b ModLauncher launch target: fmluserdevclient ModLauncher naming: mcp ModLauncher services: /eventbus-2.0.0-milestone.1-service.jar eventbus PLUGINSERVICE /forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar object_holder_definalize PLUGINSERVICE /forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtime_enum_extender PLUGINSERVICE /accesstransformers-2.0.0-milestone.1-shadowed.jar accesstransformer PLUGINSERVICE /forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar capability_inject_definalize PLUGINSERVICE /forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar runtimedistcleaner PLUGINSERVICE /forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-launcher.jar fml TRANSFORMATIONSERVICE FML: 31.1 Forge: net.minecraftforge:31.1.0 FML Language Providers: [email protected] minecraft@1 Mod List: client-extra.jar Minecraft {[email protected] DONE} main Delicious Foods Mod {[email protected] DONE} forge-1.15.2-31.1.0_mapped_snapshot_20190719-1.14.3-recomp.jar Forge {[email protected] DONE} Player Count: 1 / 8; [ServerPlayerEntity['Dev'/272, l='New World', x=185.70, y=67.00, z=148.83]] Data Packs: vanilla, mod:delicious-foods, mod:forge (incompatible) Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'forge'
May 14, 20205 yr 12 minutes ago, TheRedWaffle said: ConcurrentModificationException You can't modify an array while iterating over it. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
May 14, 20205 yr 19 minutes ago, Draco18s said: You can't modify an array while iterating over it. Half true: if you want to remove-while-iterating, you will want to get the Collection's Iterator (Collection<T>: public default Iterator<T> iterator()). Iterators may or may not support element removal like this: if (!thingCollection.isEmpty()) { Iterator<Thing> itr = thingCollection.iterator(); do { Thing thing = itr.next(); if (shouldRemove(thing)) { itr.remove(); } } while (itr.hasNext()); } `Collection<T>` also should have a `default void removeIf(Predicate<T> returnTrueToRemove)` method that is more amenable to lambdas like you seem to want to use here (lambdas are really great like that, keep using them) Edited May 14, 20205 yr by Vinyarion removeIf Have you ever want the new operator to return a type that you didn't ask for? Well, now you can!
May 14, 20205 yr Author 1 hour ago, Vinyarion said: Half true: if you want to remove-while-iterating, you will want to get the Collection's Iterator (Collection<T>: public default Iterator<T> iterator()). Iterators may or may not support element removal like this: if (!thingCollection.isEmpty()) { Iterator<Thing> itr = thingCollection.iterator(); do { Thing thing = itr.next(); if (shouldRemove(thing)) { itr.remove(); } } while (itr.hasNext()); } `Collection<T>` also should have a `default void removeIf(Predicate<T> returnTrueToRemove)` method that is more amenable to lambdas like you seem to want to use here (lambdas are really great like that, keep using them) Sweet thanks for the help. Do I need to make my own 'shouldRemove()' method? I have this right now but shouldRemove isn't a real method if (!worldIn.isRemote) { if (!entityLiving.getActivePotionEffects().isEmpty()) { Iterator<EffectInstance> itr = entityLiving.getActivePotionEffects().iterator(); do { EffectInstance effectInstance = itr.next(); int duration = effectInstance.getDuration(); int amplifier = effectInstance.getAmplifier(); duration -= 600; Effect effectPotion = effectInstance.getPotion(); if(shouldRemove(effectInstance)) { entityLiving.removeActivePotionEffect(effectPotion); entityLiving.addPotionEffect(new EffectInstance(effectPotion, duration, amplifier)); } } while (itr.hasNext()); } } Let me know if I have something wrong.
May 14, 20205 yr 5 minutes ago, TheRedWaffle said: Sweet thanks for the help. Do I need to make my own 'shouldRemove()' method? I have this right now but shouldRemove isn't a real method if (!worldIn.isRemote) { if (!entityLiving.getActivePotionEffects().isEmpty()) { Iterator<EffectInstance> itr = entityLiving.getActivePotionEffects().iterator(); do { EffectInstance effectInstance = itr.next(); int duration = effectInstance.getDuration(); int amplifier = effectInstance.getAmplifier(); duration -= 600; Effect effectPotion = effectInstance.getPotion(); if(shouldRemove(effectInstance)) { entityLiving.removeActivePotionEffect(effectPotion); entityLiving.addPotionEffect(new EffectInstance(effectPotion, duration, amplifier)); } } while (itr.hasNext()); } } Let me know if I have something wrong. Vinyarion doesn't actually mean "make a method called shouldRemove(EffectInstance e) that returns a boolean". the shouldRemove(object) expression is a stand in for whatever expression you want to use to determine if an object should be removed.
May 14, 20205 yr Author 1 minute ago, TheThorneCorporation said: Vinyarion doesn't actually mean "make a method called shouldRemove(EffectInstance e) that returns a boolean". the shouldRemove(object) expression is a stand in for whatever expression you want to use to determine if an object should be removed. Ugh I should have thought of that, sorry.
May 14, 20205 yr Author Ok so everything works in game but the effect display doesn't visibly show the duration changing could this be because I instantly remove and change the effect? Here's the code if (!worldIn.isRemote) { if (!entityLiving.getActivePotionEffects().isEmpty()) { Iterator<EffectInstance> itr = entityLiving.getActivePotionEffects().stream().iterator(); do { EffectInstance effectInstance = itr.next(); int duration = effectInstance.getDuration(); int amplifier = effectInstance.getAmplifier(); duration -= 600; Effect effectPotion = effectInstance.getPotion(); entityLiving.removeActivePotionEffect(effectPotion); entityLiving.addPotionEffect(new EffectInstance(effectPotion, duration, amplifier)); } while (itr.hasNext()); } }
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.