Posted January 11, 201510 yr Ok so im trying to get back into modding and to get something done i never managed before...packets i spent a fair while following some well made guides but nothing went right....turns out they were out of date lol so i searched more and i see "simple network wrapper" is the way to go, and i thought i had it sorted....untill i tried to use them in my main mod file i have public static SimpleNetworkWrapper network; ..snip.. @Mod.EventHandler public void preInit(FMLPreInitializationEvent event) { configHandler.init(event.getSuggestedConfigurationFile()); network = NetworkRegistry.INSTANCE.newSimpleChannel("messengerBunny"); //so we create the channel //here is where we add the pacets...registering one packet per class network.registerMessage(speechPacket.speechPacketHandler.class,speechPacket.class,0, Side.CLIENT);//so we are registering a packet called speechpacket to channel one of our network (the messenger bunny) hmmm ok can understand that permissions.init();//lets give the artists thier well deserved credit! creativeTabs.init();//set up the creative tabs blocks.init(); //lets load our blocks if (configHandler.RecordsEnabled){ records.init();} //load the records if (configHandler.BunnysEnabled){ bunnys.init();} // if bunnys are enabled we load them (this modular stuff is gonna kill me lol) FMLCommonHandler.instance().bus().register(new eventHandler());// load the event handlers MinecraftForge.EVENT_BUS.register(new eventHandler()); } ..snip.. then my packet is package com.mrgreaper.themrgmod.network; import com.mrgreaper.themrgmod.themrgmod; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; import net.minecraft.nbt.NBTTagCompound; /** * Created by david on 11/01/2015. */ public class speechPacket implements IMessage { private String message; private double voice; private float pitch; private float pitchRange; private float pitchShift; //private String voiceName; public speechPacket(){} //without this blank one the packet crashes ...why do we need it? arghhhhhhhhhh public speechPacket(String message,double voice,float pitch, float pitchRange, float pitchShift ){ this.message=message; this.voice=voice; this.pitchRange = pitchRange; this.pitch = pitch; this.pitchShift= pitchShift; } @Override public void fromBytes(ByteBuf buf) { // so we will need an nbt tag to store the info we want to send...here we read it NBTTagCompound tag = ByteBufUtils.readTag(buf); message = tag.getString("message"); voice = tag.getDouble("voice"); pitch = tag.getFloat("pitch"); pitchRange = tag.getFloat("pitchRange"); pitchShift = tag.getFloat("pitchShift"); } @Override public void toBytes(ByteBuf buf) { //and here we create it NBTTagCompound tag = new NBTTagCompound(); tag.setString("message",message); tag.setDouble("voice",voice); tag.setFloat("pitch",pitch); tag.setFloat("pitchRange",pitchRange); tag.setFloat("pitchShift",pitchShift); } public static class speechPacketHandler implements IMessageHandler <speechPacket,IMessage> { //so dont lile classes inside classes but everything i read suggests this is the way to go...still grrrrrr @Override public IMessage onMessage(speechPacket message, MessageContext ctx) { themrgmod.proxy.speechCreate(message.message,message.voice,message.pitch,message.pitchRange,message.pitchShift); return null; } } } that has the handler class inside it too now its called from my eventhandler (as a test) package com.mrgreaper.themrgmod.lib; import com.mrgreaper.themrgmod.network.speechPacket; import com.mrgreaper.themrgmod.themrgmod; import cpw.mods.fml.client.event.ConfigChangedEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.PlayerEvent; /** * Created by david on 11/01/2015. */ public class eventHandler { @SubscribeEvent public void onConfigurationChangeEvent(ConfigChangedEvent.OnConfigChangedEvent event) { if (event.modID.equalsIgnoreCase(constants.modid)) { configHandler.loadConfiguration(); } } @SubscribeEvent//test event public void TwistedPickupEvent(PlayerEvent.ItemPickupEvent event) { logHelper.info("if i can read this then the event handler is working" + event.pickedUp); themrgmod.network.sendToAll(new speechPacket("hello i think im working",12,23,12,3)); } } first a note on sendToAll.... i tried sentToAllAround as that seems perfect for the end goal....but it wanted a target point and nothing i tried to use as the target was valid including event.player.getPlayerCoordinates() which would be the specific co-ords to use but it wasnt having it event.player was also not valid for send to specific player. anyway the above results in this when you pickup an item [22:45:35] [server thread/INFO] [The Mr G Mod]: if i can read this then the event handler is workingEntityItem['item.tile.themrgmod_TestBlock'/602, l='New World', x=8.88, y=65.13, z=-1.88] [22:45:35] [Client thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[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.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] 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/:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:?] Caused by: java.lang.IndexOutOfBoundsException at io.netty.buffer.EmptyByteBuf.readShort(EmptyByteBuf.java:449) ~[EmptyByteBuf.class:?] at net.minecraft.network.PacketBuffer.readShort(PacketBuffer.java:569) ~[PacketBuffer.class:?] at net.minecraft.network.PacketBuffer.readNBTTagCompoundFromBuffer(PacketBuffer.java:105) ~[PacketBuffer.class:?] at cpw.mods.fml.common.network.ByteBufUtils.readTag(ByteBufUtils.java:206) ~[byteBufUtils.class:?] at com.mrgreaper.themrgmod.network.speechPacket.fromBytes(speechPacket.java:35) ~[speechPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[simpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[simpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] ... 25 more [22:45:35] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[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.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] 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/:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:?] Caused by: java.lang.IndexOutOfBoundsException at io.netty.buffer.EmptyByteBuf.readShort(EmptyByteBuf.java:449) ~[EmptyByteBuf.class:?] at net.minecraft.network.PacketBuffer.readShort(PacketBuffer.java:569) ~[PacketBuffer.class:?] at net.minecraft.network.PacketBuffer.readNBTTagCompoundFromBuffer(PacketBuffer.java:105) ~[PacketBuffer.class:?] at cpw.mods.fml.common.network.ByteBufUtils.readTag(ByteBufUtils.java:206) ~[byteBufUtils.class:?] at com.mrgreaper.themrgmod.network.speechPacket.fromBytes(speechPacket.java:35) ~[speechPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[simpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[simpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] ... 25 more [22:45:35] [Client thread/ERROR] [FML]: There was a critical exception handling a packet on channel messengerBunny io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:99) ~[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.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] 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/:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_25] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_25] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_25] at java.lang.reflect.Method.invoke(Method.java:483) ~[?:1.8.0_25] at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:?] Caused by: java.lang.IndexOutOfBoundsException at io.netty.buffer.EmptyByteBuf.readShort(EmptyByteBuf.java:449) ~[EmptyByteBuf.class:?] at net.minecraft.network.PacketBuffer.readShort(PacketBuffer.java:569) ~[PacketBuffer.class:?] at net.minecraft.network.PacketBuffer.readNBTTagCompoundFromBuffer(PacketBuffer.java:105) ~[PacketBuffer.class:?] at cpw.mods.fml.common.network.ByteBufUtils.readTag(ByteBufUtils.java:206) ~[byteBufUtils.class:?] at com.mrgreaper.themrgmod.network.speechPacket.fromBytes(speechPacket.java:35) ~[speechPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:17) ~[simpleIndexedCodec.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleIndexedCodec.decodeInto(SimpleIndexedCodec.java:7) ~[simpleIndexedCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:77) ~[FMLIndexedMessageToMessageCodec.class:?] at cpw.mods.fml.common.network.FMLIndexedMessageToMessageCodec.decode(FMLIndexedMessageToMessageCodec.java:17) ~[FMLIndexedMessageToMessageCodec.class:?] at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81) ~[MessageToMessageCodec$2.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89) ~[MessageToMessageDecoder.class:?] ... 25 more I did have an unknown function error before i added the blank method call (as advised to someone with the same issue i had) also i realise i have a redundent step, the packet is sent to the client side so i dont really need to use the proxy (that makes sure the code is only run on the client side) but i cant see that hurting it (unless im wrong).
January 11, 201510 yr Check out diesieben07's tutorial on packets. Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
January 11, 201510 yr You never write the NBT tag to the byte buffer, so the buffer index goes out of bounds when you try to read values from it. As for the nested handler class, it is simply convenient because you can then access the message class' private members without adding getter methods, and your handler is 99.9999999999999999999% likely to never be used in isolation anyways. http://i.imgur.com/NdrFdld.png[/img]
January 11, 201510 yr Author Check out diesieben07's tutorial on packets. The reply is appreciated but i have read that a few times, thats how im as far as i am (it seemed the only uptodate one i could find and was referenced in a lot of other places) That doesnt help the issue though registering the packet....yep its registered implementing the packet class ...yep thats done implementing the packet handler...yep done (even did it inside the other class as shown, though i dont like having classes inside classes as thats new to me) sending packets.... done...but not working packet responses...not needed a response so havent done that, but it looks self explanatory
January 11, 201510 yr You should finish packet-responses to make it easier to see if the packet has been received. The packet might have been received but nothing happened because Minecraft didn't know what do with it, so the packet was discarded. Don't make mods if you don't know Java. Check out my website: http://shadowfacts.net Developer of many mods
January 11, 201510 yr Author You never write the NBT tag to the byte buffer, so the buffer index goes out of bounds when you try to read values from it. As for the nested handler class, it is simply convenient because you can then access the message class' private members without adding getter methods, and your handler is 99.9999999999999999999% likely to never be used in isolation anyways. ah! ok now its working! thank you i still dont get targetpoints though. Lets take an example of what i want to do, a tile entity will emit the speech synth and all with in a range of x will hear it.. now how i would do that on 1.6.4 is to use the code from the beacon to get all the players in a box and then play a sound at them (or in this case send a packet to them, 1 by 1 just going through the list of players in that range), the sendToAllAround seems like a god send, but i just dont know how to make it use the tile entitiy (or any entitiy/co-ords) as the main point...or how to tell it the range
January 12, 201510 yr You're sending the packet from your TileEntity, right? So you should have x/y/zCoord available to create the TargetPoint: // for example, to send to all within 64 blocks: yourNetworkInstance.sendToAllAround(message, new NetworkRegistry.TargetPoint(dimension, xCoord, yCoord, zCoord, 64.0D)); http://i.imgur.com/NdrFdld.png[/img]
January 12, 201510 yr Author You're sending the packet from your TileEntity, right? So you should have x/y/zCoord available to create the TargetPoint: // for example, to send to all within 64 blocks: yourNetworkInstance.sendToAllAround(message, new NetworkRegistry.TargetPoint(dimension, xCoord, yCoord, zCoord, 64.0D)); ah i see, for some reason i thought it took only one value....hence my confusion. seems rather simple now lol thank you.
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.