#How to modify vanilla items using mixin?
44 messages · Page 1 of 1 (latest)
This is my code currently
@Mixin(Items.class)
public abstract class ItemsMixin {
@Shadow
public static final Item GOLDEN_SWORD = register("golden_sword", new Item.Settings().sword(ToolMaterial.GOLD, 5.0F, -2.4F));
}
1.21.8 btw
not sure if you actually can change static final variables
The Shadow annotation does not allow you to change the definition* of a var. It only lets you use it
I'd suggest using a @Inject injecting into the register method
uhmm this does not work
public abstract class ItemsMixin {
@Shadow
public static Item GOLDEN_SWORD;
@Inject(method = "<clinit>", at = @At("TAIL"))
public static void ModifyGoldenSword(CallbackInfo ci) {
GOLDEN_SWORD = new Item.Settings().sword(ToolMaterial.GOLD, 5.0F, -2.4F);
}
}
did I do anything wrong?
Edit: Added ModifyGoldenSword between void and (CallbackInfo ci), still not working
I did something similar to this to modify ToolMaterial and it worked, but it doesn't work with Items
no, this is not good
don't reinitialize the item, this will override anything other mods would add.
you should do precise changes, in this case only to the item settings
that way for example if someone makes a sword edible, that wouldn't be lost
it will have both settings
- use a
@Sliceto narrow down the search scope, generally you can easily target a constant value like "golden_sword" - use a injector that lets you do precise changes: ModifyExpressionValue, ModifyArg
can you provide some examples, because I'm still a beginner and those wiki pages don't make much sense to me?
why not just use the default item component event from fapi
you can use an accessor on ComponentMap$Builder to access its components which would let you modify them instead of overwriting (if needed)
does it let you modify the tool material?
or is that not needed in OP's case?
wait tool material is a part of the component
yes it did
all I did was
@Mixin(ToolMaterial.class)
public abstract class ToolMaterialMixin {
@Shadow
public static final ToolMaterial GOLD = new ToolMaterial(BlockTags.INCORRECT_FOR_GOLD_TOOL, 984, 8.0F, 0.0F, 22, ItemTags.GOLD_TOOL_MATERIALS);
}
and it worked perfectly fine
It technically lets you reassign to it also, as shadow initializers / assignments are merged
But it should never be used like that, so I pretend it doesn't work 
Wdym?
It's quite common to do and actually quite useful
Saves an injector
but it's not stackable
I mean, it depends on what you want to stack
If you use the original value it stacks just fine
I did this for ToolMaterial and it worked
but when I used similar code for Items
@Mixin(Items.class)
public abstract class ItemsMixin {
@Shadow
public static final Item GOLDEN_SWORD = register("golden_sword", new Item.Settings().sword(ToolMaterial.GOLD, 5.0F, -2.4F));
}
it didn't work
.
or mixin into the register method
which method?
Items.register
@Mixin(Items.class)
public abstract class ItemMixin {
@Shadow
public static final Item GOLDEN_SWORD = Items.register("golden_sword", new Item.Settings().sword(ToolMaterial.GOLD, 9.0F, 4F));
}
still crashing
well thats not doing what I said
so how would you do it?
either doing what diced said, or modifying the args passed to the other overload in the String, Item$Settings overload (which is less compatible with other injectors mixing into the same overload)
I tried to read the wiki he sent and it just went over my head