Jump to content

Item information not displaying properly


theoneandonly2004

Recommended Posts

OK so I am working on a feature and I have the base of it somewhat functional. Currently whenever the player crafts an item it will display who owns it.

However I am having a few problems which include

 

1)information will only display whenever a single item is selected it will not add if you shift click an item from the crafting slot

2)even through repeating this process similarly for smelting and EntityItemPickups they do not show the information .

 

item pickup Event

@SubscribeEvent
   public void ItemPickup(EntityItemPickupEvent event)
   {

      System.out.println("pick up called");
      if(event.item.getEntityItem().stackTagCompound == null)
      {
         event.item.getEntityItem().stackTagCompound=new NBTTagCompound();
      }

      if(event.item.getEntityItem().stackTagCompound.getString("Owner")== null)
      {
         event.item.getEntityItem().stackTagCompound.setString("Owner", event.entityPlayer.getDisplayName());

      }
   }

 

Smelting event

  @SubscribeEvent
   public void onSmelting(PlayerEvent.ItemSmeltedEvent event)
   {      
      if(event.smelting.stackTagCompound==null)
      {
         event.smelting.setTagCompound(new NBTTagCompound());
      }
      if(event.smelting.stackTagCompound.getString("Owner")== null)
      {
         event.smelting.stackTagCompound.setString("Owner",event.player.getCommandSenderName());
      }
}

 

crafting handler


   @SubscribeEvent
   public void onPlayerItemCrafted(PlayerEvent.ItemCraftedEvent event)
   {
      if(event.crafting.stackTagCompound==null)
      {
         event.crafting.stackTagCompound=new NBTTagCompound();
      }
      
      if(event.crafting.stackTagCompound.getString("Owner")==null)
      {
         event.crafting.stackTagCompound.setString("Owner", event.player.getCommandSenderName());
      }
}

 

tooltip display code

@SubscribeEvent
   public void ToolTip(ItemTooltipEvent event)
   {

      if(event.itemStack.stackTagCompound==null)
      {
         event.itemStack.setTagCompound(new NBTTagCompound());
      }


      event.toolTip.add("Items owner is: "+ event.itemStack.stackTagCompound.getString("Owner")) ;
   }

 

not sure what the problem is so any help is appreciated.

Thanks

 

Link to comment
Share on other sites

NBT Tags will not work for stacked items, So I think that will cause first problem.

For second, I dont know..

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

Ah, what tattyseal said is right..

You have to check if there is the key,

For event.smelting.stackTagCompound.getString("Owner") will give "".

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

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.