use of net.silentchaos512.gems.api.tool.part.ToolPart in project SilentGems by SilentChaos512.
the class ArmorHelper method constructArmor.
public static ItemStack constructArmor(Item item, ItemStack frame, 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()));
}
// Frame
part = ToolPartRegistry.fromStack(frame);
if (part != null) {
setTagPart(result, ArmorPartPosition.FRAME.getKey(0), part, EnumMaterialGrade.NONE);
}
// Create name
String displayName = ToolHelper.createToolName(item, materials);
result.setStackDisplayName(displayName);
recalculateStats(result);
return result;
}
use of net.silentchaos512.gems.api.tool.part.ToolPart in project SilentGems by SilentChaos512.
the class ToolHelper method createToolName.
public static String createToolName(Item item, List<ItemStack> materials) {
ToolPart part;
LocalizationHelper loc = SilentGems.localizationHelper;
Set<String> prefixSet = Sets.newLinkedHashSet();
Set<String> materialSet = Sets.newLinkedHashSet();
for (ItemStack stack : materials) {
part = ToolPartRegistry.fromStack(stack);
if (part != null) {
String prefix = part.getDisplayNamePrefix(stack);
if (prefix != null && !prefix.isEmpty())
prefixSet.add(prefix);
materialSet.add(part.getDisplayName(stack));
}
}
String prefix = String.join(" ", prefixSet);
if (!prefix.isEmpty())
prefix += " ";
String delimiter = loc.getLocalizedString("tool.silentgems:delimiter");
String materialName = String.join(delimiter, materialSet);
String toolName = ((IRegistryObject) item).getName();
String name = loc.getLocalizedString("tool", toolName, materialName);
return prefix + name;
}
use of net.silentchaos512.gems.api.tool.part.ToolPart in project SilentGems by SilentChaos512.
the class ToolHelper method constructTool.
public static ItemStack constructTool(Item item, ItemStack rod, ItemStack... materials) {
if (materials.length == 1) {
ItemStack[] newMats = new ItemStack[3];
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(NBT_TEMP_PARTLIST, new NBTTagCompound());
// Set construction materials
ToolPart part;
// Head
for (int i = 0; i < materials.length; ++i) {
if (StackHelper.isEmpty(materials[i])) {
String str = "ToolHelper.constructTool: empty part! ";
for (ItemStack stack : materials) str += stack + ", ";
throw new IllegalArgumentException(str);
}
part = ToolPartRegistry.fromStack(materials[i]);
EnumMaterialGrade grade = EnumMaterialGrade.fromStack(materials[i]);
setTagPart(result, ToolPartPosition.HEAD.getKey(i), part, grade);
// Write part list for client-side name generation.
result.getTagCompound().getCompoundTag(NBT_TEMP_PARTLIST).setTag("part" + i, materials[i].writeToNBT(new NBTTagCompound()));
}
// Rod
part = ToolPartRegistry.fromStack(rod);
if (part == null) {
return StackHelper.empty();
}
setTagPart(result, ToolPartPosition.ROD.getKey(0), part, EnumMaterialGrade.NONE);
// Create name
String displayName = createToolName(item, materials);
result.setStackDisplayName(displayName);
recalculateStats(result);
// Is this tier valid for this tool class?
EnumMaterialTier toolTier = getToolTier(result);
if (item instanceof ITool && !((ITool) item).getValidTiers().contains(toolTier)) {
return StackHelper.empty();
}
return result;
}
use of net.silentchaos512.gems.api.tool.part.ToolPart in project SilentGems by SilentChaos512.
the class ToolHelper method getConstructionParts.
public static ToolPart[] getConstructionParts(ItemStack tool) {
if (StackHelper.isEmpty(tool))
return new ToolPart[] {};
List<ToolPart> parts = Lists.newArrayList();
int index = -1;
String key;
ToolPart part;
do {
key = getPartId(tool, ToolPartPosition.HEAD.getKey(++index));
if (key != null) {
part = ToolPartRegistry.getPart(key);
if (part != null)
parts.add(part);
}
} while (key != null && !key.isEmpty());
return parts.toArray(new ToolPart[parts.size()]);
}
use of net.silentchaos512.gems.api.tool.part.ToolPart 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;
}
Aggregations