From 926764b0b5080b9415514b9ec345056453cdc7af Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Sat, 7 Jun 2014 16:43:05 +0200 Subject: [PATCH] picker board not takes parameters into account, #1732 --- .../core/robots/RobotIntegrationRecipe.java | 2 +- .../core/robots/boards/BoardRobotPicker.java | 51 ++++++++++++++++++- .../robots/boards/BoardRobotPickerNBT.java | 2 +- .../buildcraft/silicon/ItemRedstoneBoard.java | 1 - .../silicon/gui/GuiRedstoneBoard.java | 14 ++++- 5 files changed, 63 insertions(+), 7 deletions(-) diff --git a/common/buildcraft/core/robots/RobotIntegrationRecipe.java b/common/buildcraft/core/robots/RobotIntegrationRecipe.java index 54d9c6f2..615e1631 100755 --- a/common/buildcraft/core/robots/RobotIntegrationRecipe.java +++ b/common/buildcraft/core/robots/RobotIntegrationRecipe.java @@ -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; diff --git a/common/buildcraft/core/robots/boards/BoardRobotPicker.java b/common/buildcraft/core/robots/boards/BoardRobotPicker.java index 693ea7ea..6cb722e2 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPicker.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPicker.java @@ -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 { 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 { 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 { 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(), diff --git a/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java b/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java index 028c91a0..0433bfad 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java @@ -57,7 +57,7 @@ public final class BoardRobotPickerNBT extends RedstoneBoardRobotNBT { @Override public IRedstoneBoardRobot create(NBTTagCompound nbt) { - return new BoardRobotPicker(); + return new BoardRobotPicker(nbt); } @Override diff --git a/common/buildcraft/silicon/ItemRedstoneBoard.java b/common/buildcraft/silicon/ItemRedstoneBoard.java index dfc26f40..8f5f6731 100755 --- a/common/buildcraft/silicon/ItemRedstoneBoard.java +++ b/common/buildcraft/silicon/ItemRedstoneBoard.java @@ -47,7 +47,6 @@ public class ItemRedstoneBoard extends ItemBuildCraft { if (cpt.hasKey("id") && !"".equals(cpt.getString("id"))) { RedstoneBoardRegistry.instance.getRedstoneBoard(cpt).addInformation(stack, player, list, advanced); } - } @Override diff --git a/common/buildcraft/silicon/gui/GuiRedstoneBoard.java b/common/buildcraft/silicon/gui/GuiRedstoneBoard.java index 13c8b190..b234e2f0 100755 --- a/common/buildcraft/silicon/gui/GuiRedstoneBoard.java +++ b/common/buildcraft/silicon/gui/GuiRedstoneBoard.java @@ -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); } } }