Search in sources :

Example 1 with EnumPartPosition

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

the class ToolPartGem method getModel.

@Override
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos, int frame) {
    String name = ((IRegistryObject) tool.getItem()).getName();
    name = SilentGems.RESOURCE_PREFIX + name + "/" + name;
    String gemNum = tool.getItem() instanceof ItemGemBow ? "" : "" + gem.ordinal();
    String frameNum = frame == 3 ? "_3" : "";
    switch(pos) {
        case HEAD_LEFT:
            name += gemNum + "l" + frameNum;
            break;
        case HEAD_MIDDLE:
            name += gemNum + frameNum;
            break;
        case HEAD_RIGHT:
            name += gemNum + "r" + frameNum;
            break;
        case ROD_DECO:
            name += "deco" + gemNum;
            break;
        default:
            return null;
    }
    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) ItemGemBow(net.silentchaos512.gems.item.tool.ItemGemBow) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 2 with EnumPartPosition

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

the class ToolPartWool method getModel.

@Override
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos, int frame) {
    if (tool.getItem() instanceof ItemGemBow)
        return null;
    String name = ((IRegistryObject) tool.getItem()).getName();
    name = SilentGems.RESOURCE_PREFIX + name + "/" + name + "Wool" + color.getMetadata();
    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) ItemGemBow(net.silentchaos512.gems.item.tool.ItemGemBow) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 3 with EnumPartPosition

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

the class ToolRenderHelper method getModel.

/**
 * Gets the model for the specified tool and position. Gets the animation frame on its own. Stores model index in tool
 * NBT for fast acess.
 */
public ModelResourceLocation getModel(ItemStack tool, EnumPartPosition pos) {
    if (tool == null || !tool.hasTagCompound()) {
        return modelError;
    }
    NBTTagCompound tags = tool.getTagCompound().getCompoundTag(NBT_MODEL_INDEX);
    int frame = getAnimationFrame(tool);
    String key = "Layer" + pos.ordinal() + (frame > 0 ? "_" + frame : "");
    boolean isBow = tool.getItem() instanceof ItemGemBow;
    if (!tags.hasKey(key)) {
        // Bow "arrow" models
        if (pos == EnumPartPosition.ROD_GRIP && isBow) {
            return getArrowModel(tool, frame);
        }
        // Get the render part for this position.
        ToolPart part = ToolHelper.getRenderPart(tool, pos);
        if (part == null) {
            tags.setInteger(key, -1);
            tool.getTagCompound().setTag(NBT_MODEL_INDEX, tags);
            return null;
        }
        // Get the desired model for the current position and animation frame.
        ModelResourceLocation target = part.getModel(tool, pos, frame);
        // Find the model in the list. Store the index in NBT for fast access.
        for (int i = 0; i < models.length; ++i) {
            if (models[i].equals(target)) {
                tags.setInteger(key, i);
                tool.getTagCompound().setTag(NBT_MODEL_INDEX, tags);
                return target;
            }
        }
        return modelError;
    }
    // Grab the indexed model.
    return getModel(tags.getInteger(key));
}
Also used : ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) ItemGemBow(net.silentchaos512.gems.item.tool.ItemGemBow) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation)

Example 4 with EnumPartPosition

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

the class ToolRenderHelper method buildModelSet.

/**
 * Creates the list of all possible models.
 */
protected void buildModelSet() {
    if (modelSet != null) {
        return;
    }
    Set<ModelResourceLocation> set = Sets.newConcurrentHashSet();
    for (ToolPart part : ToolPartRegistry.getValues()) {
        for (EnumPartPosition pos : EnumPartPosition.values()) {
            for (Item itemTool : ModItems.tools) {
                for (int frame = 0; frame < (itemTool instanceof ItemGemBow ? 4 : 1); ++frame) {
                    ModelResourceLocation model = part.getModel(new ItemStack(itemTool), pos, frame);
                    if (model != null) {
                        set.add(model);
                    }
                }
            }
        }
    }
    // Bow "arrow" models
    arrowModels = new ModelResourceLocation[8];
    for (int i = 0; i < 8; ++i) {
        String tier = i < 4 ? "regular" : "super";
        ModelResourceLocation model = new ModelResourceLocation(SilentGems.RESOURCE_PREFIX + "bow/bowarrow" + tier + (i & 3));
        if (model != null)
            set.add(model);
        arrowModels[i] = model;
    }
    modelSet = set;
    models = set.toArray(new ModelResourceLocation[set.size()]);
}
Also used : Item(net.minecraft.item.Item) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumPartPosition(net.silentchaos512.gems.api.lib.EnumPartPosition) ItemGemBow(net.silentchaos512.gems.item.tool.ItemGemBow) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Example 5 with EnumPartPosition

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

the class ToolRenderHelper method addInformation.

@Override
public void addInformation(ItemStack tool, EntityPlayer player, List list, boolean advanced) {
    LocalizationHelper loc = SilentGems.instance.localizationHelper;
    boolean controlDown = KeyTracker.isControlDown();
    boolean altDown = KeyTracker.isAltDown();
    boolean shiftDown = KeyTracker.isShiftDown();
    String line;
    // Tipped upgrade
    ToolPartTip partTip = (ToolPartTip) ToolHelper.getConstructionTip(tool);
    if (partTip != null) {
        String tipName = partTip.getUnlocalizedName().replaceFirst("[^:]+:", "");
        tipName = loc.getMiscText("Tooltip." + tipName);
        line = loc.getMiscText("Tooltip.Tipped", tipName);
        list.add(line);
    }
    // Show original owner?
    if (controlDown) {
        String owner = ToolHelper.getOriginalOwner(tool);
        if (owner.equals(SilentGems.localizationHelper.getMiscText("Tooltip.OriginalOwner.Creative")))
            owner = TextFormatting.LIGHT_PURPLE + owner;
        if (!owner.isEmpty())
            list.add(loc.getMiscText("Tooltip.OriginalOwner", owner));
        else
            list.add(loc.getMiscText("Tooltip.OriginalOwner.Unknown"));
    }
    // Missing data?
    if (ToolHelper.hasNoConstruction(tool)) {
        list.add(loc.getMiscText("Tooltip.NoData1"));
        list.add(loc.getMiscText("Tooltip.NoData2"));
    } else // Broken?
    if (ToolHelper.isBroken(tool)) {
        line = loc.getMiscText("Tooltip.Broken");
        list.add(line);
    }
    final Item item = tool.getItem();
    final boolean isSword = item instanceof ItemGemSword;
    final boolean isAxe = item instanceof ItemGemAxe;
    final boolean isWeapon = isSword || isAxe;
    final boolean isCaster = isSword && ToolHelper.getToolTier(tool).ordinal() >= EnumMaterialTier.SUPER.ordinal();
    final boolean isBow = item instanceof ItemGemBow;
    final boolean isDigger = item instanceof ItemTool;
    final boolean isShield = item instanceof ItemGemShield;
    final String sep = loc.getMiscText("Tooltip.Separator");
    if (controlDown) {
        // Properties Header
        line = loc.getMiscText("Tooltip.Properties");
        list.add(line);
        TextFormatting color = TextFormatting.YELLOW;
        // Tier
        EnumMaterialTier tier = ToolHelper.getToolTier(tool);
        line = TextFormatting.RESET + loc.getMiscText("ToolTier." + tier);
        list.add("  " + color + loc.getMiscText("ToolTier", line));
        int durabilityMax = ToolHelper.getMaxDamage(tool);
        int durability = durabilityMax - tool.getItemDamage();
        String s1 = String.format(durability > 9999 ? "%,d" : "%d", durability);
        String s2 = String.format(durabilityMax > 9999 ? "%,d" : "%d", durabilityMax);
        line = loc.getMiscText("Tooltip.Durability", s1 + " / " + s2);
        list.add(color + "  " + line);
        if (isShield)
            list.add(color + getTooltipLine("BlockingPower", ToolHelper.getBlockingPower(tool)));
        if (isDigger) {
            // @formatter:off
            int harvestLevel = ToolHelper.getHarvestLevel(tool);
            String str = color + getTooltipLine("HarvestLevel", harvestLevel);
            String key = "Tooltip.level" + harvestLevel;
            String val = SilentGems.localizationHelper.getMiscText(key);
            if (!val.equals("misc.silentgems:" + key))
                str += " (" + val + ")";
            list.add(str);
            list.add(color + getTooltipLine("HarvestSpeed", ToolHelper.getDigSpeedOnProperMaterial(tool)));
        }
        if (isWeapon) {
            list.add(color + getTooltipLine("MeleeSpeed", ToolHelper.getMeleeSpeedModifier(tool) + 4).replaceFirst("%", ""));
            list.add(color + getTooltipLine("MeleeDamage", ToolHelper.getMeleeDamageModifier(tool)));
            if (isCaster)
                list.add(color + getTooltipLine("MagicDamage", ToolHelper.getMagicDamageModifier(tool)));
        }
        if (isBow) {
            list.add(color + getTooltipLine("DrawDelay", ModItems.bow.getDrawDelay(tool)));
            list.add(color + getTooltipLine("ArrowDamage", 2f + ModItems.bow.getArrowDamage(tool)));
        }
        list.add(color + getTooltipLine("ChargeSpeed", ToolHelper.getChargeSpeed(tool)));
    } else {
        list.add(TextFormatting.GOLD + loc.getMiscText("Tooltip.CtrlForProp"));
    }
    if (altDown) {
        // Statistics Header
        list.add(sep);
        line = loc.getMiscText("Tooltip.Statistics");
        list.add(line);
        list.add(getTooltipLine("BlocksMined", ToolHelper.getStatBlocksMined(tool)));
        if (isDigger) {
            list.add(getTooltipLine("BlocksPlaced", ToolHelper.getStatBlocksPlaced(tool)));
        }
        if (item instanceof ItemGemShovel) {
            list.add(getTooltipLine("PathsMade", ToolHelper.getStatPathsMade(tool)));
        }
        if (item instanceof ItemGemHoe) {
            list.add(getTooltipLine("BlocksTilled", ToolHelper.getStatBlocksTilled(tool)));
        }
        list.add(getTooltipLine("HitsLanded", ToolHelper.getStatHitsLanded(tool)));
        if (isCaster || isBow)
            list.add(getTooltipLine("ShotsFired", ToolHelper.getStatShotsFired(tool)));
        if (item instanceof ItemGemTomahawk)
            list.add(getTooltipLine("ThrownCount", ToolHelper.getStatThrownCount(tool)));
        if (isWeapon)
            list.add(getTooltipLine("KillCount", ToolHelper.getStatKillCount(tool)));
        list.add(getTooltipLine("Redecorated", ToolHelper.getStatRedecorated(tool)));
        list.add(sep);
        line = loc.getMiscText("Tooltip.Construction");
        list.add(line);
        ToolPart[] parts = ToolHelper.getConstructionParts(tool);
        EnumMaterialGrade[] grades = ToolHelper.getConstructionGrades(tool);
        for (int i = 0; i < parts.length; ++i) {
            ToolPart part = parts[i];
            EnumMaterialGrade grade = grades[i];
            line = "  " + TextFormatting.YELLOW + part.getKey() + TextFormatting.GOLD + " (" + grade + ")";
            list.add(line);
        }
        list.add(sep);
    } else {
        list.add(TextFormatting.GOLD + loc.getMiscText("Tooltip.AltForStat"));
    }
    // Debug render layers
    if (controlDown && shiftDown && tool.hasTagCompound()) {
        if (!altDown)
            list.add(sep);
        for (EnumPartPosition pos : EnumPartPosition.values()) {
            NBTTagCompound tags = tool.getTagCompound().getCompoundTag(NBT_MODEL_INDEX);
            if (tags != null) {
                String key = "Layer" + pos.ordinal();
                String str = "%s: %d, %X";
                str = String.format(str, key, tags.getInteger(key), tags.getInteger(key + "Color"));
                list.add(str);
            }
        }
    }
}
Also used : ItemTool(net.minecraft.item.ItemTool) ItemGemShield(net.silentchaos512.gems.item.tool.ItemGemShield) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemGemAxe(net.silentchaos512.gems.item.tool.ItemGemAxe) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper) Item(net.minecraft.item.Item) ToolPartTip(net.silentchaos512.gems.api.tool.part.ToolPartTip) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumPartPosition(net.silentchaos512.gems.api.lib.EnumPartPosition) ItemGemBow(net.silentchaos512.gems.item.tool.ItemGemBow) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) ItemGemTomahawk(net.silentchaos512.gems.item.tool.ItemGemTomahawk) ItemGemSword(net.silentchaos512.gems.item.tool.ItemGemSword) TextFormatting(net.minecraft.util.text.TextFormatting) ItemGemHoe(net.silentchaos512.gems.item.tool.ItemGemHoe) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemGemShovel(net.silentchaos512.gems.item.tool.ItemGemShovel)

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