diff --git a/api/buildcraft/api/core/Position.java b/api/buildcraft/api/core/Position.java index 84e58e2b..4d9a7ea9 100644 --- a/api/buildcraft/api/core/Position.java +++ b/api/buildcraft/api/core/Position.java @@ -64,6 +64,13 @@ public class Position { orientation = ForgeDirection.UNKNOWN; } + public Position(BlockIndex index) { + x = index.x; + y = index.y; + z = index.z; + orientation = ForgeDirection.UNKNOWN; + } + public void moveRight(double step) { switch (orientation) { case SOUTH: @@ -171,5 +178,4 @@ public class Position { return !(sqrDis > f * f); } - } diff --git a/buildcraft_resources/assets/buildcraft/textures/blocks/constructMarkerRec.png b/buildcraft_resources/assets/buildcraft/textures/blocks/constructMarkerRec.png new file mode 100755 index 00000000..a4af8124 Binary files /dev/null and b/buildcraft_resources/assets/buildcraft/textures/blocks/constructMarkerRec.png differ diff --git a/common/buildcraft/builders/ItemConstructionMarker.java b/common/buildcraft/builders/ItemConstructionMarker.java index 8e8e2d84..292288f3 100755 --- a/common/buildcraft/builders/ItemConstructionMarker.java +++ b/common/buildcraft/builders/ItemConstructionMarker.java @@ -9,16 +9,29 @@ package buildcraft.builders; import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +import buildcraft.api.core.Position; import buildcraft.core.utils.NBTUtils; public class ItemConstructionMarker extends ItemBlock { + @SideOnly(Side.CLIENT) + public IIcon iconBase; + + @SideOnly(Side.CLIENT) + public IIcon iconRecording; + public ItemConstructionMarker(Block block) { super(block); } @@ -37,6 +50,10 @@ public class ItemConstructionMarker extends ItemBlock { TileEntity tile1 = world.getTileEntity(ox, oy, oz); + if (!new Position(ox, oy, oz).isClose(new Position(x, y, z), 64)) { + return; + } + if (tile1 != null && (tile1 instanceof TileArchitect)) { TileArchitect architect = (TileArchitect) tile1; TileEntity tile2 = world.getTileEntity(x, y, z); @@ -61,4 +78,46 @@ public class ItemConstructionMarker extends ItemBlock { nbt.setInteger("y", y); nbt.setInteger("z", z); } + + @Override + public IIcon getIconIndex(ItemStack marker) { + NBTTagCompound nbt = NBTUtils.getItemData(marker); + + if (nbt.hasKey("x")) { + return iconRecording; + } else { + return iconBase; + } + } + + @Override + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) { + super.registerIcons(par1IconRegister); + + iconBase = par1IconRegister.registerIcon("buildcraft:constructMarker"); + iconRecording = par1IconRegister.registerIcon("buildcraft:constructMarkerRec"); + } + + @Override + public boolean onItemUse(ItemStack marker, EntityPlayer player, World world, int x, + int y, int z, int side, float par8, float par9, float par10) { + + TileEntity tile = world.getTileEntity(x, y, z); + NBTTagCompound nbt = NBTUtils.getItemData(marker); + + if (nbt.hasKey("x") + && !(tile instanceof TileBuilder + || tile instanceof TileArchitect + || tile instanceof TileConstructionMarker)) { + + nbt.removeTag("x"); + nbt.removeTag("y"); + nbt.removeTag("z"); + + return true; + } else { + return super.onItemUse(marker, player, world, x, y, z, side, par8, par9, par10); + } + } } diff --git a/common/buildcraft/builders/TileArchitect.java b/common/buildcraft/builders/TileArchitect.java index a8d1ccbc..ebe96b65 100644 --- a/common/buildcraft/builders/TileArchitect.java +++ b/common/buildcraft/builders/TileArchitect.java @@ -15,9 +15,12 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.common.util.Constants; + import buildcraft.api.core.BlockIndex; import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.NetworkData; @@ -153,41 +156,59 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro } @Override - public void readFromNBT(NBTTagCompound nbttagcompound) { - super.readFromNBT(nbttagcompound); + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); - if (nbttagcompound.hasKey("box")) { - box.initialize(nbttagcompound.getCompoundTag("box")); + if (nbt.hasKey("box")) { + box.initialize(nbt.getCompoundTag("box")); } - inv.readFromNBT(nbttagcompound); + inv.readFromNBT(nbt); - name = nbttagcompound.getString("name"); - currentAuthorName = nbttagcompound.getString("lastAuthor"); + name = nbt.getString("name"); + currentAuthorName = nbt.getString("lastAuthor"); - if (nbttagcompound.hasKey("readConfiguration")) { - readConfiguration.readFromNBT(nbttagcompound.getCompoundTag("readConfiguration")); + if (nbt.hasKey("readConfiguration")) { + readConfiguration.readFromNBT(nbt.getCompoundTag("readConfiguration")); + } + + NBTTagList subBptList = nbt.getTagList("subBlueprints", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < subBptList.tagCount(); ++i) { + BlockIndex index = new BlockIndex(subBptList.getCompoundTagAt(i)); + + addSubBlueprint(index); } } @Override - public void writeToNBT(NBTTagCompound nbttagcompound) { - super.writeToNBT(nbttagcompound); + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); if (box.isInitialized()) { NBTTagCompound boxStore = new NBTTagCompound(); box.writeToNBT(boxStore); - nbttagcompound.setTag("box", boxStore); + nbt.setTag("box", boxStore); } - inv.writeToNBT(nbttagcompound); + inv.writeToNBT(nbt); - nbttagcompound.setString("name", name); - nbttagcompound.setString("lastAuthor", currentAuthorName); + nbt.setString("name", name); + nbt.setString("lastAuthor", currentAuthorName); NBTTagCompound readConf = new NBTTagCompound(); readConfiguration.writeToNBT(readConf); - nbttagcompound.setTag("readConfiguration", readConf); + nbt.setTag("readConfiguration", readConf); + + NBTTagList subBptList = new NBTTagList(); + + for (BlockIndex b : subBlueprints) { + NBTTagCompound subBpt = new NBTTagCompound(); + b.writeTo(subBpt); + subBptList.appendTag(subBpt); + } + + nbt.setTag("subBlueprints", subBptList); } @Override @@ -239,8 +260,8 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro public AxisAlignedBB getRenderBoundingBox() { Box completeBox = new Box(this).extendToEncompass(box); - for (BlockIndex b : subBlueprints) { - completeBox.extendToEncompass(b); + for (LaserData d : subLasers) { + completeBox.extendToEncompass(d.tail); } return completeBox.getBoundingBox(); @@ -258,9 +279,15 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro } public void addSubBlueprint(TileEntity sub) { - subBlueprints.add(new BlockIndex(sub)); + addSubBlueprint(new BlockIndex(sub)); - LaserData laser = new LaserData(new Position(sub), new Position(this)); + sendNetworkUpdate(); + } + + private void addSubBlueprint(BlockIndex index) { + subBlueprints.add(index); + + LaserData laser = new LaserData(new Position(index), new Position(this)); laser.head.x += 0.5F; laser.head.y += 0.5F; @@ -271,7 +298,5 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro laser.tail.z += 0.5F; subLasers.add(laser); - - sendNetworkUpdate(); } } \ No newline at end of file