use of net.silentchaos512.gems.api.tool.ToolStats in project SilentGems by SilentChaos512.
the class ToolHelper method getStats.
public static ToolStats getStats(ItemStack toolOrArmor, boolean applySoulModifiers) {
ToolPart[] parts = getConstructionParts(toolOrArmor);
EnumMaterialGrade[] grades = getConstructionGrades(toolOrArmor);
if (parts.length == 0)
return new ToolStats(toolOrArmor);
ToolStats stats = new ToolStats(toolOrArmor, parts, grades);
if (toolOrArmor.getTagCompound().getBoolean(NBT_LOCK_STATS)) {
// TODO: Is this right?
stats.chargeSpeed = getChargeSpeed(toolOrArmor);
stats.durability = getMaxDamage(toolOrArmor);
stats.enchantability = getItemEnchantability(toolOrArmor);
stats.harvestLevel = getHarvestLevel(toolOrArmor);
stats.harvestSpeed = getDigSpeedOnProperMaterial(toolOrArmor);
stats.magicDamage = getMagicDamage(toolOrArmor);
stats.meleeDamage = getMeleeDamage(toolOrArmor);
stats.meleeSpeed = getMeleeSpeed(toolOrArmor);
stats.protection = getProtection(toolOrArmor);
return stats;
}
stats.calculate();
if (applySoulModifiers) {
ToolSoul soul = SoulManager.getSoul(toolOrArmor);
if (soul != null) {
soul.applyToStats(stats);
}
}
return stats;
}
use of net.silentchaos512.gems.api.tool.ToolStats in project SilentGems by SilentChaos512.
the class ToolStats method calculate.
public ToolStats calculate() {
if (parts.length == 0)
return this;
Set<ToolPart> uniqueParts = Sets.newConcurrentHashSet();
// Head (main) parts
for (int i = 0; i < parts.length; ++i) {
ToolPart part = parts[i];
EnumMaterialGrade grade = grades[i];
float multi = (100 + grade.bonusPercent) / 100f;
durability += part.getDurability() * multi;
harvestSpeed += part.getHarvestSpeed() * multi;
meleeDamage += part.getMeleeDamage() * multi;
magicDamage += part.getMagicDamage() * multi;
meleeSpeed += part.getMeleeSpeed() * multi;
enchantability += part.getEnchantability() * multi;
chargeSpeed += part.getChargeSpeed() * multi;
blockingPower += part.getProtection() / 16f * multi;
harvestLevel = Math.max(harvestLevel, part.getHarvestLevel());
uniqueParts.add(part);
}
// Variety bonus
int variety = MathHelper.clamp(uniqueParts.size(), 1, GemsConfig.VARIETY_CAP);
float bonus = 1.0f + GemsConfig.VARIETY_BONUS * (variety - 1);
// Average head parts
durability = bonus * durability / parts.length;
harvestSpeed = bonus * harvestSpeed / parts.length;
meleeDamage = bonus * meleeDamage / parts.length;
magicDamage = bonus * magicDamage / parts.length;
meleeSpeed = bonus * meleeSpeed / parts.length;
chargeSpeed = bonus * chargeSpeed / parts.length;
enchantability = bonus * enchantability / parts.length;
blockingPower = Math.max(bonus * blockingPower / parts.length, ItemGemShield.MIN_BLOCKING_POWER);
// Tool class multipliers
if (tool.getItem() instanceof ITool) {
ITool itool = (ITool) tool.getItem();
durability *= itool.getDurabilityMultiplier();
harvestSpeed *= itool.getHarvestSpeedMultiplier();
}
// Rod, tip, grip
ToolPart partRod = ToolHelper.getConstructionRod(tool);
ToolPart partTip = ToolHelper.getConstructionTip(tool);
ToolPart partGrip = ToolHelper.getPart(tool, EnumPartPosition.ROD_GRIP);
for (ToolPart part : Lists.newArrayList(partRod, partTip, partGrip)) {
if (part != null) {
part.applyStats(this);
}
}
return this;
}
use of net.silentchaos512.gems.api.tool.ToolStats 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);
}
}
}
}
use of net.silentchaos512.gems.api.tool.ToolStats 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());
}
Aggregations