Search in sources :

Example 11 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class ItemToolSoul method clAddInformation.

@Override
public void clAddInformation(ItemStack stack, World world, List<String> list, boolean advanced) {
    super.clAddInformation(stack, world, list, advanced);
    ToolSoul soul = getSoul(stack);
    if (soul != null) {
        soul.addInformation(stack, world, list, advanced);
    }
}
Also used : ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul)

Example 12 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class ItemGemArmor method clAddInformation.

@Override
public void clAddInformation(ItemStack stack, World world, List<String> list, boolean advanced) {
    LocalizationHelper loc = SilentGems.localizationHelper;
    ToolRenderHelper helper = ToolRenderHelper.getInstance();
    boolean controlDown = KeyTracker.isControlDown();
    boolean shiftDown = KeyTracker.isShiftDown();
    boolean altDown = KeyTracker.isAltDown();
    String line;
    // UUID
    if (GemsConfig.DEBUG_MODE && controlDown && shiftDown) {
        UUID uuid = ToolHelper.hasUUID(stack) ? ToolHelper.getUUID(stack) : null;
        list.add(uuid == null ? "No UUID" : uuid.toString());
        uuid = ToolHelper.getSoulUUID(stack);
        list.add(uuid == null ? "No Soul UUID" : uuid.toString());
    }
    // Tool Soul
    ToolSoul soul = SoulManager.getSoul(stack);
    if (soul != null) {
        soul.addInformation(stack, world, list, advanced);
    }
    // Show original owner?
    if (controlDown) {
        String owner = ArmorHelper.getOriginalOwner(stack);
        if (!owner.isEmpty()) {
            list.add(loc.getMiscText("Tooltip.OriginalOwner", owner));
        } else {
            list.add(loc.getMiscText("Tooltip.OriginalOwner.Unknown"));
        }
    }
    // TODO: Remove me
    if (altDown) {
        list.add(TextFormatting.RED + "Armor models WIP.");
    }
    // Broken?
    if (ArmorHelper.isBroken(stack)) {
        list.add(loc.getMiscText("Tooltip.Broken"));
    }
    final String sep = loc.getMiscText("Tooltip.Separator");
    if (controlDown) {
        // Properties header
        list.add(loc.getMiscText("Tooltip.Properties"));
        TextFormatting color = TextFormatting.YELLOW;
        float durabilityBoost = ToolSoul.getDurabilityModifierForDisplay(soul);
        list.add(color + helper.getTooltipLine("Durability", getMaxDamage(stack), durabilityBoost));
        float protectionBoost = ToolSoul.getProtectionModifierForDisplay(soul);
        list.add(color + helper.getTooltipLine("Protection", getProtection(stack), protectionBoost));
        // Statistics Header
        list.add(sep);
        list.add(loc.getMiscText("Tooltip.Statistics"));
        list.add(helper.getTooltipLine("DamageTaken", ArmorHelper.getStatDamageTaken(stack), 0f));
        list.add(helper.getTooltipLine("Redecorated", ArmorHelper.getStatRedecorated(stack), 0f));
        list.add(sep);
    } else {
        list.add(TextFormatting.GOLD + loc.getMiscText("PressCtrl"));
    }
    if (altDown) {
        list.add(loc.getMiscText("Tooltip.Construction"));
        ToolPart[] parts = ArmorHelper.getConstructionParts(stack);
        EnumMaterialGrade[] grades = ArmorHelper.getConstructionGrades(stack);
        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);
        }
        ToolPart partFrame = ArmorHelper.getPart(stack, ArmorPartPosition.FRAME);
        if (partFrame != null)
            list.add("  " + TextFormatting.YELLOW + partFrame.getKey());
        list.add(sep);
    } else {
        list.add(TextFormatting.GOLD + loc.getMiscText("PressAlt"));
    }
}
Also used : ToolRenderHelper(net.silentchaos512.gems.item.ToolRenderHelper) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) EnumMaterialGrade(net.silentchaos512.gems.api.lib.EnumMaterialGrade) TextFormatting(net.minecraft.util.text.TextFormatting) UUID(java.util.UUID)

Example 13 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class ColorHandlers method init.

public static void init() {
    ItemColors itemColors = Minecraft.getMinecraft().getItemColors();
    // Tools
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return ToolRenderHelper.getInstance().getColor(stack, ToolPartPosition.forRenderPass(tintIndex));
        }
    }, ModItems.tools.toArray(new Item[ModItems.tools.size()]));
    // Shields
    itemColors.registerItemColorHandler(new IItemColor() {

        int[] passes = { ToolRenderHelper.PASS_HEAD, ToolRenderHelper.PASS_ROD };

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex < 0 || tintIndex >= passes.length)
                return 0xFFFFFF;
            return ToolRenderHelper.getInstance().getColor(stack, ToolPartPosition.forRenderPass(tintIndex));
        }
    }, ModItems.shield);
    // Armor (temp)
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            // FIXME: Multiple passes needed?
            return ArmorHelper.getRenderColor(stack, ArmorPartPosition.NORTH);
        }
    }, ModItems.gemHelmet, ModItems.gemChestplate, ModItems.gemLeggings, ModItems.gemBoots);
    // Enchantment Tokens
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex == 1)
                return ModItems.enchantmentToken.getOutlineColor(stack);
            return 0xFFFFFF;
        }
    }, ModItems.enchantmentToken);
    // Return Home Charm
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex == 0) {
                int meta = stack.getItemDamage();
                if (meta >= 0 && meta < EnumGem.values().length) {
                    EnumGem gem = EnumGem.values()[meta];
                    return gem.color;
                }
            }
            return 0xFFFFFF;
        }
    }, ModItems.returnHomeCharm);
    // Node Mover
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return tintIndex != 1 ? 0xFFFFFF : ClientTickHandler.nodeMoverColor.getColor();
        }
    }, ModItems.nodeMover);
    // Drawing Compass
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            return tintIndex == 0 ? ModItems.drawingCompass.getColor(stack).getColor() : 0xFFFFFF;
        }
    }, ModItems.drawingCompass);
    // Chaos Runes
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex == 1) {
                ChaosBuff buff = ModItems.chaosRune.getBuff(stack);
                if (buff != null) {
                    return buff.getColor();
                }
            }
            return 0xFFFFFF;
        }
    }, ModItems.chaosRune);
    // Holding Gem
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            if (tintIndex == 1) {
                if (stack.hasTagCompound()) {
                    int id = stack.getTagCompound().getShort(ItemHoldingGem.NBT_GEM_ID);
                    if (id >= 0 && id < EnumGem.values().length)
                        return EnumGem.values()[id].color;
                }
            } else if (tintIndex == 2) {
                IBlockState state = ModItems.holdingGem.getBlockPlaced(stack);
                if (state != null) {
                    return 0xFFFFFF;
                // return state.getMapColor().colorValue;
                }
            }
            return 0xFFFFFF;
        }
    }, ModItems.holdingGem);
    // Soul Gems
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            Soul soul = ModItems.soulGem.getSoul(stack);
            if (soul == null) {
                return 0xFFFFFF;
            } else if (tintIndex == 1) {
                return soul.colorSecondary;
            } else {
                return soul.colorPrimary;
            }
        }
    }, ModItems.soulGem);
    // Tool Soul
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            // TODO Auto-generated method stub
            ToolSoul soul = ModItems.toolSoul.getSoul(stack);
            if (soul == null)
                return tintIndex == 1 ? 0xFF00FF : tintIndex == 2 ? 0x0 : 0xFFFFFF;
            switch(tintIndex) {
                case 0:
                    float ratio = 0.5f + MathHelper.sin((float) ClientTickHandler.ticksInGame / 15) / 6;
                    return Color.blend(soul.getPrimaryElement().color, soul.getSecondaryElement().color, ratio);
                case 1:
                    return soul.getPrimaryElement().color;
                case 2:
                    return soul.getSecondaryElement().color;
                default:
                    return 0xFFFFFF;
            }
        }
    }, ModItems.toolSoul);
    // Arrows
    itemColors.registerItemColorHandler(new IItemColor() {

        @Override
        public int getColorFromItemstack(ItemStack stack, int tintIndex) {
            // TODO Auto-generated method stub
            return 0xFFFFFF;
        }
    }, ModItems.arrow);
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) Item(net.minecraft.item.Item) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) IBlockState(net.minecraft.block.state.IBlockState) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) Soul(net.silentchaos512.gems.item.ItemSoulGem.Soul) ItemColors(net.minecraft.client.renderer.color.ItemColors) ItemStack(net.minecraft.item.ItemStack)

Example 14 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class SoulSkill method selectSkillToLearn.

public static SoulSkill selectSkillToLearn(ToolSoul soul, ItemStack tool) {
    // if (soul.getLevel() == 5) {
    // return SUPER_SKILL;
    // }
    Map<SoulSkill, Double> candidates = new LinkedHashMap<>();
    // Create list of candidates
    for (SoulSkill skill : SKILL_LIST.values()) {
        if (skill.canLearn(soul, tool)) {
            boolean favorsElement = false;
            // Select a weight based on favored elements.
            double weight = skill.favoredElements.length < 1 ? 20 : 7;
            for (EnumSoulElement elem : skill.favoredElements) {
                if (elem == soul.getPrimaryElement()) {
                    weight = 20;
                    favorsElement = true;
                    break;
                } else if (elem == soul.getSecondaryElement()) {
                    weight = 15;
                    favorsElement = true;
                    break;
                }
            }
            // Favors certain tool types?
            if (skill.favoredType != EnumToolType.NONE) {
                EnumToolType toolType = tool.getItem() instanceof ITool ? ((ITool) tool.getItem()).getToolType() : tool.getItem() instanceof IArmor ? ((IArmor) tool.getItem()).getToolType() : EnumToolType.NONE;
                if (toolType == skill.favoredType) {
                    weight += 5;
                }
            }
            // If skill has a median level, apply that to the weight.
            if (skill.medianXpLevel > 0) {
                int diff = Math.abs(soul.level - skill.medianXpLevel);
                if (diff > 6) {
                    diff = 6;
                }
                weight -= 0.75 * diff;
            }
            // If a lower level of the skill is already known, reduce the weight.
            if (soul.skills.containsKey(skill)) {
                weight -= 2.5 * soul.skills.get(skill);
            }
            // Base weight diff, favors multiplier
            weight += skill.weightDiff;
            if (favorsElement) {
                weight *= skill.favorWeightMulti;
            }
            // Make sure weight is at least 1.
            if (weight < 1) {
                weight = 1;
            }
            candidates.put(skill, weight);
        }
    }
    // Seed based on soul elements, level, and tool UUID.
    Random rand = new Random(soul.getPrimaryElement().ordinal() + (soul.getSecondaryElement().ordinal() << 4) + (soul.getLevel() << 8) + (ToolHelper.getUUID(tool).getLeastSignificantBits() << 16));
    // Weighted random selection.
    SoulSkill selected = null;
    double bestValue = Double.MIN_VALUE;
    for (SoulSkill skill : candidates.keySet()) {
        double value = -Math.log(rand.nextFloat() / candidates.get(skill));
        SilentGems.logHelper.debug(skill.id, candidates.get(skill), value, bestValue);
        if (value > bestValue) {
            bestValue = value;
            selected = skill;
        }
    }
    return selected;
}
Also used : Random(java.util.Random) EnumToolType(net.silentchaos512.gems.lib.EnumToolType) EnumSoulElement(net.silentchaos512.gems.lib.soul.EnumSoulElement) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with ToolSoul

use of net.silentchaos512.gems.lib.soul.ToolSoul in project SilentGems by SilentChaos512.

the class ToolSoul method randomSoul.

public static ToolSoul randomSoul() {
    ToolSoul soul = new ToolSoul();
    List<EnumSoulElement> elements = new ArrayList<>();
    for (EnumSoulElement elem : EnumSoulElement.values()) {
        if (elem != EnumSoulElement.NONE) {
            elements.add(elem);
        }
    }
    soul.element1 = elements.get(SilentGems.random.nextInt(elements.size()));
    elements.remove(soul.element1);
    elements.add(EnumSoulElement.NONE);
    soul.element2 = elements.get(SilentGems.random.nextInt(elements.size()));
    return soul;
}
Also used : ItemToolSoul(net.silentchaos512.gems.item.ItemToolSoul) ArrayList(java.util.ArrayList)

Aggregations

ToolSoul (net.silentchaos512.gems.lib.soul.ToolSoul)25 ItemStack (net.minecraft.item.ItemStack)14 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 IArmor (net.silentchaos512.gems.api.IArmor)5 ITool (net.silentchaos512.gems.api.ITool)5 UUID (java.util.UUID)4 IBlockState (net.minecraft.block.state.IBlockState)4 ItemToolSoul (net.silentchaos512.gems.item.ItemToolSoul)4 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)3 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)3 SoulSkill (net.silentchaos512.gems.lib.soul.SoulSkill)3 LinkedHashMap (java.util.LinkedHashMap)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 Item (net.minecraft.item.Item)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 TextFormatting (net.minecraft.util.text.TextFormatting)2 ToolStats (net.silentchaos512.gems.api.tool.ToolStats)2 PlayerData (net.silentchaos512.gems.handler.PlayerDataHandler.PlayerData)2