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

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

 

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.

if(event.smelting.stackTagCompound.getString("Owner")== null)

 

should be

 

if(!event.smelting.stackTagCompound.hasKey("Owner"))

  • Author

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

For second, I dont know..

 

yeah i had thought that but then when i was able to get a furnace to display its owner when crafted. Then it wouldn't stack with others(as i had expected) but would stack with anotherr one with the same name

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.

  • Author

ok I have pickups and smelting working now, just one problem of shift clicking an item from the furnace and crafting bench, since it'll set the owner if it's a single item takn at a time but not a stack although the single items can then be placed into a stack with others of the same owner.

Any suggestions?

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.