use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class RecipeMixedMaterialItem method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
if (!partTiersMatch(inv)) {
return StackHelper.empty();
}
ItemStack rod = getRod(inv);
ItemStack frame = getFrame(inv);
ItemStackList materials = getMaterials(inv);
ItemStack[] array = materials.toArray(new ItemStack[materials.size()]);
if (toolItem instanceof ITool)
return ((ITool) toolItem).constructTool(rod, array);
if (toolItem instanceof IArmor)
return ((IArmor) toolItem).constructArmor(frame, array);
return StackHelper.empty();
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class SoulManager method getSoul.
@Nullable
public static ToolSoul getSoul(ItemStack tool) {
if (StackHelper.isEmpty(tool) || !(tool.getItem() instanceof ITool || tool.getItem() instanceof IArmor) || ToolHelper.isExampleItem(tool)) {
return null;
}
UUID uuid = ToolHelper.getSoulUUID(tool);
// Soul already in map?
ToolSoul soul = map.get(uuid);
if (soul != null) {
return soul;
}
// Does soul exist in NBT?
ToolHelper.initRootTag(tool);
if (!tool.getTagCompound().hasKey(ToolHelper.NBT_ROOT_TOOL_SOUL)) {
return null;
}
// Read from NBT, place in map for fast access.
soul = ToolSoul.readFromNBT(ToolHelper.getRootTag(tool, ToolHelper.NBT_ROOT_TOOL_SOUL));
if (uuid == null) {
ToolHelper.setRandomSoulUUID(tool);
uuid = ToolHelper.getSoulUUID(tool);
}
map.put(uuid, soul);
// SilentGems.logHelper.debug("Put tool soul " + soul + " in the map! Total count: " + map.size());
return soul;
}
use of net.silentchaos512.gems.api.ITool 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 toolOrArmor
*/
public static void recalculateStats(ItemStack toolOrArmor) {
// Make sure the item has a UUID!
getUUID(toolOrArmor);
ToolPart[] parts = getConstructionParts(toolOrArmor);
if (parts.length == 0)
return;
// Clear old render cache
clearOldRenderCache(toolOrArmor);
if (!toolOrArmor.getTagCompound().getBoolean(NBT_LOCK_STATS)) {
ToolStats stats = getStats(toolOrArmor, true);
String root = NBT_ROOT_PROPERTIES;
// Tools only
if (toolOrArmor.getItem() instanceof ITool) {
setTagFloat(toolOrArmor, root, NBT_PROP_HARVEST_SPEED, stats.harvestSpeed);
setTagFloat(toolOrArmor, root, NBT_PROP_MELEE_DAMAGE, stats.meleeDamage);
setTagFloat(toolOrArmor, root, NBT_PROP_MAGIC_DAMAGE, stats.magicDamage);
setTagFloat(toolOrArmor, root, NBT_PROP_MELEE_SPEED, stats.meleeSpeed);
setTagFloat(toolOrArmor, root, NBT_PROP_CHARGE_SPEED, stats.chargeSpeed);
setTagInt(toolOrArmor, root, NBT_PROP_HARVEST_LEVEL, stats.harvestLevel);
}
// Tools and armor
setTagInt(toolOrArmor, root, NBT_PROP_DURABILITY, (int) stats.durability);
setTagFloat(toolOrArmor, root, NBT_PROP_PROTECTION, stats.protection);
setTagInt(toolOrArmor, root, NBT_PROP_ENCHANTABILITY, (int) stats.enchantability);
setTagInt(toolOrArmor, root, NBT_TOOL_TIER, parts[0].getTier().ordinal());
}
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolHelper method addExampleRecipe.
public static void addExampleRecipe(Item item, EnumMaterialTier[] tiers, String[] lines, Object... extraParams) {
// New ingredient-based recipes
ConfigOptionToolClass config = item instanceof ITool ? ((ITool) item).getConfig() : null;
for (EnumMaterialTier tier : tiers) {
// Only add recipes for valid tiers
if (config != null && !config.validTiers.contains(tier))
continue;
// Head parts for tier
List<ItemStack> heads = new ArrayList<>();
for (ToolPart part : ToolPartRegistry.getMains()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getTier() == tier && StackHelper.isValid(part.getCraftingStack()))
heads.add(part.getCraftingStack());
IngredientSL headIngredient = IngredientSL.from(heads.toArray(new ItemStack[0]));
// Rods for tier
List<ItemStack> rods = new ArrayList<>();
for (ToolPart part : ToolPartRegistry.getRods()) if (!part.isBlacklisted(part.getCraftingStack()) && part.getCompatibleTiers().contains(tier))
rods.add(part.getCraftingStack());
IngredientSL rodIngredient = IngredientSL.from(rods.toArray(new ItemStack[0]));
// Armor frames
List<ItemStack> frames = new ArrayList<>();
if (item instanceof ItemGemArmor) {
EntityEquipmentSlot slot = ((ItemGemArmor) item).armorType;
for (ToolPart part : ToolPartRegistry.getValues()) if (part instanceof ArmorPartFrame && ((ArmorPartFrame) part).getSlot() == slot && part.getTier() == tier && !part.isBlacklisted(part.getCraftingStack()))
frames.add(part.getCraftingStack());
}
IngredientSL frameIngredient = IngredientSL.from(frames.toArray(new ItemStack[0]));
ResourceLocation recipeName = new ResourceLocation(item.getRegistryName().toString() + "_" + tier.name().toLowerCase() + "_example");
ItemStack result = new ItemStack(item);
NBTTagCompound tags = new NBTTagCompound();
tags.setInteger(NBT_EXAMPLE_TOOL_TIER, tier.ordinal());
result.setTagCompound(tags);
// Super ugly, but I've got never better at the moment.
List<Object> params = new ArrayList<>();
for (String line : lines) params.add(line);
if (recipeContainsKey(lines, "h")) {
params.add('h');
params.add(headIngredient);
}
if (recipeContainsKey(lines, "r")) {
params.add('r');
params.add(rodIngredient);
}
if (recipeContainsKey(lines, "a")) {
params.add('a');
params.add(frameIngredient);
}
for (Object obj : extraParams) params.add(obj);
EXAMPLE_RECIPES.add(SilentGems.registry.recipes.makeShaped(recipeName.getResourcePath(), result, params.toArray()));
}
}
use of net.silentchaos512.gems.api.ITool in project SilentGems by SilentChaos512.
the class ToolHelper method getSubItems.
public static List<ItemStack> getSubItems(Item item, int materialLength) {
if (toolSubItems.containsKey(item)) {
// Return cached list.
return toolSubItems.get(item);
}
List<ItemStack> list = Lists.newArrayList();
// final boolean isSuperTool = item instanceof ITool && ((ITool) item).isSuperTool();
final ItemStack rodWood = new ItemStack(Items.STICK);
final ItemStack rodIron = ModItems.craftingMaterial.toolRodIron;
final ItemStack rodGold = ModItems.craftingMaterial.toolRodGold;
for (ToolPartMain part : ToolPartRegistry.getMains()) {
// Check for parts with empty crafting stacks and scream at the user if any are found.
if (StackHelper.isEmpty(part.getCraftingStack())) {
if (!emptyPartSet.contains(part)) {
emptyPartSet.add(part);
SilentGems.logHelper.severe("Part with empty crafting stack: " + part);
if (!foundEmptyPart) {
Greetings.addExtraMessage(TextFormatting.RED + "Errored tool part found! Please report this issue on the GitHub issue tracker.");
foundEmptyPart = true;
}
Greetings.addExtraMessage(TextFormatting.ITALIC + part.toString());
}
} else {
if (!part.isBlacklisted(part.getCraftingStack())) {
if (item instanceof ITool && !((ITool) item).getValidTiers().contains(part.getTier())) {
continue;
}
ItemStack rod = part.getTier() == EnumMaterialTier.SUPER ? rodGold : item instanceof ItemGemShield && part.getTier() == EnumMaterialTier.REGULAR ? rodIron : rodWood;
ItemStack tool = constructTool(item, rod, part.getCraftingStack());
tool.getTagCompound().setBoolean(NBT_EXAMPLE_TOOL, true);
list.add(tool);
}
}
}
// Set maker name.
String makerName = SilentGems.localizationHelper.getMiscText("Tooltip.OriginalOwner.Creative");
for (ItemStack stack : list) ToolHelper.setOriginalOwner(stack, makerName);
// Save for later to prevent duplicates with different UUIDs.
toolSubItems.put(item, list);
return list;
}
Aggregations