Posted July 8, 20169 yr I created a new Entity that has two properties - bundleId and npcId: public EntityQuestNpc(World world, String bundleId, String npcId) { super(world); this.bundleId = bundleId; this.npcId = npcId; preventEntitySpawning = true; } Currently the entity is only spawned via a console command: private void commandSpawnNpc(ICommandSender sender, String bundleId, String npcId) { EntityQuestNpc npc = new EntityQuestNpc(sender.getEntityWorld(), bundleId, npcId); npc.setLocationAndAngles(sender.getPlayerCoordinates().posX, sender.getPlayerCoordinates().posY, sender.getPlayerCoordinates().posZ, 0.0F, 0.0F); sender.getEntityWorld().spawnEntityInWorld(npc); } And I have the properties being saved with the NBT data: @Override public void readEntityFromNBT(NBTTagCompound tag) { super.readEntityFromNBT(tag); NBTTagCompound data = tag.getCompoundTag(PROP_NAME); bundleId = data.getString("bundleId"); npcId = data.getString("npcId"); System.out.println("[readEntityFromNBT] BUNDLE:" + bundleId + " NPC:" + npcId); } @Override public void writeEntityToNBT(NBTTagCompound tag) { super.writeEntityToNBT(tag); NBTTagCompound data = new NBTTagCompound(); data.setString("bundleId", bundleId); data.setString("npcId", npcId); tag.setTag(PROP_NAME, data); System.out.println("[writeEntityToNBT] BUNDLE:" + bundleId + " NPC:" + npcId); } The logs show that the correct data is being written and read. However when I use the following command to attempt to print the properties to the chat window, they are null: private void commandNpcInfo(ICommandSender sender) { if (Minecraft.getMinecraft().objectMouseOver.entityHit != null) { if (Minecraft.getMinecraft().objectMouseOver.entityHit instanceof EntityQuestNpc) { EntityQuestNpc npc = (EntityQuestNpc) Minecraft.getMinecraft().objectMouseOver.entityHit; sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "ID:" + npc.npcId + " BUNDLE:" + npc.bundleId)); } else { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You must be looking at a quest NPC")); } } else { sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "You must be looking at a quest NPC")); } } From my understanding all commands are run on the server, so even if I'm not syncing the properties with clients it should still be printing out a value?
July 8, 20169 yr Author I just discovered IEntityAdditionalSpawnData which seems to have fixed the issue, but as you pointed out, I'm using the client to get the entity the player is looking at. What would be the alternative for the server?
July 8, 20169 yr Author Oh I just assumed that since the command was being run on the server that it should check the entity on the server rather than the client, but if this isn't a problem then I will leave it!
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.