Jump to content

[1.7.10] Missing Entity Data


SHiLLySiT

Recommended Posts

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?

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.