Update to support updated recipe format in reborn core.

This commit is contained in:
modmuss50 2017-01-08 21:43:15 +00:00
parent d435d5d772
commit 6aa8fde64a
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
7 changed files with 54 additions and 91 deletions

View file

@ -26,7 +26,6 @@ import reborncore.common.util.LogHelper;
import reborncore.common.util.VersionChecker;
import techreborn.achievement.TRAchievements;
import techreborn.api.TechRebornAPI;
import techreborn.api.recipe.recipeConfig.RecipeConfigManager;
import techreborn.client.GuiHandler;
import techreborn.command.TechRebornDevCommand;
import techreborn.compat.CompatManager;
@ -105,8 +104,6 @@ public class Core {
OreDict.init();
proxy.preInit(event);
RecipeConfigManager.load(event.getModConfigurationDirectory());
versionChecker = new VersionChecker("TechReborn", new ModInfo());
versionChecker.checkVersionThreaded();
logHelper.info("PreInitialization Complete");

View file

@ -3,6 +3,7 @@ package techreborn.api.recipe;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import reborncore.api.recipe.IBaseRecipeType;
import reborncore.common.recipes.RecipeTranslator;
import java.security.InvalidParameterException;
import java.util.ArrayList;
@ -16,7 +17,7 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
public String name;
public int tickTime;
public int euPerTick;
private ArrayList<ItemStack> inputs;
private ArrayList<Object> inputs;
private ArrayList<ItemStack> outputs;
private boolean oreDict = true;
@ -47,7 +48,7 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
}
@Override
public List<ItemStack> getInputs() {
public List<Object> getInputs() {
return inputs;
}
@ -101,10 +102,18 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
return outputs;
}
public void addInput(ItemStack inuput) {
if (inuput == null || inuput.isEmpty()) {
public void addInput(Object inuput) {
if (inuput == null) {
throw new InvalidParameterException("input is invalid!");
}
if(inuput instanceof ItemStack){
if(((ItemStack) inuput).isEmpty()){
throw new InvalidParameterException("input is invalid!");
}
}
if(RecipeTranslator.getStackFromObject(inuput) == null){
throw new InvalidParameterException("Could not determin recipe input for " + inuput);
}
inputs.add(inuput);
}
}

View file

@ -1,63 +0,0 @@
package techreborn.api.recipe.recipeConfig;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.minecraft.item.ItemStack;
import reborncore.api.recipe.IBaseRecipeType;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class RecipeConfigManager {
public static ArrayList<RecipeConfig> configs = new ArrayList<>();
static File configFile = null;
public static void load(File configDir) {
if (configFile == null) {
configFile = new File(configDir, "techRebornRecipes.json");
}
}
public static void save() {
if (configFile.exists()) {
configFile.delete();
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(configs);
try {
FileWriter writer = new FileWriter(configFile);
writer.write(json);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean canLoadRecipe(IBaseRecipeType recipeType) {
RecipeConfig config = new RecipeConfig();
for (ItemStack stack : recipeType.getInputs()) {
config.addInputs(itemToConfig(stack));
}
for (ItemStack stack : recipeType.getOutputs()) {
config.addOutputs(itemToConfig(stack));
}
config.enabled = true;
config.setMachine(recipeType.getRecipeName());
configs.add(config);
return config.enabled;
}
public static ConfigItem itemToConfig(ItemStack stack) {
ConfigItem newItem = new ConfigItem();
newItem.setItemName(stack.getItem().getUnlocalizedName());
newItem.setMeta(stack.getItemDamage());
newItem.setStackSize(stack.getCount());
newItem.setLocalName(stack.getDisplayName());
return newItem;
}
}

View file

@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
import reborncore.api.recipe.IBaseRecipeType;
import reborncore.api.recipe.RecipeHandler;
import reborncore.common.container.RebornContainer;
import reborncore.common.recipes.RecipeTranslator;
import reborncore.common.util.ItemUtils;
import techreborn.api.recipe.machines.AlloySmelterRecipe;
import techreborn.tiles.TileAlloyFurnace;
@ -65,7 +66,7 @@ public class ContainerAlloyFurnace extends RebornContainer {
ItemStack stack) {
for(IBaseRecipeType recipe : RecipeHandler.recipeList){
if(recipe instanceof AlloySmelterRecipe){
if(ItemUtils.isItemEqual(recipe.getInputs().get(recipeSlot), stack, true, true, true)){
if(ItemUtils.isInputEqual(recipe.getInputs().get(recipeSlot), stack, true, true, true)){
return true;
}
}

View file

@ -22,12 +22,17 @@ public abstract class BaseRecipeWrapper<T extends BaseRecipe> extends BlankRecip
inputs = new ArrayList<>();
outputs = new ArrayList<>();
for (ItemStack input : baseRecipe.getInputs()) {
if (baseRecipe.useOreDic()) {
List<ItemStack> oreDictInputs = expandOreDict(input);
inputs.add(oreDictInputs);
} else {
inputs.add(Collections.singletonList(input));
for (Object input : baseRecipe.getInputs()) {
if(input instanceof ItemStack){
ItemStack stack = (ItemStack) input;
if (baseRecipe.useOreDic()) {
List<ItemStack> oreDictInputs = expandOreDict(stack);
inputs.add(oreDictInputs);
} else {
inputs.add(Collections.singletonList(stack));
}
} else if (input instanceof String){
inputs.add(OreDictionary.getOres((String) input));
}
}
for (ItemStack input : baseRecipe.getOutputs()) {

View file

@ -129,11 +129,13 @@ public class MTGeneric {
@Override
public void apply() {
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(name)) {
for (ItemStack stack : recipeType.getInputs()) {
if (output.matches(MineTweakerMC.getIItemStack(stack))) {
removedRecipes.add((BaseRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
for (Object stack : recipeType.getInputs()) {
if(stack instanceof ItemStack){
if (output.matches(MineTweakerMC.getIItemStack((ItemStack) stack))) {
removedRecipes.add((BaseRecipe) recipeType);
RecipeHandler.recipeList.remove(recipeType);
break;
}
}
}
}

View file

@ -12,6 +12,7 @@ import reborncore.api.recipe.IBaseRecipeType;
import reborncore.api.recipe.RecipeHandler;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.recipes.RecipeTranslator;
import reborncore.common.tile.TileLegacyMachineBase;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
@ -124,14 +125,20 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
if (recipeType == null) {
return false;
}
for (ItemStack input : recipeType.getInputs()) {
Boolean hasItem = false;
for (Object input : recipeType.getInputs()) {
boolean hasItem = false;
boolean useOreDict = input instanceof String || recipeType.useOreDic();
boolean checkSize = input instanceof ItemStack;
for (int inputslot = 0; inputslot < 2; inputslot++) {
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true,
recipeType.useOreDic()) && inventory.getStackInSlot(inputslot).getCount() >= input.getCount()) {
hasItem = true;
if (ItemUtils.isInputEqual(input, inventory.getStackInSlot(inputslot), true, true,
useOreDict)) {
ItemStack stack = RecipeTranslator.getStackFromObject(input);
if(!checkSize || inventory.getStackInSlot(inputslot).getCount() >= stack.getCount()){
hasItem = true;
}
}
}
if (!hasItem)
return false;
}
@ -199,11 +206,16 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
hasAllRecipes = false;
}
if (hasAllRecipes) {
for (ItemStack input : recipeType.getInputs()) {
for (Object input : recipeType.getInputs()) {
boolean useOreDict = input instanceof String || recipeType.useOreDic();
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true,
recipeType.useOreDic())) {
inventory.decrStackSize(inputSlot, input.getCount());
if (ItemUtils.isInputEqual(input, inventory.getStackInSlot(inputSlot), true, true,
useOreDict)) {
int count = 1;
if(input instanceof ItemStack){
count = RecipeTranslator.getStackFromObject(input).getCount();
}
inventory.decrStackSize(inputSlot, count);
break;
}
}