use of net.silentchaos512.gems.api.lib.EnumMaterialTier in project SilentGems by SilentChaos512.
the class ActionAddMixedMaterialRecipe method apply.
@Override
public void apply() {
// Add the real recipe.
IRecipe irecipe = new RecipeMixedMaterialItem(tier, toolItem, recipe);
irecipe.setRegistryName(new ResourceLocation("crafttweaker", calculateName()));
ForgeRegistries.RECIPES.register(irecipe);
// Also add example recipes.
List<EnumMaterialTier> tiers = new ArrayList<>();
if (tier == null) {
for (EnumMaterialTier t : EnumMaterialTier.values()) {
tiers.add(t);
}
} else {
tiers.add(tier);
}
List<String> recipeLines = new ArrayList<>();
int index = 0;
while (index < recipe.length && recipe[index] instanceof String) {
recipeLines.add((String) recipe[index++]);
}
List<Object> extraParams = new ArrayList<>();
for (; index < recipe.length; ++index) {
extraParams.add(recipe[index]);
}
EnumMaterialTier[] arrayTiers = tiers.toArray(new EnumMaterialTier[tiers.size()]);
String[] arrayLines = recipeLines.toArray(new String[recipeLines.size()]);
Object[] arrayExtraParams = extraParams.toArray();
if (toolItem instanceof ITool)
ToolHelper.addExampleRecipe(toolItem, arrayTiers, arrayLines, arrayExtraParams);
}
use of net.silentchaos512.gems.api.lib.EnumMaterialTier in project SilentGems by SilentChaos512.
the class CTSilentGems method setToolRecipe.
@ZenMethod
public static void setToolRecipe(String itemClass, int tierRestriction, String[] recipe, Object... ingredients) {
Item toolItem = Item.getByNameOrId(SilentGems.RESOURCE_PREFIX + itemClass.toLowerCase());
EnumMaterialTier tier = null;
if (tierRestriction >= 0 && tierRestriction < EnumMaterialTier.values().length) {
tier = EnumMaterialTier.values()[tierRestriction];
}
Object[] params = new Object[recipe.length + ingredients.length];
for (int i = 0; i < recipe.length; ++i) {
params[i] = recipe[i];
}
for (int i = 0; i < ingredients.length; ++i) {
if (ingredients[i] instanceof String) {
String str = (String) ingredients[i];
if (str.length() == 1) {
// Character?
params[recipe.length + i] = str.charAt(0);
} else if (str.startsWith("ore:")) {
// Oredict key?
params[recipe.length + i] = str.replaceFirst("ore:", "");
} else {
// Item string?
// We can't use CraftTweaker's typical ingredient annotation (<mod:item_name:meta>) because it doesn't yield
// any values I can use. :(
String[] array = str.split(":");
String itemName = array[0] + ":" + array[1];
Item item = Item.getByNameOrId(itemName);
if (item != null) {
int meta = 0;
if (array.length > 2) {
try {
meta = Integer.parseInt(array[2]);
} catch (NumberFormatException ex) {
// Ignore
}
}
params[recipe.length + i] = new ItemStack(item, 1, meta);
}
}
} else {
// Nothing else will work, I assume? But pass it along anyway.
params[recipe.length + i] = ingredients[i];
}
}
ActionAddMixedMaterialRecipe action = new ActionAddMixedMaterialRecipe(toolItem, tier, params);
MCRecipeManager.recipesToAdd.add(action);
// RECIPES_TO_ADD.add(action);
}
use of net.silentchaos512.gems.api.lib.EnumMaterialTier in project SilentGems by SilentChaos512.
the class ItemGemArmor method getMaxDamage.
@Override
public int getMaxDamage(ItemStack stack) {
EnumMaterialTier tier = ToolHelper.getToolTier(stack);
int x = ArmorHelper.getMaxDamage(stack);
float y = (1.8f * x + 1515) / 131;
float z = tier != null ? y * (tier.ordinal() + 1f) / 2f : y;
return (int) (MAX_DAMAGE_ARRAY[armorType.getIndex()] * z);
}
use of net.silentchaos512.gems.api.lib.EnumMaterialTier in project SilentGems by SilentChaos512.
the class RecipeMultiGemArmor method getCraftingResult.
@Override
public ItemStack getCraftingResult(InventoryCrafting inv) {
// Get the middle stack, which determines the armor type.
ItemStack centerStack = inv.getStackInRowAndColumn(1, 1);
if (StackHelper.isEmpty(centerStack) || !(centerStack.getItem() instanceof ItemArmorFrame)) {
return StackHelper.empty();
}
// Make sure nothing is in the corners.
if (StackHelper.isValid(inv.getStackInRowAndColumn(0, 0)) || StackHelper.isValid(inv.getStackInRowAndColumn(2, 0)) || StackHelper.isValid(inv.getStackInRowAndColumn(2, 2)) || StackHelper.isValid(inv.getStackInRowAndColumn(0, 2))) {
return StackHelper.empty();
}
// Determine the target tier and output item.
ItemArmorFrame item = (ItemArmorFrame) centerStack.getItem();
Item outputItem = item.getOutputItem(centerStack);
EnumMaterialTier targetTier = item.getTier(centerStack);
// Get armor parts. Check tiers match (getGems checks all materials are same tier, or it returns null).
ItemStack[] stacks = getGems(inv);
if (stacks == null || EnumMaterialTier.fromStack(stacks[0]) != targetTier)
return StackHelper.empty();
return ArmorHelper.constructArmor(outputItem, stacks);
}
use of net.silentchaos512.gems.api.lib.EnumMaterialTier in project SilentGems by SilentChaos512.
the class RecipeMultiGemArmor method getGems.
public ItemStack[] getGems(InventoryCrafting inv) {
// Get materials from slots.
ItemStack[] stacks = new ItemStack[4];
// West
stacks[0] = inv.getStackInRowAndColumn(0, 1);
// North
stacks[1] = inv.getStackInRowAndColumn(1, 0);
// East
stacks[2] = inv.getStackInRowAndColumn(2, 1);
// South
stacks[3] = inv.getStackInRowAndColumn(1, 2);
// Make sure all are same tier and parts aren't blacklisted.
ToolPart part;
EnumMaterialTier tier = EnumMaterialTier.fromStack(stacks[0]);
for (int i = 1; i < stacks.length; ++i) {
part = ToolPartRegistry.fromStack(stacks[i]);
if (tier == null || part == null || part.isBlacklisted(stacks[i]) || part.getTier() != tier) {
return null;
}
}
return stacks;
}
Aggregations