Posted July 24, 201411 yr Hi there! I made a TileEntity for a door to store some data into NBT's. Now i want to set its data via a GUI so i opening the GUI in the .onBlockActivated() method. I also sends some data when im opening the GUI and i checked the data arrives. In the gui i set some more stuff and get all the data so i can send a packet to the server. Now i don't get it why if i set my TE data in a packet(Server side) its start acting wierd. The boolean is true and false at the same time, for example. NOTE: If im setting the stuff in the GUI(client only) its works, but we all know server will have no clue about the data change. So my code works, but im just failed to sync the data between client and server. My question is, what side i have to send the packet and by what method(.sendToAll or .sendToServer) will work? I tried all logic way but all of them refused to work. Im i need pakets for this, by the way? Thanks!
July 24, 201411 yr Author Okey, than i have a problem. I send the data to the server and change the TE data, but it becomes wierd. In my door block class i have a boolean from my TE. In my TE its false by default. So if i send the packet it becomes true. But my door not realy recognises it. In my .onBlockActivated() method its acting like true and false. I print out a message and it says false rater than true and in my code: if(boolean){ //This activates! }else{ //This also activates! } I just confused a bit right now.
July 24, 201411 yr Author Door(only .onBlockActivated): http://pastebin.com/fNpV4NQE GUI: http://pastebin.com/PBeq1FQa Package: http://pastebin.com/RNDT76ib TE: http://pastebin.com/NDxRYGJh Thanks for helping!
July 24, 201411 yr Author Sorry for the mess. I made a major clean so its better now. For the .serndToAll its just for testing. The actual code is .sendToServer. So the problem is something else.
July 24, 201411 yr Author Door(only .onBlockActivated): http://pastebin.com/fNpV4NQE GUI: http://pastebin.com/PBeq1FQa Package: http://pastebin.com/RNDT76ib TE: http://pastebin.com/NDxRYGJh
July 25, 201411 yr Author Sorry i say it in a wrong way. (Englis is not my main lang) Its still not working with the server world.
July 25, 201411 yr Author I just changed the client player to server in my packet. ctx.getServerHandler().playerEntity. But here you go: http://pastebin.com/RNDT76ib
July 26, 201411 yr Author I mayebe found out the problem, but i can't find a way around it. Im basically opening my GUI in .onBlockActivated() with this: Minecraft.getMinecraft().displayGuiScreen(new KeyGui(entityplayer, x, y, z, i1)); Now if i open up a server it crases because Gui is client side only. If i use: entityplayer.openGui(Amnesia.instance, 21, x, y, z); It works, but i need some data for the gui and with this method i don't know how to send it. Can somebody tell me how to open a GUI with custom data properly? I can't realy find any method other than the "Minecraft.getMinecraft()" one. Thanks!
July 26, 201411 yr Author Thank you! The "call through proxy" method slove my crash. For the a), b) i can use return packet to the client, right?
July 26, 201411 yr Author Open gui -> send data to server -> send data to client for update. I thought its a simple way, but if its more than what i needed ,i will try something else.
July 26, 201411 yr Author Okey so its not realy want to work. I will post my code a bit later when i'm sure i didn't derp. Also can you tell me why is that refuse to work? if (i.hasTagCompound() && i.getTagCompound().hasKey("HasEffect")) Even if i do something like: "tag.setBoolean("HasEffect", false);" its still not pass the if statement, but it has "HasEffect". Thanks!
July 26, 201411 yr Author Okey now i fixed the problems with NBT's and the door. But my item is looses its data. I set its data via(client&server): Key.setKeyName(player.getCurrentEquippedItem(), "Test"); Key.setConsume(player.getCurrentEquippedItem(), message.consume); Key.setEffect(player.getCurrentEquippedItem(), true); Key class: http://pastebin.com/AuL6KFtC I can see the effect set for like 0.1sec. Thanks.
July 26, 201411 yr Author Derp... Thanks you for everything. Mind if i ask a last question? How to use String in IMessageHandler? I found StringBuffer, but how can i put that in my packet? There is only toBytes and fromBytes and there is no toString and fromString.
July 26, 201411 yr Author Thank you very much for helping me. Its works like a dream. If i have more free time i will write a program that press [apploud] every hour under your name.
August 2, 201411 yr Author Sorry for bunping this back up, but its looks like the proxy GUI open is broken if i play on a dedicated server. My question is do i realy have to send a packet to the player who is opened the GUI from my ServerProxy? Thanks!
August 2, 201411 yr Author Still not working on a server. This can help i think: Client Proxy: @Override public void openKeyGui(EntityPlayer player, int x, int y, int z, int i1){ Minecraft.getMinecraft().displayGuiScreen(new KeyGui(player, x, y, z, i1)); } Server Proxy: public void openKeyGui(EntityPlayer player, int x, int y, int z, int i1){ } I call it like so: Amnesia.proxy.openKeyGui(entityplayer, x, y, z, i1); Without any kind of world checking. Amnesia.proxy is my ServerProxy! So on client side it works. On a dedicated server it only runs the method in my ServerProxy. Thats why i think i need pakets, but i just want to ask it first.
August 3, 201411 yr Author Yes im calling it in my OnBlockActivated method, but its not working for some reason. And i don't checking for any side. I checked out with .pirntLn and it runs both side. But when im on a server the method in my ClientProxy never gets called trough my ServerProxy.
August 4, 201411 yr Author No there is no .isRemote in that part of the code at all. Here take a look: @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int par1, float par2, float par3, float par4) { int i1 = this.func_150012_g(world, x, y, z); int j1 = i1 & 7; int k1 = i1 & 7; j1 ^= 4; TileEntityDoor TEDoor = ((TileEntityDoor)world.getTileEntity(x, y, z)); boolean isLocked = TEDoor.isLocked; boolean hasLock = TEDoor.hasLock; String doorName = TEDoor.doorName; if(entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().getItem() == Amnesia.Key){ if(hasLock){ if(entityplayer.getCurrentEquippedItem().getDisplayName().equals(doorName)){ if(!isLocked){ if(!world.isRemote){ if ((i1 & == 0) { ((TileEntityDoor)world.getTileEntity(x, y, z)).isLocked = true; ((TileEntityDoor)world.getTileEntity(x, y+1, z)).isLocked = true; world.playSoundEffect(x, y, z, "amnesia:door.UnlockDoor", 0.8F, 1.0F); }else{ ((TileEntityDoor)world.getTileEntity(x, y, z)).isLocked = true; ((TileEntityDoor)world.getTileEntity(x, y-1, z)).isLocked = true; world.playSoundEffect(x, y, z, "amnesia:door.UnlockDoor", 0.8F, 1.0F); } } }else{ if(!world.isRemote){ if ((i1 & == 0) { ((TileEntityDoor)world.getTileEntity(x, y, z)).isLocked = false; ((TileEntityDoor)world.getTileEntity(x, y+1, z)).isLocked = false; world.playSoundEffect(x, y, z, "amnesia:door.UnlockDoor", 0.8F, 1.0F); }else{ ((TileEntityDoor)world.getTileEntity(x, y, z)).isLocked = false; ((TileEntityDoor)world.getTileEntity(x, y-1, z)).isLocked = false; world.playSoundEffect(x, y, z, "amnesia:door.UnlockDoor", 0.8F, 1.0F); } } if(Key.getConsume(entityplayer.getCurrentEquippedItem())){ entityplayer.inventory.consumeInventoryItem(entityplayer.inventory.getCurrentItem().getItem()); } } }else{ if(!world.isRemote) entityplayer.addChatComponentMessage(new ChatComponentText("The key isn't for this door!")); } }else{ Amnesia.proxy.openKeyGui(entityplayer, x, y, z, i1); //This is opening part } return true; } if(hasLock){ if(!isLocked){ if(!world.isRemote){ if ((i1 & == 0){ world.setBlockMetadataWithNotify(x, y, z, j1, 2); world.markBlockRangeForRenderUpdate(x, y, z, x, y, z); } else { world.setBlockMetadataWithNotify(x, y - 1, z, j1, 2); world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z); } world.playSoundEffect(x, y, z, "amnesia:door.WoodenDoor1", 0.5F, 1.0F); } }else{ if(!world.isRemote) entityplayer.addChatComponentMessage(new ChatComponentText("Door is locked!")); world.playSoundEffect(x, y, z, "amnesia:door.WoodenDoorLocked", 0.5F, 1.0F); } return true; }else{ if(!world.isRemote){ if ((i1 & == 0){ world.setBlockMetadataWithNotify(x, y, z, j1, 2); world.markBlockRangeForRenderUpdate(x, y, z, x, y, z); } else { world.setBlockMetadataWithNotify(x, y - 1, z, j1, 2); world.markBlockRangeForRenderUpdate(x, y - 1, z, x, y, z); } world.playSoundEffect(x, y, z, "amnesia:door.WoodenDoor1", 0.5F, 1.0F); } return true; } }
August 4, 201411 yr Author What about if i send a packet from the server to the player and open a gui there? If that is a stupid idea, can you tell me a bit about where should i start with my custom packet?
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.