Posted September 9, 201312 yr Hello, I've set up a packet to send entity data from the server to the client. However, I cannot get the instance of the entity on the client side to change its variables. Here is my packet class: public class MyEntityPacket extends MyModPacket { int entityID,flag; public MyEntityPacket(int entityID, int flag) { this.entityID = entityID; this.flag = flag; } public MyEntityPacket() {} @Override public void write(ByteArrayDataOutput out) { out.writeInt(entityID); out.writeInt(flag); } @Override public void read(ByteArrayDataInput in) { entityID = in.readInt(); flag = in.readInt(); } @Override public void execute(EntityPlayer player, Side side) { if (side.isClient()) { if (Minecraft.getMinecraft().theWorld.getEntityByID(entityID) instanceof MyEntity) { MyEntity e = (MyEntity) player.worldObj.getEntityByID(entityID); e.setFlag(flag == 1 ? true : false); } else { System.out.println("Something ****** up! - supposed my entity with id: " + entityID + " isn't"); } } } } That all works fine. My problem is that the method getEntityByID(entityID) always returns null instead of the entity. I'm using this to create the packet in the constructor of the entity (it is the final thing in the constructor so the entity should be fine). PacketDispatcher.sendPacketToAllAround(par2, par4, par6, 250, this.dimension, new MyEntityPacket(this.entityId, flag ? 1 : 0).makePacket()); // 250 is view radius Can anyone enlighten me? Do I need to use the UUID (persistent id) instead? If so, how would I get the entity from it?
September 9, 201312 yr Where is the code where you get the entity id from server side ? Do you check that you are on server side ?
September 9, 201312 yr Author The code is in the entities constructor, and there is no server side check, does this matter?
September 10, 201312 yr Author Checking that it's on the server side did nothing, it still cannot find the entity
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.