re-implemented template, close #1489

This commit is contained in:
SpaceToad 2014-03-10 23:33:36 +01:00
parent 1e02e58ffd
commit 909b28a6df
10 changed files with 124 additions and 104 deletions

View file

@ -330,6 +330,7 @@ public class BuildCraftCore extends BuildCraftMod {
BuildCraftAPI.softBlocks.add(Blocks.snow);
BuildCraftAPI.softBlocks.add(Blocks.vine);
BuildCraftAPI.softBlocks.add(Blocks.fire);
BuildCraftAPI.softBlocks.add(Blocks.air);
FMLCommonHandler.instance().bus().register(new TickHandlerCoreClient());
}

View file

@ -49,14 +49,6 @@ public abstract class ItemBlueprint extends ItemBuildCraft {
}
}
public static ItemStack getBlueprintItem(BlueprintBase blueprint) {
ItemStack stack = new ItemStack(BuildCraftBuilders.blueprintItem, 1);
NBTTagCompound nbt = NBTUtils.getItemData(stack);
blueprint.id.write (nbt);
nbt.setString("author", blueprint.author);
return stack;
}
public static BlueprintId getId (ItemStack stack) {
NBTTagCompound nbt = NBTUtils.getItemData(stack);
BlueprintId id = new BlueprintId ();

View file

@ -9,6 +9,7 @@
package buildcraft.builders;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -21,8 +22,8 @@ public class ItemBlueprintTemplate extends ItemBlueprint {
}
@Override
public IIcon getIconFromDamage(int i) {
if (i == 0) {
public IIcon getIconIndex(ItemStack stack) {
if (getId(stack) == null) {
return itemIcon;
} else {
return usedTemplate;

View file

@ -24,7 +24,9 @@ import buildcraft.core.Box.Kind;
import buildcraft.core.IBoxProvider;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BlueprintBase;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.blueprints.Template;
import buildcraft.core.network.NetworkData;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
@ -34,7 +36,7 @@ import buildcraft.core.utils.Utils;
public class TileArchitect extends TileBuildCraft implements IInventory, IBoxProvider {
private final static int SCANNER_ITERATION = 100;
private Blueprint writingBlueprint;
private BlueprintBase writingBlueprint;
private BptContext writingContext;
private BlockScanner blockScanner;
public int computingTime = 0;
@ -86,7 +88,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
}
} else if (writingBlueprint.getData() != null) {
createBpt();
createBlueprint();
computingTime = 0;
}
@ -110,11 +112,11 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
sendNetworkUpdate();
}
public void createBpt() {
public void createBlueprint() {
writingBlueprint.id.name = name;
BuildCraftBuilders.serverDB.add(writingBlueprint);
setInventorySlotContents(1, ItemBlueprint.getBlueprintItem(writingBlueprint));
setInventorySlotContents(1, writingBlueprint.getStack());
setInventorySlotContents(0, null);
writingBlueprint = null;
@ -319,7 +321,13 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
}
blockScanner = new BlockScanner(box, getWorld(), SCANNER_ITERATION);
writingBlueprint = new Blueprint(box.sizeX(), box.sizeY(), box.sizeZ());
if (items[0].getItem() instanceof ItemBlueprintStandard) {
writingBlueprint = new Blueprint(box.sizeX(), box.sizeY(), box.sizeZ());
} else if (items[0].getItem() instanceof ItemBlueprintTemplate) {
writingBlueprint = new Template(box.sizeX(), box.sizeY(), box.sizeZ());
}
writingContext = writingBlueprint.getContext(worldObj, box);
writingBlueprint.id.name = name;
@ -327,8 +335,6 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
writingBlueprint.anchorX = xCoord - box.xMin;
writingBlueprint.anchorY = yCoord - box.yMin;
writingBlueprint.anchorZ = zCoord - box.zMin;
} else {
}
} else {
blockScanner = null;

View file

@ -268,7 +268,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
bpt.setData(data);
bpt.id = id;
BuildCraftBuilders.serverDB.add(bpt);
setInventorySlotContents(3, ItemBlueprint.getBlueprintItem(bpt));
setInventorySlotContents(3, bpt.getStack());
} else {
setInventorySlotContents(3, stack[2]);
}

View file

@ -39,6 +39,7 @@ import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BlueprintBase;
import buildcraft.core.blueprints.BptBuilderBase;
import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.network.NetworkData;
import buildcraft.core.network.RPC;
@ -290,10 +291,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
BptBuilderBase result = null;
if (items[0].getItem() instanceof ItemBlueprint) {
if (items[0].getItem() instanceof ItemBlueprintStandard) {
result = new BptBuilderBlueprint((Blueprint) bpt, worldObj, x, y, z);
/*} else if (items[0].getItem() instanceof ItemBptBluePrint) {
return new BptBuilderTemplate(bpt, worldObj, x, y, z);*/
} else if (items[0].getItem() instanceof ItemBlueprintTemplate) {
return new BptBuilderTemplate(bpt, worldObj, x, y, z);
} else {
result = null;
}
@ -687,8 +688,12 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
SchematicToBuild slot = bluePrintBuilder.getNextBlock(worldObj, this);
if (slot != null) {
slot.schematic.writeToWorld(bluePrintBuilder.context, slot.x,
if (slot.schematic == null) {
getWorld().setBlockToAir(slot.x, slot.y, slot.z);
} else {
slot.schematic.writeToWorld(bluePrintBuilder.context, slot.x,
slot.y, slot.z);
}
}
if (bluePrintBuilder instanceof BptBuilderBlueprint) {

View file

@ -10,13 +10,16 @@ package buildcraft.core.blueprints;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.core.utils.BCLog;
import buildcraft.core.utils.NBTUtils;
import buildcraft.core.utils.Utils;
public class Blueprint extends BlueprintBase {
@ -28,6 +31,7 @@ public class Blueprint extends BlueprintBase {
super(sizeX, sizeY, sizeZ);
}
@Override
public void readFromWorld(IBuilderContext context, TileEntity anchorTile, int x, int y, int z) {
Block block = anchorTile.getWorldObj().getBlock(x, y, z);
@ -111,4 +115,14 @@ public class Blueprint extends BlueprintBase {
}
}
}
@Override
public ItemStack getStack () {
ItemStack stack = new ItemStack(BuildCraftBuilders.blueprintItem, 1);
NBTTagCompound nbt = NBTUtils.getItemData(stack);
id.write (nbt);
nbt.setString("author", author);
return stack;
}
}

View file

@ -11,12 +11,15 @@ package buildcraft.core.blueprints;
import java.io.IOException;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.builders.blueprints.BlueprintId;
import buildcraft.core.Box;
import buildcraft.core.Version;
@ -124,7 +127,7 @@ public abstract class BlueprintBase {
BlueprintBase bpt;
if ("template".equals("kind")) {
if ("template".equals(kind)) {
bpt = new Template ();
} else {
bpt = new Blueprint();
@ -263,10 +266,6 @@ public abstract class BlueprintBase {
return new BptContext(world, box, mapping);
}
public abstract void loadContents(NBTTagCompound nbt) throws BptError;
public abstract void saveContents(NBTTagCompound nbt);
class ComputeDataThread extends Thread {
public NBTTagCompound nbt;
@ -304,4 +303,12 @@ public abstract class BlueprintBase {
public synchronized void setData (byte [] b) {
data = b;
}
public abstract void loadContents(NBTTagCompound nbt) throws BptError;
public abstract void saveContents(NBTTagCompound nbt);
public abstract void readFromWorld(IBuilderContext context, TileEntity anchorTile, int x, int y, int z);
public abstract ItemStack getStack ();
}

View file

@ -14,6 +14,7 @@ import net.minecraft.world.World;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicToBuild;
import buildcraft.api.blueprints.SchematicToBuild.Mode;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.core.IBuilderInventory;
public class BptBuilderTemplate extends BptBuilderBase {
@ -34,14 +35,9 @@ public class BptBuilderTemplate extends BptBuilderBase {
Schematic slot = bluePrint.contents[i][j][k];
if (slot == null || slot.block == null) {
slot = new Schematic();
slot.meta = 0;
slot.block = null;
SchematicToBuild b = new SchematicToBuild();
b.schematic = slot;
b.schematic = null;
b.x = xCoord;
b.y = yCoord;
b.z = zCoord;
@ -63,23 +59,15 @@ public class BptBuilderTemplate extends BptBuilderBase {
Schematic slot = bluePrint.contents[i][j][k];
if (slot != null) {
slot = slot.clone();
} else {
slot = new Schematic();
slot.meta = 0;
slot.block = null;
}
SchematicToBuild b = new SchematicToBuild();
SchematicToBuild b = new SchematicToBuild();
b.schematic = slot;
b.x = xCoord;
b.y = yCoord;
b.z = zCoord;
b.schematic = slot;
b.x = xCoord;
b.y = yCoord;
b.z = zCoord;
b.mode = Mode.Build;
b.mode = Mode.Build;
if (slot.block != null) {
buildList.add(b);
}
}
@ -103,8 +91,6 @@ public class BptBuilderTemplate extends BptBuilderBase {
if (slot != null) {
return slot;
} else {
return null;
}
}
@ -114,8 +100,6 @@ public class BptBuilderTemplate extends BptBuilderBase {
if (slot != null) {
return slot;
} else {
return null;
}
}
@ -128,34 +112,19 @@ public class BptBuilderTemplate extends BptBuilderBase {
SchematicToBuild result = null;
while (list.size() > 0) {
SchematicToBuild slot = list.getFirst();
SchematicToBuild slot = list.removeFirst();
// Note from CJ: I have no idea what this code is supposed to do, so I'm not touching it.
/*if (slot.blockId == world.getBlockId(slot.x, slot.y, slot.z)) {
list.removeFirst();
} else if (slot.mode == Mode.ClearIfInvalid) {
if (slot.mode == Mode.ClearIfInvalid
&& !BuildCraftAPI.softBlocks.contains(context.world()
.getBlock(slot.x, slot.y, slot.z))) {
result = slot;
list.removeFirst();
break;
} else {
int size = inv.getSizeInventory();
for (int i = 0; i < size; ++i) {
if (!inv.isBuildingMaterial(i)) {
continue;
}
ItemStack stack = inv.decrStackSize(i, 1);
if (stack != null && stack.stackSize > 0) {
result = slot.clone();
result.stackToUse = stack;
list.removeFirst();
break;
}
}
} else if (slot.mode == Mode.Build
&& BuildCraftAPI.softBlocks.contains(context.world()
.getBlock(slot.x, slot.y, slot.z))) {
result = slot;
break;
}*/
}
}
return result;

View file

@ -8,7 +8,16 @@
*/
package buildcraft.core.blueprints;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.core.utils.NBTUtils;
/**
* Use the template system to describe fillers
@ -23,49 +32,65 @@ public class Template extends BlueprintBase {
}
@Override
public void saveContents(NBTTagCompound nbt) {
/*writer.write("mask:");
public void readFromWorld(IBuilderContext context, TileEntity anchorTile, int x, int y, int z) {
Block block = anchorTile.getWorldObj().getBlock(x, y, z);
boolean first = true;
int posX = (int) (x - context.surroundingBox().pMin().x);
int posY = (int) (y - context.surroundingBox().pMin().y);
int posZ = (int) (z - context.surroundingBox().pMin().z);
if (!BuildCraftAPI.softBlocks.contains(block)) {
contents [posX][posY][posZ] = SchematicRegistry.newSchematic(Blocks.stone);
}
}
@Override
public void saveContents(NBTTagCompound nbt) {
// Note: this way of storing data is suboptimal, we really need a bit
// per mask entry, not a byte. However, this is fine, as compression
// will fix it.
byte [] data = new byte [sizeX * sizeY * sizeZ];
int ind = 0;
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (first) {
first = false;
} else {
writer.write(",");
}
writer.write(contents[x][y][z].blockId + "");
data [ind] = (byte) ((contents[x][y][z] == null) ? 0 : 1);
ind++;
}
}
}*/
}
nbt.setByteArray("mask", data);
}
@Override
public void loadContents(NBTTagCompound nbt) throws BptError {
/*if (attr.equals("mask")) {
contents = new BptSlot[sizeX][sizeY][sizeZ];
byte [] data = nbt.getByteArray("mask");
int ind = 0;
String[] mask = val.split(",");
int maskIndex = 0;
/*for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
contents[x][y][z] = new BptSlot();
contents[x][y][z].x = x;
contents[x][y][z].y = y;
contents[x][y][z].z = z;
contents[x][y][z].blockId = Integer.parseInt(mask[maskIndex]);
maskIndex++;
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (data [ind] == 1) {
contents [x][y][z] = SchematicRegistry.newSchematic(Blocks.stone);
}
ind++;
}
}
}*/
}
}
@Override
public ItemStack getStack () {
ItemStack stack = new ItemStack(BuildCraftBuilders.templateItem, 1);
NBTTagCompound nbt = NBTUtils.getItemData(stack);
id.write (nbt);
nbt.setString("author", author);
return stack;
}
}