made progress for robot implementation, #1732
This commit is contained in:
parent
e6ff3d7825
commit
e7b680f29e
7 changed files with 171 additions and 40 deletions
23
api/buildcraft/api/boards/IRedstoneBoardNBT.java
Executable file
23
api/buildcraft/api/boards/IRedstoneBoardNBT.java
Executable file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* 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;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
public interface IRedstoneBoardNBT {
|
||||
|
||||
String getID();
|
||||
|
||||
String getName(NBTTagCompound nbt);
|
||||
|
||||
IRedstoneBoard create(NBTTagCompound nbt);
|
||||
|
||||
IIcon getIcon(NBTTagCompound nbt);
|
||||
}
|
|
@ -8,11 +8,15 @@
|
|||
*/
|
||||
package buildcraft.api.boards;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public abstract class RedstoneBoardRegistry {
|
||||
|
||||
public static RedstoneBoardRegistry instance;
|
||||
|
||||
public abstract void registerBoardClass(Class<? extends IRedstoneBoard> boardClass, float probability);
|
||||
public abstract void registerBoardClass(IRedstoneBoardNBT redstoneBoardNBT, float probability);
|
||||
|
||||
public abstract IRedstoneBoard createRandomBoard();
|
||||
public abstract void createRandomBoard(NBTTagCompound nbt);
|
||||
|
||||
public abstract IRedstoneBoardNBT getRedstoneBoard(NBTTagCompound nbt);
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import buildcraft.core.proxy.CoreProxy;
|
|||
import buildcraft.core.robots.EntityRobot;
|
||||
import buildcraft.core.robots.EntityRobotBuilder;
|
||||
import buildcraft.core.robots.EntityRobotPicker;
|
||||
import buildcraft.core.robots.boards.BoardRobotPickerNBT;
|
||||
import buildcraft.silicon.BlockLaser;
|
||||
import buildcraft.silicon.BlockLaserTable;
|
||||
import buildcraft.silicon.GuiHandler;
|
||||
|
@ -51,6 +52,7 @@ import buildcraft.silicon.TileAdvancedCraftingTable;
|
|||
import buildcraft.silicon.TileAssemblyTable;
|
||||
import buildcraft.silicon.TileIntegrationTable;
|
||||
import buildcraft.silicon.TileLaser;
|
||||
import buildcraft.silicon.boards.BoardRecipe;
|
||||
import buildcraft.silicon.boards.ImplRedstoneBoardRegistry;
|
||||
import buildcraft.silicon.network.PacketHandlerSilicon;
|
||||
import buildcraft.silicon.recipes.AdvancedFacadeRecipe;
|
||||
|
@ -114,6 +116,8 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
CoreProxy.proxy.registerItem(robotBuilderItem);
|
||||
|
||||
RedstoneBoardRegistry.instance = new ImplRedstoneBoardRegistry();
|
||||
|
||||
RedstoneBoardRegistry.instance.registerBoardClass(new BoardRobotPickerNBT(), 10);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
|
@ -215,6 +219,8 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
|||
'R', redstoneCrystal,
|
||||
'C', Chipset.DIAMOND.getStack());
|
||||
|
||||
BuildcraftRecipes.assemblyTable.addRecipe(new BoardRecipe());
|
||||
|
||||
// REVERSAL RECIPES
|
||||
EnumSet<GateMaterial> materials = EnumSet.allOf(GateMaterial.class);
|
||||
materials.remove(GateMaterial.REDSTONE);
|
||||
|
|
46
common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java
Executable file
46
common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java
Executable file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* 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.robots.boards;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import buildcraft.api.boards.IRedstoneBoard;
|
||||
import buildcraft.api.boards.IRedstoneBoardNBT;
|
||||
|
||||
public class BoardRobotPickerNBT implements IRedstoneBoardNBT {
|
||||
|
||||
public IIcon icon;
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "buildcraft:boardRobotPicker";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(NBTTagCompound nbt) {
|
||||
return getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRedstoneBoard create(NBTTagCompound nbt) {
|
||||
return new BoardRobotPicker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIcon(NBTTagCompound nbt) {
|
||||
if (icon == null) {
|
||||
icon = Minecraft.getMinecraft().getTextureMapBlocks().registerIcon("buildcraft:board_green");
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,18 +10,20 @@ package buildcraft.silicon;
|
|||
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
import buildcraft.core.ItemBuildCraft;
|
||||
import buildcraft.core.utils.NBTUtils;
|
||||
|
||||
public class ItemRedstoneBoard extends ItemBuildCraft {
|
||||
|
||||
public IIcon cleanBoard;
|
||||
public IIcon usedBoard;
|
||||
public IIcon unknownBoard;
|
||||
|
||||
public ItemRedstoneBoard() {
|
||||
super();
|
||||
|
@ -29,15 +31,19 @@ public class ItemRedstoneBoard extends ItemBuildCraft {
|
|||
|
||||
@Override
|
||||
public int getItemStackLimit(ItemStack stack) {
|
||||
return NBTUtils.getItemData(stack).hasKey("kind") ? 1 : 16;
|
||||
return NBTUtils.getItemData(stack).hasKey("id") ? 1 : 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconIndex(ItemStack stack) {
|
||||
if (!NBTUtils.getItemData(stack).hasKey("kind")) {
|
||||
NBTTagCompound cpt = NBTUtils.getItemData(stack);
|
||||
|
||||
if (!cpt.hasKey("id")) {
|
||||
itemIcon = cleanBoard;
|
||||
} else if (cpt.getString("id").equals("<unknown>")) {
|
||||
itemIcon = unknownBoard;
|
||||
} else {
|
||||
itemIcon = usedBoard;
|
||||
itemIcon = RedstoneBoardRegistry.instance.getRedstoneBoard(cpt).getIcon(cpt);
|
||||
}
|
||||
|
||||
return itemIcon;
|
||||
|
@ -47,7 +53,7 @@ public class ItemRedstoneBoard extends ItemBuildCraft {
|
|||
@SideOnly(Side.CLIENT)
|
||||
public void registerIcons(IIconRegister par1IconRegister) {
|
||||
cleanBoard = par1IconRegister.registerIcon("buildcraft:board_clean");
|
||||
usedBoard = par1IconRegister.registerIcon("buildcraft:board_used");
|
||||
unknownBoard = par1IconRegister.registerIcon("buildcraft:board_unknown");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,31 +11,42 @@ package buildcraft.silicon.boards;
|
|||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.recipes.IAssemblyRecipe;
|
||||
import buildcraft.api.transport.PipeWire;
|
||||
import buildcraft.core.inventory.ITransactor;
|
||||
import buildcraft.core.inventory.InventoryIterator;
|
||||
import buildcraft.core.inventory.Transactor;
|
||||
import buildcraft.core.inventory.filters.ArrayStackFilter;
|
||||
import buildcraft.core.utils.NBTUtils;
|
||||
|
||||
public class BoardRecipe implements IAssemblyRecipe {
|
||||
|
||||
private Object[] inputs;
|
||||
private ItemStack[] inputs;
|
||||
private ItemStack output;
|
||||
|
||||
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)};
|
||||
inputs = new ItemStack[] {
|
||||
new ItemStack(BuildCraftSilicon.redstoneBoard)};
|
||||
|
||||
output = new ItemStack(BuildCraftSilicon.redstoneBoard);
|
||||
NBTUtils.getItemData(output).setString("id", "<unknown>");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getOutput() {
|
||||
return new ItemStack(BuildCraftSilicon.redstoneBoard, 1, 1);
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack makeOutput() {
|
||||
return null;
|
||||
ItemStack stack = new ItemStack(BuildCraftSilicon.redstoneBoard);
|
||||
RedstoneBoardRegistry.instance.createRandomBoard(stack.stackTagCompound);
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,16 +59,53 @@ public class BoardRecipe implements IAssemblyRecipe {
|
|||
return 10;
|
||||
}
|
||||
|
||||
// FIXME: canBeDone and useItems could use some improvements and
|
||||
// factorization. See AssemblyRecipe as well.
|
||||
|
||||
@Override
|
||||
public boolean canBeDone(IInventory inv) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
for (ItemStack requirement : inputs) {
|
||||
if (requirement == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int found = 0; // Amount of ingredient found in inventory
|
||||
int expected = requirement.stackSize;
|
||||
|
||||
for (IInvSlot slot : InventoryIterator.getIterable(inv, ForgeDirection.UNKNOWN)) {
|
||||
ItemStack item = slot.getStackInSlot();
|
||||
if (item == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.isItemEqual(requirement)) {
|
||||
found += item.stackSize; // Adds quantity of stack to
|
||||
// amount found
|
||||
}
|
||||
|
||||
if (found >= expected) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Return false if the amount of ingredient found
|
||||
// is not enough
|
||||
if (found < expected) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useItems(IInventory inv) {
|
||||
// TODO Auto-generated method stub
|
||||
ITransactor tran = Transactor.getTransactorFor(inv);
|
||||
|
||||
for (ItemStack requirement : inputs) {
|
||||
for (int num = 0; num < requirement.stackSize; num++) {
|
||||
tran.remove(new ArrayStackFilter(requirement), ForgeDirection.UNKNOWN, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,57 +8,55 @@
|
|||
*/
|
||||
package buildcraft.silicon.boards;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import buildcraft.api.boards.IRedstoneBoard;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import buildcraft.api.boards.IRedstoneBoardNBT;
|
||||
import buildcraft.api.boards.RedstoneBoardRegistry;
|
||||
|
||||
public class ImplRedstoneBoardRegistry extends RedstoneBoardRegistry {
|
||||
|
||||
private static class BoardFactory {
|
||||
public Class<? extends IRedstoneBoard> clas;
|
||||
public IRedstoneBoardNBT boardNBT;
|
||||
public float probability;
|
||||
}
|
||||
|
||||
private float totalProbability;
|
||||
|
||||
private ArrayList<BoardFactory> boards = new ArrayList<BoardFactory>();
|
||||
private HashMap<String, BoardFactory> boards = new HashMap<String, BoardFactory>();
|
||||
|
||||
private Random rand = new Random();
|
||||
|
||||
@Override
|
||||
public void registerBoardClass(Class<? extends IRedstoneBoard> boardClass, float probability) {
|
||||
public void registerBoardClass(IRedstoneBoardNBT redstoneBoardNBT, float probability) {
|
||||
BoardFactory factory = new BoardFactory();
|
||||
factory.clas = boardClass;
|
||||
factory.boardNBT = redstoneBoardNBT;
|
||||
factory.probability = probability;
|
||||
|
||||
totalProbability += probability;
|
||||
boards.add(factory);
|
||||
boards.put(redstoneBoardNBT.getID(), factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRedstoneBoard createRandomBoard() {
|
||||
public void createRandomBoard(NBTTagCompound nbt) {
|
||||
float value = rand.nextFloat() * totalProbability;
|
||||
|
||||
float accumulatedSearch = 0;
|
||||
|
||||
for (BoardFactory f : boards) {
|
||||
for (BoardFactory f : boards.values()) {
|
||||
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();
|
||||
}
|
||||
nbt.setString("id", f.boardNBT.getID());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@Override
|
||||
public IRedstoneBoardNBT getRedstoneBoard(NBTTagCompound nbt) {
|
||||
return boards.get(nbt.getString("id")).boardNBT;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue