made progress with robot recipes and boards, #1732
This commit is contained in:
parent
379ea6e278
commit
7acb8b4592
14 changed files with 396 additions and 163 deletions
15
api/buildcraft/api/boards/IRedstoneBoard.java
Executable file
15
api/buildcraft/api/boards/IRedstoneBoard.java
Executable file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* 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.boards;
|
||||
|
||||
public interface IRedstoneBoard<T> {
|
||||
|
||||
void updateBoard(T container);
|
||||
|
||||
}
|
18
api/buildcraft/api/boards/RedstoneBoardRegistry.java
Executable file
18
api/buildcraft/api/boards/RedstoneBoardRegistry.java
Executable file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* 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.boards;
|
||||
|
||||
public abstract class RedstoneBoardRegistry {
|
||||
|
||||
public static RedstoneBoardRegistry instance;
|
||||
|
||||
public abstract void registerBoardClass(Class<? extends IRedstoneBoard> boardClass, float probability);
|
||||
|
||||
public abstract IRedstoneBoard createRandomBoard();
|
||||
}
|
27
api/buildcraft/api/recipes/IAssemblyRecipe.java
Executable file
27
api/buildcraft/api/recipes/IAssemblyRecipe.java
Executable file
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* 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.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IAssemblyRecipe {
|
||||
|
||||
ItemStack getOutput();
|
||||
|
||||
ItemStack makeOutput();
|
||||
|
||||
Object[] getInputs();
|
||||
|
||||
double getEnergyCost();
|
||||
|
||||
boolean canBeDone(IInventory inv);
|
||||
|
||||
public void useItems(IInventory inv);
|
||||
}
|
|
@ -14,15 +14,6 @@ import net.minecraft.item.ItemStack;
|
|||
|
||||
public interface IAssemblyRecipeManager {
|
||||
|
||||
public interface IAssemblyRecipe {
|
||||
|
||||
ItemStack getOutput();
|
||||
|
||||
Object[] getInputs();
|
||||
|
||||
double getEnergyCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an Assembly Table recipe.
|
||||
*
|
||||
|
@ -36,5 +27,7 @@ public interface IAssemblyRecipeManager {
|
|||
*/
|
||||
void addRecipe(double energyCost, ItemStack output, Object... input);
|
||||
|
||||
void addRecipe(IAssemblyRecipe recipe);
|
||||
|
||||
List<? extends IAssemblyRecipe> getRecipes();
|
||||
}
|
||||
|
|
BIN
buildcraft_resources/assets/buildcraft/textures/items/board_unknown.png
Executable file
BIN
buildcraft_resources/assets/buildcraft/textures/items/board_unknown.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 251 B |
|
@ -26,6 +26,7 @@ import cpw.mods.fml.common.network.NetworkRegistry;
|
|||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import buildcraft.api.blueprints.SchematicRegistry;
|
||||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
import buildcraft.api.recipes.BuildcraftRecipes;
|
||||
import buildcraft.api.transport.PipeWire;
|
||||
import buildcraft.builders.schematics.SchematicRotateMeta;
|
||||
|
@ -50,6 +51,7 @@ import buildcraft.silicon.TileAdvancedCraftingTable;
|
|||
import buildcraft.silicon.TileAssemblyTable;
|
||||
import buildcraft.silicon.TileIntegrationTable;
|
||||
import buildcraft.silicon.TileLaser;
|
||||
import buildcraft.silicon.boards.ImplRedstoneBoardRegistry;
|
||||
import buildcraft.silicon.network.PacketHandlerSilicon;
|
||||
import buildcraft.silicon.recipes.AdvancedFacadeRecipe;
|
||||
import buildcraft.silicon.recipes.GateExpansionRecipe;
|
||||
|
@ -110,6 +112,8 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
|
||||
robotBuilderItem = new ItemRobot(EntityRobotBuilder.class).setUnlocalizedName("robotBuilder");
|
||||
CoreProxy.proxy.registerItem(robotBuilderItem);
|
||||
|
||||
RedstoneBoardRegistry.instance = new ImplRedstoneBoardRegistry();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
@ -192,6 +196,25 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
addGateRecipe(40000, GateMaterial.GOLD, Chipset.GOLD, PipeWire.RED, PipeWire.BLUE, PipeWire.GREEN);
|
||||
addGateRecipe(80000, GateMaterial.DIAMOND, Chipset.DIAMOND, PipeWire.RED, PipeWire.BLUE, PipeWire.GREEN, PipeWire.YELLOW);
|
||||
|
||||
// ROBOTS AND BOARDS
|
||||
BuildcraftRecipes.assemblyTable.addRecipe(100000, new ItemStack(redstoneCrystal), new ItemStack(
|
||||
Blocks.redstone_block));
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(redstoneBoard),
|
||||
"PPP",
|
||||
"PRP",
|
||||
"PPP",
|
||||
'R', Items.redstone,
|
||||
'P', Items.paper);
|
||||
|
||||
CoreProxy.proxy.addCraftingRecipe(new ItemStack(robotBaseItem),
|
||||
"PPP",
|
||||
"PRP",
|
||||
"C C",
|
||||
'P', Items.iron_ingot,
|
||||
'R', redstoneCrystal,
|
||||
'C', Chipset.DIAMOND.getStack());
|
||||
|
||||
// REVERSAL RECIPES
|
||||
EnumSet<GateMaterial> materials = EnumSet.allOf(GateMaterial.class);
|
||||
materials.remove(GateMaterial.REDSTONE);
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraftforge.oredict.OreDictionary;
|
|||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.recipes.IAssemblyRecipe;
|
||||
import buildcraft.api.recipes.IAssemblyRecipeManager;
|
||||
import buildcraft.core.inventory.ITransactor;
|
||||
import buildcraft.core.inventory.InventoryIterator;
|
||||
|
@ -30,7 +31,7 @@ import buildcraft.core.inventory.filters.ArrayStackFilter;
|
|||
public class AssemblyRecipeManager implements IAssemblyRecipeManager {
|
||||
|
||||
public static final AssemblyRecipeManager INSTANCE = new AssemblyRecipeManager();
|
||||
private List<AssemblyRecipe> assemblyRecipes = new LinkedList<AssemblyRecipe>();
|
||||
private List<IAssemblyRecipe> assemblyRecipes = new LinkedList<IAssemblyRecipe>();
|
||||
|
||||
@Override
|
||||
public void addRecipe(double energyCost, ItemStack output, Object... input) {
|
||||
|
@ -44,7 +45,12 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<AssemblyRecipe> getRecipes() {
|
||||
public void addRecipe(IAssemblyRecipe recipe) {
|
||||
assemblyRecipes.add(recipe);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IAssemblyRecipe> getRecipes() {
|
||||
return assemblyRecipes;
|
||||
}
|
||||
|
||||
|
@ -93,6 +99,7 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
|
|||
return energyCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeDone(IInventory inv) {
|
||||
for (int i = 0; i < processedInput.length; i++) {
|
||||
if (processedInput[i] == null) {
|
||||
|
@ -158,6 +165,7 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useItems(IInventory inv) {
|
||||
ITransactor tran = Transactor.getTransactorFor(inv);
|
||||
Object[] input = processedInput;
|
||||
|
@ -183,5 +191,10 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack makeOutput() {
|
||||
return getOutput().copy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class EntityRobot extends EntityLiving implements
|
|||
public DockingStation dockingStation = new DockingStation();
|
||||
public boolean isDocked = false;
|
||||
|
||||
protected RobotAIBase currentAI;
|
||||
public RobotAIBase currentAI;
|
||||
protected RobotAIBase nextAI;
|
||||
|
||||
private boolean needsUpdate = false;
|
||||
|
|
|
@ -8,11 +8,6 @@
|
|||
*/
|
||||
package buildcraft.core.robots;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -20,34 +15,22 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.api.boards.IRedstoneBoard;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.inventory.TransactorSimple;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.TravelingItem;
|
||||
import buildcraft.core.robots.boards.BoardRobotPicker;
|
||||
|
||||
public class EntityRobotPicker extends EntityRobot implements IInventory {
|
||||
|
||||
private static ResourceLocation texture = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_picker.png");
|
||||
private static Set<Integer> targettedItems = new HashSet<Integer>();
|
||||
|
||||
SafeTimeTracker scanTracker = new SafeTimeTracker(40, 10);
|
||||
SafeTimeTracker pickTracker = new SafeTimeTracker(20, 0);
|
||||
SafeTimeTracker unloadTracker = new SafeTimeTracker(20, 0);
|
||||
|
||||
TransactorSimple inventoryInsert = new TransactorSimple(this);
|
||||
|
||||
int pickTime = -1;
|
||||
|
||||
ItemStack[] inv = new ItemStack[6];
|
||||
|
||||
private EntityItem target;
|
||||
private IRedstoneBoard<EntityRobotPicker> board;
|
||||
|
||||
public EntityRobotPicker(World par1World) {
|
||||
super(par1World);
|
||||
|
||||
board = new BoardRobotPicker();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,102 +42,7 @@ public class EntityRobotPicker extends EntityRobot implements IInventory {
|
|||
public void onUpdate () {
|
||||
super.onUpdate();
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target != null) {
|
||||
if (target.isDead) {
|
||||
targettedItems.remove(target.getEntityId());
|
||||
target = null;
|
||||
setMainAI(new RobotAIReturnToDock(this));
|
||||
hideLaser();
|
||||
scan ();
|
||||
} else if (pickTime == -1) {
|
||||
if (currentAI.isDone()) {
|
||||
setLaserDestination((float) target.posX, (float) target.posY, (float) target.posZ);
|
||||
showLaser();
|
||||
pickTracker = new SafeTimeTracker (200);
|
||||
pickTime = 0;
|
||||
}
|
||||
} else {
|
||||
pickTime++;
|
||||
|
||||
if (pickTime > 20) {
|
||||
target.getEntityItem().stackSize -= inventoryInsert.inject(
|
||||
target.getEntityItem(), ForgeDirection.UNKNOWN,
|
||||
true);
|
||||
|
||||
if (target.getEntityItem().stackSize <= 0) {
|
||||
target.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isDocked) {
|
||||
TileGenericPipe pipe = (TileGenericPipe) worldObj
|
||||
.getTileEntity(dockingStation.x, dockingStation.y,
|
||||
dockingStation.z);
|
||||
|
||||
if (pipe != null && pipe.pipe.transport instanceof PipeTransportItems) {
|
||||
if (unloadTracker.markTimeIfDelay(worldObj)) {
|
||||
for (int i = 0; i < inv.length; ++i) {
|
||||
if (inv[i] != null) {
|
||||
float cx = dockingStation.x + 0.5F + 0.2F * dockingStation.side.offsetX;
|
||||
float cy = dockingStation.y + 0.5F + 0.2F * dockingStation.side.offsetY;
|
||||
float cz = dockingStation.z + 0.5F + 0.2F * dockingStation.side.offsetZ;
|
||||
|
||||
TravelingItem item = TravelingItem.make(cx, cy,
|
||||
cz, inv[i]);
|
||||
|
||||
((PipeTransportItems) pipe.pipe.transport)
|
||||
.injectItem(item, dockingStation.side.getOpposite());
|
||||
|
||||
inv[i] = null;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scanTracker.markTimeIfDelay(worldObj)) {
|
||||
scan ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void scan () {
|
||||
for (Object o : worldObj.loadedEntityList) {
|
||||
Entity e = (Entity) o;
|
||||
|
||||
if (!e.isDead && e instanceof EntityItem && !targettedItems.contains(e.getEntityId())) {
|
||||
double dx = e.posX - posX;
|
||||
double dy = e.posY - posY;
|
||||
double dz = e.posZ - posZ;
|
||||
|
||||
double sqrDistance = dx * dx + dy * dy + dz * dz;
|
||||
double maxDistance = 100 * 100;
|
||||
|
||||
if (sqrDistance <= maxDistance) {
|
||||
EntityItem item = (EntityItem) e;
|
||||
|
||||
if (inventoryInsert.inject(item.getEntityItem(),
|
||||
ForgeDirection.UNKNOWN, false) > 0) {
|
||||
|
||||
target = item;
|
||||
targettedItems.add(e.getEntityId());
|
||||
isDocked = false;
|
||||
setMainAI(new RobotAIMoveTo(this, (float) e.posX,
|
||||
(float) e.posY, (float) e.posZ));
|
||||
pickTime = -1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
board.updateBoard(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
134
common/buildcraft/core/robots/boards/BoardRobotPicker.java
Executable file
134
common/buildcraft/core/robots/boards/BoardRobotPicker.java
Executable file
|
@ -0,0 +1,134 @@
|
|||
package buildcraft.core.robots.boards;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.boards.IRedstoneBoard;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import buildcraft.core.inventory.TransactorSimple;
|
||||
import buildcraft.core.robots.EntityRobotPicker;
|
||||
import buildcraft.core.robots.RobotAIMoveTo;
|
||||
import buildcraft.core.robots.RobotAIReturnToDock;
|
||||
import buildcraft.transport.PipeTransportItems;
|
||||
import buildcraft.transport.TileGenericPipe;
|
||||
import buildcraft.transport.TravelingItem;
|
||||
|
||||
public class BoardRobotPicker implements IRedstoneBoard<EntityRobotPicker> {
|
||||
|
||||
private static Set<Integer> targettedItems = new HashSet<Integer>();
|
||||
|
||||
SafeTimeTracker scanTracker = new SafeTimeTracker(40, 10);
|
||||
SafeTimeTracker pickTracker = new SafeTimeTracker(20, 0);
|
||||
SafeTimeTracker unloadTracker = new SafeTimeTracker(20, 0);
|
||||
|
||||
private EntityItem target;
|
||||
|
||||
int pickTime = -1;
|
||||
|
||||
@Override
|
||||
public void updateBoard(EntityRobotPicker robot) {
|
||||
TransactorSimple inventoryInsert = new TransactorSimple(robot);
|
||||
|
||||
if (robot.worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target != null) {
|
||||
if (target.isDead) {
|
||||
targettedItems.remove(target.getEntityId());
|
||||
target = null;
|
||||
robot.setMainAI(new RobotAIReturnToDock(robot));
|
||||
scan(robot);
|
||||
} else if (pickTime == -1) {
|
||||
if (robot.currentAI.isDone()) {
|
||||
robot.setLaserDestination((float) target.posX, (float) target.posY, (float) target.posZ);
|
||||
pickTracker = new SafeTimeTracker(200);
|
||||
pickTime = 0;
|
||||
}
|
||||
} else {
|
||||
pickTime++;
|
||||
|
||||
if (pickTime > 20) {
|
||||
target.getEntityItem().stackSize -= inventoryInsert.inject(
|
||||
target.getEntityItem(), ForgeDirection.UNKNOWN,
|
||||
true);
|
||||
|
||||
if (target.getEntityItem().stackSize <= 0) {
|
||||
target.setDead();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (robot.isDocked) {
|
||||
TileGenericPipe pipe = (TileGenericPipe) robot.worldObj
|
||||
.getTileEntity(robot.dockingStation.x, robot.dockingStation.y,
|
||||
robot.dockingStation.z);
|
||||
|
||||
if (pipe != null && pipe.pipe.transport instanceof PipeTransportItems) {
|
||||
if (unloadTracker.markTimeIfDelay(robot.worldObj)) {
|
||||
for (int i = 0; i < robot.getSizeInventory(); ++i) {
|
||||
if (robot.getStackInSlot(i) != null) {
|
||||
float cx = robot.dockingStation.x + 0.5F + 0.2F * robot.dockingStation.side.offsetX;
|
||||
float cy = robot.dockingStation.y + 0.5F + 0.2F * robot.dockingStation.side.offsetY;
|
||||
float cz = robot.dockingStation.z + 0.5F + 0.2F * robot.dockingStation.side.offsetZ;
|
||||
|
||||
TravelingItem item = TravelingItem.make(cx, cy,
|
||||
cz, robot.getStackInSlot(i));
|
||||
|
||||
((PipeTransportItems) pipe.pipe.transport)
|
||||
.injectItem(item, robot.dockingStation.side.getOpposite());
|
||||
|
||||
robot.setInventorySlotContents(i, null);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (scanTracker.markTimeIfDelay(robot.worldObj)) {
|
||||
scan(robot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void scan(EntityRobotPicker robot) {
|
||||
TransactorSimple inventoryInsert = new TransactorSimple(robot);
|
||||
|
||||
for (Object o : robot.worldObj.loadedEntityList) {
|
||||
Entity e = (Entity) o;
|
||||
|
||||
if (!e.isDead && e instanceof EntityItem && !targettedItems.contains(e.getEntityId())) {
|
||||
double dx = e.posX - robot.posX;
|
||||
double dy = e.posY - robot.posY;
|
||||
double dz = e.posZ - robot.posZ;
|
||||
|
||||
double sqrDistance = dx * dx + dy * dy + dz * dz;
|
||||
double maxDistance = 100 * 100;
|
||||
|
||||
if (sqrDistance <= maxDistance) {
|
||||
EntityItem item = (EntityItem) e;
|
||||
|
||||
if (inventoryInsert.inject(item.getEntityItem(),
|
||||
ForgeDirection.UNKNOWN, false) > 0) {
|
||||
|
||||
target = item;
|
||||
targettedItems.add(e.getEntityId());
|
||||
robot.isDocked = false;
|
||||
robot.setMainAI(new RobotAIMoveTo(robot, (float) e.posX,
|
||||
(float) e.posY, (float) e.posZ));
|
||||
pickTime = -1;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,20 +26,20 @@ import net.minecraftforge.common.util.Constants;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.recipes.IAssemblyRecipe;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketNBT;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager.AssemblyRecipe;
|
||||
import buildcraft.core.triggers.ActionMachineControl;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public class TileAssemblyTable extends TileLaserTableBase implements IMachine, IInventory {
|
||||
|
||||
public AssemblyRecipe currentRecipe;
|
||||
private Set<AssemblyRecipe> plannedOutput = new LinkedHashSet<AssemblyRecipe>();
|
||||
public IAssemblyRecipe currentRecipe;
|
||||
private Set<IAssemblyRecipe> plannedOutput = new LinkedHashSet<IAssemblyRecipe>();
|
||||
|
||||
public static class SelectionMessage {
|
||||
|
||||
|
@ -62,10 +62,10 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
}
|
||||
}
|
||||
|
||||
public List<AssemblyRecipe> getPotentialOutputs() {
|
||||
List<AssemblyRecipe> result = new LinkedList<AssemblyRecipe>();
|
||||
public List<IAssemblyRecipe> getPotentialOutputs() {
|
||||
List<IAssemblyRecipe> result = new LinkedList<IAssemblyRecipe>();
|
||||
|
||||
for (AssemblyRecipe recipe : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
for (IAssemblyRecipe recipe : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
if (recipe.canBeDone(this)) {
|
||||
result.add(recipe);
|
||||
}
|
||||
|
@ -98,10 +98,9 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
setEnergy(0);
|
||||
|
||||
if (currentRecipe.canBeDone(this)) {
|
||||
|
||||
currentRecipe.useItems(this);
|
||||
|
||||
ItemStack remaining = currentRecipe.output.copy();
|
||||
ItemStack remaining = currentRecipe.makeOutput();
|
||||
remaining.stackSize -= Utils.addToRandomInventoryAround(worldObj, xCoord, yCoord, zCoord, remaining);
|
||||
|
||||
if (remaining.stackSize > 0) {
|
||||
|
@ -109,7 +108,8 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
}
|
||||
|
||||
if (remaining.stackSize > 0) {
|
||||
EntityItem entityitem = new EntityItem(worldObj, xCoord + 0.5, yCoord + 0.7, zCoord + 0.5, currentRecipe.output.copy());
|
||||
EntityItem entityitem = new EntityItem(worldObj, xCoord + 0.5, yCoord + 0.7, zCoord + 0.5,
|
||||
remaining);
|
||||
|
||||
worldObj.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
|
@ -153,8 +153,9 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
continue;
|
||||
}
|
||||
|
||||
for (AssemblyRecipe r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
if (r.output.getItem() == stack.getItem() && r.output.getItemDamage() == stack.getItemDamage()) {
|
||||
for (IAssemblyRecipe r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
if (r.getOutput().getItem() == stack.getItem()
|
||||
&& r.getOutput().getItemDamage() == stack.getItemDamage()) {
|
||||
plannedOutput.add(r);
|
||||
break;
|
||||
}
|
||||
|
@ -164,8 +165,9 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
if (nbt.hasKey("recipe")) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("recipe"));
|
||||
|
||||
for (AssemblyRecipe r : plannedOutput) {
|
||||
if (r.output.getItem() == stack.getItem() && r.output.getItemDamage() == stack.getItemDamage()) {
|
||||
for (IAssemblyRecipe r : plannedOutput) {
|
||||
if (r.getOutput().getItem() == stack.getItem()
|
||||
&& r.getOutput().getItemDamage() == stack.getItemDamage()) {
|
||||
setCurrentRecipe(r);
|
||||
break;
|
||||
}
|
||||
|
@ -179,9 +181,9 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
|
||||
NBTTagList list = new NBTTagList();
|
||||
|
||||
for (AssemblyRecipe recipe : plannedOutput) {
|
||||
for (IAssemblyRecipe recipe : plannedOutput) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
recipe.output.writeToNBT(cpt);
|
||||
recipe.getOutput().writeToNBT(cpt);
|
||||
list.appendTag(cpt);
|
||||
}
|
||||
|
||||
|
@ -189,12 +191,12 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
|
||||
if (currentRecipe != null) {
|
||||
NBTTagCompound recipe = new NBTTagCompound();
|
||||
currentRecipe.output.writeToNBT(recipe);
|
||||
currentRecipe.getOutput().writeToNBT(recipe);
|
||||
nbt.setTag("recipe", recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPlanned(AssemblyRecipe recipe) {
|
||||
public boolean isPlanned(IAssemblyRecipe recipe) {
|
||||
if (recipe == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -202,11 +204,11 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
return plannedOutput.contains(recipe);
|
||||
}
|
||||
|
||||
public boolean isAssembling(AssemblyRecipe recipe) {
|
||||
public boolean isAssembling(IAssemblyRecipe recipe) {
|
||||
return recipe != null && recipe == currentRecipe;
|
||||
}
|
||||
|
||||
private void setCurrentRecipe(AssemblyRecipe recipe) {
|
||||
private void setCurrentRecipe(IAssemblyRecipe recipe) {
|
||||
this.currentRecipe = recipe;
|
||||
}
|
||||
|
||||
|
@ -218,7 +220,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
return 0;
|
||||
}
|
||||
|
||||
public void planOutput(AssemblyRecipe recipe) {
|
||||
public void planOutput(IAssemblyRecipe recipe) {
|
||||
if (recipe != null && !isPlanned(recipe)) {
|
||||
plannedOutput.add(recipe);
|
||||
|
||||
|
@ -228,7 +230,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
}
|
||||
}
|
||||
|
||||
public void cancelPlanOutput(AssemblyRecipe recipe) {
|
||||
public void cancelPlanOutput(IAssemblyRecipe recipe) {
|
||||
if (isAssembling(recipe)) {
|
||||
setCurrentRecipe(null);
|
||||
}
|
||||
|
@ -243,7 +245,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
public void setNextCurrentRecipe() {
|
||||
boolean takeNext = false;
|
||||
|
||||
for (AssemblyRecipe recipe : plannedOutput) {
|
||||
for (IAssemblyRecipe recipe : plannedOutput) {
|
||||
if (recipe == currentRecipe) {
|
||||
takeNext = true;
|
||||
} else if (takeNext && recipe.canBeDone(this)) {
|
||||
|
@ -252,7 +254,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
}
|
||||
}
|
||||
|
||||
for (AssemblyRecipe recipe : plannedOutput) {
|
||||
for (IAssemblyRecipe recipe : plannedOutput) {
|
||||
if (recipe.canBeDone(this)) {
|
||||
setCurrentRecipe(recipe);
|
||||
return;
|
||||
|
@ -263,8 +265,9 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
}
|
||||
|
||||
public void handleSelectionMessage(SelectionMessage message) {
|
||||
for (AssemblyRecipe recipe : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
if (recipe.output.isItemEqual(message.stack) && ItemStack.areItemStackTagsEqual(recipe.output, message.stack)) {
|
||||
for (IAssemblyRecipe recipe : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
if (recipe.getOutput().isItemEqual(message.stack)
|
||||
&& ItemStack.areItemStackTagsEqual(recipe.getOutput(), message.stack)) {
|
||||
if (message.select) {
|
||||
planOutput(recipe);
|
||||
} else {
|
||||
|
@ -277,10 +280,10 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
}
|
||||
|
||||
public void sendSelectionTo(EntityPlayer player) {
|
||||
for (AssemblyRecipe recipe : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
for (IAssemblyRecipe recipe : AssemblyRecipeManager.INSTANCE.getRecipes()) {
|
||||
SelectionMessage message = new SelectionMessage();
|
||||
|
||||
message.stack = recipe.output;
|
||||
message.stack = recipe.getOutput();
|
||||
|
||||
if (isPlanned(recipe)) {
|
||||
message.select = true;
|
||||
|
|
55
common/buildcraft/silicon/boards/BoardRecipe.java
Executable file
55
common/buildcraft/silicon/boards/BoardRecipe.java
Executable file
|
@ -0,0 +1,55 @@
|
|||
package buildcraft.silicon.boards;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.recipes.IAssemblyRecipe;
|
||||
import buildcraft.api.transport.PipeWire;
|
||||
|
||||
public class BoardRecipe implements IAssemblyRecipe {
|
||||
|
||||
private Object[] inputs;
|
||||
|
||||
public BoardRecipe () {
|
||||
inputs = new Object[] {
|
||||
new ItemStack(BuildCraftSilicon.redstoneBoard, 1, 0),
|
||||
PipeWire.RED.getStack(1),
|
||||
PipeWire.BLUE.getStack(1),
|
||||
PipeWire.YELLOW.getStack(1),
|
||||
PipeWire.GREEN.getStack(1)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
return new ItemStack(BuildCraftSilicon.redstoneBoard, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack makeOutput() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getEnergyCost() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeDone(IInventory inv) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useItems(IInventory inv) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
64
common/buildcraft/silicon/boards/ImplRedstoneBoardRegistry.java
Executable file
64
common/buildcraft/silicon/boards/ImplRedstoneBoardRegistry.java
Executable file
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* 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.boards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import buildcraft.api.boards.IRedstoneBoard;
|
||||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
|
||||
public class ImplRedstoneBoardRegistry extends RedstoneBoardRegistry {
|
||||
|
||||
private static class BoardFactory {
|
||||
public Class<? extends IRedstoneBoard> clas;
|
||||
public float probability;
|
||||
}
|
||||
|
||||
private float totalProbability;
|
||||
|
||||
private ArrayList<BoardFactory> boards = new ArrayList<BoardFactory>();
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
@Override
|
||||
public void registerBoardClass(Class<? extends IRedstoneBoard> boardClass, float probability) {
|
||||
BoardFactory factory = new BoardFactory();
|
||||
factory.clas = boardClass;
|
||||
factory.probability = probability;
|
||||
|
||||
totalProbability += probability;
|
||||
boards.add(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRedstoneBoard createRandomBoard() {
|
||||
float value = rand.nextFloat() * totalProbability;
|
||||
|
||||
float accumulatedSearch = 0;
|
||||
|
||||
for (BoardFactory f : boards) {
|
||||
accumulatedSearch += f.probability;
|
||||
|
||||
if (accumulatedSearch < value) {
|
||||
try {
|
||||
return f.clas.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.ResourceLocation;
|
|||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.recipes.IAssemblyRecipe;
|
||||
import buildcraft.core.CoreIconProvider;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.gui.AdvancedSlot;
|
||||
|
@ -28,7 +29,6 @@ import buildcraft.core.gui.GuiAdvancedInterface;
|
|||
import buildcraft.core.network.PacketCoordinates;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketNBT;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager.AssemblyRecipe;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
import buildcraft.silicon.TileAssemblyTable;
|
||||
import buildcraft.silicon.TileAssemblyTable.SelectionMessage;
|
||||
|
@ -81,7 +81,7 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
|
|||
|
||||
class RecipeSlot extends AdvancedSlot {
|
||||
|
||||
public AssemblyRecipe recipe;
|
||||
public IAssemblyRecipe recipe;
|
||||
|
||||
public RecipeSlot(int x, int y) {
|
||||
super(GuiAssemblyTable.this, x, y);
|
||||
|
@ -125,8 +125,8 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
|
|||
}
|
||||
|
||||
public void updateRecipes() {
|
||||
List<AssemblyRecipe> potentialRecipes = table.getPotentialOutputs();
|
||||
Iterator<AssemblyRecipe> cur = potentialRecipes.iterator();
|
||||
List<IAssemblyRecipe> potentialRecipes = table.getPotentialOutputs();
|
||||
Iterator<IAssemblyRecipe> cur = potentialRecipes.iterator();
|
||||
|
||||
for (int p = 0; p < 8; ++p) {
|
||||
if (cur.hasNext()) {
|
||||
|
@ -199,7 +199,7 @@ public class GuiAssemblyTable extends GuiAdvancedInterface {
|
|||
message.select = true;
|
||||
}
|
||||
|
||||
message.stack = slot.recipe.output;
|
||||
message.stack = slot.recipe.getOutput();
|
||||
|
||||
if (table.getWorldObj().isRemote) {
|
||||
PacketNBT packet = new PacketNBT(PacketIds.SELECTION_ASSEMBLY, message.getNBT(), table.xCoord, table.yCoord, table.zCoord);
|
||||
|
|
Loading…
Reference in a new issue