Jump to content

Detect When An Item Is Spawned?


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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.