Jump to content

GUI Button Packet handling


bigbaddevil6

Recommended Posts

Well, I thought I understood it and after looking for quite a while at other Open Source Code. I have come to the realization, I have hardly any clue what I'm doing with this. I have sent a packet I've gotten that far, but this one is stumping me cause I need to get the TileEntity, buttonId and handle it. I think it comes down to it, I'm handling getting the TileEntity completely wrong and most likely going to be told so. Hopefully you can look past my stupidity, and give me a few pointers on the proper way to do this. Once I get it the first time I'm usually golden. It's just getting it that first time....

 

The idea is simple click the button in the machine's GUI and the machine will be disabled and the texture will change to show. Here is what I got so far.

 

MessageButtonPressed

 

 

package com.bigbaddevil7.rustic.network.Message;

import com.bigbaddevil7.rustic.test.TileEntityMachine;
import com.bigbaddevil7.rustic.utility.LogHelper;
import cpw.mods.fml.client.FMLClientHandler;
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.tileentity.TileEntity;

/**
* Created by bigbaddevil7 on 11/5/2014.
*/
public class MessageButtonPressed implements IMessage{

    public byte id;
    public int x,y,z;

    static TileEntityMachine machine;
    public MessageButtonPressed(){

    }

    public MessageButtonPressed(TileEntityMachine tileEntityMachine, byte id){
        LogHelper.info("Entered Constructor");
        this.id = id;
        this.x = tileEntityMachine.xCoord;
        this.y = tileEntityMachine.yCoord;
        this.z = tileEntityMachine.zCoord;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        LogHelper.info("Reading Bytes");
        this.id = buf.readByte();
        this.x = buf.readInt();
        this.y = buf.readInt();
        this.z = buf.readInt();
        LogHelper.info("Done Reading Bytes");
    }

    @Override
    public void toBytes(ByteBuf buf) {
        LogHelper.info("Writing Bytes");
        buf.writeByte(id);
        buf.writeInt(x);
        buf.writeInt(y);
        buf.writeInt(z);
        LogHelper.info("Done Writing bytes");
    }

    public static class Handler implements IMessageHandler<MessageButtonPressed, IMessage>{


        @Override
        public IMessage onMessage(MessageButtonPressed message, MessageContext ctx) {
            LogHelper.info("Got Request");
            TileEntity tileEntity = FMLClientHandler.instance().getClient().theWorld.getTileEntity(message.x, message.y, message.z);
            if(tileEntity instanceof TileEntityMachine){
                ((TileEntityMachine)tileEntity).recieveButtonEvent(message.id);
                LogHelper.info("Not Machine");
            }
            LogHelper.info("Recieved Packet" + message.id);
            return null;
        }
    }

}

 

 

 

The actionPerformed() that is in the GUI class for the machine to send the packet

 

 

    @Override
    protected void actionPerformed(GuiButton button) {
        Rustic.network.sendToServer(new MessageButtonPressed(machine, (byte)button.id));
        LogHelper.info("Sent Packet");
    }

 

 

 

recieveButtonEvent() Handles the actual disabling of the machine

 

 

public void recieveButtonEvent(byte buttonId){
        switch (buttonId){
            case 0:
            int meta = worldObj.getBlockMetadata(xCoord,yCoord,zCoord);//gets the metadata

            int type = meta / 2;//uses the groups of two

            int disabled = meta % 2 == 0 ? 1: 0;//uses the groups of two using % to see if it is disabled

            int newMeta = type * 2 + disabled;

            worldObj.setBlockMetadataWithNotify(xCoord,yCoord,zCoord, newMeta, 3);//updates the block with the new metadata
                break;
        }
    }

 

 

 

It's not that I crash or anything just nothing happens, the packet gets sent, but the onMessage() never seems to be fired.

 

Link to comment
Share on other sites

a) Why are you sending the TE coordinates? The server knows what Gui the player is looking at.

b) Why are you using the client world in a message received on the server? You need to use the world you can get from the MessageContext.

 

What I saw used in other source code.

 

 

Alright I made changes. Now I get a crash. The Id from I can tell is 0, but It throws an OutOfBounds exception.

 

 

 

[12:06:46] [server thread/ERROR] [FML]: FMLIndexedMessageCodec exception caught
io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(1) + length(4) exceeds writerIndex(1): SlicedByteBuf(ridx: 1, widx: 1, cap: 1/1, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 2, cap: 2/2))
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.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.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.IndexOutOfBoundsException: readerIndex(1) + length(4) exceeds writerIndex(1): SlicedByteBuf(ridx: 1, widx: 1, cap: 1/1, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 2, cap: 2/2))
at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1160) ~[AbstractByteBuf.class:?]
at io.netty.buffer.AbstractByteBuf.readInt(AbstractByteBuf.java:611) ~[AbstractByteBuf.class:?]
at com.bigbaddevil7.rustic.network.Message.MessageButtonPressed.fromBytes(MessageButtonPressed.java:37) ~[MessageButtonPressed.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:?]
... 13 more
[12:06:46] [server thread/ERROR] [FML]: There was a critical exception handling a packet on channel Rustic
io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(1) + length(4) exceeds writerIndex(1): SlicedByteBuf(ridx: 1, widx: 1, cap: 1/1, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 2, cap: 2/2))
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.network.NetworkSystem.networkTick(NetworkSystem.java:182) [NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.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.IndexOutOfBoundsException: readerIndex(1) + length(4) exceeds writerIndex(1): SlicedByteBuf(ridx: 1, widx: 1, cap: 1/1, unwrapped: UnpooledHeapByteBuf(ridx: 1, widx: 2, cap: 2/2))
at io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1160) ~[AbstractByteBuf.class:?]
at io.netty.buffer.AbstractByteBuf.readInt(AbstractByteBuf.java:611) ~[AbstractByteBuf.class:?]
at com.bigbaddevil7.rustic.network.Message.MessageButtonPressed.fromBytes(MessageButtonPressed.java:37) ~[MessageButtonPressed.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:?]
... 13 more

 

 

 

Here is the changes I did to the MessageButtonPressed(). Is this what you were looking for.

 

 

package com.bigbaddevil7.rustic.network.Message;

import com.bigbaddevil7.rustic.client.interfaces.ContainerMachine;
import com.bigbaddevil7.rustic.test.TileEntityMachine;
import com.bigbaddevil7.rustic.utility.LogHelper;
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.inventory.Container;


/**
* Created by bigbaddevil7 on 11/5/2014.
*/
public class MessageButtonPressed implements IMessage{

    public byte id;
    public int x,y,z;

    static TileEntityMachine machine;
    public MessageButtonPressed(){

    }

    public MessageButtonPressed(byte id){
        LogHelper.info("Entered Constructor");
        this.id = id;

    }

    @Override
    public void fromBytes(ByteBuf buf) {
        LogHelper.info("Reading Bytes");
        LogHelper.info(id);
        this.id = buf.readByte();
        this.x = buf.readInt();
        this.y = buf.readInt();
        this.z = buf.readInt();
        LogHelper.info("Done Reading Bytes");
    }

    @Override
    public void toBytes(ByteBuf buf) {
        LogHelper.info("Writing Bytes");
        buf.writeByte(id);
        LogHelper.info(id);
        LogHelper.info("Done Writing bytes");
    }

    public static class Handler implements IMessageHandler<MessageButtonPressed, IMessage>{


        @Override
        public IMessage onMessage(MessageButtonPressed message, MessageContext ctx) {
            LogHelper.info("Got Request");
            Container container = ctx.getServerHandler().playerEntity.openContainer;
            if(container instanceof ContainerMachine){
                TileEntityMachine machine = ((ContainerMachine)container).getMachine();
                machine.recieveButtonEvent(message.id);
                LogHelper.info("Not Machine");
            }
            LogHelper.info("Recieved Packet" + message.id);
            return null;
        }
    }

}

 

 

Link to comment
Share on other sites

Oh ok. I thought the client would have to get the cords back from the server to update the proper GUI. Since the cords doesn't need to get sent, that means they don't need to be read either? The onMessage() still never gets called. I'm gonna be glad once I figure this one out.... I'm sorry for taking up your time with what seems like a simple thing. Means a lot to have people help. 

Link to comment
Share on other sites

Ahh. I had it registered for Side.CLIENT. IT WORKS!!!! OH FOR THE DEAR LOVE OF THE ALL MIGHTY, MIGHTINESS..... OF MIGHT. Queue the "IT LIVES" from Dr. Frankenstein. This is a revolutionary moment here for me. I've been putting this off for a very long time. Now I have an idea of how to use a very powerful tool. Now that it's all in place. This is a hell of a lot simpler than 1.6 it seems. I guess the name fits. Now that I got this down, I move to one step closer to eventually understanding this modding enough to start doing my steam power system. Thank you so much diesieben you have been a great help over the times.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • SLOT PULSA TANPA POTONGAN : SLOT PULSA 5000 VIA INDOSAT IM3 TANPA POTONGAN - SLOT PULSA XL TELKOMSEL TANPA POTONGAN  KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << KLIK DISINI DAFTAR DISINI SLOT VVIP << SITUS SLOT GACOR 88 MAXWIN X500 HARI INI TERBAIK DAN TERPERCAYA GAMPANG MENANG Dunia Game gacor terus bertambah besar seiring berjalannya waktu, dan sudah tentu dunia itu terus berkembang serta merta bersamaan dengan berkembangnya SLOT GACOR sebagai website number #1 yang pernah ada dan tidak pernah mengecewakan sekalipun. Dengan banyaknya member yang sudah mempercayakan untuk terus menghasilkan uang bersama dengan SLOT GACOR pastinya mereka sudah percaya untuk bermain Game online bersama dengan kami dengan banyaknya testimoni yang sudah membuktikan betapa seringnya member mendapatkan jackpot besar yang bisa mencapai ratusan juta rupiah. Best online Game website that give you more money everyday, itu lah slogan yang tepat untuk bermain bersama SLOT GACOR yang sudah pasti menang setiap harinya dan bisa menjadikan bandar ini sebagai patokan untuk mendapatkan penghasilan tambahan yang efisien dan juga sesuatu hal yang fix setiap hari nya. Kami juga mendapatkan julukan sebagai Number #1 website bocor yang berarti terus memberikan member uang asli dan jackpot setiap hari nya, tidak lupa bocor itu juga bisa diartikan dalam bentuk berbagi promosi untuk para official member yang terus setia bermain bersama dengan kami. Berbagai provider Game terus bertambah banyak setiap harinya dan terus melakukan support untuk membuat para official member terus bisa menang dan terus maxwin dalam bentuk apapun maka itu langsung untuk feel free to try yourself, play with SLOT GACOR now or never !
    • BRI4D adalah pilihan tepat bagi Anda yang menginginkan pengalaman bermain slot dengan RTP tinggi dan transaksi yang akurat melalui Bank BRI. Berikut adalah beberapa alasan mengapa Anda harus memilih BRI4D: Tingkat Pengembalian (RTP) Tertinggi Kami bangga menjadi salah satu agen situs slot dengan RTP tertinggi, mencapai 99%! Ini berarti Anda memiliki peluang lebih besar untuk meraih kemenangan dalam setiap putaran permainan. Transaksi Melalui Bank BRI yang Akurat Proses deposit dan penarikan dana di BRI4D cepat, mudah, dan akurat. Kami menyediakan layanan transaksi melalui Bank BRI untuk kenyamanan Anda. Dengan begitu, Anda dapat melakukan transaksi dengan lancar dan tanpa khawatir. Beragam Pilihan Permainan BRI4D menyajikan koleksi permainan slot yang beragam dan menarik dari berbagai provider terkemuka. Mulai dari tema klasik hingga yang paling modern, Anda akan menemukan banyak pilihan permainan yang sesuai dengan selera dan preferensi Anda.  
    • SPARTA88 adalah pilihan tepat bagi Anda yang menginginkan agen situs slot terbaik dengan RTP tinggi dan transaksi yang mudah melalui Bank BNI. Berikut adalah beberapa alasan mengapa Anda harus memilih SPARTA88: Tingkat Pengembalian (RTP) Tinggi Kami bangga menjadi salah satu agen situs slot dengan RTP tertinggi, mencapai 98%! Ini berarti Anda memiliki peluang lebih besar untuk meraih kemenangan dalam setiap putaran permainan. Beragam Pilihan Permainan SPARTA88 menyajikan koleksi permainan slot yang beragam dan menarik dari berbagai provider terkemuka. Mulai dari tema klasik hingga yang paling modern, Anda akan menemukan banyak pilihan permainan yang sesuai dengan selera dan preferensi Anda. Kemudahan Bertransaksi Melalui Bank BNI Proses deposit dan penarikan dana di SPARTA88 cepat, mudah, dan aman. Kami menyediakan layanan transaksi melalui Bank BNI untuk kenyamanan Anda. Dengan begitu, Anda dapat melakukan transaksi dengan lancar tanpa perlu khawatir.
    • Slot Bank ALADIN atau Daftar slot Bank ALADIN bisa anda lakukan pada situs WINNING303 kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di WINNING303 adalah anda akan mendapatkan bonus 100% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 5 ribu rupiah saja anda sudah bisa bermain bersama kami di WINNING303 . Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.
    • Slot Bank PAPUA atau Daftar slot Bank PAPUA bisa anda lakukan pada situs WINNING303 kapanpun dan dimanapun, Bermodalkan Hp saja anda bisa mengakses chat ke agen kami selama 24 jam full. keuntungan bergabung bersama kami di WINNING303 adalah anda akan mendapatkan bonus 100% khusus member baru yang bergabung dan deposit. Tidak perlu banyak, 5 ribu rupiah saja anda sudah bisa bermain bersama kami di WINNING303 . Tunggu apa lagi ? Segera Klik DAFTAR dan anda akan jadi Jutawan dalam semalam.  
  • Topics

×
×
  • Create New...

Important Information

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