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

Is there anyway I can detect if an item is spawned from either a creative tab or /give command? I know that there's an onUpdate function for each item but I only need to call my code once when the item enters the player inventory.

Nope.

 

Even if catching ItemStack's creation would be applied to vanilla (there are quite few places to cover), it would be impossible to catch it for all mods.

 

What you can track is:

* Joining ItemStack to world (joining in any way like dropping, spawning, etc.)

* Change to Player's inventory (by checking last tick stacks with current ones)

 

As to catching levels of creation you mentioned:

1. For command you might be able to catch commands themselves.

2. For creative inventory I don't think so. (but maybe)

3. Mentioned "Change to Player's inventory" will be able to track anything "new", but it won't recognise source of added ItemStack.

 

Any particulat purpose? There might be some way around it.

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Nope.

 

Even if catching ItemStack's creation would be applied to vanilla (there are quite few places to cover), it would be impossible to catch it for all mods.

 

What you can track is:

* Joining ItemStack to world (joining in any way like dropping, spawning, etc.)

* Change to Player's inventory (by checking last tick stacks with current ones)

 

As to catching levels of creation you mentioned:

1. For command you might be able to catch commands themselves.

2. For creative inventory I don't think so. (but maybe)

3. Mentioned "Change to Player's inventory" will be able to track anything "new", but it won't recognise source of added ItemStack.

 

Any particulat purpose? There might be some way around it.

I think ItemStack joining the world would do the trick. I need to initialize custom NBT data for the item when it is first created and I was able to do that with onCreated but that only includes crafting and smelting. If the item is spawned from creative mode and used, it crashes the game.

Then nope - you should not do it that way. You are looking in the wrong way, use standard Java techiques.

 

Use lazy inicialization technique.

Something like:

getStacksNBT()
{
    if (nbt null)
       setNBT(some new NBT);
    return theNBT;
}

If null-checking is not enough (you can have more than null or non-null cases) you can hold e.g boolean like "has been just created"

1.7.10 is no longer supported by forge, you are on your own.

  • Author

Then nope - you should not do it that way. You are looking in the wrong way, use standard Java techiques.

 

Use lazy inicialization technique.

Something like:

getStacksNBT()
{
    if (nbt null)
       setNBT(some new NBT);
    return theNBT;
}

If null-checking is not enough (you can have more than null or non-null cases) you can hold e.g boolean like "has been just created"

Thanks for your help. Now, the NBT won't get initialized unless the user actually uses the item which is more efficient.

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.