Posted January 25, 20169 yr I have a custom inventory and some extended properties and when I equip an item in the slot in the custom inventory, it renders an accessory onto the player like armor, but the only problem I have is that when on a server, it doesn't show the accessory to other players. I assume I will need packets.
January 25, 20169 yr Author So I taken a look at how vanilla does this with the armor, and I took a look at S04PacketEntityEquipment and NetHandlerPlayClient#handleEntityEquipment, now what I am wondering is how within my packet would I go about getting an entity from its ID, since it is handled client side?
January 26, 20169 yr Nope. Every entity has entityId. It is always the same on client and server (server sets client's entityId on spawn). You need to send packet from server to client with: player.entityId, itemStack, slotId. On client you read them, world.getEntityById(message.entityId) and then set player's client side inventory to received itemStack in some slotId. 1.7.10 is no longer supported by forge, you are on your own.
January 26, 20169 yr Author I am aware that the id is the same on both sides, better wording would have been, where should I get the World from inside the packet.
January 26, 20169 yr On the client there's only one World : Minecraft#theWorld . Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
January 26, 20169 yr Author So, upon trying, inside the packet: EntityPlayer player = Minecraft.getMinecraft().theWorld.getEntityById(id); and trying to use the variable in any way returns null.
January 26, 20169 yr Are you getting "id" field from message passed to receive method? Post full code. 1.7.10 is no longer supported by forge, you are on your own.
January 26, 20169 yr Author After a bit of debugging, and looking at the code, I realized I missed the dumbest thing, I forgot to assign the entityId to the entityId in the packet in the constructor... so it was only returning 0, but fixed it, and it is now working.
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.