Further progress on composite blueprints (#1544).

Markers now display if they're recording a composition or not.
Architects save / load their sub-blueprints.
Composition links have a maximum reach.
This commit is contained in:
SpaceToad 2014-09-07 11:52:15 +02:00
parent f814fa67f7
commit 579252a473
4 changed files with 113 additions and 23 deletions

View file

@ -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);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

View file

@ -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);
}
}
}

View file

@ -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();
}
}