Jump to content

Sending packets for Tile Entities that aren't just ints?


Zeretul4

Recommended Posts

Hey everyone, some of you may know that if you want numbers that you use in tile entities to interact with the gui, you need to send packets which is done in the container class. In vanilla it's only possible to update ints because that's all vanilla minecraft needs. I want to see things like booleans, floats, and other information which i've been getting around by using ints. The problem now is that I want to use lists and the way I have it working isn't going to work for that.

 

Right now the process is this and I don't know how it works, I sorta just pieced it together from random examples and tutorials.

 

int lastVariable

public void addCraftingToCrafters(ICrafting par1ICrafting)
    {
        super.addCraftingToCrafters(par1ICrafting);
       par1ICrafting.sendProgressBarUpdate(this, 0, (int)this.tileEntity.variable);
    }
    
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int var1 = 0; var1 < this.crafters.size(); ++var1)
        {
            ICrafting var2 = (ICrafting)this.crafters.get(var1);

            if (this.lastVariable = this.tileEntity.variable)
            {
                var2.sendProgressBarUpdate(this, 0, (int)this.tileEntity.variable);
            }

        }

        lastVariable= (int)tileEntity.variable;
    }
    
    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int par1, int par2)
    {
        if (par1 == 0)
        {
            this.tileEntity.variable= par2;
        }     
    }

 

I have no idea what this is doing but I have to do it for each variable I want to work with in a gui. Whenever I try to change it from ints to anything else it stops working. I know it has something to do with packets but I have no idea where to begin with that.

Link to comment
Share on other sites

You're going to want a proper packet handler.

 

Essentially, you need to construct an instance of Packet250CustomPayload, containing a byte array of whatever information you want to send, then dispatch it along a predefined channel (defined in your @NetworkMod annotation). Your packet handler then determines what to do with the packet once it arrives.

 

You should be able to figure it out by Googling for Packet250CustomPayload and IPacketHandler. There are a few tutorials on how to implement it properly.

Link to comment
Share on other sites

Thanks for the reply, I tried to do what you said and looked up Packet250CustomPayload and IPacketHandler but all I found were basic tutorials that showed how to print random numbers to the chat. This doesn't really help because I have no idea how I can turn that into updating numbers for the gui, they look nothing like what I currently do for updating ints.

 

http://www.minecraftforge.net/wiki/Packet_Handling this tutorial mentions that a good use for packets is for exactly what I need but doesn't get into how to do that. I've been searching and searching but can't figure this out. Any ideas? Thanks for the help so far!

Link to comment
Share on other sites

Does anyone know how packet handlers can help update a Tile Entities GUI? Every example I find is just something like sending pointless numbers to the player chat. Vanilla code isn't helping either, the interface for that only deals with ints and i need to update other things like booleans and lists.

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.



×
×
  • Create New...

Important Information

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