Jump to content

Recommended Posts

Posted

I made a small and simple test mod to try to understand how packets work for a larger mod. This is a boat mod that when a key is pressed, the boat speeds up. Offline it works just fine, on the server it crashes.

 

Crash Log

 

 

---- Minecraft Crash Report ----
// I feel sad now 

Time: 5/10/13 7:31 AM
Description: Exception in server tick loop

java.lang.NoClassDefFoundError: net/minecraft/client/settings/KeyBinding
at speedboats.BoatKeyHandler.<clinit>(BoatKeyHandler.java:13)
at speedboats.EntitySpeedBoat.onUpdate(EntitySpeedBoat.java:358)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2337)
at net.minecraft.world.WorldServer.uncheckedUpdateEntity(WorldServer.java:726)
at net.minecraft.network.NetServerHandler.handleFlying(NetServerHandler.java:237)
at net.minecraft.network.packet.Packet10Flying.processPacket(Packet10Flying.java:51)
at net.minecraft.network.TcpConnection.processReadPackets(TcpConnection.java:461)
at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:134)
at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:53)
at net.minecraft.server.dedicated.DedicatedServerListenThread.networkTick(DedicatedServerListenThread.java:34)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:675)
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:275)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:571)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:469)
at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16)
Caused by: java.lang.ClassNotFoundException: net.minecraft.client.settings.KeyBinding
at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:238)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 15 more
Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/settings/KeyBinding for invalid side SERVER
at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50)
at cpw.mods.fml.relauncher.RelaunchClassLoader.runTransformers(RelaunchClassLoader.java:352)
at cpw.mods.fml.relauncher.RelaunchClassLoader.findClass(RelaunchClassLoader.java:225)
... 17 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
Minecraft Version: 1.5.2
Operating System: Windows 7 (amd64) version 6.1
Java Version: 1.7.0_17, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 968044856 bytes (923 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 4305 (241080 bytes; 0 MB) allocated, 4145 (232120 bytes; 0 MB) used
Suspicious classes: FML and Forge are installed
IntCache: cache: 13, tcache: 0, allocated: 3, tallocated: 71
FML: MCP v7.51 FML v5.2.5.686 Minecraft Forge 7.8.0.686 4 mods loaded, 4 mods active
mcp{7.44} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{5.2.5.686} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{7.8.0.686} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
SpeedBoats{0.1.0} [speedBoats] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 924 (51744 bytes; 0 MB) allocated, 718 (40208 bytes; 0 MB) used
Player Count: 1 / 10; [EntityPlayerMP['Player830'/312, l='mcpworld', x=1.31, y=63.35, z=205.54]]
Is Modded: Definitely; Server brand changed to 'fml,forge'
Type: Dedicated Server (map_server.txt)

 

 

 

PacketHandler

 

 

public class SpeedBoatPacketHandler implements IPacketHandler
{

@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) 
{
	if("SpeedBoats".equals(packet.channel))
	{
		DataInputStream in = new DataInputStream(new ByteArrayInputStream(packet.data));
		try
        {
			int EntityID = in.readInt();
			float Forward = in.readFloat();

			Entity E0 =((EntityPlayerMP)player).worldObj.getEntityByID(EntityID);
			if(E0 instanceof EntitySpeedBoat)
			{
				((EntitySpeedBoat) E0).Speed = Forward;
			}
        }
        catch (IOException e)
        {
            throw new RuntimeException(e);
        }
	}

}

}

 

 

 

keyhandler

 

 

public class BoatKeyHandler extends KeyBindingRegistry
{
    public static KeyBinding forwardKeyBinding = new KeyBinding("forwardKey", 33);
    public static boolean pressedKey;

    public BoatKeyHandler()
    {
        super();
    }

    public boolean isForwardPressed()
    {
        return pressedKey;
    }

    public String getLabel()
    {
        return "BoatHandler";
    }

    public void keyDown(EnumSet var1, KeyBinding var2, boolean var3, boolean var4)
    {
        if (var2.keyCode == forwardKeyBinding.keyCode)
        {
            pressedKey = true;
        }
    }

    public void keyUp(EnumSet var1, KeyBinding var2, boolean var3)
    {
        if (var2.keyCode == forwardKeyBinding.keyCode)
        {
            pressedKey = false;
        }
    }

    public EnumSet ticks()
    {
        return EnumSet.of(TickType.PLAYER);
    }
}

 

 

 

snip from the entity class

 

 

referenced area

if (this.riddenByEntity != null)
            {
            	this.motionX += this.riddenByEntity.motionX * this.speedMultiplier;
                this.motionZ += this.riddenByEntity.motionZ * this.speedMultiplier;
            	
                boolean k = BoatKeyHandler.pressedKey;
            	
                 if(k)
                 {
                	 motionX += riddenByEntity.motionX * 10.199999999999999D;
                     motionZ += riddenByEntity.motionZ * 10.199999999999999D;
                 } 
                 else
                 {
                     motionX += riddenByEntity.motionX * 0.20000000000000001D;
                     motionZ += riddenByEntity.motionZ * 0.20000000000000001D;
                 }
            }

How I am handling the code to the packet

if(FMLCommonHandler.instance().getSide().isClient() && this.riddenByEntity!=null && this.riddenByEntity instanceof EntityPlayerSP)
            	{
            		boolean NeedsTransfer=false;
            		EntityPlayerSP P = (EntityPlayerSP)this.riddenByEntity;
            		if(P.movementInput.moveForward!=this.Speed)
            		{
            			this.Speed=P.movementInput.moveForward;
            			NeedsTransfer=true;
            		}
            		
            		if(NeedsTransfer)
            		{
            			ByteArrayOutputStream var3 = new ByteArrayOutputStream();
            	        DataOutputStream var4 = new DataOutputStream(var3);
            	        try
            	        {
            	        	var4.writeInt(this.entityId);
            	        	var4.writeFloat(this.Speed);
            	        }
            	        catch(Exception e)
            	        {
            	        	System.err.println("ERROR WHILE WRITING Rider Input Data to Packet");
            	        }
            			Minecraft.getMinecraft().getNetHandler().addToSendQueue(new Packet250CustomPayload("RiderInput",var3.toByteArray()));
            		}
            }

 

 

 

This code came from a team member from the Fossil/Archeology mod, whos time is very limited at the moment and hasnt had a chance to help with this. I am hoping you can. Whats missing, whats broken, etc...Mazetar has helped a bit, but I am still getting lost and confused as this is my first go round with packets and keybinding.

Posted

At the same place as you check for a ridet inn the entity, check to see if the world.isRemote and only let the block of code get run on the CLIENT side.

 

The crash is because the server can'tread the key input line, it has no understanding of it and crashes.

I'm still at work so I can'tgo into detail on the other things, but understand and fix this issue first :)

If you guys dont get it.. then well ya.. try harder...

Posted

I tried that, and in the 2 places and the 2 different ways I added it, it will either let me in the boat and have no control at all, or crash when placing the boat. I have looked at the src for the steamship mod and also the spiderman mod and half wonder if this is even right<the way I am doing it> because neither use a key handler, and neither have the packet code in the entity class. Also both seem to use a tick handler...

Posted

I have looked at some source on github provided by GotoLink and tried to model mine using the same code more or less, and while his works for the hotairballon mine is not working for the speedboat.....I have posted my source for this to github hoping someone could take a look and let me know why. Or if there is a better way to do this, possibly show me how. I would really like to figure this out so I can apply this to another mod I am actually working on and make it so I can fly my chickens around in MP....

 

https://github.com/microjunk/speedboats

Posted

From your KeyHandler:

if (ent!=null && ent instanceof EntitySpeedBoat)

 

From here, you say that if you are driving a SpeedBoat, then you do NOTHING!!!

and else if, you do something, but you only do that IF you are not riding a entity :P

 

If you guys dont get it.. then well ya.. try harder...

Posted

yeah, I think I see it now....duh, how did I miss that. I went through the code he had like 20 times before making changes, just to make sure I understood it. I dont know how I missed that. I am at work right now, so when I get home I will fix it. When All goes well, I should be able to add it to the other mod then just fine. Thanks for pointing that out. I tried to add you to skype, but I guess it didnt work....

Posted

Thanks for pointing that out Mazetar, with that I was able to find 2 other smaller mistakes and fix them too....All is working now, so now I can add this to the other issue I had with the actual mod this learning experience was intended for, riding vanilla mobs....

 

(whipping sound) ride that creeper, just a soon as I figure out how to stop the swell timer when mounted....

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.