Jump to content

Recommended Posts

Posted

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 

Posted

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

  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.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)

Posted (edited)
21 hours ago, diesieben07 said:

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 by Toma™

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.