From 3f925ae0e940417f4662d2becd504401e577dd66 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Thu, 29 May 2014 21:58:08 +0200 Subject: [PATCH] completed a first robot+board, #1732 --- api/buildcraft/api/boards/IRedstoneBoard.java | 1 + .../api/boards/IRedstoneBoardRobot.java | 17 ++ .../api/boards/IRedstoneBoardRobotNBT.java | 21 ++ .../api/boards/RedstoneBoardRegistry.java | 2 + .../assets/buildcraft/lang/en_US.lang | 3 + common/buildcraft/BuildCraftCore.java | 5 - common/buildcraft/BuildCraftSilicon.java | 21 +- common/buildcraft/core/ItemRobot.java | 62 +++++- .../core/proxy/CoreProxyClient.java | 6 +- .../buildcraft/core/render/RenderRobot.java | 19 +- .../buildcraft/core/robots/EntityRobot.java | 128 ++++++++++++- .../core/robots/EntityRobotBuilder.java | 179 ------------------ .../core/robots/EntityRobotPicker.java | 142 -------------- .../core/robots/RobotIntegrationRecipe.java | 61 ++++++ .../core/robots/boards/BoardRobotPicker.java | 21 +- .../robots/boards/BoardRobotPickerNBT.java | 15 +- .../boards/ImplRedstoneBoardRegistry.java | 14 +- .../transport/BlockGenericPipe.java | 2 +- .../transport/PipeIconProvider.java | 10 - 19 files changed, 335 insertions(+), 394 deletions(-) create mode 100755 api/buildcraft/api/boards/IRedstoneBoardRobot.java create mode 100755 api/buildcraft/api/boards/IRedstoneBoardRobotNBT.java delete mode 100644 common/buildcraft/core/robots/EntityRobotBuilder.java delete mode 100755 common/buildcraft/core/robots/EntityRobotPicker.java create mode 100755 common/buildcraft/core/robots/RobotIntegrationRecipe.java diff --git a/api/buildcraft/api/boards/IRedstoneBoard.java b/api/buildcraft/api/boards/IRedstoneBoard.java index f3ff0377..6abf8877 100755 --- a/api/buildcraft/api/boards/IRedstoneBoard.java +++ b/api/buildcraft/api/boards/IRedstoneBoard.java @@ -12,4 +12,5 @@ public interface IRedstoneBoard { void updateBoard(T container); + String getID(); } diff --git a/api/buildcraft/api/boards/IRedstoneBoardRobot.java b/api/buildcraft/api/boards/IRedstoneBoardRobot.java new file mode 100755 index 00000000..3c3a6173 --- /dev/null +++ b/api/buildcraft/api/boards/IRedstoneBoardRobot.java @@ -0,0 +1,17 @@ +/** + * 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.util.ResourceLocation; + +public interface IRedstoneBoardRobot extends IRedstoneBoard { + + ResourceLocation getRobotTexture(); + +} diff --git a/api/buildcraft/api/boards/IRedstoneBoardRobotNBT.java b/api/buildcraft/api/boards/IRedstoneBoardRobotNBT.java new file mode 100755 index 00000000..db0a11b1 --- /dev/null +++ b/api/buildcraft/api/boards/IRedstoneBoardRobotNBT.java @@ -0,0 +1,21 @@ +/** + * 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.ResourceLocation; + +public interface IRedstoneBoardRobotNBT extends IRedstoneBoardNBT { + + @Override + IRedstoneBoardRobot create(NBTTagCompound nbt); + + ResourceLocation getRobotTexture(); + +} diff --git a/api/buildcraft/api/boards/RedstoneBoardRegistry.java b/api/buildcraft/api/boards/RedstoneBoardRegistry.java index 24a465bd..5370cc24 100755 --- a/api/buildcraft/api/boards/RedstoneBoardRegistry.java +++ b/api/buildcraft/api/boards/RedstoneBoardRegistry.java @@ -21,5 +21,7 @@ public abstract class RedstoneBoardRegistry { public abstract IRedstoneBoardNBT getRedstoneBoard(NBTTagCompound nbt); + public abstract IRedstoneBoardNBT getRedstoneBoard(String id); + public abstract void registerIcons(IIconRegister par1IconRegister); } diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 077d1323..fbf6ce99 100755 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -1,5 +1,7 @@ # Master language file +buildcraft.boardRobotPicker=Picker Program + chat.pipe.power.iron.mode=Switched to %d MJ/t limit chat.pipe.power.energyConverter=Energy conversion: %s chat.pipe.power.energyConverter.from_old_to_new=From old API to new API @@ -133,6 +135,7 @@ item.redstone_pulsating_chipset.name=Pulsating Chipset item.redstone_quartz_chipset.name=Quartz Chipset item.redstone_comp_chipset.name=Redstone Comp Chipset item.redstone_board.name=Redstone Board +item.robot.name=Robot item.blueprintItem.name=Blueprint item.blueprint.unnamed= item.blueprint.author=by diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index a32019ac..4c7de2d7 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -85,8 +85,6 @@ import buildcraft.core.recipes.IntegrationRecipeManager; import buildcraft.core.recipes.RefineryRecipeManager; import buildcraft.core.render.BlockHighlightHandler; import buildcraft.core.robots.EntityRobot; -import buildcraft.core.robots.EntityRobotBuilder; -import buildcraft.core.robots.EntityRobotPicker; import buildcraft.core.triggers.ActionMachineControl; import buildcraft.core.triggers.ActionMachineControl.Mode; import buildcraft.core.triggers.ActionRedstoneOutput; @@ -322,10 +320,7 @@ public class BuildCraftCore extends BuildCraftMod { loadRecipes(); } EntityRegistry.registerModEntity(EntityRobot.class, "bcRobot", EntityIds.ROBOT, instance, 50, 1, true); - EntityRegistry.registerModEntity(EntityRobotPicker.class, "bcRobotPicker", EntityIds.ROBOT_PICKER, instance, 50, 1, true); - EntityRegistry.registerModEntity(EntityRobotBuilder.class, "bcRobotBuilder", EntityIds.ROBOT_BUILDER, instance, 50, 1, true); EntityRegistry.registerModEntity(EntityRobotUrbanism.class, "bcRobotUrbanism", EntityIds.ROBOT_URBANISM, instance, 50, 1, true); - EntityList.classToStringMapping.remove(EntityRobotBuilder.class); EntityList.stringToClassMapping.remove("BuildCraft|Core.bcRobot"); EntityList.stringToClassMapping.remove("BuildCraft|Core.bcLaser"); EntityList.stringToClassMapping.remove("BuildCraft|Core.bcEnergyLaser"); diff --git a/common/buildcraft/BuildCraftSilicon.java b/common/buildcraft/BuildCraftSilicon.java index 824e0a4f..9a270bbd 100644 --- a/common/buildcraft/BuildCraftSilicon.java +++ b/common/buildcraft/BuildCraftSilicon.java @@ -36,9 +36,7 @@ import buildcraft.core.ItemBuildCraft; import buildcraft.core.ItemRobot; import buildcraft.core.Version; import buildcraft.core.proxy.CoreProxy; -import buildcraft.core.robots.EntityRobot; -import buildcraft.core.robots.EntityRobotBuilder; -import buildcraft.core.robots.EntityRobotPicker; +import buildcraft.core.robots.RobotIntegrationRecipe; import buildcraft.core.robots.boards.BoardRobotPickerNBT; import buildcraft.silicon.BlockLaser; import buildcraft.silicon.BlockLaserTable; @@ -76,9 +74,7 @@ public class BuildCraftSilicon extends BuildCraftMod { public static BuildCraftSilicon instance; public static Item redstoneCrystal; - public static Item robotBaseItem; - public static Item robotBuilderItem; - public static Item robotPickerItem; + public static Item robotItem; @Mod.EventHandler public void preInit(FMLPreInitializationEvent evt) { @@ -106,14 +102,8 @@ public class BuildCraftSilicon extends BuildCraftMod { CoreProxy.proxy.registerItem(redstoneCrystal); OreDictionary.registerOre("redstoneCrystal", new ItemStack(redstoneCrystal)); - robotBaseItem = new ItemRobot(EntityRobot.class).setUnlocalizedName("robotBase"); - CoreProxy.proxy.registerItem(robotBaseItem); - - robotPickerItem = new ItemRobot(EntityRobotPicker.class).setUnlocalizedName("robotPicker"); - CoreProxy.proxy.registerItem(robotPickerItem); - - robotBuilderItem = new ItemRobot(EntityRobotBuilder.class).setUnlocalizedName("robotBuilder"); - CoreProxy.proxy.registerItem(robotBuilderItem); + robotItem = new ItemRobot().setUnlocalizedName("robot"); + CoreProxy.proxy.registerItem(robotItem); RedstoneBoardRegistry.instance = new ImplRedstoneBoardRegistry(); @@ -211,7 +201,7 @@ public class BuildCraftSilicon extends BuildCraftMod { 'R', Items.redstone, 'P', Items.paper); - CoreProxy.proxy.addCraftingRecipe(new ItemStack(robotBaseItem), + CoreProxy.proxy.addCraftingRecipe(new ItemStack(robotItem), "PPP", "PRP", "C C", @@ -220,6 +210,7 @@ public class BuildCraftSilicon extends BuildCraftMod { 'C', Chipset.DIAMOND.getStack()); BuildcraftRecipes.assemblyTable.addRecipe(new BoardRecipe()); + BuildcraftRecipes.integrationTable.addRecipe(new RobotIntegrationRecipe()); // REVERSAL RECIPES EnumSet materials = EnumSet.allOf(GateMaterial.class); diff --git a/common/buildcraft/core/ItemRobot.java b/common/buildcraft/core/ItemRobot.java index 9c52d6be..7c3eacc8 100755 --- a/common/buildcraft/core/ItemRobot.java +++ b/common/buildcraft/core/ItemRobot.java @@ -8,27 +8,75 @@ */ package buildcraft.core; +import java.util.List; + +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; +import buildcraft.api.boards.IRedstoneBoardNBT; +import buildcraft.api.boards.IRedstoneBoardRobot; +import buildcraft.api.boards.IRedstoneBoardRobotNBT; +import buildcraft.api.boards.RedstoneBoardRegistry; import buildcraft.core.robots.EntityRobot; +import buildcraft.core.utils.NBTUtils; public class ItemRobot extends ItemBuildCraft { - Class robotClass; - - public ItemRobot(Class robotClass) { + public ItemRobot() { super(CreativeTabBuildCraft.ITEMS); - - this.robotClass = robotClass; } - public EntityRobot createRobot (World world) { + public EntityRobot createRobot(ItemStack stack, World world) { try { - return this.robotClass.getConstructor(World.class).newInstance(world); + IRedstoneBoardRobot board = null; + NBTTagCompound nbt = NBTUtils.getItemData(stack); + + if (nbt.hasKey("board")) { + NBTTagCompound boardCpt = nbt.getCompoundTag("board"); + IRedstoneBoardNBT boardNBT = RedstoneBoardRegistry.instance.getRedstoneBoard(boardCpt); + + if (boardNBT instanceof IRedstoneBoardRobotNBT) { + board = ((IRedstoneBoardRobotNBT) boardNBT).create(boardCpt); + } + } + + EntityRobot robot = new EntityRobot(world, board); + + return robot; } catch (Throwable e) { e.printStackTrace(); return null; } } + public ResourceLocation getTextureRobot(ItemStack stack) { + NBTTagCompound nbt = NBTUtils.getItemData(stack); + + if (!nbt.hasKey("board")) { + return EntityRobot.ROBOT_BASE; + } else { + NBTTagCompound board = nbt.getCompoundTag("board"); + IRedstoneBoardNBT boardNBT = RedstoneBoardRegistry.instance.getRedstoneBoard(board); + + if (boardNBT instanceof IRedstoneBoardRobotNBT) { + return ((IRedstoneBoardRobotNBT) boardNBT).getRobotTexture(); + } else { + return EntityRobot.ROBOT_BASE; + } + } + } + + @Override + public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced) { + NBTTagCompound cpt = NBTUtils.getItemData(stack).getCompoundTag("board"); + + if (cpt.hasKey("id") && !cpt.getString("id").equals("")) { + RedstoneBoardRegistry.instance.getRedstoneBoard(cpt).addInformation(stack, player, list, advanced); + } + + } + } diff --git a/common/buildcraft/core/proxy/CoreProxyClient.java b/common/buildcraft/core/proxy/CoreProxyClient.java index 7ccb9f74..d4f41a73 100644 --- a/common/buildcraft/core/proxy/CoreProxyClient.java +++ b/common/buildcraft/core/proxy/CoreProxyClient.java @@ -38,7 +38,6 @@ import buildcraft.core.render.RenderRobot; import buildcraft.core.render.RenderingEntityBlocks; import buildcraft.core.render.RenderingMarkers; import buildcraft.core.robots.EntityRobot; -import buildcraft.core.robots.EntityRobotBuilder; import buildcraft.transport.render.TileEntityPickupFX; public class CoreProxyClient extends CoreProxy { @@ -101,16 +100,13 @@ public class CoreProxyClient extends CoreProxy { RenderingRegistry.registerBlockHandler(new RenderingMarkers()); // TODO: Move these to a Silicon proxy renderer - MinecraftForgeClient.registerItemRenderer(BuildCraftSilicon.robotBaseItem, new RenderRobot()); - MinecraftForgeClient.registerItemRenderer(BuildCraftSilicon.robotBuilderItem, new RenderRobot()); - MinecraftForgeClient.registerItemRenderer(BuildCraftSilicon.robotPickerItem, new RenderRobot()); + MinecraftForgeClient.registerItemRenderer(BuildCraftSilicon.robotItem, new RenderRobot()); } @Override public void initializeEntityRendering() { RenderingRegistry.registerEntityRenderingHandler(EntityBlock.class, RenderEntityBlock.INSTANCE); RenderingRegistry.registerEntityRenderingHandler(EntityRobot.class, new RenderRobot()); - RenderingRegistry.registerEntityRenderingHandler(EntityRobotBuilder.class, new RenderRobot()); } /* BUILDCRAFT PLAYER */ diff --git a/common/buildcraft/core/render/RenderRobot.java b/common/buildcraft/core/render/RenderRobot.java index bae08350..94318083 100644 --- a/common/buildcraft/core/render/RenderRobot.java +++ b/common/buildcraft/core/render/RenderRobot.java @@ -22,16 +22,12 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.IItemRenderer; import buildcraft.BuildCraftSilicon; -import buildcraft.core.DefaultProps; import buildcraft.core.EntityLaser; +import buildcraft.core.ItemRobot; import buildcraft.core.robots.EntityRobot; public class RenderRobot extends Render implements IItemRenderer { - public static final ResourceLocation TEXTURE_BASE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_base.png"); - public static final ResourceLocation TEXTURE_BUILDER = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png"); - public static final ResourceLocation TEXTURE_PICKER = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_picker.png"); - protected ModelBase model = new ModelBase() { }; private ModelRenderer box; @@ -75,7 +71,7 @@ public class RenderRobot extends Render implements IItemRenderer { @Override protected ResourceLocation getEntityTexture(Entity entity) { - return TEXTURE_BASE; + return ((EntityRobot) entity).getTexture(); } @Override @@ -106,14 +102,9 @@ public class RenderRobot extends Render implements IItemRenderer { GL11.glPushMatrix(); GL11.glDisable(GL11.GL_LIGHTING); - // FIXME: Texture localisation should be factorized between items and - // entities. - if (item.getItem() == BuildCraftSilicon.robotBaseItem) { - RenderManager.instance.renderEngine.bindTexture(TEXTURE_BASE); - } else if (item.getItem() == BuildCraftSilicon.robotBuilderItem) { - RenderManager.instance.renderEngine.bindTexture(TEXTURE_BUILDER); - } else if (item.getItem() == BuildCraftSilicon.robotPickerItem) { - RenderManager.instance.renderEngine.bindTexture(TEXTURE_PICKER); + if (item.getItem() == BuildCraftSilicon.robotItem) { + ItemRobot robot = (ItemRobot) item.getItem(); + RenderManager.instance.renderEngine.bindTexture(robot.getTextureRobot(item)); } float factor = (float) (1.0 / 16.0); diff --git a/common/buildcraft/core/robots/EntityRobot.java b/common/buildcraft/core/robots/EntityRobot.java index 591adeb4..5e8422fd 100755 --- a/common/buildcraft/core/robots/EntityRobot.java +++ b/common/buildcraft/core/robots/EntityRobot.java @@ -11,6 +11,8 @@ package buildcraft.core.robots; import io.netty.buffer.ByteBuf; import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; @@ -20,13 +22,24 @@ import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.boards.IRedstoneBoardNBT; +import buildcraft.api.boards.IRedstoneBoardRobot; +import buildcraft.api.boards.IRedstoneBoardRobotNBT; +import buildcraft.api.boards.RedstoneBoardRegistry; import buildcraft.api.core.SafeTimeTracker; import buildcraft.core.DefaultProps; import buildcraft.core.LaserData; import buildcraft.transport.TileGenericPipe; public class EntityRobot extends EntityLiving implements - IEntityAdditionalSpawnData { + IEntityAdditionalSpawnData, IInventory { + + public static final ResourceLocation ROBOT_BASE = new ResourceLocation("buildcraft", + DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_base.png"); + public static final ResourceLocation ROBOT_BUILDER = new ResourceLocation("buildcraft", + DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png"); + public static final ResourceLocation ROBOT_TRANSPORT = new ResourceLocation("buildcraft", + DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_picker.png"); private static ResourceLocation defaultTexture = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_base.png"); @@ -37,16 +50,28 @@ public class EntityRobot extends EntityLiving implements public DockingStation dockingStation = new DockingStation(); public boolean isDocked = false; + public IRedstoneBoardRobot board; + public RobotAIBase currentAI; protected RobotAIBase nextAI; private boolean needsUpdate = false; + private ItemStack[] inv = new ItemStack[6]; + private String boardID; + private ResourceLocation texture; public class DockingStation { public int x, y, z; public ForgeDirection side; } + public EntityRobot(World world, IRedstoneBoardRobot iBoard) { + this(world); + + board = iBoard; + dataWatcher.updateObject(16, board.getID()); + } + public EntityRobot(World par1World) { super(par1World); @@ -73,10 +98,7 @@ public class EntityRobot extends EntityLiving implements dataWatcher.addObject(13, Float.valueOf(0)); dataWatcher.addObject(14, Float.valueOf(0)); dataWatcher.addObject(15, Byte.valueOf((byte) 0)); - dataWatcher.addObject(16, Float.valueOf(0)); - dataWatcher.addObject(17, Float.valueOf(0)); - dataWatcher.addObject(18, Float.valueOf(0)); - dataWatcher.addObject(19, Byte.valueOf((byte) 0)); + dataWatcher.addObject(16, ""); } protected void updateDataClient() { @@ -84,6 +106,13 @@ public class EntityRobot extends EntityLiving implements laser.tail.y = dataWatcher.getWatchableObjectFloat(13); laser.tail.z = dataWatcher.getWatchableObjectFloat(14); laser.isVisible = dataWatcher.getWatchableObjectByte(15) == 1; + + IRedstoneBoardNBT boardNBT = RedstoneBoardRegistry.instance.getRedstoneBoard(dataWatcher + .getWatchableObjectString(16)); + + if (boardNBT != null) { + texture = ((IRedstoneBoardRobotNBT) boardNBT).getRobotTexture(); + } } protected void updateDataServer() { @@ -143,6 +172,8 @@ public class EntityRobot extends EntityLiving implements } if (!worldObj.isRemote) { + board.updateBoard(this); + if (currentTask == null) { if (scanForTasks.markTimeIfDelay(worldObj)) { RobotTaskProviderRegistry.scanForTask(this); @@ -259,7 +290,7 @@ public class EntityRobot extends EntityLiving implements } public ResourceLocation getTexture () { - return defaultTexture; + return texture; } @Override @@ -278,6 +309,14 @@ public class EntityRobot extends EntityLiving implements NBTTagCompound nbtLaser = new NBTTagCompound(); laser.writeToNBT(nbtLaser); nbt.setTag("laser", nbtLaser); + + for (int i = 0; i < inv.length; ++i) { + NBTTagCompound stackNbt = new NBTTagCompound(); + + if (inv[i] != null) { + nbt.setTag("inv[" + i + "]", inv[i].writeToNBT(stackNbt)); + } + } } @Override @@ -296,6 +335,12 @@ public class EntityRobot extends EntityLiving implements */ laser.readFromNBT(nbt.getCompoundTag("laser")); + + for (int i = 0; i < inv.length; ++i) { + inv[i] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("inv[" + i + "]")); + } + + setDead(); } public void setDockingStation (TileGenericPipe tile, ForgeDirection side) { @@ -323,4 +368,75 @@ public class EntityRobot extends EntityLiving implements public void setMainAI (RobotAIBase ai) { nextAI = ai; } + + @Override + public int getSizeInventory() { + return inv.length; + } + + @Override + public ItemStack getStackInSlot(int var1) { + return inv[var1]; + } + + @Override + public ItemStack decrStackSize(int var1, int var2) { + ItemStack result = inv[var1].splitStack(var2); + + if (inv[var1].stackSize == 0) { + inv[var1] = null; + } + + return result; + } + + @Override + public ItemStack getStackInSlotOnClosing(int var1) { + return inv[var1].splitStack(var1); + } + + @Override + public void setInventorySlotContents(int var1, ItemStack var2) { + inv[var1] = var2; + } + + @Override + public String getInventoryName() { + return null; + } + + @Override + public boolean hasCustomInventoryName() { + return false; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public void markDirty() { + } + + @Override + public boolean isUseableByPlayer(EntityPlayer var1) { + return false; + } + + @Override + public void openInventory() { + } + + @Override + public void closeInventory() { + } + + @Override + public boolean isItemValidForSlot(int var1, ItemStack var2) { + return inv[var1] == null + || (inv[var1].isItemEqual(var2) && inv[var1].isStackable() && inv[var1].stackSize + + var2.stackSize <= inv[var1].getItem() + .getItemStackLimit()); + } } diff --git a/common/buildcraft/core/robots/EntityRobotBuilder.java b/common/buildcraft/core/robots/EntityRobotBuilder.java deleted file mode 100644 index e8f142b3..00000000 --- a/common/buildcraft/core/robots/EntityRobotBuilder.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * 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; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; - -import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; - -import buildcraft.builders.blueprints.IBlueprintBuilderAgent; -import buildcraft.builders.urbanism.TaskBuildSchematic; -import buildcraft.core.DefaultProps; -import buildcraft.core.proxy.CoreProxy; - -public class EntityRobotBuilder extends EntityRobot implements - IEntityAdditionalSpawnData, IBlueprintBuilderAgent, IInventory { - - private static ResourceLocation texture = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_ENTITIES + "/robot_builder.png"); - - ItemStack buildingStack = null; - float curBlockDamage = 0; - float buildEnergy = 0; - - public EntityRobotBuilder(World par1World) { - super (par1World); - } - - /** - * Operate a block break. Return true is the block has indeed been broken. - */ - @Override - public boolean breakBlock (int x, int y, int z) { - Block block = worldObj.getBlock(x, y, z); - - if (block != null) { - curBlockDamage += 1 / (block.getBlockHardness(worldObj, x, y, z) * 20); - } - - if (block != null && curBlockDamage < 1) { - worldObj.destroyBlockInWorldPartially(getEntityId(), x, y, z, - (int) (this.curBlockDamage * 10.0F) - 1); - - setLaserDestination(x + 0.5F, y + 0.5F, z + 0.5F); - showLaser(); - - return false; - } else { - worldObj.destroyBlockInWorldPartially(getEntityId(), x, y, z, -1); - worldObj.setBlock(x, y, z, Blocks.air); - curBlockDamage = 0; - - hideLaser(); - - return true; - } - } - - @Override - public boolean buildBlock(int x, int y, int z) { - if (buildingStack == null) { - if (worldObj.getBlock(x, y, z) != Blocks.air) { - breakBlock(x, y, z); - } else { - setLaserDestination(x + 0.5F, y + 0.5F, z + 0.5F); - showLaser(); - - buildingStack = getInventory().decrStackSize(0, 1); - buildEnergy = 0; - } - - return false; - } else { - buildEnergy++; - - if (buildEnergy >= 25) { - buildingStack.getItem().onItemUse(buildingStack, - CoreProxy.proxy.getBuildCraftPlayer((WorldServer) worldObj).get(), - worldObj, x, y - 1, z, 1, 0.0f, 0.0f, 0.0f); - - buildingStack = null; - - hideLaser(); - return true; - } else { - return false; - } - } - } - - @Override - public IInventory getInventory() { - return this; - } - - @Override - public int getSizeInventory() { - return 1; - } - - @Override - public ItemStack getStackInSlot(int i) { - // Fake inventory filled with bricks - return new ItemStack(Blocks.brick_block); - } - - @Override - public ItemStack decrStackSize(int i, int j) { - // Fake inventory filled with bricks - return new ItemStack(Blocks.brick_block); - } - - @Override - public ItemStack getStackInSlotOnClosing(int i) { - return null; - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemstack) { - } - - @Override - public int getInventoryStackLimit() { - return 0; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer entityplayer) { - return false; - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemstack) { - return false; - } - - @Override - public String getInventoryName() { - return null; - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public void markDirty() { - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean acceptTask (IRobotTask task) { - return task instanceof TaskBuildSchematic; - } - - @Override - public ResourceLocation getTexture () { - return texture; - } -} diff --git a/common/buildcraft/core/robots/EntityRobotPicker.java b/common/buildcraft/core/robots/EntityRobotPicker.java deleted file mode 100755 index 3f31093f..00000000 --- a/common/buildcraft/core/robots/EntityRobotPicker.java +++ /dev/null @@ -1,142 +0,0 @@ -/** - * 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; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; - -import buildcraft.api.boards.IRedstoneBoard; -import buildcraft.core.DefaultProps; -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"); - - ItemStack[] inv = new ItemStack[6]; - - private IRedstoneBoard board; - - public EntityRobotPicker(World par1World) { - super(par1World); - - board = new BoardRobotPicker(); - } - - @Override - public ResourceLocation getTexture () { - return texture; - } - - @Override - public void onUpdate () { - super.onUpdate(); - - board.updateBoard(this); - } - - @Override - public int getSizeInventory() { - return inv.length; - } - - @Override - public ItemStack getStackInSlot(int var1) { - return inv [var1]; - } - - @Override - public ItemStack decrStackSize(int var1, int var2) { - ItemStack result = inv [var1].splitStack(var2); - - if (inv [var1].stackSize == 0) { - inv [var1] = null; - } - - return result; - } - - @Override - public ItemStack getStackInSlotOnClosing(int var1) { - return inv [var1].splitStack(var1); - } - - @Override - public void setInventorySlotContents(int var1, ItemStack var2) { - inv [var1] = var2; - } - - @Override - public String getInventoryName() { - return null; - } - - @Override - public boolean hasCustomInventoryName() { - return false; - } - - @Override - public int getInventoryStackLimit() { - return 64; - } - - @Override - public void markDirty() { - } - - @Override - public boolean isUseableByPlayer(EntityPlayer var1) { - return false; - } - - @Override - public void openInventory() { - } - - @Override - public void closeInventory() { - } - - @Override - public boolean isItemValidForSlot(int var1, ItemStack var2) { - return inv[var1] == null - || (inv[var1].isItemEqual(var2) && inv[var1].isStackable() && inv[var1].stackSize - + var2.stackSize <= inv[var1].getItem() - .getItemStackLimit()); - } - - @Override - public void writeEntityToNBT(NBTTagCompound nbt) { - super.writeEntityToNBT(nbt); - - for (int i = 0; i < inv.length; ++i) { - NBTTagCompound stackNbt = new NBTTagCompound(); - - if (inv [i] != null) { - nbt.setTag("inv[" + i + "]", inv [i].writeToNBT(stackNbt)); - } - } - } - - @Override - public void readEntityFromNBT(NBTTagCompound nbt) { - super.readEntityFromNBT(nbt); - - for (int i = 0; i < inv.length; ++i) { - inv [i] = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("inv[" + i + "]")); - } - - setDead(); - } -} diff --git a/common/buildcraft/core/robots/RobotIntegrationRecipe.java b/common/buildcraft/core/robots/RobotIntegrationRecipe.java new file mode 100755 index 00000000..160559fb --- /dev/null +++ b/common/buildcraft/core/robots/RobotIntegrationRecipe.java @@ -0,0 +1,61 @@ +/** + * 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; + +import net.minecraft.item.ItemStack; + +import buildcraft.BuildCraftSilicon; +import buildcraft.api.recipes.IIntegrationRecipeManager.IIntegrationRecipe; +import buildcraft.core.ItemRobot; +import buildcraft.core.utils.NBTUtils; +import buildcraft.silicon.ItemRedstoneBoard; + +public class RobotIntegrationRecipe implements IIntegrationRecipe { + + @Override + public double getEnergyCost() { + // return 10000; + return 100; + } + + @Override + public boolean isValidInputA(ItemStack inputA) { + return inputA != null && inputA.getItem() instanceof ItemRobot; + } + + @Override + public boolean isValidInputB(ItemStack inputB) { + return inputB != null && inputB.getItem() instanceof ItemRedstoneBoard; + } + + @Override + public ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components) { + ItemStack robot = new ItemStack(BuildCraftSilicon.robotItem); + + NBTUtils.getItemData(robot).setTag("board", NBTUtils.getItemData(inputB)); + + return robot; + } + + @Override + public ItemStack[] getComponents() { + return new ItemStack[0]; + } + + @Override + public ItemStack[] getExampleInputsA() { + return null; + } + + @Override + public ItemStack[] getExampleInputsB() { + return null; + } + +} diff --git a/common/buildcraft/core/robots/boards/BoardRobotPicker.java b/common/buildcraft/core/robots/boards/BoardRobotPicker.java index f4ca6819..5798654d 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPicker.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPicker.java @@ -5,20 +5,21 @@ import java.util.Set; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.api.boards.IRedstoneBoard; +import buildcraft.api.boards.IRedstoneBoardRobot; import buildcraft.api.core.SafeTimeTracker; import buildcraft.core.inventory.TransactorSimple; -import buildcraft.core.robots.EntityRobotPicker; +import buildcraft.core.robots.EntityRobot; 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 { +public class BoardRobotPicker implements IRedstoneBoardRobot { private static Set targettedItems = new HashSet(); @@ -29,7 +30,7 @@ public class BoardRobotPicker implements IRedstoneBoard { private int pickTime = -1; @Override - public void updateBoard(EntityRobotPicker robot) { + public void updateBoard(EntityRobot robot) { TransactorSimple inventoryInsert = new TransactorSimple(robot); if (robot.worldObj.isRemote) { @@ -96,7 +97,7 @@ public class BoardRobotPicker implements IRedstoneBoard { } } - public void scan(EntityRobotPicker robot) { + public void scan(EntityRobot robot) { TransactorSimple inventoryInsert = new TransactorSimple(robot); for (Object o : robot.worldObj.loadedEntityList) { @@ -129,4 +130,14 @@ public class BoardRobotPicker implements IRedstoneBoard { } } } + + @Override + public ResourceLocation getRobotTexture() { + return EntityRobot.ROBOT_TRANSPORT; + } + + @Override + public String getID() { + return "buildcraft:boardRobotPicker"; + } } diff --git a/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java b/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java index 6ffedd0f..ed80a6c5 100755 --- a/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java +++ b/common/buildcraft/core/robots/boards/BoardRobotPickerNBT.java @@ -15,12 +15,14 @@ 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.IRedstoneBoard; -import buildcraft.api.boards.IRedstoneBoardNBT; +import buildcraft.api.boards.IRedstoneBoardRobot; +import buildcraft.api.boards.IRedstoneBoardRobotNBT; +import buildcraft.core.robots.EntityRobot; import buildcraft.core.utils.StringUtils; -public class BoardRobotPickerNBT implements IRedstoneBoardNBT { +public class BoardRobotPickerNBT implements IRedstoneBoardRobotNBT { public IIcon icon; @@ -35,7 +37,7 @@ public class BoardRobotPickerNBT implements IRedstoneBoardNBT { } @Override - public IRedstoneBoard create(NBTTagCompound nbt) { + public IRedstoneBoardRobot create(NBTTagCompound nbt) { return new BoardRobotPicker(); } @@ -49,4 +51,9 @@ public class BoardRobotPickerNBT implements IRedstoneBoardNBT { icon = iconRegister.registerIcon("buildcraft:board_green"); } + @Override + public ResourceLocation getRobotTexture() { + return EntityRobot.ROBOT_TRANSPORT; + } + } diff --git a/common/buildcraft/silicon/boards/ImplRedstoneBoardRegistry.java b/common/buildcraft/silicon/boards/ImplRedstoneBoardRegistry.java index a377ac90..c74a0dec 100755 --- a/common/buildcraft/silicon/boards/ImplRedstoneBoardRegistry.java +++ b/common/buildcraft/silicon/boards/ImplRedstoneBoardRegistry.java @@ -58,7 +58,18 @@ public class ImplRedstoneBoardRegistry extends RedstoneBoardRegistry { @Override public IRedstoneBoardNBT getRedstoneBoard(NBTTagCompound nbt) { - return boards.get(nbt.getString("id")).boardNBT; + return getRedstoneBoard(nbt.getString("id")); + } + + @Override + public IRedstoneBoardNBT getRedstoneBoard(String id) { + BoardFactory factory = boards.get(id); + + if (factory != null) { + return factory.boardNBT; + } else { + return null; + } } @Override @@ -67,4 +78,5 @@ public class ImplRedstoneBoardRegistry extends RedstoneBoardRegistry { f.boardNBT.registerIcons(par1IconRegister); } } + } diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index 259f41c3..ab073533 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -788,7 +788,7 @@ public class BlockGenericPipe extends BlockBuildCraft { if (rayTraceResult.hitPart == Part.RobotStation) { EntityRobot robot = ((ItemRobot) currentItem.getItem()) - .createRobot(world); + .createRobot(currentItem, world); float px = x + 0.5F + rayTraceResult.sideHit.offsetX * 0.5F; float py = y + 0.5F + rayTraceResult.sideHit.offsetY * 0.5F; diff --git a/common/buildcraft/transport/PipeIconProvider.java b/common/buildcraft/transport/PipeIconProvider.java index 72a4765c..d6488730 100644 --- a/common/buildcraft/transport/PipeIconProvider.java +++ b/common/buildcraft/transport/PipeIconProvider.java @@ -113,16 +113,6 @@ public class PipeIconProvider implements IIconProvider { PipePowerIronM64("pipePowerIronM64"), PipePowerIronM128("pipePowerIronM128"), // - PipePowerHeat0("pipePowerHeat0"), - PipePowerHeat1("pipePowerHeat1"), - PipePowerHeat2("pipePowerHeat2"), - PipePowerHeat3("pipePowerHeat3"), - PipePowerHeat4("pipePowerHeat4"), - PipePowerHeat5("pipePowerHeat5"), - PipePowerHeat6("pipePowerHeat6"), - PipePowerHeat7("pipePowerHeat7"), - PipePowerHeat8("pipePowerHeat8"), - // PipeRobotStation("pipeRobotStation"), // Power_Normal("texture_cyan"),