API and/or Approach Question

25 views
Skip to first unread message

Ben Rimmasch

unread,
Jun 5, 2019, 12:15:02 AM6/5/19
to inventor...@googlegroups.com

Hello, Inventory Tweaks Group.

 

I have a mod that contains a boomerang.  When the player rights clicks the Item in inventory it creates an entity that flies off with a copy of the ItemStack and removes it from the player’s inventory until it returns.  When it returns the entity places the ItemStack back in the empty spot that was left from the right click event.  This is all typically done from the entity’s update method when collision is detected.  This works very well until Inventory Tweak’s replace tool functionality is turned on and a second boomerang exists in the inventory.

 

When it is enabled there are race conditions that (infrequently) duplicate the boomerang or lose it because Inventory Tweaks is placing a new boomerang over the empty slot around the time the boomerang is returning and something gets overwritten.  I can see the API doesn’t have methods for removing or placing ItemStacks on the player.  Without having to pour over the code can somebody tell me the best way I can handle what I’m doing to avoid getting stepped on by the replace functionality?

 

Thanks in advance,

Ben

 

Jimeo Wan

unread,
Jun 5, 2019, 8:35:39 AM6/5/19
to inventor...@googlegroups.com
Hi Ben,

For the looks of it, if the item breaks for Inventory Tweaks there are chances it also breaks for more vanilla scenarios, like the player picking up an item (at the same slot) between the moment they launch the boomerang and the moment it comes back.
A safe bet would be to check the slot when the boomerang comes back: if there is another item the stole that slot in the meanwhile, pick any other free slot instead.

I could also see an even more tricky (but super rare) case: what if the inventory is actually full when the boomerang comes back? You can either choose to destroy the item or, ideally, look into dropping it on the ground.

Maybe looking at the Inventory Tweaks sources can help you figure out how to use the Minecraft API to do those things (an entry point could be the DirectContainerManager class).

I hope this helps,

Jimeo Wan


--
You received this message because you are subscribed to the Google Groups "Inventory Tweaks developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to inventory-twea...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/inventory-tweaks/5cf741c4.1c69fb81.880bc.2613%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

Kobata

unread,
Jun 5, 2019, 10:25:12 AM6/5/19
to inventor...@googlegroups.com
I'm going to propose that in general, you probably want to simply not remove/readd the item at all, simply change its state so it is unusable. There are edge cases here as well of course: someone could drop the item, or put in in a chest or modded storage of some kind, but at least in those cases ensuring the item can fix itself later when in a player's inventory is something that only involves your item's code and not large amounts of extra vanilla and mod code as trying to play with the player's inventory.

Reply all
Reply to author
Forward
0 new messages