Jump to content

Ermans

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by Ermans

  1. Thanks, but I already knew that, I was just asking if there was other ways better than vanilla way. I think I will use containers so
  2. I need to update values for the GUI (energy bar and progress bar), I already use IMessage for things that need to sync all the clients in a range, but I don't want to use them because I need to send message only to player who have the gui open. About Block Events, I apologize for not being specific, I mean World#addBlockEvent, Block#onBlockEventReceived and TileEntity#receiveClientEvent and I need to know if these methods are a good way to update values in the GUI. About the third question, I mean IInventory#getField, IInventory#setField and IInventory#getFieldCount. These methods are use by vanilla furnace to update the GUI, I just wondering why these methods are inside IInventory interface and not in a ISyncable interface or something like this.
  3. Hello, I have some questions about these way to sync data. 1) Custom Packets a. I shouldn't use them for update values in the GUIs, rigth? 2) BlockEvents a. On which side should I call them? b. Are they a good way to update values in the GUIs? c. Now I know this: World#addBlockEvent (called server-side) fires Block#onBlockEventReceived (both sides) and here I have to call TileEntity#receiveClientEvent (both sides) and update values. It is right? 3) IInventory Fields a. Are these the better way to update values in the GUIs? b. Why these methods are on the IInventory interface instead of an ISyncable or something like this? So, what should I choose to sync values in the GUIs? Thanks
  4. Ok, so is better if inside Container#detectAndSendChanges I get the message from the tile (if it is changed) and send it to crafter (checking if is a player) ?
  5. I'm trying to send GUI-only things (like progress bar update or energy stored) with a custom packet only to player who have the gui open. Obviously I can do this: for (playersWithGuiOpen) PacketHandler.INSTANCE.sendTo(new myCustomMessage(), playerWhoHaveTheGuiOpen); but from my tile I don't know the players, so I decided to use my container: ///////////////Inside myTile///////////////////// protected void syncMachine() { container.sendMessageToCrafters(new MessageTile(this)); markDirty(); } /////////////Inside myContainer////////////// public void sendMessageToCrafters(IMessage message) { for (Object crafter : this.crafters) { EntityPlayerMP player = (EntityPlayerMP) crafter; if (player != null) { PacketHandler.INSTANCE.sendTo(message, player); } } } But this code works fine with just a player (this.crafters contains just a player even there are three different players with the gui open), if I use open to LAN feature and I join with other different players, only the last player who opened the gui is updated. Basically I need to sync only the players who have the gui open, so I can't use "PacketHandler.INSTANCE.sendToAllAround" but I need to use "sendTo". The problem is that I don't know the players who need to be updated. I hope I made it clear.
  6. Thanks both for introducing me to all these possibilities. This is what I've done to resolve my problem: On the super class of all my tiles I decided to add this two methods: public void fromBytes(ByteBuf buf) { } public void toBytes(ByteBuf buf) { } So my tiles can override them. And on the IMessage class: public class MessageTilev2 implements IMessage{ private MyTile tile; private int x; private int y; private int z; public MessageTilev2() { } public MessageTilev2(MyTile tile) { this.tile = tile; this.x = tile.xCoord; this.y = tile.yCoord; this.z = tile.zCoord; } @Override public void fromBytes(ByteBuf buf) { this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); TileEntity entity = Minecraft.getMinecraft().thePlayer.worldObj.getTileEntity(this.x, this.y, this.z); if (entity instanceof MyTile){ ((MyTile) entity).fromBytes(buf); } } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.x); buf.writeInt(this.y); buf.writeInt(this.z); tile.toBytes(buf); } public static class Handler implements IMessageHandler<MessageTilev2, IMessage> { @Override public IMessage onMessage(MessageTilev2 message, MessageContext ctx) { return null; } } } Last question not closely related to this topic... Is it good to send a message every tick when a tile receive energy (to sync the server energy storage with the client)?
  7. As you know, the IMessage lets you to create your own packet to exchange data with your tiles, but if you have a lot of tiles which basically do the same things except for one thing, you have to create (at least this is what I am doing) an IMessage for each of them. How can I make the IMessage like the NBT tags? I mean when you deal with NBT you just override the two methods (calling the super) and use the NBTTagCompound object to write/get the things you want. How I achieve the same result with IMessage? Or Where can I find some code that have already implemented such things? I don't even know if I need to keep using IMessage interface.
×
×
  • Create New...

Important Information

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