Skip to content

[1.21.5] Add item model/item renderer related events #10528

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

Open
wants to merge 5 commits into
base: 1.21.x
Choose a base branch
from

Conversation

CheIlia
Copy link

@CheIlia CheIlia commented Apr 9, 2025

IClientItemExtensions.getCustomRenderer() has been gone since 1.21.4 (if not earlier), and there is no way to make custom item renderers without using access transformers or mixins at the moment. This pull request makes it possible again, as well as adds a couple new events that allow users to register important item model related stuff

…sterColorHandlersEvent.Item and RegisterItemModelPropertiesEvent
@CLAassistant
Copy link

CLAassistant commented Apr 9, 2025

CLA assistant check
All committers have signed the CLA.

@autoforge autoforge bot added Triage This request requires the active attention of the Triage Team. Requires labelling or reviews. LTS This issue/PR is related to the current LTS version. 1.21 Feature This request implements a new feature. New Event This request implements a new event. labels Apr 9, 2025
@autoforge autoforge bot requested a review from a team April 9, 2025 07:49
@Jonathing
Copy link
Member

Jonathing commented Apr 9, 2025

This PR needs game tests to validate that these events are working as intended with examples. You can find our game tests in the src/test/java folder in the net.minecraftforge.debug package.

@CheIlia
Copy link
Author

CheIlia commented Apr 9, 2025

This PR needs game tests to validate that these events are working as intended with examples. You can find our game tests in the src/test/java folder in the net.minecraftforge.debug package.

Done :) Now if you run forge client test you'll notice 6 new items, and they are proof that each of the 6 new events works properly

Copy link
Member

@Jonathing Jonathing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably won't get around to properly reviewing this for a little while. But I'm kind of on the fence with this PR. It's been on the back-burner since I've been working on the toolchain, but I've wanted to make some sort of proper, simple API for working with the new model system that was introduced in 1.21.3, and subsequently expanded upon with item models in 1.21.4. So, I'm not the biggest fan of the "let's add an event here and hope people use it!" mentality, but for this it might have to do. We'll see some time later.

Also, please allow me to make clear now that all of my comments are not an attempt to dismiss your work. I am doing my best to make sure that all PRs that are submitted to Forge, and thus reviewed, are done so consistently, as simple as possible, and with as few issues as possible. I understand that sometimes my review comments may come across as harsh, but I'd rather make sure you understand my issues with something rather than sugarcoat it and risk something being lost in translation.

A few key things to note:

  • Your test mod does not actually include game tests. Game tests include code that are executed with the /test command, similar to unit tests. I know Minecraft kind of destroyed how game tests are registered in 1.21.5, but if Lex got them working, please add some of your own. What I expect is for you to be able to use Minecraft.getInstance().getModelManager().getItemModel(key) (or similar if this was removed in 1.21.5) to verify that the model you got is using the correct type and has the correct details.
  • The formatting you are using for this PR is outdated and inconsistent (some classes use either or).
    • Please stick to bracket-on-same-line style.
    • I prefer that short Javadoc comments be single-lined (/** like this */).

Comment on lines 55 to 62
IEventBus bus = ctx.getModEventBus();
DeferredRegister<Item> register = DeferredRegister.create(ForgeRegistries.ITEMS, modid());
for (String s: new String[] {"your_head", "warden_plushy", "yellow_cap_covered_in_snow", "rod_of_game_mode", "swim_with_this", "fullinventorymeter"}) {
RegistryObject<Item> registryObject = register.register(s, () -> new Item(name(modid(), s, new Item.Properties())));
testItem(provider -> registryObject.get().getDefaultInstance());
}
register.register(bus);
bus.register(ItemModelsTest.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look in BaseMod, all fields of type DeferredRegister are automatically registered for you. You can create a DeferredRegister field in this class without needing to register it yourself. Please do the same for your registry objects, so that they can be directly referenced in your tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should only be this:

clientSideOnly=true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a data generator to make this file. See ModelRenderLayerTest for example generators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a data generator to make this file. See ModelRenderLayerTest for example generators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a data generator to make this file. See ModelRenderLayerTest for example generators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a data generator to make this file. See ModelRenderLayerTest for example generators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a data generator to make this file. See ModelRenderLayerTest for example generators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a data generator to make this file. See ModelRenderLayerTest for example generators.

Comment on lines 83 to 96
public static class Item extends RegisterColorHandlersEvent
{

@ApiStatus.Internal
public Item() {}

/**
* Register an {@linkplain ItemTintSource item tint source} {@linkplain MapCodec map codec} with a specific id.
*/
public void register(ResourceLocation id, MapCodec<? extends ItemTintSource> codec) {
ItemTintSources.ID_MAPPER.put(id, codec);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use consistent formatting with the rest of the class file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should replace the parameter srg names (shit like p_12345_) with an actual name, to make the code easier to read.

@Jonathing
Copy link
Member

Also I realized that several times while reviewing this, I mistakenly thought this was for 1.21.4. Can you prefix [1.21.5] to the beginning of your PR title? Thanks 😎👍

@CheIlia CheIlia changed the title Add item model/item renderer related events Add item model/item renderer related events [1.21.5] Apr 9, 2025
@CheIlia CheIlia changed the title Add item model/item renderer related events [1.21.5] [1.21.5] Add item model/item renderer related events Apr 10, 2025
@CheIlia
Copy link
Author

CheIlia commented Apr 11, 2025

I probably won't get around to properly reviewing this for a little while. But I'm kind of on the fence with this PR. It's been on the back-burner since I've been working on the toolchain, but I've wanted to make some sort of proper, simple API for working with the new model system that was introduced in 1.21.3, and subsequently expanded upon with item models in 1.21.4. So, I'm not the biggest fan of the "let's add an event here and hope people use it!" mentality, but for this it might have to do. We'll see some time later.

Also, please allow me to make clear now that all of my comments are not an attempt to dismiss your work. I am doing my best to make sure that all PRs that are submitted to Forge, and thus reviewed, are done so consistently, as simple as possible, and with as few issues as possible. I understand that sometimes my review comments may come across as harsh, but I'd rather make sure you understand my issues with something rather than sugarcoat it and risk something being lost in translation.

A few key things to note:

  • Your test mod does not actually include game tests. Game tests include code that are executed with the /test command, similar to unit tests. I know Minecraft kind of destroyed how game tests are registered in 1.21.5, but if Lex got them working, please add some of your own. What I expect is for you to be able to use Minecraft.getInstance().getModelManager().getItemModel(key) (or similar if this was removed in 1.21.5) to verify that the model you got is using the correct type and has the correct details.

  • The formatting you are using for this PR is outdated and inconsistent (some classes use either or).

    • Please stick to bracket-on-same-line style.
    • I prefer that short Javadoc comments be single-lined (/** like this */).

Hello! I've changed code formatting and deleted item model test assets as you asked. Datagen doesn't work for now, and there are still no game tests, but I'll work on that soon. Also, I totally understand that it might seem like the item model event system could've been done easier, without creating .register() method in vanilla classes. I tried calling the events directly inside ItemModels, SpecialModelRenderers, ItemTintSources, SelectItemModelProperties, ConditionalItemModelProperties and RangeSelectItemModelProperties, but all these classes are called only during bootstrap, and forge "cowardly refuses to send events to a broken mod state" because it's too early to send events. Thus, these events have to be posted in a different class. I made it so that they are called in ForgeHooksClient.initClientHooks(), but turns out that method is never fired when running datagen, so I'll probably have to call them in ClientModLoader and DatagenModLoader instead

@CheIlia
Copy link
Author

CheIlia commented Apr 12, 2025

Alright, I've fixed datagen and added an actual game test. Now everything should be done, I guess. Well, if you will, I can delete the new register() methods in ItemModels, SpecialModelRenderers, etc. and just use an access transformer to make the id mappers public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.21 Feature This request implements a new feature. LTS This issue/PR is related to the current LTS version. New Event This request implements a new event. Triage This request requires the active attention of the Triage Team. Requires labelling or reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants