Jump to content

[Solved][1.12.2] Problem creating merchant recipe to return enchanted item


Recommended Posts

Posted (edited)

I have a custom villager profession "cloud enchanter" that is supposed to allow you to use emeralds to buy boots of "safe falling" which are golden boots with a custom enchantment (of "safe falling" of course). The enchantment works fine on its own -- I can print out the enchantment registry and see it listed, and I can use the /enchant command and it can enchant golden boots which begin to shimmer and also work as intended (prevent fall damage completely). 

 

The villager trade also generally works -- clicking on the villager brings up a trade GUI with a single trade that shows emeralds resulting in golden boots, and placing emeralds gets the boots. However, the problem is that the boots are not enchanted -- they don't glimmer and they don't protect the player.

 

The weird thing is that if I print out the merchant recipe at the time it is "added" (which seems to be when the GUI is opened) the console shows that the recipe includes enchanted boots (11 is id of my custom enchantment): 

[com.blogspot.jabelarminecraft.examplemod.init.ModProfessions$TradeEmeraldsForEnchantedBoots:addMerchantRecipe:110]: Merchant recipe list = {Recipes:[{maxUses:7,buy:{id:"minecraft:emerald",Count:47b,Damage:0s},sell:{id:"minecraft:golden_boots",Count:1b,tag:{ench:[{lvl:2s,id:11s}]},Damage:0s},uses:0,rewardExp:1b}]}

 

Even weirder is I tried the built-in merchant trades such as ListEnchantedItemForEmeralds and they also do not seem to work! I would get non-enchanted items in the GUI even though the merchant recipe prints out that the buy item is enchanted.

 

I then tried to trace the call hierarchy and I'm now suspicious that the merchant recipe system may have a bug -- it creates the buying item with the ItemStack(NBTTagCompound) constructor. However, it seems to me that that constructor may not work for enchantment NBT data. If you look at the addEnchantment() method you'll see it adds a compound with key "ench". But the ItemStack(NBTTagCompound) doesn't seem to handle that at all.

 

Am I missing something?

 

In summary, the merchant recipe prints out (at time of GUI opening) and shows that the recipe sells an enchanted item but the GUI doesn't show the item as enchanted. Looking at how the GUI creates the item using ItemStack(NBTTagCompound) it seems to me that enchantment tags may not be applied.

 

Here are some relevant classes:

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

EDIT: Corail31 helped me solve this. I kept testing with the same saved world with the same villager. So the villagers already generated never got my updated merchant lists.

 

I didn't realize that merchant list was associated at time of villager generation, which makes sense now that I think that it needs to remember the offers and number of uses.

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.