Implemented leave cutter, close #1876

This commit is contained in:
SpaceToad 2014-06-12 18:29:02 +02:00
parent e60950db9b
commit 101f591f8f
21 changed files with 361 additions and 98 deletions

View file

@ -41,6 +41,8 @@ public abstract class RedstoneBoardNBT<T> {
public abstract void createRandomBoard(NBTTagCompound nbt);
public abstract void createDefaultBoard(NBTTagCompound nbt);
public IBoardParameter[] getParameters(NBTTagCompound nbt) {
NBTTagList paramsNBT = nbt.getTagList("parameters", Constants.NBT.TAG_COMPOUND);
IBoardParameter[] result = new IBoardParameter[paramsNBT.tagCount()];
@ -79,4 +81,5 @@ public abstract class RedstoneBoardNBT<T> {
public float nextFloat(int difficulty) {
return 1F - (float) Math.pow(rand.nextFloat(), 1F / difficulty);
}
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.api.boards;
import java.util.Collection;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.nbt.NBTTagCompound;
@ -31,4 +33,6 @@ public abstract class RedstoneBoardRegistry {
public abstract String getKindForParam(IBoardParameter param);
public abstract Collection<RedstoneBoardNBT> getAllBoardNBTs();
}

View file

@ -8,11 +8,16 @@
*/
package buildcraft.api.boards;
import java.util.HashSet;
import buildcraft.core.BlockIndex;
import buildcraft.robots.AIRobot;
import buildcraft.robots.EntityRobotBase;
public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoard<EntityRobotBase> {
public static HashSet<BlockIndex> reservedBlocks = new HashSet<BlockIndex>();
public RedstoneBoardRobot(EntityRobotBase iRobot) {
super(iRobot);
}
@ -26,4 +31,29 @@ public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoa
}
public static boolean isFreeBlock(BlockIndex index) {
synchronized (reservedBlocks) {
return !reservedBlocks.contains(index);
}
}
public static boolean reserveBlock(BlockIndex index) {
synchronized (reservedBlocks) {
if (!reservedBlocks.contains(index)) {
reservedBlocks.add(index);
return true;
} else {
return false;
}
}
}
public static void releaseBlock(BlockIndex index) {
synchronized (reservedBlocks) {
if (reservedBlocks.contains(index)) {
reservedBlocks.remove(index);
}
}
}
}

View file

@ -24,6 +24,7 @@ public final class BuildCraftAPI {
public static WorldProperty isSoftProperty;
public static WorldProperty isWoodProperty;
public static WorldProperty isLeavesProperty;
/**
* Deactivate constructor

View file

@ -3,6 +3,7 @@
buildcraft.boardRobotPicker=Picker
buildcraft.boardRobotLumberjack=Lumberjack
buildcraft.boardRobotPlanter=Planter
buildcraft.boardRobotLeaveCutter=Leave Cutter
buildcraft.boardDetail.parameters=Parameters
buildcraft.boardDetail.range=Range

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -57,6 +57,7 @@ import net.minecraftforge.fluids.BlockFluidBase;
import net.minecraftforge.oredict.OreDictionary;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IIconProvider;
@ -102,6 +103,7 @@ import buildcraft.core.triggers.TriggerInventoryLevel;
import buildcraft.core.triggers.TriggerMachine;
import buildcraft.core.triggers.TriggerRedstoneInput;
import buildcraft.core.utils.CraftingHandler;
import buildcraft.core.utils.WorldPropertyIsLeave;
import buildcraft.core.utils.WorldPropertyIsSoft;
import buildcraft.core.utils.WorldPropertyIsWood;
import buildcraft.robots.DockingStationRegistry;
@ -355,6 +357,7 @@ public class BuildCraftCore extends BuildCraftMod {
BuildCraftAPI.isSoftProperty = new WorldPropertyIsSoft();
BuildCraftAPI.isWoodProperty = new WorldPropertyIsWood();
BuildCraftAPI.isLeavesProperty = new WorldPropertyIsLeave();
}
@Mod.EventHandler
@ -456,6 +459,8 @@ public class BuildCraftCore extends BuildCraftMod {
DockingStationRegistry.clear();
BuildCraftAPI.isSoftProperty.clear();
BuildCraftAPI.isWoodProperty.clear();
BuildCraftAPI.isLeavesProperty.clear();
RedstoneBoardRobot.reservedBlocks.clear();
}
@Mod.EventHandler

View file

@ -37,6 +37,7 @@ import buildcraft.core.Version;
import buildcraft.core.network.BuildCraftChannelHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.robots.RobotIntegrationRecipe;
import buildcraft.core.robots.boards.BoardRobotLeaveCutterNBT;
import buildcraft.core.robots.boards.BoardRobotLumberjackNBT;
import buildcraft.core.robots.boards.BoardRobotPickerNBT;
import buildcraft.core.robots.boards.BoardRobotPlanterNBT;
@ -112,6 +113,7 @@ public class BuildCraftSilicon extends BuildCraftMod {
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotPickerNBT.instance, 10);
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotLumberjackNBT.instance, 10);
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotPlanterNBT.instance, 5);
RedstoneBoardRegistry.instance.registerBoardClass(BoardRobotLeaveCutterNBT.instance, 5);
}
@Mod.EventHandler

View file

@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory;
import buildcraft.BuildCraftSilicon;
import buildcraft.BuildCraftTransport;
import buildcraft.transport.ItemFacade;
@ -25,7 +26,8 @@ public enum CreativeTabBuildCraft {
BLOCKS,
ITEMS,
PIPES,
FACADES;
FACADES,
BOARDS;
private final CreativeTabs tab;
private CreativeTabBuildCraft() {
@ -50,6 +52,8 @@ public enum CreativeTabBuildCraft {
return new ItemStack (BuildCraftTransport.pipeItemsDiamond, 1);
case FACADES:
return ItemFacade.getFacade(Blocks.brick_block, 0);
case BOARDS:
return new ItemStack(BuildCraftSilicon.redstoneBoard, 1);
}
return ItemFacade.getFacade(Blocks.brick_block, 0);

View file

@ -16,13 +16,14 @@ import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeHooks;
import buildcraft.core.BlockIndex;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtil;
import buildcraft.robots.AIRobot;
import buildcraft.robots.EntityRobotBase;
public class AIRobotCutWood extends AIRobot {
public class AIRobotBreakWithTool extends AIRobot {
public BlockIndex woodToChop;
public BlockIndex blockToBreak;
private float blockDamage = 0;
private Block block;
@ -30,20 +31,20 @@ public class AIRobotCutWood extends AIRobot {
private float hardness;
private float speed;
public AIRobotCutWood(EntityRobotBase iRobot, BlockIndex iWoodToChop) {
public AIRobotBreakWithTool(EntityRobotBase iRobot, BlockIndex iBlockToBreak) {
super(iRobot, 2);
woodToChop = iWoodToChop;
blockToBreak = iBlockToBreak;
}
@Override
public void start() {
robot.aimItemAt(woodToChop.x, woodToChop.y, woodToChop.z);
robot.aimItemAt(blockToBreak.x, blockToBreak.y, blockToBreak.z);
robot.setItemActive(true);
block = robot.worldObj.getBlock(woodToChop.x, woodToChop.y, woodToChop.z);
meta = robot.worldObj.getBlockMetadata(woodToChop.x, woodToChop.y, woodToChop.z);
hardness = block.getBlockHardness(robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z);
block = robot.worldObj.getBlock(blockToBreak.x, blockToBreak.y, blockToBreak.z);
meta = robot.worldObj.getBlockMetadata(blockToBreak.x, blockToBreak.y, blockToBreak.z);
hardness = block.getBlockHardness(robot.worldObj, blockToBreak.x, blockToBreak.y, blockToBreak.z);
speed = getBreakSpeed(robot, robot.getItemInUse(), block, meta);
}
@ -52,12 +53,15 @@ public class AIRobotCutWood extends AIRobot {
blockDamage += speed / hardness / 30F;
if (blockDamage > 1.0F) {
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x,
woodToChop.y, woodToChop.z, -1);
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), blockToBreak.x,
blockToBreak.y, blockToBreak.z, -1);
blockDamage = 0;
BlockUtil.breakBlock((WorldServer) robot.worldObj, woodToChop.x, woodToChop.y, woodToChop.z, 6000);
robot.getItemInUse().getItem().onBlockDestroyed(robot.getItemInUse(), robot.worldObj, block, woodToChop.x,
woodToChop.y, woodToChop.z, robot);
robot.getItemInUse().getItem()
.onBlockStartBreak(robot.getItemInUse(), blockToBreak.x, blockToBreak.y, blockToBreak.z,
CoreProxy.proxy.getBuildCraftPlayer((WorldServer) robot.worldObj).get());
BlockUtil.breakBlock((WorldServer) robot.worldObj, blockToBreak.x, blockToBreak.y, blockToBreak.z, 6000);
robot.getItemInUse().getItem().onBlockDestroyed(robot.getItemInUse(), robot.worldObj, block, blockToBreak.x,
blockToBreak.y, blockToBreak.z, robot);
if (robot.getItemInUse().getItemDamage() >= robot.getItemInUse().getMaxDamage()) {
robot.setItemInUse(null);
@ -65,16 +69,16 @@ public class AIRobotCutWood extends AIRobot {
terminate();
} else {
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x,
woodToChop.y, woodToChop.z, (int) (blockDamage * 10.0F) - 1);
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), blockToBreak.x,
blockToBreak.y, blockToBreak.z, (int) (blockDamage * 10.0F) - 1);
}
}
@Override
public void end() {
robot.setItemActive(false);
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), woodToChop.x,
woodToChop.y, woodToChop.z, -1);
robot.worldObj.destroyBlockInWorldPartially(robot.getEntityId(), blockToBreak.x,
blockToBreak.y, blockToBreak.z, -1);
}
private float getBreakSpeed(EntityRobotBase robot, ItemStack usingItem, Block block, int meta) {

View file

@ -10,9 +10,6 @@ package buildcraft.core.robots.boards;
import java.util.LinkedList;
import net.minecraft.world.World;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.core.BlockIndex;
import buildcraft.core.robots.AIRobotMoveToBlock;
import buildcraft.core.utils.IPathFound;
@ -21,39 +18,32 @@ import buildcraft.core.utils.PathFindingJob;
import buildcraft.robots.AIRobot;
import buildcraft.robots.EntityRobotBase;
public class AIRobotGoToWood extends AIRobot {
public class AIRobotSearchBlock extends AIRobot {
public BlockIndex woodFound;
private PathFinding woodScanner = null;
private PathFindingJob woodScannerJob;
public BlockIndex blockFound;
private PathFinding blockScanner = null;
private PathFindingJob blockScannerJob;
private IPathFound pathFound;
public AIRobotGoToWood(EntityRobotBase iRobot) {
public AIRobotSearchBlock(EntityRobotBase iRobot, IPathFound iPathFound) {
super(iRobot, 2);
pathFound = iPathFound;
}
@Override
public void start() {
woodScanner = new PathFinding(robot.worldObj, new BlockIndex(robot), new IPathFound() {
@Override
public boolean endReached(World world, int x, int y, int z) {
if (BuildCraftAPI.isWoodProperty.get(world, x, y, z)) {
return BoardRobotLumberjack.isFreeWoodTarget(new BlockIndex(x, y, z));
} else {
return false;
}
}
});
woodScannerJob = new PathFindingJob(woodScanner);
woodScannerJob.start();
blockScanner = new PathFinding(robot.worldObj, new BlockIndex(robot), pathFound);
blockScannerJob = new PathFindingJob(blockScanner);
blockScannerJob.start();
}
@Override
public void update() {
if (!woodScannerJob.isAlive()) {
if (woodScanner.isDone()) {
LinkedList<BlockIndex> path = woodScanner.getResult();
woodFound = path.removeLast();
if (!blockScannerJob.isAlive()) {
if (blockScanner.isDone()) {
LinkedList<BlockIndex> path = blockScanner.getResult();
blockFound = path.removeLast();
startDelegateAI(new AIRobotMoveToBlock(robot, path));
}
}

View file

@ -0,0 +1,67 @@
/**
* 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.item.ItemStack;
import net.minecraft.world.World;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.core.BlockIndex;
import buildcraft.core.inventory.filters.IStackFilter;
import buildcraft.core.utils.IPathFound;
import buildcraft.robots.AIRobot;
import buildcraft.robots.EntityRobotBase;
public abstract class BoardRobotGenericBreakBlock extends RedstoneBoardRobot {
public BoardRobotGenericBreakBlock(EntityRobotBase iRobot) {
super(iRobot);
}
public abstract boolean isExpectedTool(ItemStack stack);
public abstract boolean isExpectedBlock(World world, int x, int y, int z);
@Override
public final void update() {
if (robot.getItemInUse() == null) {
startDelegateAI(new AIRobotFetchItemStack(robot, new IStackFilter() {
@Override
public boolean matches(ItemStack stack) {
return isExpectedTool(stack);
}
}));
} else {
startDelegateAI(new AIRobotSearchBlock(robot, new IPathFound() {
@Override
public boolean endReached(World world, int x, int y, int z) {
if (isExpectedBlock(world, x, y, z)) {
return RedstoneBoardRobot.isFreeBlock(new BlockIndex(x, y, z));
} else {
return false;
}
}
}));
}
}
@Override
public final void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotSearchBlock) {
BlockIndex index = ((AIRobotSearchBlock) ai).blockFound;
if (reserveBlock(index)) {
startDelegateAI(new AIRobotBreakWithTool(robot, ((AIRobotSearchBlock) ai).blockFound));
}
} else if (ai instanceof AIRobotBreakWithTool) {
releaseBlock(((AIRobotBreakWithTool) ai).blockToBreak);
}
}
}

View file

@ -0,0 +1,40 @@
/**
* 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.item.ItemShears;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.robots.EntityRobotBase;
public class BoardRobotLeaveCutter extends BoardRobotGenericBreakBlock {
public BoardRobotLeaveCutter(EntityRobotBase iRobot) {
super(iRobot);
}
@Override
public RedstoneBoardRobotNBT getNBTHandler() {
return BoardRobotLeaveCutterNBT.instance;
}
@Override
public boolean isExpectedTool(ItemStack stack) {
return stack.getItem() instanceof ItemShears;
}
@Override
public boolean isExpectedBlock(World world, int x, int y, int z) {
return BuildCraftAPI.isLeavesProperty.get(world, x, y, z);
}
}

View file

@ -0,0 +1,75 @@
/**
* 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 java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.core.DefaultProps;
import buildcraft.core.utils.StringUtils;
import buildcraft.robots.EntityRobotBase;
public final class BoardRobotLeaveCutterNBT extends RedstoneBoardRobotNBT {
public static BoardRobotLeaveCutterNBT instance = new BoardRobotLeaveCutterNBT();
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft",
DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_leave_cutter.png");
private IIcon icon;
@Override
public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) {
return new BoardRobotLeaveCutter(robot);
}
@Override
public ResourceLocation getRobotTexture() {
return TEXTURE;
}
@Override
public String getID() {
return "buildcraft:leave_cutter";
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
list.add(StringUtils.localize("buildcraft.boardRobotLeaveCutter"));
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:board_blue");
}
@Override
public IIcon getIcon(NBTTagCompound nbt) {
return icon;
}
@Override
public void createRandomBoard(NBTTagCompound nbt) {
}
@Override
public void createDefaultBoard(NBTTagCompound itemData) {
}
}

View file

@ -8,71 +8,33 @@
*/
package buildcraft.core.robots.boards;
import java.util.HashSet;
import net.minecraft.init.Items;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import buildcraft.api.boards.RedstoneBoardRobot;
import buildcraft.api.boards.RedstoneBoardRobotNBT;
import buildcraft.core.BlockIndex;
import buildcraft.core.inventory.filters.ArrayStackFilter;
import buildcraft.robots.AIRobot;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.robots.EntityRobotBase;
public class BoardRobotLumberjack extends RedstoneBoardRobot {
public static HashSet<BlockIndex> woodTargets = new HashSet<BlockIndex>();
public class BoardRobotLumberjack extends BoardRobotGenericBreakBlock {
public BoardRobotLumberjack(EntityRobotBase iRobot, NBTTagCompound nbt) {
super(iRobot);
}
@Override
public void update() {
if (robot.getItemInUse() == null) {
startDelegateAI(new AIRobotFetchItemStack(robot, new ArrayStackFilter(new ItemStack(
Items.wooden_axe))));
} else {
startDelegateAI(new AIRobotGoToWood(robot));
}
}
@Override
public void delegateAIEnded(AIRobot ai) {
if (ai instanceof AIRobotGoToWood) {
BlockIndex index = ((AIRobotGoToWood) ai).woodFound;
if (reserveWoodTarget(index)) {
startDelegateAI(new AIRobotCutWood(robot, ((AIRobotGoToWood) ai).woodFound));
}
} else if (ai instanceof AIRobotCutWood) {
synchronized (woodTargets) {
woodTargets.remove(((AIRobotCutWood) ai).woodToChop);
}
}
}
public static boolean isFreeWoodTarget(BlockIndex index) {
synchronized (woodTargets) {
return !woodTargets.contains(index);
}
}
public static boolean reserveWoodTarget (BlockIndex index) {
synchronized (woodTargets) {
if (!woodTargets.contains(index)) {
woodTargets.add(index);
return true;
} else {
return false;
}
}
}
@Override
public RedstoneBoardRobotNBT getNBTHandler() {
return BoardRobotLumberjackNBT.instance;
}
@Override
public boolean isExpectedTool(ItemStack stack) {
return stack.getItem() instanceof ItemAxe;
}
@Override
public boolean isExpectedBlock(World world, int x, int y, int z) {
return BuildCraftAPI.isWoodProperty.get(world, x, y, z);
}
}

View file

@ -73,6 +73,11 @@ public final class BoardRobotLumberjackNBT extends RedstoneBoardRobotNBT {
nbt.setInteger("range", range);
}
@Override
public void createDefaultBoard(NBTTagCompound nbt) {
nbt.setInteger("range", 250);
}
@Override
public ResourceLocation getRobotTexture() {
return TEXTURE;

View file

@ -89,6 +89,11 @@ public final class BoardRobotPickerNBT extends RedstoneBoardRobotNBT {
nbt.setInteger("range", range);
}
@Override
public void createDefaultBoard(NBTTagCompound nbt) {
nbt.setInteger("range", 250);
}
@Override
public ResourceLocation getRobotTexture() {
return EntityRobot.ROBOT_TRANSPORT;

View file

@ -23,9 +23,10 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.utils.StringUtils;
import buildcraft.robots.EntityRobotBase;
public class BoardRobotPlanterNBT extends RedstoneBoardRobotNBT {
public final class BoardRobotPlanterNBT extends RedstoneBoardRobotNBT {
public static BoardRobotPlanterNBT instance = new BoardRobotPlanterNBT();
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft",
DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_planter.png");
@ -49,7 +50,6 @@ public class BoardRobotPlanterNBT extends RedstoneBoardRobotNBT {
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) {
list.add(StringUtils.localize("buildcraft.boardRobotPlanter"));
}
@Override
@ -67,4 +67,8 @@ public class BoardRobotPlanterNBT extends RedstoneBoardRobotNBT {
}
@Override
public void createDefaultBoard(NBTTagCompound nbt) {
}
}

View file

@ -0,0 +1,30 @@
/**
* 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.utils;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.oredict.OreDictionary;
public class WorldPropertyIsLeave extends WorldProperty {
private int leavesId = 0;
public WorldPropertyIsLeave() {
leavesId = OreDictionary.getOreID("treeLeaves");
}
@Override
public boolean get(IBlockAccess blockAccess, Block block, int meta, int x, int y, int z) {
return block != null
&& OreDictionary.getOreID(new ItemStack(block, 1, OreDictionary.WILDCARD_VALUE)) == leavesId;
}
}

View file

@ -11,7 +11,9 @@ package buildcraft.silicon;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
@ -21,7 +23,9 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.BuildCraftSilicon;
import buildcraft.api.boards.RedstoneBoardNBT;
import buildcraft.api.boards.RedstoneBoardRegistry;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.GuiIds;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.utils.NBTUtils;
@ -32,7 +36,7 @@ public class ItemRedstoneBoard extends ItemBuildCraft {
public IIcon unknownBoard;
public ItemRedstoneBoard() {
super();
super(CreativeTabBuildCraft.BOARDS);
}
@Override
@ -82,4 +86,18 @@ public class ItemRedstoneBoard extends ItemBuildCraft {
return par1ItemStack;
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
for (RedstoneBoardNBT nbt : RedstoneBoardRegistry.instance.getAllBoardNBTs()) {
ItemStack stack = new ItemStack(BuildCraftSilicon.redstoneBoard);
NBTTagCompound nbtData = NBTUtils.getItemData(stack);
nbtData.setString("id", nbt.getID());
nbt.createDefaultBoard(nbtData);
itemList.add(stack.copy());
}
}
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.silicon.boards;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Random;
@ -105,4 +107,15 @@ public class ImplRedstoneBoardRegistry extends RedstoneBoardRegistry {
}
}
@Override
public Collection<RedstoneBoardNBT> getAllBoardNBTs() {
ArrayList<RedstoneBoardNBT> result = new ArrayList<RedstoneBoardNBT>();
for (BoardFactory f : boards.values()) {
result.add(f.boardNBT);
}
return result;
}
}