Update to support updated recipe format in reborn core.
This commit is contained in:
parent
d435d5d772
commit
6aa8fde64a
7 changed files with 54 additions and 91 deletions
|
@ -26,7 +26,6 @@ import reborncore.common.util.LogHelper;
|
||||||
import reborncore.common.util.VersionChecker;
|
import reborncore.common.util.VersionChecker;
|
||||||
import techreborn.achievement.TRAchievements;
|
import techreborn.achievement.TRAchievements;
|
||||||
import techreborn.api.TechRebornAPI;
|
import techreborn.api.TechRebornAPI;
|
||||||
import techreborn.api.recipe.recipeConfig.RecipeConfigManager;
|
|
||||||
import techreborn.client.GuiHandler;
|
import techreborn.client.GuiHandler;
|
||||||
import techreborn.command.TechRebornDevCommand;
|
import techreborn.command.TechRebornDevCommand;
|
||||||
import techreborn.compat.CompatManager;
|
import techreborn.compat.CompatManager;
|
||||||
|
@ -105,8 +104,6 @@ public class Core {
|
||||||
OreDict.init();
|
OreDict.init();
|
||||||
proxy.preInit(event);
|
proxy.preInit(event);
|
||||||
|
|
||||||
RecipeConfigManager.load(event.getModConfigurationDirectory());
|
|
||||||
|
|
||||||
versionChecker = new VersionChecker("TechReborn", new ModInfo());
|
versionChecker = new VersionChecker("TechReborn", new ModInfo());
|
||||||
versionChecker.checkVersionThreaded();
|
versionChecker.checkVersionThreaded();
|
||||||
logHelper.info("PreInitialization Complete");
|
logHelper.info("PreInitialization Complete");
|
||||||
|
|
|
@ -3,6 +3,7 @@ package techreborn.api.recipe;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import reborncore.api.recipe.IBaseRecipeType;
|
import reborncore.api.recipe.IBaseRecipeType;
|
||||||
|
import reborncore.common.recipes.RecipeTranslator;
|
||||||
|
|
||||||
import java.security.InvalidParameterException;
|
import java.security.InvalidParameterException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -16,7 +17,7 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
|
||||||
public String name;
|
public String name;
|
||||||
public int tickTime;
|
public int tickTime;
|
||||||
public int euPerTick;
|
public int euPerTick;
|
||||||
private ArrayList<ItemStack> inputs;
|
private ArrayList<Object> inputs;
|
||||||
private ArrayList<ItemStack> outputs;
|
private ArrayList<ItemStack> outputs;
|
||||||
private boolean oreDict = true;
|
private boolean oreDict = true;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemStack> getInputs() {
|
public List<Object> getInputs() {
|
||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,10 +102,18 @@ public abstract class BaseRecipe implements IBaseRecipeType, Cloneable {
|
||||||
return outputs;
|
return outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addInput(ItemStack inuput) {
|
public void addInput(Object inuput) {
|
||||||
if (inuput == null || inuput.isEmpty()) {
|
if (inuput == null) {
|
||||||
throw new InvalidParameterException("input is invalid!");
|
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);
|
inputs.add(inuput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import reborncore.api.recipe.IBaseRecipeType;
|
import reborncore.api.recipe.IBaseRecipeType;
|
||||||
import reborncore.api.recipe.RecipeHandler;
|
import reborncore.api.recipe.RecipeHandler;
|
||||||
import reborncore.common.container.RebornContainer;
|
import reborncore.common.container.RebornContainer;
|
||||||
|
import reborncore.common.recipes.RecipeTranslator;
|
||||||
import reborncore.common.util.ItemUtils;
|
import reborncore.common.util.ItemUtils;
|
||||||
import techreborn.api.recipe.machines.AlloySmelterRecipe;
|
import techreborn.api.recipe.machines.AlloySmelterRecipe;
|
||||||
import techreborn.tiles.TileAlloyFurnace;
|
import techreborn.tiles.TileAlloyFurnace;
|
||||||
|
@ -65,7 +66,7 @@ public class ContainerAlloyFurnace extends RebornContainer {
|
||||||
ItemStack stack) {
|
ItemStack stack) {
|
||||||
for(IBaseRecipeType recipe : RecipeHandler.recipeList){
|
for(IBaseRecipeType recipe : RecipeHandler.recipeList){
|
||||||
if(recipe instanceof AlloySmelterRecipe){
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,17 @@ public abstract class BaseRecipeWrapper<T extends BaseRecipe> extends BlankRecip
|
||||||
|
|
||||||
inputs = new ArrayList<>();
|
inputs = new ArrayList<>();
|
||||||
outputs = new ArrayList<>();
|
outputs = new ArrayList<>();
|
||||||
for (ItemStack input : baseRecipe.getInputs()) {
|
for (Object input : baseRecipe.getInputs()) {
|
||||||
|
if(input instanceof ItemStack){
|
||||||
|
ItemStack stack = (ItemStack) input;
|
||||||
if (baseRecipe.useOreDic()) {
|
if (baseRecipe.useOreDic()) {
|
||||||
List<ItemStack> oreDictInputs = expandOreDict(input);
|
List<ItemStack> oreDictInputs = expandOreDict(stack);
|
||||||
inputs.add(oreDictInputs);
|
inputs.add(oreDictInputs);
|
||||||
} else {
|
} else {
|
||||||
inputs.add(Collections.singletonList(input));
|
inputs.add(Collections.singletonList(stack));
|
||||||
|
}
|
||||||
|
} else if (input instanceof String){
|
||||||
|
inputs.add(OreDictionary.getOres((String) input));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ItemStack input : baseRecipe.getOutputs()) {
|
for (ItemStack input : baseRecipe.getOutputs()) {
|
||||||
|
|
|
@ -129,8 +129,9 @@ public class MTGeneric {
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(name)) {
|
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(name)) {
|
||||||
for (ItemStack stack : recipeType.getInputs()) {
|
for (Object stack : recipeType.getInputs()) {
|
||||||
if (output.matches(MineTweakerMC.getIItemStack(stack))) {
|
if(stack instanceof ItemStack){
|
||||||
|
if (output.matches(MineTweakerMC.getIItemStack((ItemStack) stack))) {
|
||||||
removedRecipes.add((BaseRecipe) recipeType);
|
removedRecipes.add((BaseRecipe) recipeType);
|
||||||
RecipeHandler.recipeList.remove(recipeType);
|
RecipeHandler.recipeList.remove(recipeType);
|
||||||
break;
|
break;
|
||||||
|
@ -138,6 +139,7 @@ public class MTGeneric {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undo() {
|
public void undo() {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import reborncore.api.recipe.IBaseRecipeType;
|
||||||
import reborncore.api.recipe.RecipeHandler;
|
import reborncore.api.recipe.RecipeHandler;
|
||||||
import reborncore.api.tile.IInventoryProvider;
|
import reborncore.api.tile.IInventoryProvider;
|
||||||
import reborncore.common.IWrenchable;
|
import reborncore.common.IWrenchable;
|
||||||
|
import reborncore.common.recipes.RecipeTranslator;
|
||||||
import reborncore.common.tile.TileLegacyMachineBase;
|
import reborncore.common.tile.TileLegacyMachineBase;
|
||||||
import reborncore.common.util.Inventory;
|
import reborncore.common.util.Inventory;
|
||||||
import reborncore.common.util.ItemUtils;
|
import reborncore.common.util.ItemUtils;
|
||||||
|
@ -124,14 +125,20 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
|
||||||
if (recipeType == null) {
|
if (recipeType == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (ItemStack input : recipeType.getInputs()) {
|
for (Object input : recipeType.getInputs()) {
|
||||||
Boolean hasItem = false;
|
boolean hasItem = false;
|
||||||
|
boolean useOreDict = input instanceof String || recipeType.useOreDic();
|
||||||
|
boolean checkSize = input instanceof ItemStack;
|
||||||
for (int inputslot = 0; inputslot < 2; inputslot++) {
|
for (int inputslot = 0; inputslot < 2; inputslot++) {
|
||||||
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputslot), true, true,
|
if (ItemUtils.isInputEqual(input, inventory.getStackInSlot(inputslot), true, true,
|
||||||
recipeType.useOreDic()) && inventory.getStackInSlot(inputslot).getCount() >= input.getCount()) {
|
useOreDict)) {
|
||||||
|
ItemStack stack = RecipeTranslator.getStackFromObject(input);
|
||||||
|
if(!checkSize || inventory.getStackInSlot(inputslot).getCount() >= stack.getCount()){
|
||||||
hasItem = true;
|
hasItem = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!hasItem)
|
if (!hasItem)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -199,11 +206,16 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
|
||||||
hasAllRecipes = false;
|
hasAllRecipes = false;
|
||||||
}
|
}
|
||||||
if (hasAllRecipes) {
|
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++) {
|
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
|
||||||
if (ItemUtils.isItemEqual(input, inventory.getStackInSlot(inputSlot), true, true,
|
if (ItemUtils.isInputEqual(input, inventory.getStackInSlot(inputSlot), true, true,
|
||||||
recipeType.useOreDic())) {
|
useOreDict)) {
|
||||||
inventory.decrStackSize(inputSlot, input.getCount());
|
int count = 1;
|
||||||
|
if(input instanceof ItemStack){
|
||||||
|
count = RecipeTranslator.getStackFromObject(input).getCount();
|
||||||
|
}
|
||||||
|
inventory.decrStackSize(inputSlot, count);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue