Skip to content

Instantly share code, notes, and snippets.

@Cadiboo
Last active February 5, 2020 14:57
Show Gist options
  • Save Cadiboo/3f5cdb785affc069af2fa5fdf2d70358 to your computer and use it in GitHub Desktop.
Save Cadiboo/3f5cdb785affc069af2fa5fdf2d70358 to your computer and use it in GitHub Desktop.
[1.12.2] A simple ClientEventSubscriber that automatically registers all your item models for you
package io.github.cadiboo.examplemod.client;
import com.google.common.base.Preconditions;
import io.github.cadiboo.examplemod.util.ModReference;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nonnull;
import static net.minecraftforge.fml.relauncher.Side.CLIENT;
/**
* Subscribe to events that should be handled on the PHYSICAL CLIENT in this class
*
* @author Cadiboo
*/
@Mod.EventBusSubscriber(modid = ModReference.MOD_ID, value = CLIENT)
public final class ClientEventSubscriber {
private static final Logger LOGGER = LogManager.getLogger();
/**
* This method will be called by Forge when it is time for the mod to register its models.
* This method will always be called after the block and item registry methods.
*/
@SubscribeEvent
public static void onRegisterModelsEvent(@Nonnull final ModelRegistryEvent event) {
registerTileEntitySpecialRenderers();
LOGGER.debug("Registered tile entity special renderers");
registerEntityRenderers();
LOGGER.debug("Registered entity renderers");
for (final Item item : ForgeRegistries.ITEMS.getValues()) {
if (item.getRegistryName().getNamespace().equals(ModReference.MOD_ID)) {
ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(item.getRegistryName(), "normal"));
}
}
LOGGER.debug("Registered models");
}
/**
* Helper method to register all TESRs in
*/
private static void registerTileEntitySpecialRenderers() {
// ClientRegistry.bindTileEntitySpecialRenderer(TileEntityExampleTileEntity.class, new RenderExampleTileEntity());
}
/**
* Helper method to register all Entity Renderers in
*/
private static void registerEntityRenderers() {
// RenderingRegistry.registerEntityRenderingHandler(Entity___.class, Entity___Renderer::new);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment