Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • 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?

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.