I am currently adding a new type of minecart. The eventual goal will be to have it go faster than the vanilla minecart, therefore I named it "Fastcart". I have created my own model that is coloured differently and also created my custom renderer for it. This works as expected. The problem I have comes from the place where I want to set this renderer to go with the Fastcart Entity.
I have this code to do the registration of the renderer, in fact my main mod class.
@Mod(TotallyNotModdedMod.MODID)
public class TotallyNotModdedMod
{
public static final String MODID = "totallynotmodded";
public TotallyNotModdedMod()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
ItemInitializer.ITEMS.register(modEventBus);
BlockInitializer.BLOCKS.register(modEventBus);
MinecraftForge.EVENT_BUS.register(CreativeTabCreator.class);
registerFastcartRenderer();
}
private void registerFastcartRenderer() {
EntityRenderers.register(EntityType.MINECART, (p_174070_) -> new FastcartRenderer<>(p_174070_, ModelLayers.MINECART));
}
}
Observe the last two lines. My renderer is registered with the EntityRenderers and is attached to the EntityType.MINECART . This allowed me to test my renderer, as this would render the vanilla minecarts with my own renderer, and this works fine. The minecarts are now rendered using my own texture and renderer and stuff. Yay for me!
However, I now have to switch this to use my own EntityType so only my Fastcart Entity gets the FastcartRenderer and I don't overwrite the Renderer for the default Minecart. I thought I could do this by simply adding my own EntityType but turns out, everything in the EntityType class is private. I copied the contents of its register method and tried to create my own:
public class FastcartEntityTypeProvider {
//This seems to be the problem.
//The write in the register takes place too later after the registries are already locked.
//Might have to properly setup the Mixins to circumvent this.
public static final EntityType<Fastcart> FASTCART = register("fastcart", EntityType.Builder.<Fastcart>of(Fastcart::new, MobCategory.MISC).sized(0.98F, 0.7F).clientTrackingRange(8));
private static <T extends Entity> EntityType<T> register(String p_20635_, EntityType.Builder<T> p_20636_) {
return Registry.register(BuiltInRegistries.ENTITY_TYPE, p_20635_, p_20636_.build(p_20635_));
}
}
If I switch "EntityType.MINECART" for "FastcartEntityTypeProvider.FASTCART", I get an error that complains about the invalidity of my write, because the registries seem to already been frozen: https://haste.locutusvonborg.de/ejoquraqoz.yaml
How can I register my EntityType early enough? Do I really have to use Mixin to insert my register in the static block of the EntityType class? To be honest, I'd rather like to avoid this, but I would do it if I have no other choice.
All my code is available on https://github.com/LocutusV0nB0rg/TotallyNotModded