picker board not takes parameters into account, #1732

This commit is contained in:
SpaceToad 2014-06-07 16:43:05 +02:00
parent 1518ccdcf6
commit 926764b0b5
5 changed files with 63 additions and 7 deletions

View file

@ -43,7 +43,7 @@ public class RobotIntegrationRecipe extends IntegrationTableRecipe {
if (result != null) {
ItemStack robot = new ItemStack(BuildCraftSilicon.robotItem);
NBTUtils.getItemData(robot).setTag("board", NBTUtils.getItemData(inputA));
NBTUtils.getItemData(robot).setTag("board", NBTUtils.getItemData(inputB));
result.crafted = robot;

View file

@ -5,13 +5,21 @@ import java.util.Set;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.boards.IBoardParameter;
import buildcraft.api.boards.IBoardParameterStack;
import buildcraft.api.boards.IRedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardNBT;
import buildcraft.api.boards.RedstoneBoardRegistry;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.core.inventory.TransactorSimple;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.robots.EntityRobot;
import buildcraft.core.robots.RobotAIMoveTo;
import buildcraft.core.robots.RobotAIReturnToDock;
@ -29,6 +37,21 @@ public class BoardRobotPicker implements IRedstoneBoardRobot<EntityRobot> {
private EntityItem target;
private int pickTime = -1;
private NBTTagCompound data;
private RedstoneBoardNBT board;
private IBoardParameter[] params;
private int range;
private IStackFilter stackFilter;
private boolean initialized = false;
public BoardRobotPicker(NBTTagCompound nbt) {
data = nbt;
board = RedstoneBoardRegistry.instance.getRedstoneBoard(nbt);
params = board.getParameters(nbt);
}
@Override
public void updateBoard(EntityRobot robot) {
TransactorSimple inventoryInsert = new TransactorSimple(robot);
@ -37,6 +60,26 @@ public class BoardRobotPicker implements IRedstoneBoardRobot<EntityRobot> {
return;
}
if (!initialized) {
range = data.getInteger("range");
IBoardParameter[] params = board.getParameters(data);
ItemStack[] stacks = new ItemStack[params.length];
for (int i = 0; i < stacks.length; ++i) {
IBoardParameterStack pStak = (IBoardParameterStack) params[i];
stacks[i] = pStak.getStack();
}
if (stacks.length > 0) {
stackFilter = new ArrayStackFilter(stacks);
} else {
stackFilter = null;
}
initialized = true;
}
if (target != null) {
if (target.isDead) {
targettedItems.remove(target.getEntityId());
@ -109,9 +152,13 @@ public class BoardRobotPicker implements IRedstoneBoardRobot<EntityRobot> {
double dz = e.posZ - robot.posZ;
double sqrDistance = dx * dx + dy * dy + dz * dz;
double maxDistance = 100 * 100;
double maxDistance = range * range;
if (sqrDistance <= maxDistance) {
if (sqrDistance >= maxDistance) {
continue;
} else if (stackFilter != null && !stackFilter.matches(((EntityItem) e).getEntityItem())) {
continue;
} else {
EntityItem item = (EntityItem) e;
if (inventoryInsert.inject(item.getEntityItem(),

View file

@ -57,7 +57,7 @@ public final class BoardRobotPickerNBT extends RedstoneBoardRobotNBT {
@Override
public IRedstoneBoardRobot create(NBTTagCompound nbt) {
return new BoardRobotPicker();
return new BoardRobotPicker(nbt);
}
@Override

View file

@ -47,7 +47,6 @@ public class ItemRedstoneBoard extends ItemBuildCraft {
if (cpt.hasKey("id") && !"<unknown>".equals(cpt.getString("id"))) {
RedstoneBoardRegistry.instance.getRedstoneBoard(cpt).addInformation(stack, player, list, advanced);
}
}
@Override

View file

@ -11,6 +11,7 @@ package buildcraft.silicon.gui;
import org.lwjgl.opengl.GL11;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
@ -79,6 +80,13 @@ public class GuiRedstoneBoard extends GuiAdvancedInterface {
drawBackgroundSlots();
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
super.drawGuiContainerForegroundLayer(par1, par2);
drawForegroundSelection(par1, par2);
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
@ -97,8 +105,10 @@ public class GuiRedstoneBoard extends GuiAdvancedInterface {
slot = slots[position];
if (slot instanceof ItemSlot) {
((ItemSlot) slot).stack = mc.thePlayer.inventory.getItemStack();
RPCHandler.rpcServer(container, "setParameterStack", position, mc.thePlayer.inventory.getItemStack());
ItemStack stackCopy = mc.thePlayer.inventory.getItemStack().copy();
stackCopy.stackSize = 1;
((ItemSlot) slot).stack = stackCopy;
RPCHandler.rpcServer(container, "setParameterStack", position, stackCopy);
}
}
}