#Need help with predicates, and 1.21 enchants

1 messages · Page 1 of 1 (latest)

real charm
#

Hello! my issue is that mc won't let me load in the enchants cause i need to reload the world, but when i do it says to enter in safe mode and i was just trying to change one single enchant json file.
1.21 has added the function to create custom enchants but this enchant is suppose to run 3 different functions depending on enchant level. i thought that this might be because of the predicates but thats not the case, i will send both a sample predicate and the enchant code down below too. If anyone knows an easier way to make custom enchants that run different functions with different levels that would be really nice!

Code pasted below ;D

cinder glacierBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1721619304:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

real charm
#

{
"description": "Vampire",
"supported_items": "#minecraft:swords",
"weight": 50,
"max_level": 3,
"min_cost": {
"base": 15,
"per_level_above_first": 2
},
"max_cost": {
"base": 40,
"per_level_above_first": 5
},
"anvil_cost": 10,
"slots": [
"mainhand"
],
"effects": {
"minecraft:post_attack": [
{
"enchanted": "attacker",
"affected": "attacker",
"effect": {
"type": "minecraft:run_function",
"function": "tme:vampire/1"
},
"requirements": {
"condition": "minecraft:reference",
"name": "tme:vampire1"
}
},
{
"enchanted": "attacker",
"affected": "attacker",
"effect": {
"type": "minecraft:run_function",
"function": "tme:vampire/2"
},
"requirements": {
"condition": "minecraft:reference",
"name": "tme:vampire2"
}
},
{
"enchanted": "attacker",
"affected": "attacker",
"effect": {
"type": "minecraft:run_function",
"function": "tme:vampire/3"
},
"requirements": {
"condition": "minecraft:reference",
"name": "tme:vampire3"
}
}
]
}
}

#

That was the enchantment

#

{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"equipment": {
"mainhand": {
"components": {
"minecraft:enchantments": {
"tme:enchanment_table/vampire": 1
}
}
}
}
}
}

#

this is the predicate

swift hawk
#

What do the logs say when you try to open the world?

real charm
#

This is was it says when i try and join the world, it try's and keeps me in safe mode

swift hawk
#

Validation error in enchantment effect condition: at : Uses reference to tme:vampire3, but references are not allowed; Validation error in enchantment effect condition: at : Uses reference to tme:vampire2, but references are not allowed; Validation error in enchantment effect condition: at : Uses reference to tme:vampire1, but references are not allowed missed input

real charm
#

the weird thing is predicates work, and i have tested they will always work. just when putting them into the enchantment .json file it crashes

swift hawk
#

Supposedly you just can't use reference predicates in enchantments

real charm
#

oh, well is there any solution to running different functions for the same enchant but with different levels? or is this just a mc bug

swift hawk
#

You absolutely can

#

You may just need to write the predicates in-line instead of referencing separate predicate files

real charm
#

could you give an example? if you want!

swift hawk
#
...
"minecraft:post_attack": [
      {
        "enchanted": "attacker",
        "affected": "attacker",
        "effect": {
          "type": "minecraft:run_function",
          "function": "tme:vampire/1"
        },
        "requirements": {
          "condition": "minecraft:match_tool",
          "predicate": {
            "predicates": {
              "minecraft:enchantments": [
                {
                  "enchantments": "tme:enchantment_table/vampire",
                  "levels": 1
                }
              ]
            }
          }
        }
      },
...
real charm
#

ah yeah i tried that before and it still gave me a safe mode version, it could be because minecraft doesn't like to just check enchantments?

swift hawk
#

No

#

But I would suggest doing that anyway, as it may yield a more useful error message

real charm
#

true

#

let me try and get that error

#

yeah it gave a different error

swift hawk
#

Unbound values in registry ResourceKey[minecraft:root / minecraft:enchantment]: [tme:enchanment_table/vampire]
Yep. Usually a result of missing required fields, fields not having data in a form that they expect, or a missing or extra , or { or }

#

Are you using Misode to generate this?

real charm
#

yeah

swift hawk
#

And have you been making all your changes in Misode?

real charm
#

misode was used to generate the enchants

swift hawk
#

Or have you made some changes by hand?

real charm
#

did not change anything by had

#

just did a copy and paste

#

here is the code for ref

#

{
"description": "Vampire",
"supported_items": "#minecraft:swords",
"weight": 50,
"max_level": 3,
"min_cost": {
"base": 15,
"per_level_above_first": 2
},
"max_cost": {
"base": 40,
"per_level_above_first": 5
},
"anvil_cost": 10,
"slots": [
"mainhand"
],
"effects": {
"minecraft:post_attack": [
{
"enchanted": "attacker",
"affected": "attacker",
"effect": {
"type": "minecraft:run_function",
"function": "tme:vampire/1"
},
"requirements": {
"condition": "minecraft:match_tool",
"predicate": {
"components": {
"minecraft:enchantments": {
"tme:enchanment_table/vampire": 1
}
}
}
}
},
{
"enchanted": "attacker",
"affected": "attacker",
"effect": {
"type": "minecraft:run_function",
"function": "tme:vampire/2"
},
"requirements": {
"condition": "minecraft:match_tool",
"predicate": {
"components": {
"minecraft:enchantments": {
"tme:enchanment_table/vampire": 2
}
}
}
}
},
{
"enchanted": "attacker",
"affected": "attacker",
"effect": {
"type": "minecraft:run_function",
"function": "tme:vampire/3"
},
"requirements": {
"condition": "minecraft:match_tool",
"predicate": {
"components": {
"minecraft:enchantments": {
"tme:enchanment_table/vampire": 3
}
}
}
}
}
]
}
}

swift hawk
#

So it's unlikely to be a missing or extra character issue

#

You're positive all those functions exist at those filepaths?

real charm
#

yep

swift hawk
#

(by the way, you have all your enchantment checks under "components". You want them under "predicates")

#

"predicates" is a partial check, "components" will only work for an exact match, meaning no other enchantments on the item

real charm
#

oooooo, wait yeah i just saw that too

swift hawk
#

That shouldn't be causing the issue here, but good to fix anyway

real charm
#

yeah ima change it real quick to see if that was just the issue

swift hawk
#

The other thing I'm seeing is your enchantment listed in the tool checks is tme:enchanment_table/vampire. enchanment is misspelled here, is it misspelled the same way in the folder name?

real charm
#

ima send a picture of the full path directory

swift hawk
#

I don't really need that

real charm
#

ok

swift hawk
#

It's just a yes or no question, you can check and confirm

real charm
#

they are both spelt the same

swift hawk
#

Alright

real charm
#

here is the predicate version for code, still gives the same error too

swift hawk
#

Yeah I'm not sure what to tell you then. You may try remaking it from scratch--obviously there is something syntactically wrong here, but I can't spot it at a glance and it seems Misode can't either.

real charm
#

yeah, the thing is that even visual studio is not giving errors to this

swift hawk
#

Yep.

#

Try troubleshooting with different effects to see if it's an issue with the effects or something else, and keep iterating by removing different things, or adding them back in in different ways

#

Remake the functions and folders they are in if needed

real charm
#

well the thing is when using no predicates or level checks it works but thats not what im after, so i narrowed it down to the level check system that could be broken in a way

swift hawk
#

Then continue iterating and narrowing it down

#

Figure out what about the level system is causing an issue

real charm
#

well thanks for the help you could provide!