How To Select A Specific Custom Enchantment In A Villager Trade?

Started by Hygerian on

Topic category: Help with Minecraft modding (Java Edition)

Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How To Select A Specific Custom Enchantment In A Villager Trade?
Tue, 11/21/2023 - 12:45 (edited)

Hello,
I have a question that really changes my mod!
So, how can you make a villager trade a specific custom enchantment because I cant select the enchantment book with my enchantment, only this item called "Enchanted Book“"without any enchantment and this feature would really change my mod!
In general I think you should be able to pick these different books and potions for recipes or trades!

Version 1.19.4

Edited by Hygerian on Tue, 11/21/2023 - 12:45
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can lock a loot table, …
Tue, 11/21/2023 - 16:48

You can lock a loot table, (and presumably a villager trade, as these are a special variety of loot table), and add additional loot functions to add custom data to items in the table. (Including damage, potion effects, and specific enchantments.) Once you lock the table, you should find each entry in the table has a 'functions' section, with the only provided function being to 'set count,' randomizing the number of items based on your parameters.

Here's some common loot table functions you might find helpful: (Add a comma after the first function, and paste these into the functions section:

 

Enchant an item with random levels using the provided enchantments. You can list as many enchantments as you like, (you can find the correct registry names on the wiki, they're mostly self-explanatory); but just make sure the last one doesn't have a comma after it.

{
  "function": "enchant_randomly",
              "enchantments": [
                "power",
                "mending",
                "knockback"
              ]
}

Damage an item with durability within a set range: (In this case, between 40-70% durability remaining):

{
    "function": "set_damage",
        		"damage":{
        		"min":0.4,
        		"max":0.7
        		}
}

Set the potion value of a splash potion, bottle, lingering potion, or tipped arrow. (Again, registry names are important, but generally straightforward):

{
  "function": "set_nbt",
              "tag": "{Potion:\"minecraft:weakness\"}"
}

...Etc. Just make sure things are spelled correctly; loot tables with errors won't prevent the game from compiling, but any error in the loot table will prevent the entire thing from loading.

Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I dont really undertand, I…
Tue, 11/21/2023 - 18:41

I dont really undertand, I tried what you said but it doesnt work.

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
It's possible that villager…
Tue, 11/21/2023 - 19:00

It's possible that villager trades use different code than loot tables? There's also a Microsoft Guide that explains loot table functions better than I can. (Though a couple of them are bedrock specific, most work for java modding.)

Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Maybe.Ok thanks, I will try…
Tue, 11/21/2023 - 19:04

Maybe.
Ok thanks, I will try to ask a dev of the mcreator program, they will probably know it

Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mindthemoods Could you…
Sat, 11/25/2023 - 18:42

Mindthemoods 

Could you please show me a picture of the procedure?
Like a picture of you making a villager trade with a custom enchantment and the procedure because I dont really understand what you're trying to tell me here.
It would be best if you could make everything custom, like enchantment and trade for this example so i can easier tell what i could do.

Here are the pictures of my enchantment and my villager trade:

https://ibb.co/rmsbSvt
https://ibb.co/MBW75qh
https://ibb.co/Pr66cCq

Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
The trouble is I haven't…
Sat, 11/25/2023 - 22:05

The trouble is I haven't actually made a villager trade with enchantments; I've only ever done this with loot tables, and, looking into it, villager trades are quite a bit different. 

The principle should still be the same- you would need some sort of loot function, (the functions may be different for villager trades), that you would put in the code to enchant the traded item, and you would need to reference the enchantment using your mod's id instead of minecraft, which would likely also be kind of complicated. Possible, but I'm not personally sure how you would do this. 

Joined Feb 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ok... thats unfortunate…
Sun, 11/26/2023 - 10:21

Ok... thats unfortunate.
Maybe there is someone you know that can explain this.
You think that Klemen could know this?
And how could we @ Klemen?
Well still thanks for your help, you helped me really much with that damage block thing!