diff options
Diffstat (limited to 'src/main/java/lance5057/tDefense/util/TDModelRegistar.java')
| -rw-r--r-- | src/main/java/lance5057/tDefense/util/TDModelRegistar.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/lance5057/tDefense/util/TDModelRegistar.java b/src/main/java/lance5057/tDefense/util/TDModelRegistar.java new file mode 100644 index 0000000..ad628b0 --- /dev/null +++ b/src/main/java/lance5057/tDefense/util/TDModelRegistar.java @@ -0,0 +1,62 @@ +package lance5057.tDefense.util; + +import javax.annotation.Nonnull; + +import lance5057.tDefense.core.tools.bases.ArmorCore; +import net.minecraft.client.renderer.ItemMeshDefinition; +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.model.ModelLoader; +import slimeknights.tconstruct.TConstruct; +import slimeknights.tconstruct.library.client.model.ToolModelLoader; +import slimeknights.tconstruct.library.tools.ToolCore; + +public class TDModelRegistar { + public static ResourceLocation registerToolModel(ArmorCore armor) { + if (armor == null || armor.getRegistryName() == null) { + return null; + } + ResourceLocation itemLocation = armor.getRegistryName(); + String path = "tools/" + itemLocation.getResourcePath() + ToolModelLoader.EXTENSION; + + ResourceLocation location = new ResourceLocation(itemLocation.getResourceDomain(), path); + TDModelLoader.addPartMapping(location, armor); + + return registerToolModel(armor, location); + } + + /** + * Manual registration of a tool model. You probably shouldn't be using this. + */ + public static ResourceLocation registerToolModel(Item item, final ResourceLocation location) { + if (!location.getResourcePath().endsWith(ToolModelLoader.EXTENSION)) { + TConstruct.log.error("The material-model " + location.toString() + " does not end with '" + + ToolModelLoader.EXTENSION + "' and will therefore not be loaded by the custom model loader!"); + } + + return registerIt(item, location); + } + + private static ResourceLocation registerIt(Item item, final ResourceLocation location) { + // plop it in. + // This here is needed for the model to be found ingame when the game looks for + // a model to render an Itemstack + // we use an ItemMeshDefinition because it allows us to do it no matter what + // metadata we use + ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() { + @Nonnull + @Override + public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) { + return new ModelResourceLocation(location, "inventory"); + } + }); + + // We have to readd the default variant if we have custom variants, since it + // wont be added otherwise and therefore not loaded + ModelLoader.registerItemVariants(item, location); + + return location; + } +} |
