Posted January 10, 201411 yr Basically my problem is this: The server doesn't know that there is a new item in the custom GUI slot. If I try to take it, it disappears. I don't know why, or how to fix it. I've spend countless hours googling and everything and can't figure this out. Help would be greatly appreciated. GUI http://pastebin.com/QNEEK9HA GUIHandler http://pastebin.com/LduXKXsv TileEntity http://pastebin.com/UcCYqp66 Basically this: Click Button -> New Item Appears -> Try to take item -> Item Disappears! ->
January 10, 201411 yr Author I figured that was the problem. I read the article on the wiki about sending packets, but still don't quite get it. Mind maybe pointing me in the right direction on how to do that? I get how to send like integers and bytes. But it doesn't really explain like how do I send an ItemStack and how does it know. Or how do I send the experience level and how do I tell it what that is? Custom packets? I don't know I feel in over my head with this one.
January 10, 201411 yr But it doesn't really explain like how do I send an ItemStack and how does it know. ItemStacks are saved to NBT data, which is convertable to packet data. The cool thing about TileEntities is that this is all handled automagically. You just need to override two functions thusly: public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } public void onDataPacket(INetworkManager net, Packet132TileEntityData packet) { readFromNBT(packet.data); } Provided that your readFromNBT/writeToNBT functions are likewise up to date, this will work. Here's the thing though: this is server to client only. You need to implement a network handler and send a Packet250CustomData (sp?) when the user clicks the GUI button and have the server generate the item that goes in that slot. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 10, 201411 yr Author So I send a packet to the server, and then in the PacketHandler I have it call my tileentity.addItemStacktoSlot()? So the handler would be like: If you get an itementity in a packet, do this If you get an integer in a packet, do this EDIT: I've been looking around again and found this example: https://github.com/dvd604/Xperium/blob/master/net/dvd/xperium/server/XperiumPacketHandler.java So I have two channels, if it comes in on say "rpglevel_lus" do the stuff for the TileEntity and if it comes in on "rpglevel_xpl" do the stuff to the player. So I'd send two packets. One being a TileEntityData packet and the other being a CustomPayload and have it parse the integer data from there and apply it to the player?
January 10, 201411 yr So I send a packet to the server, and then in the PacketHandler I have it call my tileentity.addItemStacktoSlot()? So the handler would be like: If you get an itementity in a packet, do this If you get an integer in a packet, do this No no. All you need to do is send one integer. That integer says "I will be performing this set of actions" (see: my packet handler, the integer being discussed is the one that goes into the switch statement). In your case, that's all you need: an integer expressing which button was pressed. If you had additional information that needed to be passed, you'd also have to write and read those values (for example, my code handles a lot of potion effects, so I need the potion ID, power, and duration). And actually, you do have additional information to send: The location of the tile entity. This will require 4 more integers: dimension, X, Y, and Z. You can then use DimensionManager.getDimension(dimID).getBlockTileEntity(X, Y, Z) in order to get a reference to the TE and tell it to do something. (For sending, you can get the dim ID by world.provider.dimensionID) Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 10, 201411 yr Author Okay its starting to make sense. And after registering my packet handler in my @NetworkMod I should be good to go correct? I'll try this out when I get home.
January 10, 201411 yr Yep. Just build it one piece at a time, printing out data as you go until you're ready to start using it. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 10, 201411 yr Author I got it working thanks so much! Just one thing. using player.addExperienceLevel(-20); seems to take away a much larger chunk of experienced than I'd think it would.
January 10, 201411 yr That's twenty levels I think. Try player.experience Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 10, 201411 yr Author It is supposed to be 20 levels. But it takes how many it feels like. Like if i have 10s of thousands it will go wild with them. Or if I have 21 it will take all 21.
January 10, 201411 yr Let me see your code. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 10, 201411 yr Author package us.xvicario.soultether.handler; import cpw.mods.fml.common.network.IPacketHandler; import cpw.mods.fml.common.network.Player; import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import java.io.PrintStream; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraftforge.common.DimensionManager; import us.xvicario.soultether.RPGLevel; import us.xvicario.soultether.TileEntityLevelUpStation; public class PacketHandler implements IPacketHandler { private EntityPlayer player; public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) { this.player = ((EntityPlayer)player); if (packet.channel.equals("RPGLEVEL")) { handlePacket(packet, player); } } private void handlePacket(Packet250CustomPayload packet, Player player) { World world = this.player.worldObj; DataInputStream dis = new DataInputStream(new ByteArrayInputStream(packet.data)); try { int bookId = dis.readInt(); int dimension = dis.readInt(); int x = dis.readInt(); int y = dis.readInt(); int z = dis.readInt(); TileEntityLevelUpStation te = (TileEntityLevelUpStation)DimensionManager.getWorld(dimension).getBlockTileEntity(x, y, z); ItemStack levelUpBook = new ItemStack(RPGLevel.itemLevelUpBook, 1, 0); te.setInventorySlotContents(0, levelUpBook); this.player.addExperienceLevel(-20); } catch (IOException e) { System.out.println("Failed to Read Packet"); } } }
January 10, 201411 yr Add an output statement where that happens. E.g. System.out.println("Subtracting 20 levels"); this.player.addExperienceLevel(-20); Check to see that it's running only once. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
January 11, 201411 yr It is running many many times. There's you're problem, then! Now your challenge is to find a way to add a sanity check so it runs once. (Hint: flags) Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.