use of net.silentchaos512.gems.api.lib.EnumMaterialGrade 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.lib.EnumMaterialGrade 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"));
}
}
use of net.silentchaos512.gems.api.lib.EnumMaterialGrade 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.lib.EnumMaterialGrade in project SilentGems by SilentChaos512.
the class ArmorHelper method constructArmor.
public static ItemStack constructArmor(Item item, ItemStack... materials) {
// Shortcut for JEI recipes.
if (materials.length == 1) {
ItemStack[] newMats = new ItemStack[4];
for (int i = 0; i < newMats.length; ++i) newMats[i] = materials[0];
materials = newMats;
}
ItemStack result = new ItemStack(item);
result.setTagCompound(new NBTTagCompound());
result.getTagCompound().setTag(ToolHelper.NBT_TEMP_PARTLIST, new NBTTagCompound());
// Construction
ToolPart part;
EnumMaterialGrade grade;
for (int i = 0; i < materials.length; ++i) {
if (StackHelper.isEmpty(materials[i])) {
String str = "ArmorHelper.constructArmor: empty part! ";
for (ItemStack stack : materials) str += stack + ", ";
throw new IllegalArgumentException(str);
}
part = ToolPartRegistry.fromStack(materials[i]);
grade = EnumMaterialGrade.fromStack(materials[i]);
setTagPart(result, "Part" + i, part, grade);
// Write part list for client-side name generation.
result.getTagCompound().getCompoundTag(ToolHelper.NBT_TEMP_PARTLIST).setTag("part" + i, materials[i].writeToNBT(new NBTTagCompound()));
}
// Create name
String displayName = ToolHelper.createToolName(item, materials);
result.setStackDisplayName(displayName);
recalculateStats(result);
return result;
}
use of net.silentchaos512.gems.api.lib.EnumMaterialGrade in project SilentGems by SilentChaos512.
the class ArmorHelper method recalculateStats.
public static void recalculateStats(ItemStack armor) {
ToolPart[] parts = getConstructionParts(armor);
EnumMaterialGrade[] grades = getConstructionGrades(armor);
if (parts.length == 0)
return;
// TODO: Reset render cache? Will that even be a thing for armor?
float sumDurability = 0f;
float sumProtection = 0f;
// TODO: Toughness?
float sumEnchantability = 0f;
Set<ToolPart> uniqueParts = Sets.newConcurrentHashSet();
// Get sum stats for parts.
for (int i = 0; i < parts.length; ++i) {
ToolPart part = parts[i];
EnumMaterialGrade grade = grades[i];
float multi = (100 + grade.bonusPercent) / 100f;
sumDurability += part.getDurability() * multi;
sumProtection += part.getProtection() * multi;
sumEnchantability += part.getEnchantability() * multi;
uniqueParts.add(part);
}
// Set render colors
ToolPart[] renderParts = getRenderParts(armor);
for (int i = 0; i < renderParts.length; ++i) {
if (renderParts[i] != null) {
setTagInt(armor, ToolRenderHelper.NBT_MODEL_INDEX, "Layer" + i + "Color", renderParts[i].getColor(armor));
}
}
// Variety bonus
int variety = MathHelper.clamp(uniqueParts.size(), 1, 3);
float bonus = 1.0f + GemsConfig.VARIETY_BONUS * (variety - 1);
// Average stats
float durability = bonus * sumDurability / parts.length;
float protection = bonus * sumProtection / parts.length;
float enchantability = bonus * sumEnchantability / parts.length;
// Set NBT
setTagInt(armor, NBT_ROOT_PROPERTIES, NBT_PROP_DURABILITY, (int) durability);
setTagFloat(armor, NBT_ROOT_PROPERTIES, NBT_PROP_PROTECTION, protection);
setTagInt(armor, NBT_ROOT_PROPERTIES, NBT_PROP_ENCHANTABILITY, (int) enchantability);
setTagInt(armor, NBT_ROOT_PROPERTIES, NBT_ARMOR_TIER, parts[0].getTier().ordinal());
}
Aggregations