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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
    • Do you use features of inventory profiles next (ipnext) or is there a change without it?
    • Remove rubidium - you are already using embeddium, which is a fork of rubidium
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.