Darkhax-Minecraft / ItemStages

Allows items to be put into stages.
GNU Lesser General Public License v2.1
7 stars 18 forks source link

Staging items with state NBT data doesn't work #50

Closed opl- closed 3 years ago

opl- commented 5 years ago

Items with NBT data used to store their state (energy, settings, etc) cannot be locked behind a stage. This is problematic on servers where player progression happens independently, where certain items might be found in loot tables and in case of recipes that upgrade items (although these could be locked using Recipe Stages). An example of such item are the Simply Jetpacks jetpacks. Here's an example jetpack:

<simplyjetpacks:itemjetpack:2>.withTag({JetpackHoverModeOn: 0 as byte, Energy: 39415, JetpackParticleType: 0})

Trying to lock this jetpack with any of the following doesn't prevent it from being used:

mods.ItemStages.addItemStage("one", <simplyjetpacks:itemjetpack:2>); mods.ItemStages.addItemStage("one", <simplyjetpacks:itemjetpack:2>.withTag({})); mods.ItemStages.addItemStage("one", <simplyjetpacks:itemjetpack:2>.withTag({}, false));

Other examples of such items include the Reliquary Rending Gale and Blood Magic Sigils.

Minecraft: 1.12.2 CraftTweaker: 4.1.19 GameStages: 2.0.115 ItemStages: 2.0.49 Bookshelf: 2.3.585

Darkhax commented 5 years ago

NBT is supported through partial item NBT. Here is an excerpt from the example script which can be used to stage all enchantment books with a level 5 enchantment.

// Restricts access to all level 5 enchantments.
// Note: With JEI auto hiding, you will need to manually add another entry for the version of the item in JEI.
mods.ItemStages.addItemStage("one", <minecraft:enchanted_book>.withTag({StoredEnchantments: [{lvl: 5 as short}]}));
opl- commented 5 years ago

Unfortunately, as stated in the issue, that approach doesn't work for items like the jetpacks.

Darkhax commented 4 years ago

I've finally had some time to test and confirm your issue. The issue you are running into is an edge case where the jetpack uses both NBT and Metadata for different versions of the item. This makes it not possible to wildcard match the meta or the nbt. The fix for this issue will be to move from my item stack matching code to minecraft's Ingredient matching system. This will be done when the mod is updated to 1.13+

Darkhax commented 3 years ago

The fix for this issue will be to move from my item stack matching code to minecraft's Ingredient matching system. This will be done when the mod is updated to 1.13+

The mod has now been ported to 1.16.5 which uses Minecraft's ingredient system and can also support arbitrary stack matching. This is significantly cleaner than the old matching method and will have much better matching results.

Here is an example from the example script that can restrict items based on their furnace burn times.

ItemStages.restrict(stack => stack.burnTime == 150, "ex_three");