finalized recipe refactoring, close #1861

This commit is contained in:
SpaceToad 2014-06-06 09:00:11 +02:00
parent 55bc2ef39a
commit 81bc0fe11b
30 changed files with 602 additions and 429 deletions

View file

@ -14,12 +14,13 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public class CraftingResult {
public class CraftingResult<T> {
public Object crafted = null;
public T crafted = null;
public ArrayList<ItemStack> usedItems = new ArrayList<ItemStack>();
public ArrayList<FluidStack> usedFluids = new ArrayList<FluidStack>();
public double energyCost = 0;
public long craftingTime = 0;
public IFlexibleRecipe recipe;
}

View file

@ -27,7 +27,7 @@ public interface IAssemblyRecipeManager {
*/
void addRecipe(String id, double energyCost, ItemStack output, Object... input);
void addRecipe(IFlexibleRecipe recipe);
void addRecipe(IFlexibleRecipe<ItemStack> recipe);
Collection<IFlexibleRecipe> getRecipes();
Collection<IFlexibleRecipe<ItemStack>> getRecipes();
}

View file

@ -0,0 +1,29 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.recipes;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public interface IFlexibleCrafter {
public int getCraftingItemStackSize();
public ItemStack getCraftingItemStack(int slotid);
public ItemStack decrCraftingItemgStack(int slotid, int val);
public FluidStack getCraftingFluidStack(int tankid);
public FluidStack decrCraftingFluidStack(int tankid, int val);
public int getCraftingFluidStackSize();
}

View file

@ -8,17 +8,11 @@
*/
package buildcraft.api.recipes;
import net.minecraft.inventory.IInventory;
public interface IFlexibleRecipe<T> {
import net.minecraftforge.fluids.IFluidHandler;
boolean canBeCrafted(IFlexibleCrafter crafter);
public interface IFlexibleRecipe {
boolean canBeCrafted(IInventory items, IFluidHandler fluids);
CraftingResult craftPreview(IInventory items, IFluidHandler fluids);
CraftingResult craft(IInventory items, IFluidHandler fluids);
CraftingResult<T> craft(IFlexibleCrafter crafter, boolean preview);
String getId();

View file

@ -10,7 +10,7 @@ package buildcraft.api.recipes;
import net.minecraft.item.ItemStack;
public interface IIntegrationRecipeFactory extends IFlexibleRecipe {
public interface IIntegrationRecipe extends IFlexibleRecipe<ItemStack> {
boolean isValidInputA(ItemStack inputA);

View file

@ -19,7 +19,7 @@ public interface IIntegrationRecipeManager {
/**
* Add an Integration Table recipe.
*/
void addRecipe(IIntegrationRecipeFactory recipe);
void addRecipe(IIntegrationRecipe recipe);
List<? extends IIntegrationRecipeFactory> getRecipes();
List<? extends IIntegrationRecipe> getRecipes();
}

View file

@ -8,30 +8,18 @@
*/
package buildcraft.api.recipes;
import java.util.SortedSet;
import java.util.Collection;
import net.minecraftforge.fluids.FluidStack;
public interface IRefineryRecipeManager {
void addRecipe(FluidStack ingredient, FluidStack result, int energy, int delay);
void addRecipe(String id, FluidStack ingredient, FluidStack result, int energy, int delay);
void addRecipe(FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay);
void addRecipe(String id, FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay);
SortedSet<? extends IRefineryRecipe> getRecipes();
Collection<IFlexibleRecipe<FluidStack>> getRecipes();
IRefineryRecipe findRefineryRecipe(FluidStack ingredient1, FluidStack ingredient2);
IFlexibleRecipe<FluidStack> getRecipe(String currentRecipeId);
public interface IRefineryRecipe {
FluidStack getIngredient1();
FluidStack getIngredient2();
FluidStack getResult();
int getEnergyCost();
int getTimeRequired();
}
}

View file

@ -258,7 +258,8 @@ public class BuildCraftEnergy extends BuildCraftMod {
BucketHandler.INSTANCE.buckets.put(blockFuel, bucketFuel);
MinecraftForge.EVENT_BUS.register(BucketHandler.INSTANCE);
BuildcraftRecipeRegistry.refinery.addRecipe(new FluidStack(fluidOil, 1), new FluidStack(fluidFuel, 1), 12, 1);
BuildcraftRecipeRegistry.refinery.addRecipe("buildcraft:fuel", new FluidStack(fluidOil, 1), new FluidStack(
fluidFuel, 1), 12, 1);
// Iron Engine Fuels
// IronEngineFuel.addFuel("lava", 1, 20000);

View file

@ -104,17 +104,20 @@ public final class InterModComms {
failed = true;
} else {
NBTTagCompound recipe = msg.getNBTValue();
if (!recipe.hasKey("input", 10) || !recipe.hasKey("output", 10) || !recipe.hasKey("energy", 3) || !recipe.hasKey("delay", 3)) {
if (!recipe.hasKey("id") && !recipe.hasKey("input", 10) || !recipe.hasKey("output", 10)
|| !recipe.hasKey("energy", 3) || !recipe.hasKey("delay", 3)) {
failed = true;
} else {
FluidStack output = FluidStack.loadFluidStackFromNBT(recipe.getCompoundTag("output"));
FluidStack input = FluidStack.loadFluidStackFromNBT(recipe.getCompoundTag("input"));
FluidStack input2 = null;
String id = recipe.getString("id");
if (recipe.hasKey("input_2", 10)) {
input2 = FluidStack.loadFluidStackFromNBT(recipe.getCompoundTag("input_2"));
}
if (input != null && output != null) {
RefineryRecipeManager.INSTANCE.addRecipe(input, input2, output, recipe.getInteger("energy"), recipe.getInteger("delay"));
RefineryRecipeManager.INSTANCE.addRecipe(id, input, input2, output, recipe.getInteger("energy"),
recipe.getInteger("delay"));
} else {
failed = true;
}

View file

@ -92,7 +92,7 @@ public abstract class TileBuildCraft extends TileEntity implements ISynchronized
}
public void sendNetworkUpdate() {
if (!worldObj.isRemote) {
if (worldObj != null && !worldObj.isRemote) {
BuildCraftCore.instance.sendToPlayers(getUpdatePacket(), worldObj,
xCoord, yCoord, zCoord, DefaultProps.NETWORK_UPDATE_RANGE);
}

View file

@ -0,0 +1,100 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.inventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.recipes.IFlexibleCrafter;
public class CrafterCopy implements IFlexibleCrafter {
private ItemStack[] items;
private FluidStack[] fluids;
public CrafterCopy(IFlexibleCrafter origin) {
items = new ItemStack[origin.getCraftingItemStackSize()];
for (int i = 0; i < items.length; ++i) {
ItemStack s = origin.getCraftingItemStack(i);
if (s != null) {
items[i] = s.copy();
} else {
items[i] = null;
}
}
fluids = new FluidStack[origin.getCraftingFluidStackSize()];
for (int i = 0; i < fluids.length; ++i) {
FluidStack f = origin.getCraftingFluidStack(i);
if (f != null) {
fluids[i] = origin.getCraftingFluidStack(i).copy();
} else {
fluids[i] = null;
}
}
}
@Override
public int getCraftingItemStackSize() {
return items.length;
}
@Override
public ItemStack getCraftingItemStack(int slotid) {
return items[slotid];
}
@Override
public ItemStack decrCraftingItemgStack(int slotid, int val) {
ItemStack result;
if (val >= items[slotid].stackSize) {
result = items[slotid];
items[slotid] = null;
} else {
result = items[slotid].copy();
result.stackSize = val;
items[slotid].stackSize -= val;
}
return result;
}
@Override
public FluidStack getCraftingFluidStack(int tankid) {
return fluids[tankid];
}
@Override
public FluidStack decrCraftingFluidStack(int tankid, int val) {
FluidStack result;
if (val >= fluids[tankid].amount) {
result = fluids[tankid];
fluids[tankid] = null;
} else {
result = fluids[tankid].copy();
result.amount = val;
fluids[tankid].amount -= val;
}
return result;
}
@Override
public int getCraftingFluidStackSize() {
return fluids.length;
}
}

View file

@ -28,7 +28,11 @@ public class FluidHandlerCopy implements IFluidHandler {
for (int i = 0; i < contents.length; i++) {
if (originalInfo[i] != null) {
contents[i] = new FluidTankInfo(originalInfo[i].fluid.copy(), originalInfo[i].capacity);
if (originalInfo[i].fluid != null) {
contents[i] = new FluidTankInfo(originalInfo[i].fluid.copy(), originalInfo[i].capacity);
} else {
contents[i] = new FluidTankInfo(null, originalInfo[i].capacity);
}
}
}
}

View file

@ -22,7 +22,7 @@ import buildcraft.api.recipes.IFlexibleRecipe;
public class AssemblyRecipeManager implements IAssemblyRecipeManager {
public static final AssemblyRecipeManager INSTANCE = new AssemblyRecipeManager();
private Map<String, IFlexibleRecipe> assemblyRecipes = new HashMap<String, IFlexibleRecipe>();
private Map<String, IFlexibleRecipe<ItemStack>> assemblyRecipes = new HashMap<String, IFlexibleRecipe<ItemStack>>();
@Override
public void addRecipe(String id, double energyCost, ItemStack output, Object... input) {
@ -32,7 +32,7 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
return;
}
addRecipe(id, new FlexibleRecipe(id, output, energyCost, input));
addRecipe(id, new FlexibleRecipe(id, output, energyCost, 0, input));
}
@Override
@ -49,7 +49,7 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
}
@Override
public Collection<IFlexibleRecipe> getRecipes() {
public Collection<IFlexibleRecipe<ItemStack>> getRecipes() {
return assemblyRecipes.values();
}

View file

@ -12,30 +12,23 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleCrafter;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.core.inventory.FluidHandlerCopy;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.InventoryCopy;
import buildcraft.core.inventory.Transactor;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
public class FlexibleRecipe implements IFlexibleRecipe {
public class FlexibleRecipe<T> implements IFlexibleRecipe<T> {
public double energyCost = 0;
public long craftingTime = 0;
public String id;
public ItemStack outputItems = null;
public FluidStack outputFluids = null;
public T output = null;
public ArrayList<ItemStack> inputItems = new ArrayList<ItemStack>();
public ArrayList<List<ItemStack>> inputItemsWithAlternatives = new ArrayList<List<ItemStack>>();
@ -46,26 +39,27 @@ public class FlexibleRecipe implements IFlexibleRecipe {
}
public FlexibleRecipe(String id, Object output, double iEnergyCost, Object... input) {
setContents(id, output, iEnergyCost, input);
public FlexibleRecipe(String id, T output, double iEnergyCost, long craftingTime, Object... input) {
setContents(id, output, iEnergyCost, craftingTime, input);
}
public void setContents(String iid, Object output, double iEnergyCost, Object... input) {
public void setContents(String iid, Object ioutput, double iEnergyCost, long iCraftingTime, Object... input) {
id = iid;
if (output instanceof ItemStack) {
outputItems = (ItemStack) output;
} else if (output instanceof Item) {
outputItems = new ItemStack((Item) output);
} else if (output instanceof Block) {
outputItems = new ItemStack((Block) output);
} else if (output instanceof FluidStack) {
outputFluids = (FluidStack) output;
if (ioutput instanceof ItemStack) {
output = (T) ioutput;
} else if (ioutput instanceof Item) {
output = (T) new ItemStack((Item) ioutput);
} else if (ioutput instanceof Block) {
output = (T) new ItemStack((Block) ioutput);
} else if (ioutput instanceof FluidStack) {
output = (T) ioutput;
} else {
throw new IllegalArgumentException("Unknown Object passed to recipe!");
}
energyCost = iEnergyCost;
craftingTime = iCraftingTime;
for (Object i : input) {
if (i instanceof ItemStack) {
@ -79,140 +73,140 @@ public class FlexibleRecipe implements IFlexibleRecipe {
} else if (i instanceof List) {
inputItemsWithAlternatives.add((List) i);
} else {
throw new IllegalArgumentException("Unknown Object passed to recipe!");
throw new IllegalArgumentException("Unknown Object passed to recipe (" + i.getClass() + ")");
}
}
}
@Override
public boolean canBeCrafted(IInventory items, IFluidHandler fluids) {
return craftPreview(items, fluids) != null;
public boolean canBeCrafted(IFlexibleCrafter crafter) {
return craft(crafter, true) != null;
}
@Override
public final CraftingResult craftPreview(IInventory items, IFluidHandler fluids) {
return craft(items == null ? null : new InventoryCopy(items),
fluids == null ? null : new FluidHandlerCopy(fluids));
}
@Override
public CraftingResult craft(IInventory items, IFluidHandler fluids) {
CraftingResult result = new CraftingResult();
result.recipe = this;
result.energyCost = energyCost;
// Item simple stacks consumption
if (items == null && inputItems.size() > 0) {
public CraftingResult<T> craft(IFlexibleCrafter crafter, boolean preview) {
if (output == null) {
return null;
}
if (items != null) {
ITransactor tran = Transactor.getTransactorFor(items);
CraftingResult<T> result = new CraftingResult();
for (ItemStack requirement : inputItems) {
IStackFilter filter = new ArrayStackFilter(requirement);
result.recipe = this;
result.energyCost = energyCost;
result.craftingTime = craftingTime;
for (int num = 0; num < requirement.stackSize; num++) {
ItemStack s = tran.remove(filter, ForgeDirection.UNKNOWN, true);
for (ItemStack requirement : inputItems) {
IStackFilter filter = new ArrayStackFilter(requirement);
int amount = requirement.stackSize;
if (s == null) {
return null;
} else {
result.usedItems.add(s);
}
}
if (consumeItems(crafter, result, filter, amount, preview) != 0) {
return null;
}
}
// Item stacks with alternatives consumption
if (items == null && inputItemsWithAlternatives.size() > 0) {
return null;
}
for (List<ItemStack> requirements : inputItemsWithAlternatives) {
IStackFilter filter = new ArrayStackFilter(requirements.toArray(new ItemStack[0]));
int amount = requirements.get(0).stackSize;
if (items != null) {
ITransactor tran = Transactor.getTransactorFor(items);
for (List<ItemStack> requirements : inputItemsWithAlternatives) {
int required = requirements.get(0).stackSize;
IStackFilter filter = new ArrayStackFilter(requirements.toArray(new ItemStack [0]));
for (int num = 0; num < required; num++) {
ItemStack s = tran.remove(filter, ForgeDirection.UNKNOWN, true);
if (s != null) {
result.usedItems.add(s);
required--;
if (required == 0) {
break;
}
}
}
if (required > 0) {
return null;
}
if (consumeItems(crafter, result, filter, amount, preview) != 0) {
return null;
}
}
// Fluid stacks consumption
if (fluids == null && inputFluids.size() > 0) {
return null;
}
for (FluidStack requirement : inputFluids) {
int amount = requirement.amount;
if (fluids != null) {
for (FluidStack requirement : inputFluids) {
for (FluidTankInfo info : fluids.getTankInfo(ForgeDirection.UNKNOWN)) {
if (info.fluid.isFluidEqual(requirement)) {
int amountUsed = 0;
for (int tankid = 0; tankid < crafter.getCraftingFluidStackSize(); tankid++) {
FluidStack fluid = crafter.getCraftingFluidStack(tankid);
if (info.fluid.amount > requirement.amount) {
requirement.amount = 0;
info.fluid.amount -= requirement.amount;
amountUsed += requirement.amount;
} else {
requirement.amount -= info.fluid.amount;
info.fluid.amount = 0;
amountUsed += info.fluid.amount;
if (fluid != null && fluid.isFluidEqual(requirement)) {
int amountUsed = 0;
if (fluid.amount > amount) {
amountUsed = amount;
if (!preview) {
crafter.decrCraftingFluidStack(tankid, amount);
}
result.usedFluids.add(new FluidStack(requirement.fluidID, amountUsed));
amount = 0;
} else {
amountUsed = fluid.amount;
if (!preview) {
crafter.decrCraftingFluidStack(tankid, fluid.amount);
}
amount -= fluid.amount;
}
result.usedFluids.add(new FluidStack(requirement.fluidID, amountUsed));
}
if (amount == 0) {
break;
}
}
}
for (FluidStack requirement : inputFluids) {
if (requirement.amount > 0) {
if (amount != 0) {
return null;
}
}
// Output generation
if (outputItems != null) {
result.crafted = outputItems;
result.crafted = output;
return result;
} else if (outputFluids != null) {
result.crafted = outputFluids;
return result;
} else {
return null;
}
return result;
}
@Override
public String getId() {
return id;
}
private int consumeItems(IFlexibleCrafter crafter, CraftingResult<T> result, IStackFilter filter,
int amount, boolean preview) {
int expected = amount;
for (int slotid = 0; slotid < crafter.getCraftingItemStackSize(); ++slotid) {
ItemStack stack = crafter.getCraftingItemStack(slotid);
if (stack != null && filter.matches(stack)) {
ItemStack removed = null;
if (stack.stackSize >= expected) {
if (preview) {
removed = stack.copy();
removed.stackSize = expected;
} else {
removed = crafter.decrCraftingItemgStack(slotid, expected);
}
expected = 0;
} else {
if (preview) {
removed = stack.copy();
} else {
removed = crafter.decrCraftingItemgStack(slotid, stack.stackSize);
}
expected -= removed.stackSize;
}
result.usedItems.add(removed);
}
if (expected == 0) {
return 0;
}
}
return amount;
}
}

View file

@ -11,20 +11,20 @@ package buildcraft.core.recipes;
import java.util.LinkedList;
import java.util.List;
import buildcraft.api.recipes.IIntegrationRecipeFactory;
import buildcraft.api.recipes.IIntegrationRecipe;
import buildcraft.api.recipes.IIntegrationRecipeManager;
public class IntegrationRecipeManager implements IIntegrationRecipeManager {
public static final IntegrationRecipeManager INSTANCE = new IntegrationRecipeManager();
private List<IIntegrationRecipeFactory> integrationRecipes = new LinkedList<IIntegrationRecipeFactory>();
private List<IIntegrationRecipe> integrationRecipes = new LinkedList<IIntegrationRecipe>();
@Override
public void addRecipe(IIntegrationRecipeFactory recipe) {
public void addRecipe(IIntegrationRecipe recipe) {
integrationRecipes.add(recipe);
}
@Override
public List<? extends IIntegrationRecipeFactory> getRecipes() {
public List<? extends IIntegrationRecipe> getRecipes() {
return integrationRecipes;
}
}

View file

@ -8,176 +8,58 @@
*/
package buildcraft.core.recipes;
import java.util.Collection;
import java.util.Collections;
import java.util.SortedSet;
import java.util.TreeSet;
import com.google.common.base.Objects;
import java.util.HashMap;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.BuildCraftCore;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.api.recipes.IRefineryRecipeManager;
public final class RefineryRecipeManager implements IRefineryRecipeManager {
public static final RefineryRecipeManager INSTANCE = new RefineryRecipeManager();
private SortedSet<RefineryRecipe> recipes = new TreeSet<RefineryRecipe>();
private HashMap<String, IFlexibleRecipe<FluidStack>> recipes = new HashMap<String, IFlexibleRecipe<FluidStack>>();
private RefineryRecipeManager() {
}
@Override
public void addRecipe(FluidStack ingredient, FluidStack result, int energy, int delay) {
public void addRecipe(String id, FluidStack ingredient, FluidStack result, int energy, int delay) {
String name = result.getFluid().getName();
if (BuildCraftCore.recipesBlacklist.contains(name)) {
return;
}
addRecipe(ingredient, null, result, energy, delay);
FlexibleRecipe<FluidStack> recipe = new FlexibleRecipe<FluidStack>(id, result, energy, delay, ingredient);
recipes.put(id, recipe);
}
@Override
public void addRecipe(FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay) {
public void addRecipe(String id, FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy,
int delay) {
String name = result.getFluid().getName();
if (BuildCraftCore.recipesBlacklist.contains(name)) {
return;
}
RefineryRecipe recipe = new RefineryRecipe(ingredient1, ingredient2, result, energy, delay);
recipes.add(recipe);
FlexibleRecipe<FluidStack> recipe = new FlexibleRecipe<FluidStack>(id, result, energy, delay, ingredient1,
ingredient2);
recipes.put(id, recipe);
}
@Override
public SortedSet<RefineryRecipe> getRecipes() {
return Collections.unmodifiableSortedSet(recipes);
public Collection<IFlexibleRecipe<FluidStack>> getRecipes() {
return Collections.unmodifiableCollection(recipes.values());
}
@Override
public RefineryRecipe findRefineryRecipe(FluidStack liquid1, FluidStack liquid2) {
for (RefineryRecipe recipe : recipes) {
if (recipe.matches(liquid1, liquid2)) {
return recipe;
}
}
return null;
}
public static final class RefineryRecipe implements IRefineryRecipe, Comparable<RefineryRecipe> {
public final FluidStack ingredient1;
public final FluidStack ingredient2;
public final FluidStack result;
public final int energyCost;
public final int timeRequired;
private RefineryRecipe(FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay) {
if (ingredient1 == null) {
throw new IllegalArgumentException("First Ingredient cannot be null!");
}
this.ingredient1 = ingredient1;
this.ingredient2 = ingredient2;
this.result = result;
this.energyCost = energy;
this.timeRequired = delay;
}
public boolean matches(FluidStack liquid1, FluidStack liquid2) {
// No inputs, return.
if (liquid1 == null && liquid2 == null) {
return false;
}
// Return if two ingredients are required but only one was supplied.
if ((ingredient1 != null && ingredient2 != null) && (liquid1 == null || liquid2 == null)) {
return false;
}
if (liquid1 != null && liquid2 != null) {
if (liquid1.containsFluid(ingredient1) && liquid1.containsFluid(ingredient2)) {
return true;
}
if (liquid1.containsFluid(ingredient2) && liquid1.containsFluid(ingredient1)) {
return true;
}
}
if (liquid1 != null) {
return liquid1.containsFluid(ingredient1) || liquid1.containsFluid(ingredient2);
}
if (liquid2 != null) {
return liquid2.containsFluid(ingredient1) || liquid2.containsFluid(ingredient2);
}
return false;
}
// Compares to only the types of source materials.
// We consider non-null < null in order that one-ingredient recipe is checked after
// the failure of matching two-ingredient recipes which include that liquid.
@Override
public int compareTo(RefineryRecipe other) {
if (other == null) {
return -1;
} else if (ingredient1.getFluid() != other.ingredient1.getFluid()) {
return ingredient1.getFluid().getName().compareTo(other.ingredient1.getFluid().getName());
} else if (ingredient1.amount != other.ingredient1.amount) {
return other.ingredient1.amount - ingredient1.amount;
} else if (ingredient2 == null) {
return other.ingredient2 == null ? 0 : 1;
} else if (other.ingredient2 == null) {
return -1;
} else if (ingredient2.getFluid() != other.ingredient2.getFluid()) {
return ingredient2.getFluid().getName().compareTo(other.ingredient2.getFluid().getName());
} else if (ingredient2.amount != other.ingredient2.amount) {
return other.ingredient2.amount - ingredient2.amount;
}
return 0;
}
// equals() should be consistent with compareTo().
@Override
public boolean equals(Object obj) {
return obj instanceof RefineryRecipe
&& Objects.equal(ingredient1, ((RefineryRecipe) obj).ingredient1)
&& Objects.equal(ingredient2, ((RefineryRecipe) obj).ingredient2);
}
// hashCode() should be overridden because equals() was overridden.
@Override
public int hashCode() {
return Objects.hashCode(ingredient1, ingredient2);
}
@Override
public FluidStack getIngredient1() {
return ingredient1;
}
@Override
public FluidStack getIngredient2() {
return ingredient2;
}
@Override
public FluidStack getResult() {
return result;
}
@Override
public int getEnergyCost() {
return energyCost;
}
@Override
public int getTimeRequired() {
return timeRequired;
}
public IFlexibleRecipe<FluidStack> getRecipe(String id) {
return recipes.get(id);
}
}

View file

@ -8,24 +8,20 @@
*/
package buildcraft.core.robots;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IIntegrationRecipeFactory;
import buildcraft.core.ItemRobot;
import buildcraft.core.recipes.FlexibleRecipe;
import buildcraft.core.utils.NBTUtils;
import buildcraft.silicon.ItemRedstoneBoard;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.silicon.recipes.IntegrationTableRecipe;
public class RobotIntegrationRecipe extends FlexibleRecipe implements IIntegrationRecipeFactory {
public class RobotIntegrationRecipe extends IntegrationTableRecipe {
public RobotIntegrationRecipe(String id) {
setContents(id, new ItemStack(BuildCraftSilicon.robotItem), 10000);
setContents(id, new ItemStack(BuildCraftSilicon.robotItem), 10000, 0);
}
@Override
@ -39,16 +35,15 @@ public class RobotIntegrationRecipe extends FlexibleRecipe implements IIntegrati
}
@Override
public CraftingResult craft(IInventory items, IFluidHandler fluids) {
ItemStack inputA = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_A, 1);
ItemStack inputB = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_B, 1);
public CraftingResult craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
CraftingResult result = super.craft(items, fluids);
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
if (result != null) {
ItemStack robot = new ItemStack(BuildCraftSilicon.robotItem);
NBTUtils.getItemData(robot).setTag("board", NBTUtils.getItemData(items.getStackInSlot(1)));
NBTUtils.getItemData(robot).setTag("board", NBTUtils.getItemData(inputA));
result.crafted = robot;

View file

@ -28,9 +28,13 @@ import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.NetworkData;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.gates.IAction;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleCrafter;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.fluids.SingleUseTank;
@ -38,21 +42,28 @@ import buildcraft.core.fluids.TankManager;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.recipes.RefineryRecipeManager;
import buildcraft.core.recipes.RefineryRecipeManager.RefineryRecipe;
public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInventory, IMachine {
public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInventory, IMachine, IFlexibleCrafter {
public static int LIQUID_PER_SLOT = FluidContainerRegistry.BUCKET_VOLUME * 4;
public SingleUseTank tank1 = new SingleUseTank("tank1", LIQUID_PER_SLOT, this);
public SingleUseTank tank2 = new SingleUseTank("tank2", LIQUID_PER_SLOT, this);
public IFlexibleRecipe<FluidStack> currentRecipe;
public CraftingResult<FluidStack> craftingResult;
public SingleUseTank[] tanks = {new SingleUseTank("tank1", LIQUID_PER_SLOT, this),
new SingleUseTank("tank2", LIQUID_PER_SLOT, this)};
public SingleUseTank result = new SingleUseTank("result", LIQUID_PER_SLOT, this);
public TankManager<SingleUseTank> tankManager = new TankManager<SingleUseTank>(tank1, tank2, result);
public TankManager<SingleUseTank> tankManager = new TankManager<SingleUseTank>(tanks[0], tanks[1], result);
public float animationSpeed = 1;
private int animationStage = 0;
private SafeTimeTracker time = new SafeTimeTracker();
private SafeTimeTracker updateNetworkTime = new SafeTimeTracker();
private SafeTimeTracker updateNetworkTime = new SafeTimeTracker(BuildCraftCore.updateFactor);
private boolean isActive;
@NetworkData
private String currentRecipeId = "";
@MjBattery(maxCapacity = 1000, maxReceivedPerCycle = 150, minimumConsumption = 1)
private double mjStored = 0;
@ -107,47 +118,39 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
return;
}
if (updateNetworkTime.markTimeIfDelay(worldObj, BuildCraftCore.updateFactor)) {
if (updateNetworkTime.markTimeIfDelay(worldObj)) {
sendNetworkUpdate();
}
isActive = false;
RefineryRecipe currentRecipe = RefineryRecipeManager.INSTANCE.findRefineryRecipe(tank1.getFluid(), tank2.getFluid());
if (currentRecipe == null) {
decreaseAnimation();
return;
}
if (result.fill(currentRecipe.result.copy(), false) != currentRecipe.result.amount) {
decreaseAnimation();
return;
}
if (!containsInput(currentRecipe.ingredient1) || !containsInput(currentRecipe.ingredient2)) {
if (result.fill(craftingResult.crafted.copy(), false) != craftingResult.crafted.amount) {
decreaseAnimation();
return;
}
isActive = true;
if (mjStored >= currentRecipe.energyCost) {
if (mjStored >= craftingResult.energyCost) {
increaseAnimation();
} else {
decreaseAnimation();
}
if (!time.markTimeIfDelay(worldObj, currentRecipe.timeRequired)) {
if (!time.markTimeIfDelay(worldObj, craftingResult.craftingTime)) {
return;
}
if (mjStored >= currentRecipe.energyCost) {
mjStored -= currentRecipe.energyCost;
if (mjStored >= craftingResult.energyCost) {
mjStored -= craftingResult.energyCost;
if (consumeInput(currentRecipe.ingredient1) && consumeInput(currentRecipe.ingredient2)) {
result.fill(currentRecipe.result, true);
}
CraftingResult<FluidStack> r = currentRecipe.craft(this, false);
result.fill(r.crafted.copy(), true);
}
}
@ -156,8 +159,8 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
return true;
}
return (tank1.getFluid() != null && tank1.getFluid().containsFluid(ingredient))
|| (tank2.getFluid() != null && tank2.getFluid().containsFluid(ingredient));
return (tanks[0].getFluid() != null && tanks[0].getFluid().containsFluid(ingredient))
|| (tanks[1].getFluid() != null && tanks[1].getFluid().containsFluid(ingredient));
}
private boolean consumeInput(FluidStack liquid) {
@ -165,11 +168,11 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
return true;
}
if (tank1.getFluid() != null && tank1.getFluid().containsFluid(liquid)) {
tank1.drain(liquid.amount, true);
if (tanks[0].getFluid() != null && tanks[0].getFluid().containsFluid(liquid)) {
tanks[0].drain(liquid.amount, true);
return true;
} else if (tank2.getFluid() != null && tank2.getFluid().containsFluid(liquid)) {
tank2.drain(liquid.amount, true);
} else if (tanks[1].getFluid() != null && tanks[1].getFluid().containsFluid(liquid)) {
tanks[1].drain(liquid.amount, true);
return true;
}
@ -201,6 +204,8 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
animationSpeed = data.getFloat("animationSpeed");
mjStored = data.getDouble("mjStored");
updateRecipe();
}
@Override
@ -318,16 +323,39 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
int used = 0;
FluidStack resourceUsing = resource.copy();
used += tank1.fill(resourceUsing, doFill);
used += tanks[0].fill(resourceUsing, doFill);
resourceUsing.amount -= used;
used += tank2.fill(resourceUsing, doFill);
used += tanks[1].fill(resourceUsing, doFill);
updateRecipe();
return used;
}
@Override
public FluidStack drain(ForgeDirection from, int maxEmpty, boolean doDrain) {
return result.drain(maxEmpty, doDrain);
FluidStack r = result.drain(maxEmpty, doDrain);
updateRecipe();
return r;
}
private void updateRecipe() {
currentRecipe = null;
craftingResult = null;
for (IFlexibleRecipe recipe : RefineryRecipeManager.INSTANCE.getRecipes()) {
craftingResult = recipe.craft(this, true);
if (craftingResult != null) {
currentRecipe = recipe;
currentRecipeId = currentRecipe.getId();
break;
}
}
sendNetworkUpdate();
}
@Override
@ -377,4 +405,58 @@ public class TileRefinery extends TileBuildCraft implements IFluidHandler, IInve
public boolean hasCustomInventoryName() {
return false;
}
@Override
public void postPacketHandling(PacketUpdate packet) {
super.postPacketHandling(packet);
currentRecipe = RefineryRecipeManager.INSTANCE.getRecipe(currentRecipeId);
if (currentRecipe != null) {
craftingResult = currentRecipe.craft(this, true);
}
}
@Override
public int getCraftingItemStackSize() {
return 0;
}
@Override
public ItemStack getCraftingItemStack(int slotid) {
return null;
}
@Override
public ItemStack decrCraftingItemgStack(int slotid, int val) {
return null;
}
@Override
public FluidStack getCraftingFluidStack(int tankid) {
return tanks[tankid].getFluid();
}
@Override
public FluidStack decrCraftingFluidStack(int tankid, int val) {
FluidStack result;
if (val >= tanks[tankid].getFluid().amount) {
result = tanks[tankid].getFluid();
tanks[tankid].setFluid(null);
} else {
result = tanks[tankid].getFluid().copy();
result.amount = val;
tanks[tankid].getFluid().amount -= val;
}
updateRecipe();
return result;
}
@Override
public int getCraftingFluidStackSize() {
return tanks.length;
}
}

View file

@ -9,11 +9,14 @@
package buildcraft.factory.gui;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraftforge.fluids.Fluid;
import buildcraft.BuildCraftFactory;
import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.network.PacketIds;
@ -23,7 +26,7 @@ import buildcraft.factory.TileRefinery;
public class ContainerRefinery extends BuildCraftContainer {
TileRefinery refinery;
public TileRefinery refinery;
public ContainerRefinery(InventoryPlayer inventory, TileRefinery refinery) {
super(refinery.getSizeInventory());

View file

@ -17,11 +17,10 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.core.DefaultProps;
import buildcraft.core.gui.AdvancedSlot;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.recipes.RefineryRecipeManager;
import buildcraft.core.recipes.RefineryRecipeManager.RefineryRecipe;
import buildcraft.core.utils.StringUtils;
import buildcraft.factory.TileRefinery;
@ -96,9 +95,9 @@ public class GuiRefinery extends GuiAdvancedInterface {
TileRefinery ref = (TileRefinery) this.tile;
if (position == 0) {
container.setFilter(position, ref.tank1.getFluidType());
container.setFilter(position, ref.tanks[0].getFluidType());
} else if (position == 1) {
container.setFilter(position, ref.tank2.getFluidType());
container.setFilter(position, ref.tanks[1].getFluidType());
}
}
}
@ -110,9 +109,9 @@ public class GuiRefinery extends GuiAdvancedInterface {
Fluid filter1 = container.getFilter(1);
((FluidSlot) slots[0]).fluid = filter0;
((FluidSlot) slots[0]).colorRenderCache = container.refinery.tank1.colorRenderCache;
((FluidSlot) slots[0]).colorRenderCache = container.refinery.tanks[0].colorRenderCache;
((FluidSlot) slots[1]).fluid = filter1;
((FluidSlot) slots[1]).colorRenderCache = container.refinery.tank2.colorRenderCache;
((FluidSlot) slots[1]).colorRenderCache = container.refinery.tanks[1].colorRenderCache;
FluidStack liquid0 = null;
FluidStack liquid1 = null;
@ -124,11 +123,11 @@ public class GuiRefinery extends GuiAdvancedInterface {
liquid1 = new FluidStack(filter1, FluidContainerRegistry.BUCKET_VOLUME);
}
RefineryRecipe recipe = RefineryRecipeManager.INSTANCE.findRefineryRecipe(liquid0, liquid1);
CraftingResult<FluidStack> crafting = container.refinery.craftingResult;
if (recipe != null) {
((FluidSlot) slots[2]).fluid = recipe.result.getFluid();
((FluidSlot) slots[2]).colorRenderCache = recipe.result.getFluid().getColor(recipe.result);
if (crafting != null) {
((FluidSlot) slots[2]).fluid = crafting.crafted.getFluid();
((FluidSlot) slots[2]).colorRenderCache = crafting.crafted.getFluid().getColor(crafting.crafted);
} else {
((FluidSlot) slots[2]).fluid = null;
}

View file

@ -81,14 +81,14 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
int angle = 0;
ModelRenderer theMagnet = magnet[0];
if (tile != null) {
if (tile.tank1.getFluid() != null) {
liquid1 = tile.tank1.getFluid();
color1 = tile.tank1.colorRenderCache;
if (tile.tanks[0].getFluid() != null) {
liquid1 = tile.tanks[0].getFluid();
color1 = tile.tanks[0].colorRenderCache;
}
if (tile.tank2.getFluid() != null) {
liquid2 = tile.tank2.getFluid();
color2 = tile.tank2.colorRenderCache;
if (tile.tanks[1].getFluid() != null) {
liquid2 = tile.tanks[1].getFluid();
color2 = tile.tanks[1].colorRenderCache;
}
if (tile.result.getFluid() != null) {
@ -193,7 +193,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
if (list1 != null) {
bindTexture(FluidRenderer.getFluidSheet(liquid1));
RenderUtils.setGLColorFromInt(color1);
GL11.glCallList(list1[getDisplayListIndex(tile.tank1)]);
GL11.glCallList(list1[getDisplayListIndex(tile.tanks[0])]);
}
}
@ -205,7 +205,7 @@ public class RenderRefinery extends TileEntitySpecialRenderer implements IInvent
GL11.glTranslatef(0, 0, 1);
bindTexture(FluidRenderer.getFluidSheet(liquid2));
RenderUtils.setGLColorFromInt(color2);
GL11.glCallList(list2[getDisplayListIndex(tile.tank2)]);
GL11.glCallList(list2[getDisplayListIndex(tile.tanks[1])]);
GL11.glPopMatrix();
}
}

View file

@ -23,9 +23,11 @@ import cpw.mods.fml.common.FMLCommonHandler;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.core.NetworkData;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleCrafter;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.core.IMachine;
import buildcraft.core.network.PacketUpdate;
@ -37,21 +39,21 @@ import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.utils.StringUtils;
import buildcraft.core.utils.Utils;
public class TileAssemblyTable extends TileLaserTableBase implements IMachine, IInventory {
public class TileAssemblyTable extends TileLaserTableBase implements IMachine, IInventory, IFlexibleCrafter {
@NetworkData
public String currentRecipeId = "";
public IFlexibleRecipe currentRecipe;
public IFlexibleRecipe<ItemStack> currentRecipe;
@NetworkData
private HashSet<String> plannedOutput = new HashSet<String>();
public List<CraftingResult> getPotentialOutputs() {
List<CraftingResult> result = new LinkedList<CraftingResult>();
public List<CraftingResult<ItemStack>> getPotentialOutputs() {
List<CraftingResult<ItemStack>> result = new LinkedList<CraftingResult<ItemStack>>();
for (IFlexibleRecipe recipe : AssemblyRecipeManager.INSTANCE.getRecipes()) {
CraftingResult r = recipe.craftPreview(this, null);
CraftingResult<ItemStack> r = recipe.craft(this, true);
if (r != null) {
result.add(r);
@ -74,7 +76,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
return;
}
if (!currentRecipe.canBeCrafted(this, null)) {
if (!currentRecipe.canBeCrafted(this)) {
setNextCurrentRecipe();
if (currentRecipe == null) {
@ -82,12 +84,12 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
}
}
if (getEnergy() >= currentRecipe.craftPreview(this, null).energyCost
if (getEnergy() >= currentRecipe.craft(this, true).energyCost
&& lastMode != ActionMachineControl.Mode.Off) {
setEnergy(0);
if (currentRecipe.canBeCrafted(this, null)) {
ItemStack remaining = (ItemStack) currentRecipe.craft(this, null).crafted;
if (currentRecipe.canBeCrafted(this)) {
ItemStack remaining = currentRecipe.craft(this, false).crafted.copy();
remaining.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, remaining);
if (remaining.stackSize > 0) {
@ -187,7 +189,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
currentRecipeId = "";
}
if (!worldObj.isRemote) {
if (worldObj != null && !worldObj.isRemote) {
sendNetworkUpdate();
}
}
@ -195,7 +197,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
@Override
public double getRequiredEnergy() {
if (currentRecipe != null) {
CraftingResult result = currentRecipe.craftPreview(this, null);
CraftingResult<ItemStack> result = currentRecipe.craft(this, true);
if (result != null) {
return result.energyCost;
@ -237,7 +239,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
if (recipe == currentRecipe) {
takeNext = true;
} else if (takeNext && recipe.canBeCrafted(this, null)) {
} else if (takeNext && recipe.canBeCrafted(this)) {
setCurrentRecipe(recipe);
return;
}
@ -246,7 +248,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
for (String recipeId : plannedOutput) {
IFlexibleRecipe recipe = AssemblyRecipeManager.INSTANCE.getRecipe(recipeId);
if (recipe.canBeCrafted(this, null)) {
if (recipe.canBeCrafted(this)) {
setCurrentRecipe(recipe);
return;
}
@ -299,4 +301,35 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
currentRecipe = AssemblyRecipeManager.INSTANCE.getRecipe(currentRecipeId);
}
@Override
public int getCraftingItemStackSize() {
return getSizeInventory();
}
@Override
public ItemStack getCraftingItemStack(int slotid) {
return getStackInSlot(slotid);
}
@Override
public ItemStack decrCraftingItemgStack(int slotid, int val) {
return decrStackSize(slotid, val);
}
@Override
public FluidStack getCraftingFluidStack(int tankid) {
return null;
}
@Override
public FluidStack decrCraftingFluidStack(int tankid, int val) {
return null;
}
@Override
public int getCraftingFluidStackSize() {
return 0;
}
}

View file

@ -12,11 +12,13 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.recipes.BuildcraftRecipeRegistry;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleCrafter;
import buildcraft.api.recipes.IFlexibleRecipe;
import buildcraft.api.recipes.IIntegrationRecipeFactory;
import buildcraft.api.recipes.IIntegrationRecipe;
import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.InventoryMapper;
import buildcraft.core.inventory.SimpleInventory;
@ -25,7 +27,7 @@ import buildcraft.core.inventory.Transactor;
import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.utils.StringUtils;
public class TileIntegrationTable extends TileLaserTableBase {
public class TileIntegrationTable extends TileLaserTableBase implements IFlexibleCrafter {
public static final int SLOT_INPUT_A = 0;
public static final int SLOT_INPUT_B = 1;
@ -34,8 +36,8 @@ public class TileIntegrationTable extends TileLaserTableBase {
private int tick = 0;
private SimpleInventory invRecipeOutput = new SimpleInventory(1, "integrationOutput", 64);
private InventoryMapper invOutput = new InventoryMapper(inv, SLOT_OUTPUT, 1, false);
private IFlexibleRecipe activeRecipe;
private CraftingResult craftingPreview;
private IFlexibleRecipe<ItemStack> activeRecipe;
private CraftingResult<ItemStack> craftingPreview;
public IInventory getRecipeOutput() {
return invRecipeOutput;
@ -74,7 +76,7 @@ public class TileIntegrationTable extends TileLaserTableBase {
return;
}
if (!isRoomForOutput((ItemStack) craftingPreview.crafted)) {
if (!isRoomForOutput(craftingPreview.crafted)) {
setEnergy(0);
return;
}
@ -84,12 +86,12 @@ public class TileIntegrationTable extends TileLaserTableBase {
setEnergy(0);
craftingPreview = null;
CraftingResult craftResult = activeRecipe.craft(this, null);
CraftingResult<ItemStack> craftResult = activeRecipe.craft(this, false);
if (craftResult != null) {
ItemStack result = (ItemStack) craftResult.crafted;
ItemStack result = craftResult.crafted.copy();
ITransactor trans = Transactor.getTransactorFor(invOutput);
ITransactor trans = Transactor.getTransactorFor(invOutput);
trans.add(result, ForgeDirection.UP, true);
}
}
@ -98,9 +100,9 @@ public class TileIntegrationTable extends TileLaserTableBase {
private void setNewActiveRecipe(ItemStack inputA, ItemStack inputB, ItemStack[] components) {
craftingPreview = null;
for (IIntegrationRecipeFactory recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
for (IIntegrationRecipe recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
if (recipe.isValidInputA(inputA) && recipe.isValidInputB(inputB)) {
craftingPreview = recipe.craftPreview(this, null);
craftingPreview = recipe.craft(this, true);
if (craftingPreview != null) {
activeRecipe = recipe;
@ -148,7 +150,7 @@ public class TileIntegrationTable extends TileLaserTableBase {
private boolean isValidInputA(ItemStack stack) {
ItemStack inputB = inv.getStackInSlot(SLOT_INPUT_B);
for (IIntegrationRecipeFactory recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
for (IIntegrationRecipe recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
if (recipe.isValidInputA(stack) && (inputB == null || recipe.isValidInputB(inputB))) {
return true;
}
@ -159,7 +161,7 @@ public class TileIntegrationTable extends TileLaserTableBase {
private boolean isValidInputB(ItemStack stack) {
ItemStack inputA = inv.getStackInSlot(SLOT_INPUT_A);
for (IIntegrationRecipeFactory recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
for (IIntegrationRecipe recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
if (recipe.isValidInputB(stack) && (inputA == null || recipe.isValidInputA(inputA))) {
return true;
}
@ -211,10 +213,40 @@ public class TileIntegrationTable extends TileLaserTableBase {
setNewActiveRecipe(inputA, inputB, components);
if (craftingPreview != null) {
invRecipeOutput.setInventorySlotContents(0, (ItemStack) craftingPreview.crafted);
invRecipeOutput.setInventorySlotContents(0, craftingPreview.crafted);
} else {
invRecipeOutput.setInventorySlotContents(0, null);
}
}
@Override
public int getCraftingItemStackSize() {
return getSizeInventory() - 3;
}
@Override
public ItemStack getCraftingItemStack(int slotid) {
return getStackInSlot(slotid + 3);
}
@Override
public ItemStack decrCraftingItemgStack(int slotid, int val) {
return decrStackSize(slotid + 3, val);
}
@Override
public FluidStack getCraftingFluidStack(int tankid) {
return null;
}
@Override
public FluidStack decrCraftingFluidStack(int tankid, int val) {
return null;
}
@Override
public int getCraftingFluidStackSize() {
return 0;
}
}

View file

@ -8,14 +8,12 @@
*/
package buildcraft.silicon.boards;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.boards.RedstoneBoardRegistry;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleCrafter;
import buildcraft.core.recipes.FlexibleRecipe;
import buildcraft.core.utils.NBTUtils;
@ -25,12 +23,12 @@ public class BoardRecipe extends FlexibleRecipe {
ItemStack output = new ItemStack(BuildCraftSilicon.redstoneBoard);
NBTUtils.getItemData(output).setString("id", "<unknown>");
setContents(id, output, 1000, new ItemStack(BuildCraftSilicon.redstoneBoard));
setContents(id, output, 1000, 0, new ItemStack(BuildCraftSilicon.redstoneBoard));
}
@Override
public CraftingResult craft(IInventory items, IFluidHandler fluids) {
CraftingResult result = super.craft(items, fluids);
public CraftingResult craft(IFlexibleCrafter crafter, boolean preview) {
CraftingResult<ItemStack> result = super.craft(crafter, preview);
if (result != null) {
ItemStack stack = new ItemStack(BuildCraftSilicon.redstoneBoard);

View file

@ -75,7 +75,7 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
private final TileAssemblyTable table;
class RecipeSlot extends AdvancedSlot {
public CraftingResult crafting;
public CraftingResult<ItemStack> crafting;
public RecipeSlot(int x, int y) {
super(GuiAssemblyTable.this, x, y);
@ -84,7 +84,7 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
@Override
public ItemStack getItemStack() {
if (crafting != null) {
return (ItemStack) crafting.crafted;
return crafting.crafted;
} else {
return null;
}
@ -113,8 +113,8 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
}
public void updateRecipes() {
List<CraftingResult> potentialRecipes = table.getPotentialOutputs();
Iterator<CraftingResult> cur = potentialRecipes.iterator();
List<CraftingResult<ItemStack>> potentialRecipes = table.getPotentialOutputs();
Iterator<CraftingResult<ItemStack>> cur = potentialRecipes.iterator();
for (int p = 0; p < 8; ++p) {
if (cur.hasNext()) {

View file

@ -8,26 +8,23 @@
*/
package buildcraft.silicon.recipes;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.oredict.OreDictionary;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.JavaTools;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IIntegrationRecipeFactory;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.recipes.FlexibleRecipe;
import buildcraft.silicon.ItemRedstoneChipset;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.transport.ItemFacade;
import buildcraft.transport.ItemPipeWire;
public class AdvancedFacadeRecipe extends FlexibleRecipe implements IIntegrationRecipeFactory {
public class AdvancedFacadeRecipe extends IntegrationTableRecipe {
public AdvancedFacadeRecipe(String id) {
setContents(id, new ItemFacade(), 5000,
setContents(id, new ItemFacade(), 5000, 0,
new ItemStack(BuildCraftTransport.pipeWire, 1, OreDictionary.WILDCARD_VALUE),
ItemRedstoneChipset.Chipset.RED.getStack());
}
@ -44,15 +41,10 @@ public class AdvancedFacadeRecipe extends FlexibleRecipe implements IIntegration
}
@Override
public CraftingResult craft(IInventory items, IFluidHandler fluids) {
ItemStack inputA = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_A, 1);
ItemStack inputB = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_B, 1);
public CraftingResult craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
if (inputA == null || inputB == null) {
return null;
}
CraftingResult result = super.craft(items, fluids);
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
if (result == null) {
return null;

View file

@ -8,21 +8,16 @@
*/
package buildcraft.silicon.recipes;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IIntegrationRecipeFactory;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.recipes.FlexibleRecipe;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.transport.gates.ItemGate;
public class GateExpansionRecipe extends FlexibleRecipe implements IIntegrationRecipeFactory {
public class GateExpansionRecipe extends IntegrationTableRecipe {
private final IGateExpansion expansion;
private final ItemStack chipset;
@ -31,7 +26,7 @@ public class GateExpansionRecipe extends FlexibleRecipe implements IIntegrationR
this.expansion = expansion;
this.chipset = chipset.copy();
setContents(id, BuildCraftTransport.pipeGate, 10000);
setContents(id, BuildCraftTransport.pipeGate, 10000, 0);
}
@Override
@ -51,15 +46,14 @@ public class GateExpansionRecipe extends FlexibleRecipe implements IIntegrationR
}
@Override
public CraftingResult craft(IInventory items, IFluidHandler fluids) {
ItemStack inputA = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_A, 1);
ItemStack inputB = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_B, 1);
public CraftingResult craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
if (inputA == null) {
return null;
}
CraftingResult result = super.craft(items, fluids);
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
if (result == null) {
return null;

View file

@ -8,26 +8,21 @@
*/
package buildcraft.silicon.recipes;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.BuildCraftTransport;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IIntegrationRecipeFactory;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.recipes.FlexibleRecipe;
import buildcraft.silicon.ItemRedstoneChipset;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import buildcraft.transport.gates.ItemGate;
public class GateLogicSwapRecipe extends FlexibleRecipe implements IIntegrationRecipeFactory {
public class GateLogicSwapRecipe extends IntegrationTableRecipe {
public GateLogicSwapRecipe(String id) {
setContents(id, BuildCraftTransport.pipeGate, 2000);
setContents(id, BuildCraftTransport.pipeGate, 2000, 0);
}
@Override
@ -41,17 +36,16 @@ public class GateLogicSwapRecipe extends FlexibleRecipe implements IIntegrationR
}
@Override
public CraftingResult craft(IInventory items, IFluidHandler fluids) {
ItemStack inputA = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_A, 1);
ItemStack inputB = items.decrStackSize(TileIntegrationTable.SLOT_INPUT_B, 1);
public CraftingResult craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
CraftingResult result = super.craft(items, fluids);
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
if (result == null) {
return null;
}
ItemStack output = (ItemStack) result.crafted;
ItemStack output = result.crafted;
output.stackSize = 1;
ItemGate.setLogic(output, ItemGate.getLogic(output) == GateLogic.AND ? GateLogic.OR : GateLogic.AND);

View file

@ -0,0 +1,53 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.silicon.recipes;
import net.minecraft.item.ItemStack;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.recipes.IFlexibleCrafter;
import buildcraft.api.recipes.IIntegrationRecipe;
import buildcraft.core.recipes.FlexibleRecipe;
import buildcraft.silicon.TileIntegrationTable;
public abstract class IntegrationTableRecipe extends FlexibleRecipe<ItemStack> implements IIntegrationRecipe {
@Override
public final CraftingResult craft(IFlexibleCrafter crafter, boolean preview) {
TileIntegrationTable table = (TileIntegrationTable) crafter;
ItemStack inputA;
ItemStack inputB;
if (preview) {
inputA = table.getStackInSlot(TileIntegrationTable.SLOT_INPUT_A);
inputB = table.getStackInSlot(TileIntegrationTable.SLOT_INPUT_B);
if (inputA != null) {
inputA = inputA.copy();
}
if (inputB != null) {
inputB = inputB.copy();
}
} else {
inputA = table.decrStackSize(TileIntegrationTable.SLOT_INPUT_A, 1);
inputB = table.decrStackSize(TileIntegrationTable.SLOT_INPUT_B, 1);
}
return craft(table, preview, inputA, inputB);
}
public CraftingResult craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
return super.craft(crafter, preview);
}
}

View file

@ -242,11 +242,11 @@ public class ItemFacade extends ItemBuildCraft {
continue;
}
registerValidFacades("buildcraft:facade{" + Block.blockRegistry.getNameForObject(b) + "}", b, item);
registerValidFacades(b, item);
}
}
private static void registerValidFacades(String id, Block block, Item item) {
private static void registerValidFacades(Block block, Item item) {
Set<String> names = Sets.newHashSet();
for (int i = 0; i <= 15; i++) {
@ -255,7 +255,9 @@ public class ItemFacade extends ItemBuildCraft {
if (!Strings.isNullOrEmpty(stack.getUnlocalizedName())
&& names.add(stack.getUnlocalizedName())) {
ItemFacade.addFacade(id, stack);
ItemFacade.addFacade(
"buildcraft:facade{" + Block.blockRegistry.getNameForObject(block) + "#"
+ stack.getItemDamage() + "}", stack);
// prevent adding multiple facades if it's a rotatable block
if (block.getRenderType() == 31) {