Toma™ Posted November 15, 2018 Posted November 15, 2018 My minecraft does "randomly" crash when I start shooting with one weapon with small firerate, however this happens quite randomly and sometimes it's working fine for a long time and then suddenly crash. So there's some of the code: BulletEntity GunCode Shooting code for Single firemode Shooting code for Automatic firemode Entity is registered in my main class under FMLInit event using the registerModEntityMethod (I also tried to play a bit with the tracking range and update frequency since the crash was saying something about it) Crash report: Spoiler ---- Minecraft Crash Report ---- // I'm sorry, Dave. Time: 11/15/18 1:51 PM Description: Exception in server tick loop java.util.ConcurrentModificationException at java.util.HashMap$HashIterator.nextNode(Unknown Source) at java.util.HashMap$KeyIterator.next(Unknown Source) at net.minecraft.entity.EntityTracker.tick(EntityTracker.java:295) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:854) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) at java.lang.Thread.run(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_172, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 780420984 bytes (744 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP 9.42 Powered by Forge 14.23.5.2768 5 mods loaded, 5 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:--------- |:--------- |:------------ |:-------------------------------- |:--------- | | UCHIJAAAA | minecraft | 1.12.2 | minecraft.jar | None | | UCHIJAAAA | mcp | 9.42 | minecraft.jar | None | | UCHIJAAAA | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.5.2768.jar | None | | UCHIJAAAA | forge | 14.23.5.2768 | forgeSrc-1.12.2-14.23.5.2768.jar | None | | UCHIJAAAA | pubgmc | 2.2.2 | bin | None | Loaded coremods (and transformers): GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread. Profiler Position: N/A (disabled) Player Count: 1 / 8; [EntityPlayerMP['Player789'/137, l='New World', x=250.34, y=7.66, z=-292.53]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge' I hope I didn't mess some basic stuff again somewhere Quote
Cadiboo Posted November 15, 2018 Posted November 15, 2018 Where’s your packet? I think you might be calling code from one thread (the packet handler thread) that modified stuff in another thread (the Minecraft thread) causing a concurrent modification exception 1 Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)
Toma™ Posted November 15, 2018 Author Posted November 15, 2018 The packet for shooting: https://github.com/Toma1O6/PUBGMC-2.0/blob/master/java/com/toma/pubgmc/common/network/server/PacketShoot.java Quote
Toma™ Posted November 16, 2018 Author Posted November 16, 2018 (edited) 21 hours ago, diesieben07 said: Read the warning in the documentation. Okay I have reworked it a bit (based on the forge example). Is it good now? The code: Spoiler package com.toma.pubgmc.common.network.server; import com.toma.pubgmc.common.items.guns.GunBase; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.util.CooldownTracker; import net.minecraft.world.World; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class PacketShoot implements IMessage, IMessageHandler<PacketShoot, IMessage> { @Override public void toBytes(ByteBuf buf) { // TODO Auto-generated method stub } @Override public void fromBytes(ByteBuf buf) { // TODO Auto-generated method stub } @Override public IMessage onMessage(PacketShoot message, MessageContext ctx) { World world = ctx.getServerHandler().player.world; EntityPlayer player = ctx.getServerHandler().player; ItemStack stack = player.getHeldItemMainhand(); if(stack.getItem() instanceof GunBase) { GunBase gun = (GunBase)stack.getItem(); CooldownTracker tracker = player.getCooldownTracker(); if(stack.getItemDamage() < stack.getMaxDamage()) { MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); server.addScheduledTask(() -> { if(!tracker.hasCooldown(gun)) { gun.shoot(world, player, stack); tracker.setCooldown(gun, gun.getFireRate()); } }); } } return null; } } It seems to be working, but I'm not sure, but thank you both for your help Edited November 16, 2018 by Toma™ Quote
Toma™ Posted November 17, 2018 Author Posted November 17, 2018 So now, if I understand it correctly, I need to move everything into the scheduled task. Quote
Recommended Posts
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.