Search in sources :

Example 41 with Color

use of net.silentchaos512.utils.Color in project SilentGems by SilentChaos512.

the class PotionFreezing method performEffect.

@Override
public void performEffect(EntityLivingBase entityLiving, int amplifier) {
    if (CONTINUOUS_DAMAGE_ENABLED) {
        // Continuous freeze damage.
        PotionEffect effect = entityLiving.getActivePotionEffect(this);
        if (effect == null)
            return;
        int damageDelay = CONTINUOUS_DAMAGE_DELAY;
        // Extra damage for mobs immune to fire (like blazes)
        if (entityLiving.isImmuneToFire())
            damageDelay /= 4;
        if (effect.getDuration() % damageDelay == 0) {
            int damageAmount = CONTINUOUS_DAMAGE_AMOUNT;
            entityLiving.attackEntityFrom(ModDamageSource.FREEZING, damageAmount);
        }
    }
    // Spawn freeze effect particles.
    Random rand = SilentGems.random;
    for (int i = 0; i < 2; ++i) {
        double posX = entityLiving.posX + 1.2f * (rand.nextFloat() - 0.5f) * entityLiving.width;
        double posY = entityLiving.posY + 1.1f * rand.nextFloat() * entityLiving.height;
        double posZ = entityLiving.posZ + 1.2f * (rand.nextFloat() - 0.5f) * entityLiving.width;
        double motionX = 0.005 * rand.nextGaussian();
        double motionY = 0.005 * rand.nextGaussian();
        double motionZ = 0.005 * rand.nextGaussian();
        SilentGems.proxy.spawnParticles(EnumModParticles.FREEZING, new Color(0x76e3f2), entityLiving.world, posX, posY, posZ, motionX, motionY, motionZ);
    }
}
Also used : Random(java.util.Random) PotionEffect(net.minecraft.potion.PotionEffect) Color(net.silentchaos512.lib.util.Color)

Example 42 with Color

use of net.silentchaos512.utils.Color in project SilentGems by SilentChaos512.

the class PotionShocking method performEffect.

@Override
public void performEffect(EntityLivingBase entityLiving, int amplifier) {
    PotionEffect effect = entityLiving.getActivePotionEffect(this);
    if (effect == null)
        return;
    int shockTimer = effect.getDuration();
    if (!entityLiving.world.isRemote && CHAINING_ENABLED) {
        int halfTime = shockTimer / 2;
        // Chain to nearby mobs. Half this mob's time and effect level 1.
        if (shockTimer % CHAIN_DELAY == 0 && halfTime > 0) {
            for (EntityLivingBase nearby : entityLiving.world.getEntities(EntityLivingBase.class, e -> e.getDistanceSqToEntity(entityLiving) < CHAIN_RADIUS_SQUARED && !(e instanceof EntityPlayer))) {
                PotionEffect effectNearby = nearby.getActivePotionEffect(this);
                if (effectNearby == null) {
                    nearby.addPotionEffect(new PotionEffect(this, halfTime, 0, true, false));
                }
            }
        }
    }
    if (!entityLiving.world.isRemote && CONTINUOUS_DAMAGE_ENABLED) {
        // Continuous shock damage.
        int damageDelay = CONTINUOUS_DAMAGE_DELAY;
        // Add entity ID for a bit of "randomness"
        if ((shockTimer + entityLiving.getEntityId()) % damageDelay == 0) {
            int damageAmount = CONTINUOUS_DAMAGE_AMOUNT;
            entityLiving.attackEntityFrom(ModDamageSource.SHOCKING, damageAmount);
        }
    }
    // Spawn shock effect particles.
    Random rand = SilentGems.random;
    for (int i = 0; i < 3 - SilentGems.proxy.getParticleSettings(); ++i) {
        double posX = entityLiving.posX + 1.2f * (rand.nextFloat() - 0.5f) * entityLiving.width;
        double posY = entityLiving.posY + 1.1f * rand.nextFloat() * entityLiving.height;
        double posZ = entityLiving.posZ + 1.2f * (rand.nextFloat() - 0.5f) * entityLiving.width;
        double motionX = 0.02 * rand.nextGaussian();
        double motionY = 0.05 + Math.abs(0.1 * rand.nextGaussian());
        double motionZ = 0.02 * rand.nextGaussian();
        SilentGems.proxy.spawnParticles(EnumModParticles.SHOCKING, new Color(0xffef63), entityLiving.world, posX, posY, posZ, motionX, motionY, motionZ);
    }
}
Also used : Random(java.util.Random) PotionEffect(net.minecraft.potion.PotionEffect) Color(net.silentchaos512.lib.util.Color) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer)

Example 43 with Color

use of net.silentchaos512.utils.Color in project SilentGems by SilentChaos512.

the class ToolRenderHelper method clAddInformation.

@Override
public void clAddInformation(ItemStack tool, World world, 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);
    }
    // UUID
    if (GemsConfig.DEBUG_MODE && controlDown && shiftDown) {
        UUID uuid = ToolHelper.hasUUID(tool) ? ToolHelper.getUUID(tool) : null;
        list.add(uuid == null ? "No UUID" : uuid.toString());
        uuid = ToolHelper.getSoulUUID(tool);
        list.add(uuid == null ? "No Soul UUID" : uuid.toString());
    }
    // Tool Soul
    ToolSoul soul = SoulManager.getSoul(tool);
    if (soul != null) {
        soul.addInformation(tool, world, list, advanced);
    }
    // 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"));
    }
    if (controlDown && tool.getTagCompound().getBoolean(ToolHelper.NBT_LOCK_STATS)) {
        list.add(loc.getMiscText("Tooltip.LockedStats"));
    }
    // Example tool?
    if (tool.hasTagCompound() && tool.getTagCompound().hasKey(ToolHelper.NBT_EXAMPLE_TOOL_TIER)) {
        EnumMaterialTier tier = EnumMaterialTier.values()[tool.getTagCompound().getInteger(ToolHelper.NBT_EXAMPLE_TOOL_TIER)];
        list.add(loc.getMiscText("Tooltip.ExampleTool", tier));
    } else // 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 = tool.getMaxDamage();
        int durability = durabilityMax - tool.getItemDamage();
        String s1 = String.format(durability > 9999 ? "%,d" : "%d", durability);
        String s2 = String.format(durabilityMax > 9999 ? "%,d" : "%d", durabilityMax);
        float durabilityBoost = ToolSoul.getDurabilityModifierForDisplay(soul);
        String durBoostLine = durabilityBoost == 0f ? "" : " (" + TooltipHelper.numberToPercent(durabilityBoost, 0, true) + TextFormatting.RESET + ")";
        line = loc.getMiscText("Tooltip.Durability", s1 + " / " + s2 + durBoostLine);
        list.add(color + "  " + line);
        if (isShield) {
            float magicProtection = (int) (ToolHelper.getMagicProtection(tool) * 100);
            list.add(color + getTooltipLine("MagicProtection", magicProtection, 0f));
        }
        if (isDigger) {
            // @formatter:off
            int harvestLevel = ToolHelper.getHarvestLevel(tool);
            String str = color + getTooltipLine("HarvestLevel", harvestLevel, 0f);
            String key = "Tooltip.level" + harvestLevel;
            String val = SilentGems.localizationHelper.getMiscText(key);
            if (!val.equals("misc.silentgems:" + key))
                str += " (" + val + ")";
            list.add(str);
            float harvestSpeedModifier = ToolSoul.getHarvestSpeedModifierForDisplay(soul);
            list.add(color + getTooltipLine("HarvestSpeed", ToolHelper.getDigSpeedOnProperMaterial(tool), harvestSpeedModifier));
        }
        if (isWeapon) {
            float meleeSpeed = 4 + ToolHelper.getMeleeSpeedModifier(tool);
            list.add(color + getTooltipLine("MeleeSpeed", meleeSpeed, 0f).replaceFirst("%", ""));
            float meleeDamage = 1 + ToolHelper.getMeleeDamageModifier(tool);
            float meleeModifier = ToolSoul.getMeleeDamageModifierForDisplay(soul);
            list.add(color + getTooltipLine("MeleeDamage", meleeDamage, meleeModifier));
            if (isCaster) {
                EnumMagicType magicType = EnumMagicType.getMagicType(tool);
                float damagePerShot = magicType.getDamagePerShot(tool);
                String damageString = damagePerShot == (int) damagePerShot ? Integer.toString((int) damagePerShot) : String.format(TooltipHelper.FORMAT_FLOAT, damagePerShot);
                String str = damageString + "" + TextFormatting.DARK_GRAY + "x" + magicType.getShotCount(tool);
                float magicModifier = ToolSoul.getMagicDamageModifierForDisplay(soul);
                list.add(color + getTooltipLine("MagicDamage", str, magicModifier));
            }
        }
        if (isBow) {
            ToolStats statsNoSoul = ToolHelper.getStats(tool, false);
            float drawSpeed = ModItems.bow.getDrawSpeedForDisplay(tool);
            float drawSpeedPreSoul = ItemGemBow.getDrawSpeedForDisplay(statsNoSoul.meleeSpeed, statsNoSoul.harvestSpeed);
            float drawSpeedBoost = (drawSpeed - drawSpeedPreSoul) / drawSpeedPreSoul;
            list.add(color + getTooltipLine("DrawSpeed", drawSpeed, drawSpeedBoost));
            float arrowDamage = ModItems.bow.getArrowDamageForDisplay(tool);
            float arrowDamagePreSoul = ItemGemBow.getArrowDamageForDisplay(statsNoSoul.meleeDamage);
            float arrowDamageBoost = (arrowDamage - arrowDamagePreSoul) / arrowDamagePreSoul;
            list.add(color + getTooltipLine("ArrowDamage", arrowDamage, arrowDamageBoost));
        }
        list.add(color + getTooltipLine("ChargeSpeed", ToolHelper.getChargeSpeed(tool), 0f));
    } 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), 0f));
        if (isDigger) {
            list.add(getTooltipLine("BlocksPlaced", ToolHelper.getStatBlocksPlaced(tool), 0f));
        }
        if (item instanceof ItemGemShovel) {
            list.add(getTooltipLine("PathsMade", ToolHelper.getStatPathsMade(tool), 0f));
        }
        if (item instanceof ItemGemHoe) {
            list.add(getTooltipLine("BlocksTilled", ToolHelper.getStatBlocksTilled(tool), 0f));
        }
        list.add(getTooltipLine("HitsLanded", ToolHelper.getStatHitsLanded(tool), 0f));
        if (isCaster || isBow)
            list.add(getTooltipLine("ShotsFired", ToolHelper.getStatShotsFired(tool), 0f));
        if (item instanceof ItemGemTomahawk)
            list.add(getTooltipLine("ThrownCount", ToolHelper.getStatThrownCount(tool), 0f));
        if (isWeapon)
            list.add(getTooltipLine("KillCount", ToolHelper.getStatKillCount(tool), 0f));
        list.add(getTooltipLine("Redecorated", ToolHelper.getStatRedecorated(tool), 0f));
        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);
        }
        ToolPart partRod = ToolHelper.getConstructionRod(tool);
        if (partRod != null) {
            list.add("  " + TextFormatting.YELLOW + partRod.getKey());
        }
        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);
        list.add("Render Layers");
        IModelData modelData = getModelCache(tool);
        if (modelData != null) {
            for (ToolPartPosition pos : ToolPartPosition.values()) {
                String key = "Layer" + pos.ordinal();
                String str = "  %s: %s, %X";
                ToolPart renderPart = ToolHelper.getRenderPart(tool, pos);
                ModelResourceLocation model = renderPart == null ? null : renderPart.getModel(tool, pos, 0);
                str = String.format(str, pos.name(), model == null ? "null" : model.toString(), modelData.getColor(pos, 0));
                list.add(str);
            }
        }
    }
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) Item(net.minecraft.item.Item) ToolPartTip(net.silentchaos512.gems.api.tool.part.ToolPartTip) ToolPartPosition(net.silentchaos512.gems.api.lib.ToolPartPosition) TextFormatting(net.minecraft.util.text.TextFormatting) EnumMaterialTier(net.silentchaos512.gems.api.lib.EnumMaterialTier) ItemGemShovel(net.silentchaos512.gems.item.tool.ItemGemShovel) UUID(java.util.UUID) ItemTool(net.minecraft.item.ItemTool) ItemGemShield(net.silentchaos512.gems.item.tool.ItemGemShield) EnumMagicType(net.silentchaos512.gems.util.EnumMagicType) ItemGemAxe(net.silentchaos512.gems.item.tool.ItemGemAxe) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper) IModelData(net.silentchaos512.gems.lib.client.IModelData) ToolSoul(net.silentchaos512.gems.lib.soul.ToolSoul) ToolPart(net.silentchaos512.gems.api.tool.part.ToolPart) 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) ItemGemHoe(net.silentchaos512.gems.item.tool.ItemGemHoe) ToolStats(net.silentchaos512.gems.api.tool.ToolStats)

Example 44 with Color

use of net.silentchaos512.utils.Color in project Silent-Gear by SilentChaos512.

the class StatInstance method formatMul2.

private MutableComponent formatMul2(ItemStat stat, @Nonnegative int decimalPlaces, boolean addColor) {
    String format = "%s" + ("%." + decimalPlaces + "f");
    float val = 1f + this.value;
    Color color = getFormattedColor(val, 1f, addColor);
    String text = trimNumber(String.format(format, "x", val));
    return TextUtil.withColor(new TextComponent(text), color);
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) Color(net.silentchaos512.utils.Color)

Example 45 with Color

use of net.silentchaos512.utils.Color in project Silent-Gear by SilentChaos512.

the class ColorUtils method getBlendedColor.

public static int getBlendedColor(CompoundPartItem item, Collection<? extends IMaterialInstance> materials, int layer) {
    int[] componentSums = new int[3];
    int maxColorSum = 0;
    int colorCount = 0;
    int i = 0;
    for (IMaterialInstance mat : materials) {
        IMaterialDisplay model = mat.getDisplayProperties();
        List<MaterialLayer> layers = model.getLayerList(item.getGearType(), item.getPartType(), mat).getLayers();
        if (layers.size() > layer) {
            int color = model.getLayerColor(item.getGearType(), item.getPartType(), mat, layer);
            int r = (color >> 16) & 0xFF;
            int g = (color >> 8) & 0xFF;
            int b = color & 0xFF;
            int colorWeight = item.getColorWeight(i, materials.size());
            for (int j = 0; j < colorWeight; ++j) {
                maxColorSum += Math.max(r, Math.max(g, b));
                componentSums[0] += r;
                componentSums[1] += g;
                componentSums[2] += b;
                ++colorCount;
            }
            ++i;
        }
    }
    return blendColors(componentSums, maxColorSum, colorCount);
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Aggregations

Color (net.silentchaos512.lib.util.Color)12 Color (net.silentchaos512.utils.Color)9 LocalizationHelper (net.silentchaos512.lib.util.LocalizationHelper)8 EnumMaterialGrade (net.silentchaos512.gems.api.lib.EnumMaterialGrade)7 TextComponent (net.minecraft.network.chat.TextComponent)6 TextFormatting (net.minecraft.util.text.TextFormatting)6 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)6 ToolPart (net.silentchaos512.gems.api.tool.part.ToolPart)6 MutableComponent (net.minecraft.network.chat.MutableComponent)4 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)4 Random (java.util.Random)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 Item (net.minecraft.item.Item)3 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)3 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)3 ItemGemBow (net.silentchaos512.gems.item.tool.ItemGemBow)3 UUID (java.util.UUID)2 Minecraft (net.minecraft.client.Minecraft)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2