#Overwriting vanilla item into modded blockitem

8 messages · Page 1 of 1 (latest)

tiny crag
#

Hey there, I've been trying to change a vanilla item into being a blockitem for a block my mod is adding.

I've been trying mixins, but I'm pretty new to them so I've not quite been able to wrap my head around them.

The item i'm trying to change is Items.FLINT

@Mixin(Items.class)
public abstract class ItemsMixin {
    @ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Items;register(Ljava/lang/String;Lnet/minecraft/item/Item;)Lnet/minecraft/item/Item;"), index = 1)
    private Item mixin(Item item) {
        return new BlockItem(ModBlocks.FLINT_ROCK, new Item.Settings());
    }
}

I know the target is wrong since I haven't specified which defintion to target but I'm unsure how, was just wondering if anyone could point out the correct way to do this or even if mixins are the right way to go.

As far as I understand also I could use an accessor to change the item, but so long as it isn't final?

thanks

tiny crag
#

I've made some progress in understanding more, and have decided to alter the register method instead. However a new issue has arose

@Mixin(Items.class)
public class ItemsMixin {
    @Inject(method = "Lnet/minecraft/item/Items;register(Ljava/lang/String;Lnet/minecraft/item/Item;)Lnet/minecraft/item/Item;", at = @At(value = "HEAD", target = "Lnet/minecraft/item/Items;register(Ljava/lang/String;Lnet/minecraft/item/Item;)Lnet/minecraft/item/Item;"), cancellable = true)
    private static void injectRegisterMethod(String id, Item item, CallbackInfoReturnable<Item> cir) {
        if (id == "flint") {
            cir.setReturnValue(Items.register(ModBlocks.FLINT_ROCK));
        }
    }
}

This is done before my ModBlocks are registered, so I am assuming it is why it fails....

Am I approaching this problem wrong?
Are there any mods that have done something like this before?

dull coral
#

instead mixin into the static initializer <clinit>, ModifyArg the register() call where the new Item is called for flint & steel, return a new instance of your item

#

you'll need a slice since there's multiple register calls

tiny crag
#

Overwriting vanilla item into modded blockitem

tiny crag
#

I tried using slicing as suggested, I didn't quite seem to get it implmeneted correctly and I'm not quite sure I understand how I would given they're all calls to the register method but when I got the desired behaviour again it threw the same error as my previous attempt

@Mixin(Items.class)
public abstract class ItemsMixin {
    @ModifyArgs(
        method = "<clinit>", 
        at = @At(value = "INVOKE", target = "Lnet/minecraft/item/Items;register(Ljava/lang/String;Lnet/minecraft/item/Item;)Lnet/minecraft/item/Item;"),
        slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/item/Items;NETHERITE_BOOTS:Lnet/minecraft/item/Item;"))
    )
    private static void mixin(Args args) {
        if (args.get(0) == "flint") {
            args.set(1, (Item) new BlockItem(ModBlocks.FLINT_ROCK, new Item.Settings()));
        }
    }
}

The error

java.lang.IllegalStateException: Some intrusive holders were not registered: [Reference{null=air}]

I am assumign this indicates that it tried to pass my modded blockitem which didn't exist yet so it used null?

dull coral
#

i believe so, first ignore this mixin and make sure the mod blocks/items are available

tiny crag
#

I wasn't able to figure out exactly what I should have done different;y, but I found a cool library that made what I was wanting to do easier and possible without mixins. Thanks for your help iiregardless

For anyone wanting to know what it was: https://modrinth.com/mod/regedit