Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.20.6] DeferredRegister for ArmorMaterial is broken #9961

Closed
Hummel009 opened this issue May 5, 2024 · 2 comments
Closed

[1.20.6] DeferredRegister for ArmorMaterial is broken #9961

Hummel009 opened this issue May 5, 2024 · 2 comments
Labels

Comments

@Hummel009
Copy link

Hummel009 commented May 5, 2024

Minecraft Version: 1.20.6

Forge Version: 50.0.5

Logs: No crash

Description of issue:

Since 1.20.6 ArmorItem has only one constructor:

public ArmorItem(Holder<ArmorMaterial> p1, Type p2, Item.Properties p3){
...
}

It requires Holder<> of ArmorMaterial. Forge uses RegistryObject for deferred registering, so when I use deferred registration for the new ArmorMaterial, it returns not the Holder<>. But the armor constructor requires Holder<>.

I can try to get Holder<> from RegistryObject, using getHolder().orElseThrow():

public class MyItemArmor extends ArmorItem {
	public MyItemArmor (Type type) {
		super(MyArmorMaterials.MY_MATERIAL.getHolder().orElseThrow(), type, new Properties());
	}
}

But Holder<> is null in this time (items are registered via DeferredRegister, armor materials too, looks like new item constructor is called during the stage, when Holders are not created yet), so there is an Exception.

So now the only way to add and use new ArmorMaterial is to write fabric-styled code, that looks strange among forge deferred registration files.

@Hummel009 Hummel009 added the Triage This request requires the active attention of the Triage Team. Requires labelling or reviews. label May 5, 2024
@autoforge autoforge bot added the 1.20 label May 5, 2024
@JimiIT92
Copy link

JimiIT92 commented May 8, 2024

While this gets fixed, you can try doing something like this:

  • Create the Armor Material before registering the items
  • Register an armor piece (like an helmet) providing an Holder.direct(yourArmorMaterial) as the ArmorMaterial Holder

It's not the best solution but at least it works for now. Of course when this will get patched I recommend switching to the DeferredRegister methods and using the proper RegistryObjects

@autoforge autoforge bot removed the Triage This request requires the active attention of the Triage Team. Requires labelling or reviews. label May 12, 2024
@LexManos
Copy link
Member

So, it is an issue with the way I sort the registry fire events. Currently it's being sorted by the first time register is called.
Which usually works, except in cases where the first entry in the registry doesn't force another registry to be initialized, but the nth entry does.
Unfortunately, there is no generic "we're done making all vanilla entries" event in a registry. At least not one that isn't a stagnant order. So we can't gather the order on last register.

For now i've made a solution that works for this simple test case:

    private static final DeferredRegister<ArmorMaterial> ARMORS = deferred(Registries.ARMOR_MATERIAL);
    private static final RegistryObject<ArmorMaterial> ARMOR = ARMORS.register("test", () -> {
        return new ArmorMaterial(
            Collections.emptyMap(),
            1,
            SoundEvents.ARMOR_EQUIP_CHAIN,
            () -> Ingredient.of(Items.IRON_INGOT),
            Collections.emptyList(),
            1.0f, 1.0f
        );
    });
    private static final DeferredRegister<Item> ITEMS = deferred(Registries.ITEM);
    private static final RegistryObject<Item> ARMOR_CHEST = ITEMS.register("test_chest", () -> {
        return new ArmorItem(
            ARMOR.getHolder().orElseThrow(),
            ArmorItem.Type.CHESTPLATE,
            new Item.Properties().durability(ArmorItem.Type.CHESTPLATE.getDurability(15))
        );
    });
    

Eventually I need to go in and simplify the registry system yet again. I really wish Mojang would get their crap together and solve the few minor things that make all our registry hooks necessary. Namely, ID syncing between network and saves for non-data driven registries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants