Search in sources :

Example 6 with EnumPartPosition

use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.

the class ToolPartRodGems method getModel.

@Override
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos, int frame) {
    String name = ((IRegistryObject) tool.getItem()).getName();
    name = SilentGems.RESOURCE_PREFIX + name.toLowerCase() + "/" + name + rodName;
    if (modelMap.containsKey(name)) {
        return modelMap.get(name);
    }
    name = name.toLowerCase();
    ModelResourceLocation model = new ModelResourceLocation(name, "inventory");
    modelMap.put(name, model);
    return model;
}
Also used : IRegistryObject(net.silentchaos512.lib.registry.IRegistryObject) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 7 with EnumPartPosition

use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.

the class ToolPartTipGems method getModel.

@Override
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos, int frame) {
    String name = ((IRegistryObject) tool.getItem()).getName();
    name = SilentGems.MODID + ":" + name.toLowerCase() + "/" + name + tipName + (frame == 3 ? "_3" : "");
    if (modelMap.containsKey(name)) {
        return modelMap.get(name);
    }
    name = name.toLowerCase();
    ModelResourceLocation model = new ModelResourceLocation(name, "inventory");
    modelMap.put(name, model);
    return model;
}
Also used : IRegistryObject(net.silentchaos512.lib.registry.IRegistryObject) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 8 with EnumPartPosition

use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.

the class ToolModel method getQuads.

@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
    LogHelper log = SilentGems.logHelper;
    if (tool == null) {
        return new ArrayList<BakedQuad>();
    }
    if (modelManager == null) {
        modelManager = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getModelManager();
    }
    List<BakedQuad> quads = Lists.newArrayList();
    ModelResourceLocation location;
    IBakedModel model;
    IBakedModel rodModel = null;
    boolean isBroken = ToolHelper.isBroken(tool);
    Item item = tool.getItem();
    // Invalid tools models.
    if (ToolHelper.getMaxDamage(tool) <= 0 && tool.getItem() instanceof IRegistryObject) {
        String name = ((IRegistryObject) tool.getItem()).getName();
        location = new ModelResourceLocation(SilentGems.MODID + ":" + name.toLowerCase() + "/_error", "inventory");
        model = modelManager.getModel(location);
        if (model != null) {
            quads.addAll(model.getQuads(state, side, rand));
        }
        return quads;
    }
    for (EnumPartPosition partPos : EnumPartPosition.values()) {
        if (isBroken) {
            if ((partPos == EnumPartPosition.HEAD_LEFT && item != ModItems.sword && item != ModItems.bow) || (partPos == EnumPartPosition.HEAD_MIDDLE && item != ModItems.bow) || (partPos == EnumPartPosition.HEAD_RIGHT && item != ModItems.bow) || partPos == EnumPartPosition.TIP) {
                continue;
            }
        }
        // Scepter rods on top of head.
        if (tool.getItem() instanceof ItemGemScepter) {
            if (partPos == EnumPartPosition.ROD) {
                location = ToolRenderHelper.getInstance().getModel(tool, partPos);
                rodModel = modelManager.getModel(location);
                continue;
            } else if (partPos == EnumPartPosition.ROD_DECO) {
                quads.addAll(rodModel.getQuads(state, side, rand));
            }
        }
        // Normal logic.
        location = ToolRenderHelper.getInstance().getModel(tool, partPos);
        if (location != null) {
            model = modelManager.getModel(location);
            if (model != null) {
                quads.addAll(model.getQuads(state, side, rand));
            }
        }
    }
    if (ModuleAprilTricks.instance.moduleEnabled && ModuleAprilTricks.instance.isRightDay()) {
        model = modelManager.getModel(ToolRenderHelper.getInstance().modelGooglyEyes);
        quads.addAll(model.getQuads(state, side, rand));
    }
    return quads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ItemGemScepter(net.silentchaos512.gems.item.tool.ItemGemScepter) Item(net.minecraft.item.Item) EnumPartPosition(net.silentchaos512.gems.api.lib.EnumPartPosition) IRegistryObject(net.silentchaos512.lib.registry.IRegistryObject) LogHelper(net.silentchaos512.lib.util.LogHelper) ArrayList(java.util.ArrayList) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel)

Example 9 with EnumPartPosition

use of net.silentchaos512.gems.api.lib.EnumPartPosition in project SilentGems by SilentChaos512.

the class ToolHelper method recalculateStats.

/**
 * Recalculate all stats and properties, including the rendering cache for the given tool. In general, this should be
 * called any time changes are made to a tool (aside from incrementing statistics, or something like that). For
 * example, this is called during construction, decoration, and for all tools in the players inventory during login.
 *
 * @param tool
 */
public static void recalculateStats(ItemStack tool) {
    ToolPart[] parts = getConstructionParts(tool);
    EnumMaterialGrade[] grades = getConstructionGrades(tool);
    if (parts.length == 0)
        return;
    ToolStats stats = new ToolStats(tool, parts, grades).calculate();
    // Reset render cache
    for (EnumPartPosition pos : EnumPartPosition.values()) {
        NBTTagCompound compound = tool.getTagCompound().getCompoundTag(ToolRenderHelper.NBT_MODEL_INDEX);
        String str = "Layer" + pos.ordinal();
        for (int frame = 0; frame < (tool.getItem() instanceof ItemGemBow ? 4 : 1); ++frame) compound.removeTag(str + (frame > 0 ? "_" + frame : ""));
        compound.removeTag(str + "Color");
    }
    // Set color for parts
    ToolPart renderHeadM = getRenderPart(tool, EnumPartPosition.HEAD_MIDDLE);
    ToolPart renderHeadL = getRenderPart(tool, EnumPartPosition.HEAD_LEFT);
    ToolPart renderHeadR = getRenderPart(tool, EnumPartPosition.HEAD_RIGHT);
    ToolPart renderRodDeco = getRenderPart(tool, EnumPartPosition.ROD_DECO);
    ToolPart renderRod = getRenderPart(tool, EnumPartPosition.ROD);
    if (renderHeadM != null)
        setTagInt(tool, ToolRenderHelper.NBT_MODEL_INDEX, "Layer" + ToolRenderHelper.PASS_HEAD_M + "Color", renderHeadM.getColor(tool));
    if (renderHeadL != null)
        setTagInt(tool, ToolRenderHelper.NBT_MODEL_INDEX, "Layer" + ToolRenderHelper.PASS_HEAD_L + "Color", renderHeadL.getColor(tool));
    if (renderHeadR != null)
        setTagInt(tool, ToolRenderHelper.NBT_MODEL_INDEX, "Layer" + ToolRenderHelper.PASS_HEAD_R + "Color", renderHeadR.getColor(tool));
    if (renderRodDeco != null)
        setTagInt(tool, ToolRenderHelper.NBT_MODEL_INDEX, "Layer" + ToolRenderHelper.PASS_ROD_DECO + "Color", renderRodDeco.getColor(tool));
    if (renderRod != null)
        setTagInt(tool, ToolRenderHelper.NBT_MODEL_INDEX, "Layer" + ToolRenderHelper.PASS_ROD + "Color", renderRod.getColor(tool));
    setTagInt(tool, NBT_ROOT_PROPERTIES, NBT_PROP_DURABILITY, (int) stats.durability);
    setTagFloat(tool, NBT_ROOT_PROPERTIES, NBT_PROP_HARVEST_SPEED, stats.harvestSpeed);
    setTagFloat(tool, NBT_ROOT_PROPERTIES, NBT_PROP_MELEE_DAMAGE, stats.meleeDamage);
    setTagFloat(tool, NBT_ROOT_PROPERTIES, NBT_PROP_MAGIC_DAMAGE, stats.magicDamage);
    setTagFloat(tool, NBT_ROOT_PROPERTIES, NBT_PROP_MELEE_SPEED, stats.meleeSpeed);
    setTagFloat(tool, NBT_ROOT_PROPERTIES, NBT_PROP_CHARGE_SPEED, stats.chargeSpeed);
    setTagFloat(tool, NBT_ROOT_PROPERTIES, NBT_PROP_BLOCKING_POWER, stats.blockingPower);
    setTagInt(tool, NBT_ROOT_PROPERTIES, NBT_PROP_ENCHANTABILITY, (int) stats.enchantability);
    setTagInt(tool, NBT_ROOT_PROPERTIES, NBT_PROP_HARVEST_LEVEL, stats.harvestLevel);
    setTagInt(tool, NBT_ROOT_PROPERTIES, NBT_TOOL_TIER, parts[0].getTier().ordinal());
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumPartPosition(net.silentchaos512.gems.api.lib.EnumPartPosition) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) ItemGemBow(net.silentchaos512.gems.item.tool.ItemGemBow) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ToolStats(net.silentchaos512.gems.api.tool.ToolStats)

Aggregations

ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)7 ItemGemBow (net.silentchaos512.gems.item.tool.ItemGemBow)6 IRegistryObject (net.silentchaos512.lib.registry.IRegistryObject)5 EnumPartPosition (net.silentchaos512.gems.api.lib.EnumPartPosition)4 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)4 Item (net.minecraft.item.Item)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)2 ArrayList (java.util.ArrayList)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 ItemStack (net.minecraft.item.ItemStack)1 ItemTool (net.minecraft.item.ItemTool)1 TextFormatting (net.minecraft.util.text.TextFormatting)1 EnumMaterialTier (net.silentchaos512.gems.api.lib.EnumMaterialTier)1 ToolStats (net.silentchaos512.gems.api.tool.ToolStats)1 ToolPartTip (net.silentchaos512.gems.api.tool.part.ToolPartTip)1 ItemGemAxe (net.silentchaos512.gems.item.tool.ItemGemAxe)1 ItemGemHoe (net.silentchaos512.gems.item.tool.ItemGemHoe)1 ItemGemScepter (net.silentchaos512.gems.item.tool.ItemGemScepter)1