2017-02-23 13:29:43 +01:00
|
|
|
/*
|
|
|
|
* This file is part of TechReborn, licensed under the MIT License (MIT).
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 TechReborn
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2015-04-15 18:27:05 +02:00
|
|
|
package techreborn.api;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
2017-06-11 22:22:07 +02:00
|
|
|
import net.minecraft.item.crafting.Ingredient;
|
2015-04-15 18:27:05 +02:00
|
|
|
import net.minecraft.item.crafting.ShapedRecipes;
|
|
|
|
import net.minecraft.item.crafting.ShapelessRecipes;
|
2017-06-11 22:22:07 +02:00
|
|
|
import net.minecraft.util.NonNullList;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2015-04-15 18:27:05 +02:00
|
|
|
import net.minecraft.world.World;
|
2017-06-11 22:22:07 +02:00
|
|
|
import reborncore.common.util.CraftingHelper;
|
2015-04-15 18:27:05 +02:00
|
|
|
|
2016-04-03 15:07:45 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
public class RollingMachineRecipe {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public static final RollingMachineRecipe instance = new RollingMachineRecipe();
|
2017-06-11 22:22:07 +02:00
|
|
|
private final HashMap<ResourceLocation, IRecipe> recipes = new HashMap<>();
|
|
|
|
|
|
|
|
public void addShapedOreRecipe(ResourceLocation resourceLocation, ItemStack outputItemStack, Object... objectInputs) {
|
2017-06-12 15:23:32 +02:00
|
|
|
// Validate.notNull(outputItemStack);
|
|
|
|
// Validate.notNull(outputItemStack.getItem());
|
|
|
|
// if (objectInputs.length == 0) {
|
|
|
|
// Validate.notNull(null); //Quick way to crash
|
|
|
|
// }
|
|
|
|
// recipes.put(resourceLocation, new ShapedOreRecipe(resourceLocation, outputItemStack, objectInputs));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-11 22:22:07 +02:00
|
|
|
public void addShapelessOreRecipe(ResourceLocation resourceLocation, ItemStack outputItemStack, Object... objectInputs) {
|
2017-06-12 15:23:32 +02:00
|
|
|
// Validate.notNull(outputItemStack);
|
|
|
|
// Validate.notNull(outputItemStack.getItem());
|
|
|
|
// if (objectInputs.length == 0) {
|
|
|
|
// Validate.notNull(null); //Quick way to crash
|
|
|
|
// }
|
|
|
|
// recipes.put(resourceLocation, new ShapelessOreRecipe(resourceLocation, outputItemStack, objectInputs));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-11 22:22:07 +02:00
|
|
|
public void addRecipe(ResourceLocation resourceLocation, ItemStack output, Object... components) {
|
2016-10-08 21:46:16 +02:00
|
|
|
String s = "";
|
|
|
|
int i = 0;
|
|
|
|
int j = 0;
|
|
|
|
int k = 0;
|
|
|
|
if (components[i] instanceof String[]) {
|
|
|
|
String as[] = (String[]) components[i++];
|
|
|
|
for (int l = 0; l < as.length; l++) {
|
|
|
|
String s2 = as[l];
|
|
|
|
k++;
|
|
|
|
j = s2.length();
|
|
|
|
s = (new StringBuilder()).append(s).append(s2).toString();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (components[i] instanceof String) {
|
|
|
|
String s1 = (String) components[i++];
|
|
|
|
k++;
|
|
|
|
j = s1.length();
|
|
|
|
s = (new StringBuilder()).append(s).append(s1).toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HashMap hashmap = new HashMap();
|
|
|
|
for (; i < components.length; i += 2) {
|
|
|
|
Character character = (Character) components[i];
|
|
|
|
ItemStack itemstack1 = null;
|
|
|
|
if (components[i + 1] instanceof Item) {
|
|
|
|
itemstack1 = new ItemStack((Item) components[i + 1]);
|
|
|
|
} else if (components[i + 1] instanceof Block) {
|
|
|
|
itemstack1 = new ItemStack((Block) components[i + 1], 1, -1);
|
|
|
|
} else if (components[i + 1] instanceof ItemStack) {
|
|
|
|
itemstack1 = (ItemStack) components[i + 1];
|
|
|
|
}
|
|
|
|
hashmap.put(character, itemstack1);
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-11 22:22:07 +02:00
|
|
|
NonNullList<Ingredient> recipeArray = NonNullList.create();
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int i1 = 0; i1 < j * k; i1++) {
|
|
|
|
char c = s.charAt(i1);
|
|
|
|
if (hashmap.containsKey(c)) {
|
2017-06-11 22:22:07 +02:00
|
|
|
recipeArray.set(i1, CraftingHelper.toIngredient(((ItemStack) hashmap.get(c)).copy()));
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2017-06-11 22:22:07 +02:00
|
|
|
recipeArray.set(i1, CraftingHelper.toIngredient(ItemStack.EMPTY));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-11 22:22:07 +02:00
|
|
|
recipes.put(resourceLocation, new ShapedRecipes("", j, k, recipeArray, output));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-12 15:23:32 +02:00
|
|
|
public void addShapelessRecipe(ResourceLocation resourceLocation, ItemStack output, Object... components) {
|
2017-06-11 22:22:07 +02:00
|
|
|
NonNullList<Ingredient> ingredients = NonNullList.create();
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int j = 0; j < components.length; j++) {
|
2017-06-11 22:22:07 +02:00
|
|
|
ingredients.add(CraftingHelper.toIngredient(components[j]));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2017-06-11 22:22:07 +02:00
|
|
|
recipes.put(resourceLocation, new ShapelessRecipes("", output, ingredients));
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemStack findMatchingRecipe(InventoryCrafting inv, World world) {
|
|
|
|
for (int k = 0; k < recipes.size(); k++) {
|
|
|
|
IRecipe irecipe = recipes.get(k);
|
|
|
|
if (irecipe.matches(inv, world)) {
|
|
|
|
return irecipe.getCraftingResult(inv);
|
|
|
|
}
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-13 12:26:08 +02:00
|
|
|
return ItemStack.EMPTY;
|
2016-10-08 21:46:16 +02:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2017-06-11 22:22:07 +02:00
|
|
|
public HashMap<ResourceLocation, IRecipe> getRecipeList() {
|
2016-10-08 21:46:16 +02:00
|
|
|
return recipes;
|
|
|
|
}
|
2015-04-15 18:27:05 +02:00
|
|
|
|
|
|
|
}
|