#[1.21.1] Modifying /enchantable/chest_armor.json tag makes all items enchantable

75 messages · Page 1 of 1 (latest)

cedar crypt
#

I altered the minecraft/tags/item/enchantable/chest_armor.json tag which controls which enchantments can be applied to certain items. Here is the json file:

{
  "replace": false,
  "values": [
    "#betterhorses:horse_armor"
  ]
}

It does make the the intended items enchantable, but it also makes every other item enchantable, including stackables, with every enchantment. I am guessing the issue is in the tag, which is defined in my ModTags class:

public class ModTags {
    public static final TagKey<Item> HORSE_ARMOR = createTag("horse_armor");

    //Use Itemstack.isIn() to check tag
    private static TagKey<Item> createTag(String name) {
        return TagKey.of(RegistryKeys.ITEM, Identifier.of(BetterHorses.MOD_ID, name));
    }
}

made while following the Kaupenjoe custom tags tutorial. The tag is correctly registered (tested with ModTags.HORSE_ARMOR.toString() in the server mod init/loads correctly when opening world) and contains the following entries:

{
  "values": [
    "minecraft:leather_horse_armor",
    "minecraft:golden_horse_armor",
    "minecraft:iron_horse_armor",
    "minecraft:diamond_horse_armor"
  ]
}

Why does it do this and is there a way to alter enchantment's applicable items via tags? Thanks in advance! :)
-# Ping on reply please! 🔔

In this Minecraft Modding Tutorial, we are adding Custom Tags to Minecraft using the Fabric API for Minecraft 1.21.

== 1.21 MODDING COURSES ==
▶️ NeoForge Modding with Minecraft 1.21.X:
https://url.kaupenjoe.net/CourseNeoForge121X
▶️ Fabric Modding with Minecraft 1.21.X:
https://url.kaupenjoe.net/CourseFabric121X
▶️ Forge Modding ...

▶ Play video
raven cairn
#

that's vanilla behavior btw

cedar crypt
#

wait really?

raven cairn
#

don't test anything in creative

cedar crypt
#

omfg

#

bruhhh tysm

#

ok but then I have a new question

#

gimme a sec

raven cairn
#

first make sure your enchantment stuff works in survival

cedar crypt
#

well yep that worked with the enchantment stuff

#

thanks!

#

now the issue is ItemStack#isIn() isn't correctly seeing the tag if that makes sense

#
ItemStack i1 = this.input.getStack(0);
ItemStack i2 = this.input.getStack(1);
ItemStack o = i1.copy();

System.out.println("I1: " + i1.isIn(ModTags.HORSE_ARMOR));
System.out.println("I2: " + i2.isIn(ModTags.HORSE_ARMOR) + " Empty: " + i2.isEmpty());

This prints:

[09:55:14] [Server thread/INFO] (Minecraft) [STDOUT]: I2: false Empty: true```
Even though the item is in the tag
#

empty does have proper behavior btw ||I just picked a bad test lol||

#

and maybe you know a better way, but the intent in all of this is to enable combining horse armor in an anvil because its not possible to combine enchantments of items without durability in vanilla

#

so I'm adding a condition in the anvilscreenhandler

raven cairn
#

this is a wild guess, can you add a empty public static method to ModTags.java and call it in your mod init?

cedar crypt
#

running right now

#

still doesn't work :(

raven cairn
#

you'll have to debug the isIn implementation then

#

(hopefully you won't need to go in too deep)

cedar crypt
#

how do you access vanilla tags? It changed since I last did it I think

raven cairn
#

ItemTags

#

BlockTags

cedar crypt
#

oh thx

#

well it works with vanilla tags for some reason

raven cairn
#

then it's likely your tag key identifier is wrong or the placement of the json file is wrong

cedar crypt
#
public static final TagKey<Item> HORSE_ARMOR = createTag("horse_armor");

    //Use Itemstack.isIn() to check tag
    private static TagKey<Item> createTag(String name) {
        return TagKey.of(RegistryKeys.ITEM, Identifier.of(BetterHorses.MOD_ID, name));
    }```
#

do you see anything wrong?

raven cairn
#

i don't see anything odd

#

is this code in github?

cedar crypt
#

I'm just gonna rewatch the tutorial and see if I messed something up

cedar crypt
#

lemme commit and push rq

raven cairn
cedar crypt
#

anvilmixin

raven cairn
#

oh

#

this is silly

#

your mod id is "better_horses" but your asset namespace is "betterhorses"

cedar crypt
#

should modId be lowercase?

#

and should modId change to match the directory or should directory change?

#

I refactored it all a long time ago and not everything matched up intellithonk

#

the intended mod namespace is betterhorses

raven cairn
#

just remove the underscore. if you have consistently used BetterHorses.MOD_ID, you barely will have anything to change

cedar crypt
#

yeah I have

#

Ok gonna test

#

yep that fixed the tag issue and replaced it with a bunch of warns

#

but ik how to fix that lol

#

thank you so much!

#

I knew it would be smth dumb like that lmao 🤦‍♂️

raven cairn
#

also i noticed some of the anvil mixin code looks like it's copied from vanilla

#

i'd suggest not doing that, instead use precise mixins to conditionally change vanilla code

#

also the @Override in AbstractHorseMixin is considered a bad for mod compatibility. consider this pattern: #mod-dev-mixin message

cedar crypt
cedar crypt
raven cairn
raven cairn
cedar crypt
#

but how do I inject into those points via mixins? I couldn't find a point reference that worked for me here

#

ex. line 144 of the AnvilScreenHandler class would be very good to put my mixin code into

#

but how would I get it there?

#

no fields are accessed, its not near a return statement, and its not the head or tail of the method

#

line 166 would also work

raven cairn
#

also remember, mixins work on bytecode, not source code

raven cairn
cedar crypt
#

or after sry

raven cairn
#

most mixin injectors inject before

#

you can always ask in #mod-dev-mixin

#

also read the pinned message in that channel

cedar crypt
#

ok thanks for your help