Jump to content

variable help?


memcallen

Recommended Posts

I'm currently making a steam generator and I found a small problem. I have no idea how to send a variable to the TileEntity. I'm currently using a packet to relay 2 ints, one for water amount and one for temperature but I can't set the ints from my main block class. Could someone give me an example on how to do this?

The proud(ish) developer of Ancients

Link to comment
Share on other sites

main.NetworkHandler.sendToServer(new WaterSteamRequestPacket(tileEntityX,tileEntityY,tileEntityZ,waterAmount,tempAmount));

 

WaterSteamRequestHandlerPacket implements IMessageHandler<BaseNodeRequestPacket, IMessage>

{

@Override

public IMessage onMessage(BaseNodeRequestPacket message, MessageContext ctx)

{

TileEntitySteamPump te = (TileEntitySteamPump)ctx.getServerHandler().playerEntity.getEntityWorld().getTileEntity(message.x, message.y, message.z);

te.setWaterLevel(message.waterLevel);

te.setTemp(message.Temp);

return new WaterSteamResponsePacket(tileEntityX,tileEntityY,tileEntityZ,waterAmount,tempAmount);

}

}

 

the return sends another packet which is registered clientside to do the same thing. I'm assuming your GUI takes the tileEntity so you should be able to use the GUI to display te.getWaterLevel().

 

This is using the ISimpleMessageWrapper tutorial.

Link to comment
Share on other sites

I haven't actually figured out guis yet so there is no gui it's just currently a BlockContainer, a TileEntity and TileEntitySpecialRenderer. I will check out how to implement onMessage with my SteamGenerator class, and I'm using packets (the onDataPacket method).

The proud(ish) developer of Ancients

Link to comment
Share on other sites

BaseNodeRequest oops I just copied one of my packets, that would be your WaterTempRequestPacket you can have a look at how the baseNode packet is made here

https://github.com/Hugo-the-Dwarf/Rise-of-Tristram/tree/master/src/main/java/ee/rot/comms

 

You can look at how I register them in my main mod file.

 

EDIT:

also you can call them whatever you want, I just use Request for Client to Server messages and Response for Server to Client messages. It's just what I name them as you could name your packets "WaterTempServer, and WaterTempClient" if you wanted to.

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



×
×
  • Create New...

Important Information

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