<commit_before>package gigaherz.elementsofpower.client;

import com.google.common.base.Charsets;
import gigaherz.elementsofpower.CommonProxy;
import gigaherz.elementsofpower.ElementsOfPower;
import gigaherz.elementsofpower.models.CustomMeshModel;
import gigaherz.elementsofpower.models.IModelRegistrationHelper;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ItemTransformVec3f;
import net.minecraft.client.renderer.block.model.ModelBlock;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.IRegistry;
import net.minecraft.util.ResourceLocation;

import javax.vecmath.Vector3f;
import java.io.*;
import java.util.Hashtable;
import java.util.Map;

public class ClientProxy extends CommonProxy {

    @Override
    public void registerCustomBakedModels(IModelRegistrationHelper registrationHelper) {
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 0, "wand_lapis");
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 1, "wand_emerald");
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 2, "wand_diamond");
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 3, "wand_creative");
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 4, "staff_lapis");
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 5, "staff_emerald");
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 6, "staff_diamond");
        registerCustomModel(registrationHelper, ElementsOfPower.magicWand, 7, "staff_creative");
    }

    private ResourceLocation getModelLocation(ResourceLocation loc)
    {
        return new ResourceLocation(loc.getResourceDomain(), "models/" + loc.getResourcePath() + ".json");
    }

    private ModelBlock loadModelResource(Map<ResourceLocation, ModelBlock> map, final ResourceLocation loc)
    {
        Reader reader = null;
        ModelBlock modelblock = map.get(loc);

        if(modelblock != null)
            return modelblock;

        if(loc.getResourcePath().startsWith("builtin/"))
            return null;

        try
        {
            IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(getModelLocation(loc));
            if(iresource != null) {
                reader = new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8);

                modelblock = ModelBlock.deserialize(reader);
                modelblock.name = loc.toString();
                map.put(loc, modelblock);

                ResourceLocation parentLoc = modelblock.getParentLocation();
                if(parentLoc != null) {

                    ModelBlock parentModel = loadModelResource(map, parentLoc);
                    if(parentModel != null) {
                        modelblock.getParentFromMap(map);
                    }
                }
            }
        }
        catch(IOException e) {
            e.printStackTrace();
        }

        return modelblock;
    }
    private ModelBlock loadModelResource(final ResourceLocation loc)
    {
        return loadModelResource(new Hashtable<ResourceLocation, ModelBlock>(), loc);
    }

    private void registerCustomModel(IModelRegistrationHelper registrationHelper, final Item item, int meta, final String itemName) {

        ItemCameraTransforms transforms = ItemCameraTransforms.DEFAULT;

        ResourceLocation icon = new ResourceLocation(ElementsOfPower.MODID, "item/" + itemName);
        ModelBlock modelblock = loadModelResource(icon);
        if(modelblock != null) {
            transforms = new ItemCameraTransforms(
                    modelblock.getThirdPersonTransform(),
                    modelblock.getFirstPersonTransform(),
                    modelblock.getHeadTransform(),
                    modelblock.getInGuiTransform());
        }

        ResourceLocation loc = new ModelResourceLocation(ElementsOfPower.MODID + ":" + itemName, "inventory");
        registrationHelper.registerCustomModel(loc,
                new CustomMeshModel(itemName, transforms, loc, registrationHelper.getModelManager()));
        ModelBakery.addVariantName(item, ElementsOfPower.MODID + ":" + itemName);
    }

    @Override
    public void registerRenderers() {
        registerBlockTexture(ElementsOfPower.essentializer, "essentializer");
        registerItemTexture(ElementsOfPower.magicOrb, 0, "orb_fire");
        registerItemTexture(ElementsOfPower.magicOrb, 1, "orb_water");
        registerItemTexture(ElementsOfPower.magicOrb, 2, "orb_air");
        registerItemTexture(ElementsOfPower.magicOrb, 3, "orb_earth");<commit_msg>Ability to register block models with custom renderer.<commit_after>package gigaherz.elementsofpower.client;

import com.google.common.base.Charsets;
import gigaherz.elementsofpower.CommonProxy;
import gigaherz.elementsofpower.ElementsOfPower;
import gigaherz.elementsofpower.models.CustomMeshModel;
import gigaherz.elementsofpower.models.IModelRegistrationHelper;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.block.model.ModelBlock;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Hashtable;
import java.util.Map;

public class ClientProxy extends CommonProxy {

    @Override
    public void registerCustomBakedModels(IModelRegistrationHelper registrationHelper) {
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 0, "wand_lapis");
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 1, "wand_emerald");
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 2, "wand_diamond");
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 3, "wand_creative");
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 4, "staff_lapis");
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 5, "staff_emerald");
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 6, "staff_diamond");
        registerCustomItemModel(registrationHelper, ElementsOfPower.magicWand, 7, "staff_creative");
        //registerCustomBlockModel(registrationHelper, "essentializer", "normal");
        //registerCustomBlockModel(registrationHelper, "essentializer", "inventory");
    }

    private ResourceLocation getModelLocation(ResourceLocation loc) {
        return new ResourceLocation(loc.getResourceDomain(), "models/" + loc.getResourcePath() + ".json");
    }

    private ModelBlock loadModelResource(Map<ResourceLocation, ModelBlock> map, final ResourceLocation loc) {
        Reader reader = null;
        ModelBlock modelblock = map.get(loc);

        if (modelblock != null)
            return modelblock;

        if (loc.getResourcePath().startsWith("builtin/"))
            return null;

        try {
            IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(getModelLocation(loc));
            if (iresource != null) {
                reader = new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8);

                modelblock = ModelBlock.deserialize(reader);
                modelblock.name = loc.toString();
                map.put(loc, modelblock);

                ResourceLocation parentLoc = modelblock.getParentLocation();
                if (parentLoc != null) {

                    ModelBlock parentModel = loadModelResource(map, parentLoc);
                    if (parentModel != null) {
                        modelblock.getParentFromMap(map);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return modelblock;
    }

    private ModelBlock loadModelResource(final ResourceLocation loc) {
        return loadModelResource(new Hashtable<ResourceLocation, ModelBlock>(), loc);
    }

    private void registerCustomItemModel(IModelRegistrationHelper registrationHelper, final Item item, int meta, final String itemName) {

        ItemCameraTransforms transforms = ItemCameraTransforms.DEFAULT;

        ResourceLocation icon = new ResourceLocation(ElementsOfPower.MODID, "item/" + itemName);
        ModelBlock modelblock = loadModelResource(icon);
        if (modelblock != null) {
            transforms = new ItemCameraTransforms(
                    modelblock.getThirdPersonTransform(),
                    modelblock.getFirstPersonTransform(),
                    modelblock.getHeadTransform(),
                    modelblock.getInGuiTransform());
        }

        ResourceLocation loc = new ModelResourceLocation(ElementsOfPower.MODID + ":" + itemName, "inventory");
        registrationHelper.registerCustomModel(loc,
                new CustomMeshModel(itemName, transforms, loc, registrationHelper.getModelManager()));
        ModelBakery.addVariantName(item, ElementsOfPower.MODID + ":" + itemName);
    }

    private void registerCustomBlockModel(IModelRegistrationHelper registrationHelper, final String itemName, final String stateName) {

        ItemCameraTransforms transforms = ItemCameraTransforms.DEFAULT;

        ResourceLocation icon = new ResourceLocation(ElementsOfPower.MODID, "block/" + itemName);
        ModelBlock modelblock = loadModelResource(icon);
        if (modelblock != null) {
            transforms = new ItemCameraTransforms(
                    modelblock.getThirdPersonTransform(),
                    modelblock.getFirstPersonTransform(),
                    modelblock.getHeadTransform(),
                    modelblock.getInGuiTransform());
        }

        ResourceLocation loc = new ModelResourceLocation(ElementsOfPower.MODID + ":" + itemName, stateName);
        registrationHelper.registerCustomModel(loc,
                new CustomMeshModel(itemName, transforms, loc, registrationHelper.getModelManager()));
    }

    @Override
    public void registerRenderers() {
        registerBlockTexture(ElementsOfPower.essentializer, "essentializer");
        registerItemTexture(ElementsOfPower.magicOrb, 0, "orb_fire");
        registerItemTexture(ElementsOfPower.magicOrb, 1, "orb_water");
        registerItemTexture(ElementsOfPower.magicOrb, 2, "orb_air");
        registerItemTexture(ElementsOfPower.magicOrb, 3, "orb_earth");
{'fraction_non_alphanumeric': 0.09025238562382948, 'fraction_numerical': 0.0024971015785249266, 'mean_word_length': 3.4820143884892087, 'pattern_counts': {'":': 5, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6035383', 'n_tokens_mistral': 2964, 'n_tokens_neox': 2828, 'n_words': 517}