Jump to content

[SOLVED]Mod dosen't work on server ? Packet recieving and sending?


Koopamillion

Recommended Posts

Your message is being sent to the server, so you need to register it with Side.SERVER, not Side.CLIENT.

 

You put the movement code (and also the stack-damaging code) in the message handler's onMessage method, but I suggest you also keep your code that updates the client-side player motion - it will make the controls more responsive feeling.

Link to comment
Share on other sites

BTW - Thanks for not just giving up on me, it's much appreciated! :D

 

Ok, I'm very very very close :D!

 

EDIT: The server crashes even though I've done all the messages :'( It says:

 

If you can please could you post the code I need to do because these messages are so confusing....

 

 

net.minecraft.util.ReportedException: Ticking player

at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:384) ~[EntityPlayerMP.class:?]

at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) ~[NetHandlerPlayServer.class:?]

at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) ~[C03PacketPlayer.class:?]

at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:111) ~[C03PacketPlayer.class:?]

at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241) ~[NetworkManager.class:?]

at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]

at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:349) [DedicatedServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Caused by: java.lang.NoClassDefFoundError: net/minecraft/client/Minecraft

at com.koopamillion.Main.ServerProxy.keyBindJump(ServerProxy.java:40) ~[serverProxy.class:?]

at com.koopamillion.item.jetpack.onArmorTick(jetpack.java:38) ~[jetpack.class:?]

at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:355) ~[inventoryPlayer.class:?]

at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610) ~[EntityPlayer.class:?]

at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) ~[EntityLivingBase.class:?]

at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327) ~[EntityPlayer.class:?]

at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) ~[EntityPlayerMP.class:?]

... 10 more

Caused by: java.lang.ClassNotFoundException: net.minecraft.client.Minecraft

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191) ~[launchwrapper-1.11.jar:?]

at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_73]

at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_73]

at com.koopamillion.Main.ServerProxy.keyBindJump(ServerProxy.java:40) ~[serverProxy.class:?]

at com.koopamillion.item.jetpack.onArmorTick(jetpack.java:38) ~[jetpack.class:?]

at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:355) ~[inventoryPlayer.class:?]

at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610) ~[EntityPlayer.class:?]

at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) ~[EntityLivingBase.class:?]

at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327) ~[EntityPlayer.class:?]

at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) ~[EntityPlayerMP.class:?]

... 10 more

Caused by: java.lang.RuntimeException: Attempted to load class net/minecraft/client/Minecraft for invalid side SERVER

at cpw.mods.fml.common.asm.transformers.SideTransformer.transform(SideTransformer.java:50) ~[forgeSrc-1.7.10-10.13.4.1448-1.7.10.jar:?]

at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:279) ~[launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:176) ~[launchwrapper-1.11.jar:?]

at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_73]

at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_73]

at com.koopamillion.Main.ServerProxy.keyBindJump(ServerProxy.java:40) ~[serverProxy.class:?]

at com.koopamillion.item.jetpack.onArmorTick(jetpack.java:38) ~[jetpack.class:?]

at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:355) ~[inventoryPlayer.class:?]

at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:610) ~[EntityPlayer.class:?]

at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1816) ~[EntityLivingBase.class:?]

at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:327) ~[EntityPlayer.class:?]

at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:330) ~[EntityPlayerMP.class:?]

... 10 more

 

 

My proxy code and jetpack code:

 

 

@Override

public void onArmorTick(World world, EntityPlayer player, ItemStack stack){

if(stack.getItem() == Mitems.jetpack && MainRegistry.proxy.keyBindJump()){

JetpackMessage.sendToServer(new JetpackMessage(1));

/*int yaw = (int)player.rotationYaw;

 

        if (yaw<0)           

          yaw+=360; 

 

        yaw+=22;   

        yaw%=360; 

 

        int facing = yaw/45;  //  360degrees divided by 45 == 8 zones

     

 

    if(facing == 0){

    player.motionZ = 0.5;

    }

    if(facing == 1){

    player.motionZ = 0.5;

    player.motionX = -0.5;

    }

    if(facing == 2){

    player.motionX = -0.5;

    }

    if(facing == 3){

    player.motionX = -0.5;

    player.motionZ = -0.5;

    }

    if(facing == 4){

    player.motionZ = -0.5;

    }

    if(facing == 5){

    player.motionZ = -0.5;

    player.motionX = 0.5;

    }

    if(facing == 6){

   

    player.motionX = 0.5;

    }

    if(facing == 7){

    player.motionZ = 0.5;

    player.motionX = 0.5;

    }

    world.spawnParticle("flame", player.posX + 0.2, player.posY - 0.6, player.posZ - 0.2, 0, -0.3, 0);

world.spawnParticle("flame", player.posX - 0.2, player.posY - 0.6, player.posZ - 0.2, 0, -0.3, 0);

world.spawnParticle("largesmoke", player.posX + 0.2, player.posY - 0.6, player.posZ - 0.2, 0, -0.3, 0);

world.spawnParticle("largesmoke", player.posX - 0.2, player.posY - 0.6, player.posZ - 0.2, 0, -0.3, 0);

world.spawnParticle("lava", player.posX + 0.2, player.posY - 0.6, player.posZ - 0.2, 0, -0.3, 0);

world.spawnParticle("lava", player.posX - 0.2, player.posY - 0.6, player.posZ - 0.2, 0, -0.3, 0);

 

player.motionY = 0.5;*/

Mitems.jetpack.setDamage(stack, Mitems.jetpack.getDamage(stack) + 1);

 

}

 

 

Proxy:

 

public boolean keyBindJump(){

return Minecraft.getMinecraft().gameSettings.keyBindJump.getIsKeyPressed();

}

 

 

Please can you help because I've setup messages and it's not working :(

 

THE CLIENT DOSENT CRASH.

 

But when you said the update code, what code do you mean?

 

 

Link to comment
Share on other sites

I really don't get this...  ???

 

New code:

 

Crashes... I think it's because it's returning null but I did a null != check. So I'm not sure... Plus even if I fix this event I think it will still bug out because Im using minecraft.getMinecraft... How do I fix this! Thanks in advance!

 

This is my jetpack event code: (I did register it with that fmlcommonhandler.register.bus thingy)

 

 

package com.koopamillion.Main;

 

import com.koopamillion.item.Mitems;

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import cpw.mods.fml.common.gameevent.TickEvent;

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

 

public class JetpackEvent {

 

@SubscribeEvent

public void onClientTick(TickEvent.ClientTickEvent e){

if(e.phase == TickEvent.Phase.START) {

EntityPlayer player = Minecraft.getMinecraft().thePlayer;

ItemStack stack = player.getCurrentArmor(1);

if((stack != null && stack.getItem() == Mitems.jetpack && MainRegistry.proxy.keyBindJump())){

JetpackMessage.sendToServer(new JetpackMessage(1));

}else{

System.out.println(stack);

}}

 

}

}

 

 

 

Crash report:

 

 

[12:39:08] [Client thread/FATAL]: Unreported exception thrown!

java.lang.NullPointerException

at com.koopamillion.Main.JetpackEvent.onClientTick(JetpackEvent.java:17) ~[JetpackEvent.class:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler_13_JetpackEvent_onClientTick_ClientTickEvent.invoke(.dynamic) ~[?:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) ~[ASMEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138) ~[EventBus.class:?]

at cpw.mods.fml.common.FMLCommonHandler.onPreClientTick(FMLCommonHandler.java:325) ~[FMLCommonHandler.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1678) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) ~[Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:962) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_73]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_73]

at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_73]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) [start/:?]

at GradleStart.main(Unknown Source) [start/:?]

[12:39:08] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:388]: ---- Minecraft Crash Report ----

// Oh - I know what I did wrong!

 

Time: 29/03/16 12:39

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at com.koopamillion.Main.JetpackEvent.onClientTick(JetpackEvent.java:17)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_13_JetpackEvent_onClientTick_ClientTickEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:138)

at cpw.mods.fml.common.FMLCommonHandler.onPreClientTick(FMLCommonHandler.java:325)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1678)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039)

at net.minecraft.client.Minecraft.run(Minecraft.java:962)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

 

 

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

---

 

 

 

Link to comment
Share on other sites

OK, I've got it sending a message, thanks guys! But... Unfortunately I can't make the players motion change...

 

I've done sendToServer(bla bla) NOT sendTo(bla bla)

 

However, it's the onMessage that answers it, not the on server message, therefore I don't have a player parameter and can't make the player move... This is the handler:

 

 

package com.koopamillion.Main;

 

import cpw.mods.fml.common.network.simpleimpl.IMessage;

import cpw.mods.fml.common.network.simpleimpl.MessageContext;

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

 

public class JetpackHandler extends AbstractServerMessageHandler<JetpackMessage>{

 

 

 

 

 

@Override

public IMessage handleServerMessage(EntityPlayer player, JetpackMessage message, MessageContext ctx) {

 

player.motionY = 0.5;

System.out.println(message.i);

 

return null;

}

 

 

@Override

public IMessage onMessage(JetpackMessage message, MessageContext ctx) {

 

 

System.out.println(message.i);

return null;

}

public void fly(EntityPlayer player, ItemStack stack){

player.motionY = 0.5;

}

}

 

 

 

The message:

 

 

package com.koopamillion.Main;

 

import cpw.mods.fml.common.network.ByteBufUtils;

import cpw.mods.fml.common.network.simpleimpl.IMessage;

import io.netty.buffer.ByteBuf;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.EntityPlayerMP;

 

 

public class JetpackMessage implements IMessage{

 

public static int i;

 

public JetpackMessage() {}

 

    public JetpackMessage(int i) {

        this.i = i;

    }

@Override

public void fromBytes(ByteBuf buf) {

 

i = buf.readInt();

}

 

@Override

public void toBytes(ByteBuf buf) {

buf.writeInt(i);

 

}

public static final void sendToServer(IMessage message) {

MainRegistry.network.sendToServer(message);

}

public static final void sendToServe(IMessage message, EntityPlayer player) {

MainRegistry.network.sendTo(message, (EntityPlayerMP) player);

}

 

 

}

 

 

 

And the jetpack event just does mainregistry.network.sendToServer(new JetpackMessage(1)).

 

So, how do I make it move the player.. Thanks in advance :)

 

Link to comment
Share on other sites

Well...in

onMessage

you're not doing anything to make the player move.

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.

Link to comment
Share on other sites

Okay, but It dosen't do anything to the player... (But it is getting the correct player as I tested it with give experience)

 

My code on jetpack handler:

 

 

package com.koopamillion.Main;

 

import cpw.mods.fml.common.network.simpleimpl.IMessage;

import cpw.mods.fml.common.network.simpleimpl.MessageContext;

import net.minecraft.client.Minecraft;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

 

public class JetpackHandler extends AbstractServerMessageHandler<JetpackMessage>{

 

 

 

 

 

@Override

public IMessage handleServerMessage(EntityPlayer player, JetpackMessage message, MessageContext ctx) {

 

player.motionY = 0.5;

System.out.println(message.i);

 

return null;

}

 

 

@Override

public IMessage onMessage(JetpackMessage message, MessageContext ctx) {

 

 

this.fly(ctx.getServerHandler().playerEntity);

System.out.println(message.i);

return null;

}

public void fly(EntityPlayer player){

player.motionY = 0.5;

}

}

 

Thanks! 

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.