Jump to content

Recommended Posts

Posted

Ok, this may potentially be the most nooby question you will ever see, and it might make you want to shoot yourself. Please dont. So, I want to give the player an item when I click a button, but this isn't working

 

Button:

public void actionPerformed(GuiButton guibutton){
	if(guibutton.id == 24){
		// Sending packet to server
		IMessage msg = new SimplePacket.SimpleMessage(500, true);
		PacketHandler.net.sendToServer(msg);

	}
}

 

PacketHandler:

package com.bugzoo.FinancialMod;

import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

public class PacketHandler
{
public static SimpleNetworkWrapper net;
public static void initPackets()
{
net = NetworkRegistry.INSTANCE.newSimpleChannel("YourModId".toUpperCase());
registerMessage(SimplePacket.class, SimplePacket.SimpleMessage.class);
}
private static int nextPacketId = 0;
private static void registerMessage(Class packet, Class message)
{
	net.registerMessage(packet, message, nextPacketId, Side.CLIENT);
	net.registerMessage(packet, message, nextPacketId, Side.SERVER);
	nextPacketId++;
}
}

 

SimplePacket:

package com.bugzoo.FinancialMod;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;

import com.bugzoo.FinancialMod.SimplePacket.SimpleMessage;

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

public class SimplePacket implements IMessageHandler<SimpleMessage, IMessage>
{

Minecraft mc;
@Override
public IMessage onMessage(SimpleMessage message, MessageContext ctx)
{
// just to make sure that the side is correct
if (ctx.side.isClient())
{
mc.thePlayer.inventory.addItemStackToInventory(new ItemStack(FinancialMod.Wallet));
int integer = message.simpleInt;
boolean bool = message.simpleBool;
}
return message;
}
public static class SimpleMessage implements IMessage
{
	private int simpleInt;
	private boolean simpleBool;
		// this constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
	public SimpleMessage() {}
	public SimpleMessage(int simpleInt, boolean simpleBool)
	{
		this.simpleInt = simpleInt;
		this.simpleBool = simpleBool;
	}
	@Override
	public void fromBytes(ByteBuf buf)
	{
		// the order is important
		this.simpleInt = buf.readInt();
		this.simpleBool = buf.readBoolean();
	}
	@Override
		public void toBytes(ByteBuf buf)
	{
		buf.writeInt(simpleInt);
		buf.writeBoolean(simpleBool);
}
}
}

 

 

Posted

a) Why do you register your packet for being sent both ways? It should only go client -> server.

b) Why do you send and integer and a boolean when you never use them?

c) You need to use the serverside player when receiving the packet, you get it from the MessageContext.

d) Your packet has the potential of allowing players to infinitely create your Item over and over again. The server needs to check if it is ok for the client to send that packet, otherwise hacked clients could exploit it.

 

How do I get it from the MessageContext?

Posted

Post the full log.

 

 

[17:09:20] [main/INFO]: Setting user: Player187

[17:09:21] [Client thread/INFO]: LWJGL Version: 2.9.1

[17:09:22] [Client thread/ERROR]: Couldn't initialize twitch stream

[17:09:25] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:FinancialMod

[17:09:25] [sound Library Loader/INFO]: Sound engine started

[17:09:26] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas

[17:09:26] [Client thread/INFO]: Created: 256x256 textures/items-atlas

[17:09:26] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:FinancialMod

[17:09:26] [Client thread/INFO]: Created: 256x256 textures/items-atlas

[17:09:26] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas

[17:09:27] [sound Library Loader/INFO]: Sound engine started

[17:09:44] [server thread/INFO]: Starting integrated minecraft server version 1.7.10

[17:09:44] [server thread/INFO]: Generating keypair

[17:09:45] [server thread/INFO]: Preparing start region for level 0

[17:09:46] [server thread/INFO]: Changing view distance to 8, from 10

[17:09:46] [server thread/INFO]: Player187[local:E:222563d2] logged in with entity id 294 at (37.55642263672165, 64.0, 316.4772224591946)

[17:09:46] [server thread/INFO]: Player187 joined the game

[17:09:50] [server thread/INFO]: Player187 lost connection: TextComponent{text='Disconnected', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}

[17:09:50] [server thread/INFO]: Player187 left the game

[17:09:50] [server thread/INFO]: Stopping singleplayer server as player logged out

[17:09:50] [server thread/INFO]: Stopping server

[17:09:50] [server thread/INFO]: Saving players

[17:09:50] [server thread/INFO]: Saving worlds

[17:09:50] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Overworld

[17:09:50] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Nether

[17:09:50] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/The End

[17:10:40] [server thread/INFO]: Starting integrated minecraft server version 1.7.10

[17:10:40] [server thread/INFO]: Generating keypair

[17:10:40] [server thread/INFO]: Preparing start region for level 0

[17:10:41] [server thread/INFO]: Changing view distance to 8, from 10

[17:10:41] [server thread/INFO]: Player187[local:E:7af38210] logged in with entity id 1157 at (37.55642263672165, 64.0, 316.4772224591946)

[17:10:41] [server thread/INFO]: Player187 joined the game

[17:10:43] [server thread/INFO]: Stopping server

[17:10:43] [server thread/INFO]: Saving players

[17:10:43] [server thread/INFO]: Saving worlds

[17:10:43] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Overworld

[17:10:43] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Nether

[17:10:43] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/The End

[17:19:50] [server thread/INFO]: Starting integrated minecraft server version 1.7.10

[17:19:50] [server thread/INFO]: Generating keypair

[17:19:50] [server thread/INFO]: Preparing start region for level 0

[17:19:51] [server thread/INFO]: Changing view distance to 8, from 10

[17:19:52] [server thread/INFO]: Player187[local:E:cf370c52] logged in with entity id 1847 at (37.55642263672165, 64.0, 316.4772224591946)

[17:19:52] [server thread/INFO]: Player187 joined the game

[17:19:54] [server thread/INFO]: Player187 lost connection: TextComponent{text='Disconnected', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}

[17:19:54] [server thread/INFO]: Player187 left the game

[17:19:54] [server thread/INFO]: Stopping singleplayer server as player logged out

[17:19:54] [server thread/INFO]: Stopping server

[17:19:54] [server thread/INFO]: Saving players

[17:19:54] [server thread/INFO]: Saving worlds

[17:19:54] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Overworld

[17:19:54] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Nether

[17:19:54] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/The End

[17:19:57] [Client thread/INFO]: Stopping!

 

 

Posted

Copy and paste the full console output from your IDE.

 

Oh, right

 

[17:54:49] [main/INFO] [GradleStart]: Extra: []

[17:54:50] [main/INFO] [GradleStart]: Running with arguments: [--userProperties, {}, --accessToken, {REDACTED}, --assetIndex, 1.7.10, --assetsDir, C:/Users/Daniel/.gradle/caches/minecraft/assets, --version, 1.7.10, --tweakClass, cpw.mods.fml.common.launcher.FMLTweaker, --tweakClass, net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker]

[17:54:50] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLTweaker

[17:54:50] [main/INFO] [LaunchWrapper]: Using primary tweak class name cpw.mods.fml.common.launcher.FMLTweaker

[17:54:50] [main/INFO] [LaunchWrapper]: Loading tweak class name net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker

[17:54:50] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLTweaker

[17:54:50] [main/INFO] [FML]: Forge Mod Loader version 7.10.85.1230 for Minecraft 1.7.10 loading

[17:54:50] [main/INFO] [FML]: Java is Java HotSpot Client VM, version 1.7.0_67, running on Windows 8.1:x86:6.3, installed at C:\Program Files (x86)\Java\jre7

[17:54:50] [main/INFO] [FML]: Managed to load a deobfuscated Minecraft name- we are in a deobfuscated environment. Skipping runtime deobfuscation

[17:54:50] [main/INFO] [LaunchWrapper]: Calling tweak class net.minecraftforge.gradle.GradleStartCommon$GradleStartTweaker

[17:54:50] [main/INFO] [GradleStart]: Injecting location in coremod cpw.mods.fml.relauncher.FMLCorePlugin

[17:54:50] [main/INFO] [GradleStart]: Injecting location in coremod net.minecraftforge.classloading.FMLForgePlugin

[17:54:50] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker

[17:54:50] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.FMLDeobfTweaker

[17:54:50] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker

[17:54:50] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker

[17:54:50] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper

[17:54:50] [main/ERROR] [FML]: The binary patch set is missing. Either you are in a development environment, or things are not going to work!

[17:54:51] [main/ERROR] [FML]: FML appears to be missing any signature data. This is not a good thing

[17:54:51] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper

[17:54:51] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.FMLDeobfTweaker

[17:54:51] [main/INFO] [LaunchWrapper]: Loading tweak class name cpw.mods.fml.common.launcher.TerminalTweaker

[17:54:51] [main/INFO] [LaunchWrapper]: Calling tweak class cpw.mods.fml.common.launcher.TerminalTweaker

[17:54:51] [main/INFO] [LaunchWrapper]: Launching wrapped minecraft {net.minecraft.client.main.Main}

[17:54:52] [main/INFO]: Setting user: Player906

[17:54:53] [Client thread/INFO]: LWJGL Version: 2.9.1

[17:54:53] [Client thread/INFO] [sTDOUT]: [tv.twitch.StandardCoreAPI:<init>:16]: If on Windows, make sure to provide all of the necessary dll's as specified in the twitchsdk README. Also, make sure to set the PATH environment variable to point to the directory containing the dll's.

[17:54:53] [Client thread/ERROR]: Couldn't initialize twitch stream

[17:54:53] [Client thread/INFO] [MinecraftForge]: Attempting early MinecraftForge initialization

[17:54:53] [Client thread/INFO] [FML]: MinecraftForge v10.13.2.1230 Initialized

[17:54:53] [Client thread/INFO] [FML]: Replaced 182 ore recipies

[17:54:53] [Client thread/INFO] [MinecraftForge]: Completed early MinecraftForge initialization

[17:54:53] [Client thread/INFO] [FML]: Searching C:\Users\Daniel\Documents\Brain Bang\Coding\Minecraft Modding\New Mods\1.7.10\1.7.10 Bugzoos Financial Mod\eclipse\mods for mods

[17:54:53] [Client thread/INFO] [FinancialMod]: Mod FinancialMod is missing the required element 'name'. Substituting FinancialMod

[17:54:55] [Client thread/INFO] [FML]: Forge Mod Loader has identified 4 mods to load

[17:54:55] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, FinancialMod] at CLIENT

[17:54:55] [Client thread/INFO] [FML]: Attempting connection with missing mods [mcp, FML, Forge, FinancialMod] at SERVER

[17:54:55] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:FinancialMod

[17:54:55] [Client thread/INFO] [FML]: Processing ObjectHolder annotations

[17:54:55] [Client thread/INFO] [FML]: Found 341 ObjectHolder annotations

[17:54:55] [Client thread/INFO] [FML]: Configured a dormant chunk cache size of 0

[17:54:55] [Client thread/INFO] [FML]: Applying holder lookups

[17:54:55] [Client thread/INFO] [FML]: Holder lookups applied

[17:54:56] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

[17:54:56] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Starting up SoundSystem...

[17:54:56] [Thread-6/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Initializing LWJGL OpenAL

[17:54:56] [Thread-6/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

[17:54:56] [Thread-6/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: OpenAL initialized.

[17:54:56] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

[17:54:56] [sound Library Loader/INFO]: Sound engine started

[17:54:57] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas

[17:54:57] [Client thread/INFO]: Created: 256x256 textures/items-atlas

[17:54:57] [Client thread/INFO] [FML]: Forge Mod Loader has successfully loaded 4 mods

[17:54:57] [Client thread/INFO]: Reloading ResourceManager: Default, FMLFileResourcePack:Forge Mod Loader, FMLFileResourcePack:Minecraft Forge, FMLFileResourcePack:FinancialMod

[17:54:57] [Client thread/INFO]: Created: 256x256 textures/items-atlas

[17:54:58] [Client thread/INFO]: Created: 512x256 textures/blocks-atlas

[17:54:58] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

[17:54:58] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: SoundSystem shutting down...

[17:54:58] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:importantMessage:90]:    Author: Paul Lamb, www.paulscode.com

[17:54:58] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

[17:54:58] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

[17:54:58] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Starting up SoundSystem...

[17:54:58] [Thread-8/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: Initializing LWJGL OpenAL

[17:54:58] [Thread-8/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:    (The LWJGL binding of OpenAL.  For more information, see http://www.lwjgl.org)

[17:54:58] [Thread-8/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: OpenAL initialized.

[17:54:58] [sound Library Loader/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

[17:54:58] [sound Library Loader/INFO]: Sound engine started

[17:56:05] [server thread/INFO]: Starting integrated minecraft server version 1.7.10

[17:56:05] [server thread/INFO]: Generating keypair

[17:56:06] [server thread/INFO] [FML]: Injecting existing block and item data into this server instance

[17:56:06] [server thread/INFO] [FML]: Applying holder lookups

[17:56:06] [server thread/INFO] [FML]: Holder lookups applied

[17:56:06] [server thread/INFO] [FML]: Loading dimension 0 (Bugzoo's World) (net.minecraft.server.integrated.IntegratedServer@cda8e7)

[17:56:06] [server thread/INFO] [FML]: Loading dimension 1 (Bugzoo's World) (net.minecraft.server.integrated.IntegratedServer@cda8e7)

[17:56:06] [server thread/INFO] [FML]: Loading dimension -1 (Bugzoo's World) (net.minecraft.server.integrated.IntegratedServer@cda8e7)

[17:56:06] [server thread/INFO]: Preparing start region for level 0

[17:56:07] [server thread/INFO]: Preparing spawn area: 96%

[17:56:07] [server thread/INFO]: Changing view distance to 8, from 10

[17:56:08] [Netty Client IO #0/INFO] [FML]: Server protocol version 1

[17:56:08] [Netty IO #1/INFO] [FML]: Client protocol version 1

[17:56:08] [Netty IO #1/INFO] [FML]: Client attempting to join with 4 mods : [email protected],[email protected],[email protected],[email protected]

[17:56:08] [Netty IO #1/INFO] [FML]: Attempting connection with missing mods [] at CLIENT

[17:56:08] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [] at SERVER

[17:56:08] [server thread/INFO] [FML]: [server thread] Server side modded connection established

[17:56:08] [Client thread/INFO] [FML]: [Client thread] Client side modded connection established

[17:56:08] [server thread/INFO]: Player906[local:E:e0033372] logged in with entity id 302 at (37.55642263672165, 64.0, 316.4772224591946)

[17:56:08] [server thread/INFO]: Player906 joined the game

[17:56:10] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception

java.lang.ClassCastException: net.minecraft.client.network.NetHandlerPlayClient cannot be cast to net.minecraft.network.NetHandlerPlayServer

at cpw.mods.fml.common.network.simpleimpl.MessageContext.getServerHandler(MessageContext.java:36) ~[MessageContext.class:?]

at com.bugzoo.FinancialMod.SimplePacket.onMessage(SimplePacket.java:23) ~[simplePacket.class:?]

at com.bugzoo.FinancialMod.SimplePacket.onMessage(SimplePacket.java:1) ~[simplePacket.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]

at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]

at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]

at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]

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

at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?]

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

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

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

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

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_67]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]

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

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(GradleStartCommon.java:78) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

[17:56:10] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel YOURMODID

java.lang.ClassCastException: net.minecraft.client.network.NetHandlerPlayClient cannot be cast to net.minecraft.network.NetHandlerPlayServer

at cpw.mods.fml.common.network.simpleimpl.MessageContext.getServerHandler(MessageContext.java:36) ~[MessageContext.class:?]

at com.bugzoo.FinancialMod.SimplePacket.onMessage(SimplePacket.java:23) ~[simplePacket.class:?]

at com.bugzoo.FinancialMod.SimplePacket.onMessage(SimplePacket.java:1) ~[simplePacket.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:37) ~[simpleChannelHandlerWrapper.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:17) ~[simpleChannelHandlerWrapper.class:?]

at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]

at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]

at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]

at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]

at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?]

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

at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:317) [PlayerControllerMP.class:?]

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

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

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

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

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_67]

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_67]

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

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(GradleStartCommon.java:78) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

[17:56:10] [server thread/INFO]: Player906 lost connection: TextComponent{text='Disconnected', siblings=[], style=Style{hasParent=false, color=null, bold=null, italic=null, underlined=null, obfuscated=null, clickEvent=null, hoverEvent=null}}

[17:56:10] [server thread/INFO]: Player906 left the game

[17:56:10] [server thread/INFO]: Stopping singleplayer server as player logged out

[17:56:10] [server thread/INFO]: Stopping server

[17:56:10] [server thread/INFO]: Saving players

[17:56:10] [server thread/INFO]: Saving worlds

[17:56:10] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Overworld

[17:56:10] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/Nether

[17:56:10] [server thread/INFO]: Saving chunks for level 'Bugzoo's World'/The End

[17:56:10] [server thread/INFO] [FML]: Unloading dimension 0

[17:56:10] [server thread/INFO] [FML]: Unloading dimension -1

[17:56:10] [server thread/INFO] [FML]: Unloading dimension 1

[17:56:10] [server thread/INFO] [FML]: Applying holder lookups

[17:56:10] [server thread/INFO] [FML]: Holder lookups applied

[17:56:14] [Client thread/INFO]: Stopping!

[17:56:14] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

[17:56:14] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]: SoundSystem shutting down...

[17:56:14] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:importantMessage:90]:    Author: Paul Lamb, www.paulscode.com

[17:56:14] [Client thread/INFO] [sTDOUT]: [paulscode.sound.SoundSystemLogger:message:69]:

 

 

Posted

Don't return the message in onMessage! What you return there is send as a response to whoever sent the incoming packet. Normally you want to return null there. And again: Do not register your packets for both sides! (If you had fixed that the error would be different).

 

Where am I registering it on both sides?

Posted

Show your updated PacketHandler class and the Message & MessageHandler.

 

PacketHandler:

package com.bugzoo.FinancialMod;

import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

public class PacketHandler
{
public static SimpleNetworkWrapper net;
public static void initPackets()
{
net = NetworkRegistry.INSTANCE.newSimpleChannel("YourModId".toUpperCase());
registerMessage(SimplePacket.class, SimplePacket.SimpleMessage.class);
}
private static int nextPacketId = 0;
private static void registerMessage(Class packet, Class message)
{
	net.registerMessage(packet, message, nextPacketId, Side.CLIENT);
	nextPacketId++;
}
}

 

SimpleMessage:

package com.bugzoo.FinancialMod;

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;

import com.bugzoo.FinancialMod.SimplePacket.SimpleMessage;

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

public class SimplePacket implements IMessageHandler<SimpleMessage, IMessage>
{

Minecraft mc;
@Override
public IMessage onMessage(SimpleMessage message, MessageContext ctx)
{
// just to make sure that the side is correct
if (ctx.side.isClient())
{
	ctx.getServerHandler().playerEntity.inventory.addItemStackToInventory(new ItemStack(FinancialMod.Wallet));
}
return null;
}
public static class SimpleMessage implements IMessage
{
	private int simpleInt;
	private boolean simpleBool;
		// this constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
	public SimpleMessage() {}
	public SimpleMessage(int simpleInt, boolean simpleBool)
	{
		this.simpleInt = simpleInt;
		this.simpleBool = simpleBool;
	}
	@Override
	public void fromBytes(ByteBuf buf)
	{
		// the order is important
		this.simpleInt = buf.readInt();
		this.simpleBool = buf.readBoolean();
	}
	@Override
		public void toBytes(ByteBuf buf)
	{
		buf.writeInt(simpleInt);
		buf.writeBoolean(simpleBool);
}
}
}

 

Button:

public void actionPerformed(GuiButton guibutton){
	if(guibutton.id == 24){
		// Sending packet to server
		IMessage msg = new SimplePacket.SimpleMessage(500, true);
		PacketHandler.net.sendToServer(msg);
	}
}
   

Posted

a) Now you register your packet to be received on the Client, but you sent it to the server.

b) In your MessageHandler you check for client side, but your packet is only ever received on the server.

c) You are still sending unused data in your packet.

 

How do I send it to the client? I've tried this code, but the player variable doesn't exist

public void actionPerformed(GuiButton guibutton){
	if(guibutton.id == 24){
		// Sending packet to client
		if (player instanceof EntityPlayerMP)
		{
		IMessage msg = new SimplePacket.SimpleMessage(800, false);
		PacketHandler.net.sendTo(msg, (EntityPlayerMP)player);
		}
	}
}

Posted

You should send it to the server! You need to register it as being received on the server, too.

 

You said about sending unused data, where am I doing that?

Posted

It doesn't matter. Static inner classes behave just like a normal class.

 

Ok, Now

 

I stopped sending unused data

I'm now sending to the server

Now checks for server and recieves on server

 

But still, nothing happens when I click the button

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.