use of net.silentchaos512.gems.api.tool.part.ToolPart in project SilentGems by SilentChaos512.
the class TileMaterialGrader method isItemValidForSlot.
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
if (index == SLOT_INPUT) {
if (StackHelper.isEmpty(stack)) {
return false;
}
ToolPart part = ToolPartRegistry.fromStack(stack);
EnumMaterialGrade grade = EnumMaterialGrade.fromStack(stack);
if (part != null && part instanceof ToolPartMain && grade == EnumMaterialGrade.NONE) {
return true;
}
return false;
}
return false;
}
use of net.silentchaos512.gems.api.tool.part.ToolPart in project SilentGems by SilentChaos512.
the class TileMaterialGrader method update.
@Override
public void update() {
if (world.isRemote)
return;
ItemStack input = getStackInSlot(SLOT_INPUT);
ToolPart part = ToolPartRegistry.fromStack(input);
// Is input (if anything) a grade-able part?
if (part != null && part instanceof ToolPartMain && EnumMaterialGrade.fromStack(input) == EnumMaterialGrade.NONE) {
// Analyze, using chaos if possible
boolean useChaos = chaosStored >= CHAOS_PER_TICK;
// Analyzing material.
if (progress < BASE_ANALYZE_TIME) {
if (useChaos) {
chaosStored -= CHAOS_PER_TICK;
}
progress += useChaos ? ANALYZE_SPEED_WITH_CHAOS : ANALYZE_SPEED_NO_CHAOS;
requireClientSync = true;
}
// Grade material if any output slot is free.
int outputSlot = getFreeOutputSlot();
if (progress >= BASE_ANALYZE_TIME && outputSlot > 0) {
progress = 0;
// Take one from input stack.
ItemStack stack = StackHelper.safeCopy(input);
StackHelper.setCount(stack, 1);
StackHelper.shrink(input, 1);
// Assign random grade.
EnumMaterialGrade.selectRandom(SilentGems.random).setGradeOnStack(stack);
// Set to output slot, clear input slot if needed.
setInventorySlotContents(outputSlot, stack);
if (StackHelper.getCount(input) <= 0) {
setInventorySlotContents(SLOT_INPUT, StackHelper.empty());
}
requireClientSync = true;
}
} else {
progress = 0;
}
// Send update to client?
if (requireClientSync) {
IBlockState state = world.getBlockState(pos);
world.notifyBlockUpdate(pos, state, state, 3);
requireClientSync = false;
}
}
use of net.silentchaos512.gems.api.tool.part.ToolPart in project SilentGems by SilentChaos512.
the class ArmorHelper method decorate.
private static ItemStack decorate(ItemStack armor, ItemStack material, ArmorPartPosition pos) {
if (StackHelper.isEmpty(armor))
return StackHelper.empty();
if (StackHelper.isEmpty(material))
return armor;
ToolPart part = ToolPartRegistry.fromDecoStack(material);
if (part == null)
return null;
// Only main parts (like gems) work
if (!(part instanceof ToolPartMain))
return armor;
ItemStack result = StackHelper.safeCopy(armor);
setTagPart(result, pos.getDecoKey(), part, EnumMaterialGrade.fromStack(material));
return result;
}
use of net.silentchaos512.gems.api.tool.part.ToolPart 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.tool.part.ToolPart 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()));
}
}
Aggregations