some refactoring, new Integration Table

This commit is contained in:
Adrian 2015-05-06 07:45:16 +02:00
parent 339b52227b
commit 1ac9cadca9
29 changed files with 580 additions and 479 deletions

View file

@ -13,12 +13,14 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import com.google.common.collect.HashBiMap;
import net.minecraft.item.ItemStack;
public final class GateExpansions {
private static final Map<String, IGateExpansion> expansions = new HashMap<String, IGateExpansion>();
private static final ArrayList<IGateExpansion> expansionIDs = new ArrayList<IGateExpansion>();
private static final Map<IGateExpansion, ItemStack> recipes = new HashMap<IGateExpansion, ItemStack>();
private static final Map<IGateExpansion, ItemStack> recipes = HashBiMap.create();
private GateExpansions() {
}

View file

@ -10,10 +10,18 @@ package buildcraft.api.recipes;
import net.minecraft.item.ItemStack;
public interface IIntegrationRecipe extends IFlexibleRecipe<ItemStack> {
import java.util.List;
boolean isValidInputA(ItemStack inputA);
boolean isValidInputB(ItemStack inputB);
public interface IIntegrationRecipe {
int getEnergyCost();
List<ItemStack> getExampleInput();
List<List<ItemStack>> getExampleExpansions();
boolean isValidInput(ItemStack input);
boolean isValidExpansion(ItemStack expansion);
ItemStack craft(ItemStack input, List<ItemStack> expansions, boolean preview);
/**
* @return -1 for no limit, a different number otherwise
*/
int getMaximumExpansionCount();
}

View file

@ -10,15 +10,7 @@ package buildcraft.api.recipes;
import java.util.List;
/**
* The Integration Table's primary purpose is to modify an input item's NBT
* data. As such its not a "traditional" type of recipe. Rather than predefined
* inputs and outputs, it takes an input and transforms it.
*/
public interface IIntegrationRecipeManager {
/**
* Add an Integration Table recipe.
*/
void addRecipe(IIntegrationRecipe recipe);
List<? extends IIntegrationRecipe> getRecipes();

View file

@ -0,0 +1,41 @@
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* The BuildCraft API is distributed under the terms of the MIT License.
* Please check the contents of the license, which should be located
* as "LICENSE.API" in the BuildCraft source code distribution.
*/
package buildcraft.api.recipes;
import java.util.Collection;
import net.minecraft.item.ItemStack;
public interface IRecipeManager<T> {
/**
* Add a recipe.
*
* @param input
* Object... containing either an ItemStack, or a paired string
* and integer(ex: "dyeBlue", 1)
* @param energyCost
* RF cost to produce
* @param output
* resulting ItemStack
*/
void addRecipe(String id, int energyCost, T output, Object... input);
void addRecipe(String id, int energyCost, int craftingDelay, T output, Object... input);
void addRecipe(IFlexibleRecipe<T> recipe);
void removeRecipe(String id);
void removeRecipe(IFlexibleRecipe<T> recipe);
Collection<IFlexibleRecipe<T>> getRecipes();
IFlexibleRecipe<T> getRecipe(String id);
}

View file

@ -0,0 +1,23 @@
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* The BuildCraft API is distributed under the terms of the MIT License.
* Please check the contents of the license, which should be located
* as "LICENSE.API" in the BuildCraft source code distribution.
*/
package buildcraft.api.recipes;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
public final class RecipeRegistry {
public static IRecipeManager<ItemStack> assemblyTable;
public static IRecipeManager<ItemStack> integrationTable;
public static IRecipeManager<FluidStack> refinery;
public static IProgrammingRecipeManager programmingTable;
private RecipeRegistry() {
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 868 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 774 B

View file

@ -373,7 +373,7 @@ public class BuildCraftRobotics extends BuildCraftMod {
'C', ItemRedstoneChipset.Chipset.GOLD.getStack());
BuildcraftRecipeRegistry.programmingTable.addRecipe(new BoardProgrammingRecipe());
BuildcraftRecipeRegistry.integrationTable.addRecipe(new RobotIntegrationRecipe("buildcraft:robotIntegration"));
BuildcraftRecipeRegistry.integrationTable.addRecipe(new RobotIntegrationRecipe());
}
@SubscribeEvent

View file

@ -522,10 +522,6 @@ public class BuildCraftTransport extends BuildCraftMod {
public void postInit(FMLPostInitializationEvent evt) {
facadeItem.initialize();
if (Loader.isModLoaded("BuildCraft|Silicon")) {
postInitSilicon();
}
if (debugPrintFacadeList) {
try {
PrintWriter writer = new PrintWriter("FacadeDebug.txt", "UTF-8");
@ -614,17 +610,6 @@ public class BuildCraftTransport extends BuildCraftMod {
pipeExtensionListener = null;
}
private void postInitSilicon() {
Map<IGateExpansion, ItemStack> recipes = GateExpansions.getRecipesForPostInit();
int recipeId = 0;
for (IGateExpansion expansion : recipes.keySet()) {
BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateExpansionRecipe("buildcraft:expansion_" + recipeId,
expansion, recipes.get(expansion)));
recipeId++;
}
}
public void loadRecipes() {
// Add base recipe for pipe waterproof.
GameRegistry.addShapelessRecipe(new ItemStack(pipeWaterproof, 1), new ItemStack(Items.dye, 1, 2));

View file

@ -0,0 +1,83 @@
package buildcraft.core.recipes;
import buildcraft.api.recipes.IFlexibleCrafter;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
/**
* Use this class for simulated crafts.
*/
public class FakeFlexibleCrafter implements IFlexibleCrafter {
private final IFlexibleCrafter original;
private int[] usedItems, usedFluids;
public FakeFlexibleCrafter(IFlexibleCrafter original) {
this.original = original;
this.usedFluids = new int[original.getCraftingFluidStackSize()];
this.usedItems = new int[original.getCraftingItemStackSize()];
}
@Override
public ItemStack getCraftingItemStack(int slotId) {
ItemStack output = original.getCraftingItemStack(slotId);
if (usedItems[slotId] == 0) {
return output;
} else if (output.stackSize <= usedItems[slotId]) {
return null;
}
output = output.copy();
output.stackSize -= usedItems[slotId];
return output;
}
@Override
public ItemStack decrCraftingItemStack(int slotId, int amount) {
ItemStack output = original.getCraftingItemStack(slotId);
int result = Math.min(output.stackSize - usedItems[slotId], amount);
usedItems[slotId] += result;
if (result == 0) {
return null;
}
ItemStack decrOut = output.copy();
decrOut.stackSize = result;
return decrOut;
}
@Override
public int getCraftingItemStackSize() {
return this.usedItems.length;
}
@Override
public FluidStack getCraftingFluidStack(int slotId) {
FluidStack output = original.getCraftingFluidStack(slotId);
if (usedFluids[slotId] == 0) {
return output;
} else if (output.amount <= usedFluids[slotId]) {
return null;
}
output = output.copy();
output.amount -= usedFluids[slotId];
return output;
}
@Override
public FluidStack decrCraftingFluidStack(int slotId, int amount) {
FluidStack output = original.getCraftingFluidStack(slotId);
int result = Math.min(output.amount - usedFluids[slotId], amount);
usedFluids[slotId] += result;
if (result == 0) {
return null;
}
FluidStack decrOut = output.copy();
decrOut.amount = result;
return decrOut;
}
@Override
public int getCraftingFluidStackSize() {
return this.usedFluids.length;
}
}

View file

@ -146,7 +146,7 @@ public class FlexibleRecipe<T> implements IFlexibleRecipe<T>, IFlexibleRecipeVie
IFlexibleCrafter crafter = baseCrafter;
if (preview) {
crafter = new PreviewCrafter(baseCrafter);
crafter = new FakeFlexibleCrafter(baseCrafter);
}
CraftingResult<T> result = new CraftingResult<T>();
@ -159,7 +159,7 @@ public class FlexibleRecipe<T> implements IFlexibleRecipe<T>, IFlexibleRecipeVie
IStackFilter filter = new ArrayStackFilter(requirement);
int amount = requirement.stackSize;
if (consumeItems(crafter, result, filter, amount, false) != 0) {
if (consumeItems(crafter, result, filter, amount) != 0) {
return null;
}
}
@ -170,7 +170,7 @@ public class FlexibleRecipe<T> implements IFlexibleRecipe<T>, IFlexibleRecipeVie
IStackFilter filter = new ArrayStackFilter(requirements.toArray(new ItemStack[requirements.size()]));
int amount = requirements.get(0).stackSize;
if (consumeItems(crafter, result, filter, amount, false) != 0) {
if (consumeItems(crafter, result, filter, amount) != 0) {
return null;
}
}
@ -230,7 +230,7 @@ public class FlexibleRecipe<T> implements IFlexibleRecipe<T>, IFlexibleRecipeVie
}
private int consumeItems(IFlexibleCrafter crafter, CraftingResult<T> result, IStackFilter filter,
int amount, boolean preview) {
int amount) {
int expected = amount;
for (int slotid = 0; slotid < crafter.getCraftingItemStackSize(); ++slotid) {
@ -240,21 +240,10 @@ public class FlexibleRecipe<T> implements IFlexibleRecipe<T>, IFlexibleRecipeVie
ItemStack removed = null;
if (stack.stackSize >= expected) {
if (preview) {
removed = stack.copy();
removed.stackSize = expected;
} else {
removed = crafter.decrCraftingItemStack(slotid, expected);
}
removed = crafter.decrCraftingItemStack(slotid, expected);
expected = 0;
} else {
if (preview) {
removed = stack.copy();
} else {
removed = crafter.decrCraftingItemStack(slotid, stack.stackSize);
}
removed = crafter.decrCraftingItemStack(slotid, stack.stackSize);
expected -= removed.stackSize;
}

View file

@ -0,0 +1,53 @@
package buildcraft.core.recipes;
import buildcraft.api.recipes.IIntegrationRecipe;
import net.minecraft.item.ItemStack;
import java.lang.ref.SoftReference;
import java.util.List;
public abstract class IntegrationRecipeBC implements IIntegrationRecipe {
private final int energyCost, maxExpansionCount;
private SoftReference<List<ItemStack>> exampleInputs;
private SoftReference<List<List<ItemStack>>> exampleExpansions;
public IntegrationRecipeBC(int energyCost) {
this(energyCost, -1);
}
public IntegrationRecipeBC(int energyCost, int maxExpansionCount) {
this.energyCost = energyCost;
this.maxExpansionCount = maxExpansionCount;
}
public abstract List<ItemStack> generateExampleInput();
public abstract List<List<ItemStack>> generateExampleExpansions();
@Override
public int getEnergyCost() {
return energyCost;
}
@Override
public List<ItemStack> getExampleInput() {
if (exampleInputs != null && exampleInputs.get() != null) {
return exampleInputs.get();
}
exampleInputs = new SoftReference<List<ItemStack>>(generateExampleInput());
return exampleInputs.get();
}
@Override
public List<List<ItemStack>> getExampleExpansions() {
if (exampleExpansions != null && exampleExpansions.get() != null) {
return exampleExpansions.get();
}
exampleExpansions = new SoftReference<List<List<ItemStack>>>(generateExampleExpansions());
return exampleExpansions.get();
}
@Override
public int getMaximumExpansionCount() {
return maxExpansionCount;
}
}

View file

@ -0,0 +1,59 @@
/**
* Copyright (c) 2011-2015, 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.recipes;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import buildcraft.api.recipes.IRecipeManager;
import buildcraft.api.recipes.IFlexibleRecipe;
public class RecipeManager<T> implements IRecipeManager<T> {
private BiMap<String, IFlexibleRecipe<T>> recipes = HashBiMap.create();
@Override
public void addRecipe(String id, int energyCost, T output, Object... input) {
addRecipe(id, energyCost, 0, output, input);
}
@Override
public void addRecipe(String id, int energyCost, int craftingDelay, T output, Object... input) {
recipes.put(id, new FlexibleRecipe<T>(id, output, energyCost, craftingDelay, input));
}
@Override
public void addRecipe(IFlexibleRecipe<T> recipe) {
recipes.put(recipe.getId(), recipe);
}
@Override
public void removeRecipe(String id) {
recipes.remove(id);
}
@Override
public void removeRecipe(IFlexibleRecipe<T> recipe) {
recipes.remove(recipes.inverse().get(recipe));
}
@Override
public Collection<IFlexibleRecipe<T>> getRecipes() {
return Collections.unmodifiableCollection(recipes.values());
}
@Override
public IFlexibleRecipe<T> getRecipe(String id) {
return recipes.get(id);
}}

View file

@ -117,8 +117,10 @@ public class ItemRobot extends ItemBuildCraft implements IEnergyContainerItem {
public static ItemStack createRobotStack(ItemStack board, int energy) {
ItemStack robot = new ItemStack(BuildCraftRobotics.robotItem);
NBTUtils.getItemData(robot).setTag("board", NBTUtils.getItemData(board));
NBTUtils.getItemData(robot).setInteger("energy", energy);
if (board != null) {
NBTUtils.getItemData(robot).setTag("board", NBTUtils.getItemData(board));
NBTUtils.getItemData(robot).setInteger("energy", energy);
}
return robot;
}

View file

@ -8,39 +8,45 @@
*/
package buildcraft.robotics;
import buildcraft.core.recipes.IntegrationRecipeBC;
import net.minecraft.item.ItemStack;
import buildcraft.BuildCraftRobotics;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.silicon.recipes.IntegrationTableRecipe;
public class RobotIntegrationRecipe extends IntegrationTableRecipe {
import java.util.ArrayList;
import java.util.List;
public RobotIntegrationRecipe(String id) {
setContents(id, new ItemStack(BuildCraftRobotics.robotItem), 10000, 0);
public class RobotIntegrationRecipe extends IntegrationRecipeBC {
public RobotIntegrationRecipe() {
super(50000, 1);
}
@Override
public boolean isValidInputA(ItemStack inputA) {
return inputA != null && inputA.getItem() instanceof ItemRobot;
public List<ItemStack> generateExampleInput() {
ArrayList<ItemStack> example = new ArrayList<ItemStack>();
example.add(ItemRobot.createRobotStack(null, 0));
return example;
}
@Override
public boolean isValidInputB(ItemStack inputB) {
return inputB != null && inputB.getItem() instanceof ItemRedstoneBoard;
public List<List<ItemStack>> generateExampleExpansions() {
// TODO!
return null;
}
@Override
public CraftingResult<ItemStack> craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
public boolean isValidInput(ItemStack input) {
return input.getItem() instanceof ItemRobot;
}
if (result != null) {
result.crafted = ItemRobot.createRobotStack(inputB, 0);
@Override
public boolean isValidExpansion(ItemStack expansion) {
return expansion.getItem() instanceof ItemRedstoneBoard;
}
return result;
} else {
return null;
@Override
public ItemStack craft(ItemStack input, List<ItemStack> expansions, boolean preview) {
if (!preview) {
expansions.get(0).stackSize--;
}
return ItemRobot.createRobotStack(expansions.get(0), 0);
}
}

View file

@ -8,45 +8,27 @@
*/
package buildcraft.silicon;
import net.minecraft.inventory.IInventory;
import buildcraft.core.lib.inventory.InventoryMapper;
import io.netty.buffer.ByteBuf;
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.IIntegrationRecipe;
import buildcraft.core.lib.inventory.ITransactor;
import buildcraft.core.lib.inventory.InventoryMapper;
import buildcraft.core.lib.inventory.SimpleInventory;
import buildcraft.core.lib.inventory.StackHelper;
import buildcraft.core.lib.inventory.Transactor;
import buildcraft.core.lib.utils.StringUtils;
public class TileIntegrationTable extends TileLaserTableBase implements IFlexibleCrafter {
import java.util.ArrayList;
import java.util.List;
public static final int SLOT_INPUT_A = 0;
public static final int SLOT_INPUT_B = 1;
public static final int SLOT_OUTPUT = 2;
private static final int CYCLE_LENGTH = 32;
public class TileIntegrationTable extends TileLaserTableBase {
public static final int SLOT_OUTPUT = 9;
private static final int CYCLE_LENGTH = 16;
private int tick = 0;
private SimpleInventory invRecipeOutput = new SimpleInventory(1, "integrationOutput", 64);
private InventoryMapper invOutput = new InventoryMapper(inv, SLOT_OUTPUT, 1, false);
private IFlexibleRecipe<ItemStack> activeRecipe;
private CraftingResult<ItemStack> craftingPreview;
public IInventory getRecipeOutput() {
return invRecipeOutput;
}
private ItemStack[] getComponents() {
ItemStack[] components = new ItemStack[9];
for (int i = SLOT_OUTPUT + 1; i < 12; i++) {
components[i - SLOT_OUTPUT - 1] = inv.getStackInSlot(i);
}
return components;
}
private IIntegrationRecipe activeRecipe;
private InventoryMapper mappedOutput = new InventoryMapper(this, SLOT_OUTPUT, 1, false);
private int maxExpCountClient;
@Override
public void initialize() {
@ -63,7 +45,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
return;
}
if (activeRecipe == null || craftingPreview == null) {
if (activeRecipe == null) {
setEnergy(0);
return;
}
@ -73,39 +55,83 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
return;
}
if (!isRoomForOutput(craftingPreview.crafted)) {
updateRecipeOutput();
ItemStack output = getStackInSlot(10);
if (!isRoomForOutput(output)) {
setEnergy(0);
return;
}
if (getEnergy() >= craftingPreview.energyCost) {
if (getEnergy() >= activeRecipe.getEnergyCost()) {
setEnergy(0);
craftingPreview = null;
CraftingResult<ItemStack> craftResult = activeRecipe.craft(this, false);
output = activeRecipe.craft(getStackInSlot(0), getExpansions(), false);
if (craftResult != null) {
ItemStack result = craftResult.crafted.copy();
if (output != null) {
ITransactor trans = Transactor.getTransactorFor(mappedOutput);
trans.add(output, ForgeDirection.UP, true);
ITransactor trans = Transactor.getTransactorFor(invOutput);
trans.add(result, ForgeDirection.UP, true);
ItemStack input = getStackInSlot(0);
if (input.stackSize > output.stackSize) {
input.stackSize -= output.stackSize;
} else {
setInventorySlotContents(0, null);
}
for (int i = 1; i < 9; i++) {
if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
setInventorySlotContents(i, null);
}
}
}
}
}
private void setNewActiveRecipe(ItemStack inputA, ItemStack inputB, ItemStack[] components) {
craftingPreview = null;
private List<ItemStack> getExpansions() {
List<ItemStack> expansions = new ArrayList<ItemStack>();
for (int i = 1; i < 9; i++) {
if (getStackInSlot(i) != null) {
expansions.add(getStackInSlot(i));
}
}
return expansions;
}
for (IIntegrationRecipe recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
if (recipe.isValidInputA(inputA) && recipe.isValidInputB(inputB)) {
craftingPreview = recipe.craft(this, true);
private void updateRecipeOutput() {
if (activeRecipe == null) {
inv.setInventorySlotContents(10, null);
return;
}
if (craftingPreview != null) {
List<ItemStack> expansions = getExpansions();
if (expansions.size() == 0) {
return;
}
inv.setInventorySlotContents(10, activeRecipe.craft(getStackInSlot(0), expansions, true));
}
private void setNewActiveRecipe() {
ItemStack input = getStackInSlot(0);
if ((input != null && activeRecipe != null && activeRecipe.isValidInput(input)) || (input == null && activeRecipe == null)) {
return;
}
activeRecipe = null;
if (input != null && input.getItem() != null) {
for (IIntegrationRecipe recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
if (recipe.isValidInput(input)) {
activeRecipe = recipe;
break;
}
}
}
sendNetworkUpdate();
}
private boolean isRoomForOutput(ItemStack output) {
@ -119,13 +145,23 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
return false;
}
@Override
public void writeData(ByteBuf buf) {
buf.writeByte((byte) getMaxExpansionCount());
}
@Override
public void readData(ByteBuf buf) {
maxExpCountClient = buf.readByte();
}
public int getMaxExpansionCount() {
return worldObj.isRemote ? maxExpCountClient : (activeRecipe != null ? activeRecipe.getMaximumExpansionCount() : 0);
}
@Override
public int getRequiredEnergy() {
if (craftingPreview != null) {
return craftingPreview.energyCost;
} else {
return 0;
}
return hasWork() ? activeRecipe.getEnergyCost() : 0;
}
@Override
@ -135,40 +171,25 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
switch (slot) {
case SLOT_INPUT_A:
return isValidInputA(stack);
case SLOT_INPUT_B:
return isValidInputB(stack);
}
return false;
}
private boolean isValidInputA(ItemStack stack) {
ItemStack inputB = inv.getStackInSlot(SLOT_INPUT_B);
for (IIntegrationRecipe recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
if (recipe.isValidInputA(stack) && (inputB == null || recipe.isValidInputB(inputB))) {
return true;
if (slot == 0) {
return true;
} else if (activeRecipe == null) {
return false;
} else if (slot < 9) {
if (activeRecipe.getMaximumExpansionCount() > 0) {
if (slot > activeRecipe.getMaximumExpansionCount()) {
return false;
}
}
return activeRecipe.isValidExpansion(stack);
} else {
return false;
}
return false;
}
private boolean isValidInputB(ItemStack stack) {
ItemStack inputA = inv.getStackInSlot(SLOT_INPUT_A);
for (IIntegrationRecipe recipe : BuildcraftRecipeRegistry.integrationTable.getRecipes()) {
if (recipe.isValidInputB(stack) && (inputA == null || recipe.isValidInputA(inputA))) {
return true;
}
}
return false;
}
@Override
public int getSizeInventory() {
return 12;
return 11;
}
@Override
@ -183,66 +204,47 @@ public class TileIntegrationTable extends TileLaserTableBase implements IFlexibl
@Override
public boolean hasWork() {
return craftingPreview != null;
for (int i = 1; i < 9; i++) {
if (getStackInSlot(i) != null) {
return activeRecipe != null;
}
}
return false;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
super.setInventorySlotContents(slot, stack);
updateRecipe();
if (slot == 0) {
updateRecipe();
}
if (slot < 9) {
updateRecipeOutput();
}
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack result = super.decrStackSize(slot, amount);
updateRecipe();
if (slot == 0) {
updateRecipe();
}
if (slot < 9) {
updateRecipeOutput();
}
return result;
}
@Override
public void markDirty() {
super.markDirty();
updateRecipeOutput();
}
private void updateRecipe() {
ItemStack inputA = inv.getStackInSlot(SLOT_INPUT_A);
ItemStack inputB = inv.getStackInSlot(SLOT_INPUT_B);
ItemStack[] components = getComponents();
setNewActiveRecipe(inputA, inputB, components);
if (craftingPreview != null) {
invRecipeOutput.setInventorySlotContents(0, craftingPreview.crafted);
} else {
invRecipeOutput.setInventorySlotContents(0, null);
}
setNewActiveRecipe();
}
@Override
public int getCraftingItemStackSize() {
return getSizeInventory() - 3;
}
@Override
public ItemStack getCraftingItemStack(int slotid) {
return getStackInSlot(slotid + 3);
}
@Override
public ItemStack decrCraftingItemStack(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

@ -19,6 +19,12 @@ import buildcraft.core.lib.gui.slots.SlotValidated;
import buildcraft.silicon.TileIntegrationTable;
public class ContainerIntegrationTable extends BuildCraftContainer {
public static final int[] SLOT_X = {
44, 44, 68, 76, 68, 44, 20, 13, 20
};
public static final int[] SLOT_Y = {
49, 18, 25, 49, 73, 81, 73, 49, 25
};
private TileIntegrationTable table;
@ -26,23 +32,21 @@ public class ContainerIntegrationTable extends BuildCraftContainer {
super(table.getSizeInventory());
this.table = table;
addSlot(new SlotValidated(table, TileIntegrationTable.SLOT_INPUT_A, 17, 28));
addSlot(new SlotValidated(table, TileIntegrationTable.SLOT_INPUT_B, 53, 28));
addSlot(new SlotOutput(table, TileIntegrationTable.SLOT_OUTPUT, 143, 44));
addSlot(new SlotUntouchable(table.getRecipeOutput(), 0, 116, 44));
for (int i = TileIntegrationTable.SLOT_OUTPUT + 1; i < 12; i++) {
addSlot(new Slot(table, i, 8 + (i - (TileIntegrationTable.SLOT_OUTPUT + 1)) * 18, 69));
for (int i = 0; i < 9; i++) {
addSlot(new SlotValidated(table, i, SLOT_X[i], SLOT_Y[i]));
}
addSlot(new SlotOutput(table, 9, 138, 49));
addSlot(new SlotUntouchable(table, 10, 104, 36));
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 9; x++) {
addSlotToContainer(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, 91 + y * 18));
addSlotToContainer(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, 109 + y * 18));
}
}
for (int x = 0; x < 9; x++) {
addSlotToContainer(new Slot(playerInventory, x, 8 + x * 18, 149));
addSlotToContainer(new Slot(playerInventory, x, 8 + x * 18, 167));
}
}

View file

@ -25,7 +25,7 @@ public class GuiIntegrationTable extends GuiLaserTable {
super(playerInventory, new ContainerIntegrationTable(playerInventory, table), table, TEXTURE);
this.integrationTable = table;
xSize = 176;
ySize = 173;
ySize = 186;
}
@Override
@ -54,8 +54,14 @@ public class GuiIntegrationTable extends GuiLaserTable {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(TEXTURE);
if (integrationTable.getEnergy() > 0) {
int progress = integrationTable.getProgressScaled(98);
drawTexturedModalRect(guiLeft + 13, guiTop + 40, 0, flash ? 197 : 221, progress, 24);
int h = table.getProgressScaled(69);
drawTexturedModalRect(guiLeft + 164, guiTop + 18 + 74 - h, 176, 18, 4, h);
}
if (integrationTable.getMaxExpansionCount() > 0) {
for (int i = 8; i > integrationTable.getMaxExpansionCount(); i--) {
drawTexturedModalRect(guiLeft + ContainerIntegrationTable.SLOT_X[i] - 1, guiTop + ContainerIntegrationTable.SLOT_Y[i] - 1,
180, 17, 18, 18);
}
}
}
}

View file

@ -1,55 +0,0 @@
/**
* Copyright (c) 2011-2015, 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<ItemStack> 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<ItemStack> craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
return super.craft(crafter, preview);
}
@Override
public CraftingResult canCraft(ItemStack expectedOutput) {
return null;
}
}

View file

@ -45,9 +45,6 @@ public class IMCHandlerTransport extends IMCHandler {
failed = true;
return;
}
IntegrationRecipeManager.INSTANCE.addRecipe(new GateExpansionRecipe(
recipe.getString("id"), exp, is
));
}
if (failed) {
BCLog.logger.warn("Received invalid gate expansion recipe IMC message from mod %s!", msg.getSender());

View file

@ -2,6 +2,8 @@ package buildcraft.transport;
import java.util.ArrayList;
import java.util.List;
import buildcraft.transport.recipes.GateExpansionRecipe;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.Optional;
@ -19,7 +21,6 @@ import buildcraft.transport.gates.GateExpansionRedstoneFader;
import buildcraft.transport.gates.GateExpansionTimer;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.recipes.AdvancedFacadeRecipe;
import buildcraft.transport.recipes.GateLogicSwapRecipe;
public final class TransportSiliconRecipes {
private TransportSiliconRecipes() {
@ -61,11 +62,8 @@ public final class TransportSiliconRecipes {
addGateRecipe("Emerald", (int) Math.round(1200000 * BuildCraftTransport.gateCostMultiplier), GateDefinition.GateMaterial.EMERALD, ItemRedstoneChipset.Chipset.EMERALD, PipeWire.RED, PipeWire.BLUE,
PipeWire.GREEN, PipeWire.YELLOW);
// REVERSAL RECIPE
BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateLogicSwapRecipe("buildcraft:gateSwap"));
// PHASED FACADE
BuildcraftRecipeRegistry.integrationTable.addRecipe(new AdvancedFacadeRecipe("buildcraft:advancedFacade"));
BuildcraftRecipeRegistry.integrationTable.addRecipe(new GateExpansionRecipe());
BuildcraftRecipeRegistry.integrationTable.addRecipe(new AdvancedFacadeRecipe());
// This will only add recipes to the gate expansions.
GateExpansions.registerExpansion(GateExpansionPulsar.INSTANCE, ItemRedstoneChipset.Chipset.PULSATING.getStack());

View file

@ -9,107 +9,95 @@
package buildcraft.transport.recipes;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.List;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.JavaTools;
import buildcraft.api.facades.FacadeType;
import buildcraft.api.facades.IFacadeItem;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.api.transport.PipeWire;
import buildcraft.silicon.ItemRedstoneChipset;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.silicon.recipes.IntegrationTableRecipe;
import buildcraft.core.recipes.IntegrationRecipeBC;
import buildcraft.transport.ItemFacade;
import buildcraft.transport.ItemFacade.FacadeState;
import buildcraft.transport.ItemPipeWire;
import net.minecraft.item.ItemStack;
public class AdvancedFacadeRecipe extends IntegrationTableRecipe {
public AdvancedFacadeRecipe(String id) {
setContents(id, new ItemFacade(), 50000, 0,
new ItemStack(BuildCraftTransport.pipeWire, 1, OreDictionary.WILDCARD_VALUE),
ItemRedstoneChipset.Chipset.RED.getStack());
public class AdvancedFacadeRecipe extends IntegrationRecipeBC {
public AdvancedFacadeRecipe() {
super(25000, 2);
}
@Override
public boolean isValidInputA(ItemStack inputA) {
return inputA != null && inputA.getItem() instanceof ItemFacade;
public List<ItemStack> generateExampleInput() {
return ItemFacade.allFacades;
}
@Override
public boolean isValidInputB(ItemStack inputB) {
return inputB != null && (inputB.getItem() instanceof ItemFacade &&
((IFacadeItem) inputB.getItem()).getFacadeType(inputB) == FacadeType.Basic ||
inputB.getItem() == BuildCraftTransport.plugItem);
}
@Override
public CraftingResult<ItemStack> craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
if (result == null) {
return null;
public List<List<ItemStack>> generateExampleExpansions() {
List<List<ItemStack>> list = new ArrayList<List<ItemStack>>();
list.add(ItemFacade.allFacades);
List<ItemStack> pipeWires = new ArrayList<ItemStack>();
for (PipeWire wire : PipeWire.values()) {
pipeWires.add(wire.getStack());
}
list.add(pipeWires);
return list;
}
@Override
public boolean isValidInput(ItemStack input) {
return input.getItem() instanceof ItemFacade;
}
@Override
public boolean isValidExpansion(ItemStack expansion) {
return (expansion.getItem() instanceof ItemFacade &&
((IFacadeItem) expansion.getItem()).getFacadeType(expansion) == FacadeType.Basic) ||
expansion.getItem() == BuildCraftTransport.plugItem ||
expansion.getItem() == BuildCraftTransport.pipeWire;
}
@Override
public ItemStack craft(ItemStack input, List<ItemStack> expansions, boolean preview) {
PipeWire wire = null;
ItemStack facade = null;
for (ItemStack stack : result.usedItems) {
if (stack != null && stack.getItem() instanceof ItemPipeWire) {
for (ItemStack stack : expansions) {
if (wire == null && stack.getItem() instanceof ItemPipeWire) {
wire = PipeWire.fromOrdinal(stack.getItemDamage());
break;
if (!preview) {
stack.stackSize--;
}
} else if (facade == null && (stack.getItem() instanceof ItemFacade || stack.getItem() == BuildCraftTransport.pipeWire)) {
facade = stack;
if (!preview) {
stack.stackSize--;
}
}
}
if (wire != null) {
FacadeState[] states = ItemFacade.getFacadeStates(inputA);
FacadeState additionalState;
if (wire != null && facade != null) {
ItemFacade.FacadeState[] states = ItemFacade.getFacadeStates(input);
ItemFacade.FacadeState additionalState;
if (inputB.getItem() == BuildCraftTransport.plugItem) {
additionalState = FacadeState.createTransparent(wire);
if (facade.getItem() == BuildCraftTransport.plugItem) {
additionalState = ItemFacade.FacadeState.createTransparent(wire);
} else {
additionalState = ItemFacade.getFacadeStates(inputB)[0];
additionalState = FacadeState.create(additionalState.block, additionalState.metadata, wire);
additionalState = ItemFacade.getFacadeStates(facade)[0];
additionalState = ItemFacade.FacadeState.create(additionalState.block, additionalState.metadata, wire);
}
// if in states array exists state with the same wire just override it
for (int i = 0; i < states.length; i++) {
if (states[i].wire == wire) {
states[i] = additionalState;
result.energyCost = 20000;
result.crafted = ItemFacade.getFacade(states);
return result;
return ItemFacade.getFacade(states);
}
}
result.energyCost = 50000;
result.crafted = ItemFacade.getFacade(JavaTools.concat(states,
new FacadeState[] {additionalState}));
return result;
return ItemFacade.getFacade(JavaTools.concat(states,
new ItemFacade.FacadeState[]{additionalState}));
} else {
return null;
}
}
@Override
public Collection<Object> getInputs() {
ArrayList<Object> inputs = new ArrayList<Object>();
//inputs.add(ItemFacade.allFacades);
//inputs.add(ItemRedstoneChipset.Chipset.RED.getStack());
return inputs;
}
@Override
public Collection<Object> getOutput() {
ArrayList<Object> outputs = new ArrayList<Object>();
return outputs;
}
}

View file

@ -9,87 +9,85 @@
package buildcraft.transport.recipes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import buildcraft.api.gates.GateExpansions;
import buildcraft.core.recipes.IntegrationRecipeBC;
import buildcraft.silicon.ItemRedstoneChipset;
import buildcraft.transport.gates.GateDefinition;
import com.google.common.collect.BiMap;
import net.minecraft.item.ItemStack;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.core.lib.inventory.StackHelper;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.silicon.recipes.IntegrationTableRecipe;
import buildcraft.transport.gates.ItemGate;
public class GateExpansionRecipe extends IntegrationTableRecipe {
public class GateExpansionRecipe extends IntegrationRecipeBC {
private static final BiMap<IGateExpansion, ItemStack> recipes = (BiMap<IGateExpansion, ItemStack>) GateExpansions.getRecipesForPostInit();
private final IGateExpansion expansion;
private final ItemStack chipset;
public GateExpansionRecipe(String id, IGateExpansion expansion, ItemStack chipset) {
this.expansion = expansion;
this.chipset = chipset.copy();
setContents(id, BuildCraftTransport.pipeGate, 100000, 0);
public GateExpansionRecipe() {
super(25000);
}
@Override
public boolean isValidInputA(ItemStack inputA) {
if (inputA == null) {
return false;
} else if (!(inputA.getItem() instanceof ItemGate)) {
return false;
public boolean isValidInput(ItemStack input) {
return input.getItem() instanceof ItemGate;
}
@Override
public boolean isValidExpansion(ItemStack expansion) {
if (StackHelper.isMatchingItem(ItemRedstoneChipset.Chipset.RED.getStack(), expansion, true, true)) {
return true;
}
for (ItemStack s : recipes.values()) {
if (StackHelper.isMatchingItem(s, expansion, true, true)) {
return true;
}
}
return false;
}
@Override
public List<ItemStack> generateExampleInput() {
return Collections.unmodifiableList(ItemGate.getAllGates());
}
@Override
public List<List<ItemStack>> generateExampleExpansions() {
ArrayList<List<ItemStack>> list = new ArrayList<List<ItemStack>>();
ArrayList<ItemStack> list2 = new ArrayList<ItemStack>();
list2.addAll(recipes.values());
list.add(list2);
return list;
}
@Override
public ItemStack craft(ItemStack input, List<ItemStack> expansions, boolean preview) {
ItemStack output = input.copy();
int expansionsAdded = 0;
for (ItemStack chipset : expansions) {
if (StackHelper.isMatchingItem(ItemRedstoneChipset.Chipset.RED.getStack(), chipset, true, true)) {
ItemGate.setLogic(output, ItemGate.getLogic(output) == GateDefinition.GateLogic.AND ? GateDefinition.GateLogic.OR : GateDefinition.GateLogic.AND);
expansionsAdded++;
continue;
}
for (ItemStack expansion : recipes.values()) {
if (StackHelper.isMatchingItem(chipset, expansion, true, true) && !ItemGate.hasGateExpansion(output, recipes.inverse().get(expansion))) {
if (!preview) {
chipset.stackSize--;
}
ItemGate.addGateExpansion(output, recipes.inverse().get(expansion));
expansionsAdded++;
break;
}
}
}
if (expansionsAdded > 0) {
return output;
} else {
return !ItemGate.hasGateExpansion(inputA, expansion);
}
}
@Override
public boolean isValidInputB(ItemStack inputB) {
return StackHelper.isMatchingItem(inputB, chipset);
}
@Override
public CraftingResult<ItemStack> craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
if (inputA == null) {
return null;
}
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
if (result == null) {
return null;
}
ItemStack output = inputA;
output.stackSize = 1;
ItemGate.addGateExpansion(output, expansion);
result.crafted = output;
return result;
}
@Override
public Collection<Object> getInputs() {
ArrayList<Object> inputs = new ArrayList<Object>();
inputs.add(ItemGate.getAllGates());
inputs.add(chipset);
return inputs;
}
@Override
public Collection<Object> getOutput() {
ArrayList<Object> gates = new ArrayList<Object>();
for (ItemStack stack : ItemGate.getAllGates()) {
ItemStack newStack = stack.copy();
ItemGate.addGateExpansion(newStack, expansion);
gates.add(newStack);
}
return gates;
}
}

View file

@ -1,80 +0,0 @@
/**
* Copyright (c) 2011-2015, 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.transport.recipes;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.item.ItemStack;
import buildcraft.BuildCraftTransport;
import buildcraft.api.recipes.CraftingResult;
import buildcraft.core.lib.inventory.StackHelper;
import buildcraft.silicon.ItemRedstoneChipset;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.silicon.recipes.IntegrationTableRecipe;
import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import buildcraft.transport.gates.ItemGate;
public class GateLogicSwapRecipe extends IntegrationTableRecipe {
public GateLogicSwapRecipe(String id) {
setContents(id, BuildCraftTransport.pipeGate, 20000, 0);
}
@Override
public boolean isValidInputA(ItemStack inputA) {
return inputA != null && inputA.getItem() instanceof ItemGate && ItemGate.getMaterial(inputA) != GateMaterial.REDSTONE;
}
@Override
public boolean isValidInputB(ItemStack inputB) {
return StackHelper.isMatchingItem(inputB, ItemRedstoneChipset.Chipset.RED.getStack());
}
@Override
public CraftingResult<ItemStack> craft(TileIntegrationTable crafter, boolean preview, ItemStack inputA,
ItemStack inputB) {
CraftingResult<ItemStack> result = super.craft(crafter, preview, inputA, inputB);
if (result == null) {
return null;
}
ItemStack output = inputA;
output.stackSize = 1;
ItemGate.setLogic(output, ItemGate.getLogic(output) == GateLogic.AND ? GateLogic.OR : GateLogic.AND);
result.crafted = output;
return result;
}
@Override
public Collection<Object> getInputs() {
ArrayList<Object> inputs = new ArrayList<Object>();
inputs.add(ItemGate.getAllGates());
inputs.add(ItemRedstoneChipset.Chipset.RED.getStack());
return inputs;
}
@Override
public Collection<Object> getOutput() {
ArrayList<Object> gates = new ArrayList<Object>();
for (ItemStack stack : ItemGate.getAllGates()) {
ItemStack newStack = stack.copy();
ItemGate.setLogic(newStack, ItemGate.getLogic(newStack) == GateLogic.AND ? GateLogic.OR : GateLogic.AND);
gates.add(newStack);
}
return gates;
}
}