Add Blueprint and Serialization

Also renabled the Builder for testing purposes.
This commit is contained in:
CovertJaguar 2013-06-30 00:46:15 -07:00
parent 40b8c72ada
commit fd73836a67
7 changed files with 323 additions and 39 deletions

View file

@ -312,11 +312,11 @@ public class BuildCraftBuilders {
new ItemStack(Item.dyePowder, 1, 0), Character.valueOf('t'), markerBlock, Character.valueOf('y'), new ItemStack(Item.dyePowder, 1, 11),
Character.valueOf('c'), Block.workbench, Character.valueOf('g'), BuildCraftCore.goldGearItem, Character.valueOf('C'), Block.chest});
/*
CoreProxy.proxy.addCraftingRecipe(new ItemStack(builderBlock, 1), new Object[] { "btb", "ycy", "gCg", Character.valueOf('b'),
new ItemStack(Item.dyePowder, 1, 0), Character.valueOf('t'), markerBlock, Character.valueOf('y'), new ItemStack(Item.dyePowder, 1, 11),
Character.valueOf('c'), Block.workbench, Character.valueOf('g'), BuildCraftCore.diamondGearItem, Character.valueOf('C'), Block.chest });
*/
CoreProxy.proxy.addCraftingRecipe(new ItemStack(builderBlock, 1), new Object[]{"btb", "ycy", "gCg", Character.valueOf('b'),
new ItemStack(Item.dyePowder, 1, 0), Character.valueOf('t'), markerBlock, Character.valueOf('y'), new ItemStack(Item.dyePowder, 1, 11),
Character.valueOf('c'), Block.workbench, Character.valueOf('g'), BuildCraftCore.diamondGearItem, Character.valueOf('C'), Block.chest});
CoreProxy.proxy.addCraftingRecipe(new ItemStack(architectBlock, 1), new Object[]{"btb", "ycy", "gCg", Character.valueOf('b'),
new ItemStack(Item.dyePowder, 1, 0), Character.valueOf('t'), markerBlock, Character.valueOf('y'), new ItemStack(Item.dyePowder, 1, 11),
@ -325,7 +325,7 @@ public class BuildCraftBuilders {
CoreProxy.proxy.addCraftingRecipe(new ItemStack(libraryBlock, 1), new Object[]{"bbb", "bBb", "bbb", Character.valueOf('b'),
new ItemStack(blueprintItem), Character.valueOf('B'), Block.bookShelf});
// / INIT FILLER PATTERNS
FillerManager.registry.addRecipe(new FillerFillAll(), new Object[]{"bbb", "bbb", "bbb", 'g', Block.glass, 'b', Block.brick});
FillerManager.registry.addRecipe(new FillerFlattener(), new Object[]{"ggg", "bbb", "bbb", 'g', Block.glass, 'b', Block.brick});

View file

@ -8,6 +8,7 @@
package buildcraft;
import buildcraft.api.builder.BlueprintDatabase;
import java.io.File;
import java.util.TreeMap;
import java.util.logging.Logger;
@ -161,7 +162,7 @@ public class BuildCraftCore {
public static BptItem[] itemBptProps = new BptItem[Item.itemsList.length];
public static Logger bcLog = Logger.getLogger("Buildcraft");
public static final Logger bcLog = Logger.getLogger("Buildcraft");
public IIconProvider actionTriggerIconProvider = new ActionTriggerIconProvider();
@ -177,7 +178,8 @@ public class BuildCraftCore {
bcLog.info("Starting BuildCraft " + Version.getVersion());
bcLog.info("Copyright (c) SpaceToad, 2011");
bcLog.info("http://www.mod-buildcraft.com");
BlueprintDatabase.configFolder = evt.getModConfigurationDirectory();
mainConfiguration = new BuildCraftConfiguration(new File(evt.getModConfigurationDirectory(), "buildcraft/main.conf"));
try {
mainConfiguration.load();
@ -236,10 +238,10 @@ public class BuildCraftCore {
Property ironGearId = BuildCraftCore.mainConfiguration.getItem("ironGearItem.id", DefaultProps.IRON_GEAR_ID);
Property goldenGearId = BuildCraftCore.mainConfiguration.getItem("goldenGearItem.id", DefaultProps.GOLDEN_GEAR_ID);
Property diamondGearId = BuildCraftCore.mainConfiguration.getItem("diamondGearItem.id", DefaultProps.DIAMOND_GEAR_ID);
Property modifyWorld = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "modifyWorld", true);
modifyWorld.comment = "set to false if BuildCraft should not generate custom blocks (e.g. oil)";
Property modifyWorldProp = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "modifyWorld", true);
modifyWorldProp.comment = "set to false if BuildCraft should not generate custom blocks (e.g. oil)";
BuildCraftCore.modifyWorld = modifyWorld.getBoolean(true);
modifyWorld = modifyWorldProp.getBoolean(true);
if(BuildCraftCore.modifyWorld) {
springBlock = new BlockSpring(springId.getInt()).setUnlocalizedName("eternalSpring");

View file

@ -11,8 +11,30 @@ public final class BlockSchematic {
public final String blockName;
public int metadata = 0;
public NBTTagCompound blockData = null;
public int x, y, z;
public BlockSchematic(String blockName) {
this.blockName = blockName;
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setString("blockName", blockName);
nbt.setByte("metadata", (byte) metadata);
nbt.setInteger("x", x);
nbt.setInteger("y", y);
nbt.setInteger("z", z);
nbt.setCompoundTag("blockData", blockData);
}
public static BlockSchematic readFromNBT(NBTTagCompound nbt) {
BlockSchematic block = new BlockSchematic(nbt.getString("blockName"));
block.metadata = nbt.getInteger("metadata");
block.x = nbt.getInteger("x");
block.y = nbt.getInteger("y");
block.z = nbt.getInteger("z");
if (nbt.hasKey("blockData")) {
block.blockData = nbt.getCompoundTag("blockData");
}
return block;
}
}

View file

@ -0,0 +1,146 @@
/**
* Copyright (c) SpaceToad, 2011-2012
* 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.builder;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
/**
* This class is used to represent the data of the blueprint as it exists in the
* world.
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class Blueprint {
private final String version = "Blueprint-1.0";
private final UUID uuid;
private String name;
private String creator;
private final BlockSchematic[][][] blocks;
private final int sizeX, sizeY, sizeZ;
public Blueprint(int sizeX, int sizeY, int sizeZ) {
this(sizeX, sizeY, sizeZ, UUID.randomUUID());
}
private Blueprint(int sizeX, int sizeY, int sizeZ, UUID uuid) {
this.uuid = uuid;
this.sizeX = sizeX;
this.sizeY = sizeY;
this.sizeZ = sizeZ;
blocks = new BlockSchematic[sizeX][sizeY][sizeZ];
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setBlock(int x, int y, int z, BlockSchematic block) {
block.x = x;
block.y = y;
block.z = z;
blocks[x][y][z] = block;
}
public BlockSchematic getBlock(int x, int y, int z) {
return blocks[x][y][z];
}
public UUID getUUID() {
return uuid;
}
/**
* Returns a list of all blocks in the Blueprint in the order they should be
* built.
*
* Be aware that changes to the Blueprint will not propagate to the list nor
* will changes to the list propagate to the Blueprint.
*
* @return List<BlockScematic>
*/
public List<BlockSchematic> getBuildList() {
List<BlockSchematic> list = new LinkedList<BlockSchematic>();
for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) {
list.add(blocks[x][y][z]);
}
}
}
return list;
}
public void writeToNBT(NBTTagCompound nbt) {
NBTTagList blockList = new NBTTagList();
for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) {
if (blocks[x][y][z] == null)
continue;
NBTTagCompound blockNBT = new NBTTagCompound();
blocks[x][y][z].writeToNBT(nbt);
blockList.appendTag(blockNBT);
}
}
}
nbt.setTag("blocks", blockList);
nbt.setLong("uuidMost", uuid.getMostSignificantBits());
nbt.setLong("uuidLeast", uuid.getLeastSignificantBits());
nbt.setString("name", name);
nbt.setString("version", version);
nbt.setString("creator", creator);
nbt.setInteger("sizeX", sizeX);
nbt.setInteger("sizeY", sizeY);
nbt.setInteger("sizeZ", sizeZ);
}
public static Blueprint readFromNBT(NBTTagCompound nbt) {
long most = nbt.getLong("uuidMost");
long least = nbt.getLong("uuidLeast");
int sizeX = nbt.getInteger("sizeX");
int sizeY = nbt.getInteger("sizeY");
int sizeZ = nbt.getInteger("sizeZ");
Blueprint blueprint = new Blueprint(sizeX, sizeY, sizeZ, new UUID(most, least));
blueprint.name = nbt.getString("name");
blueprint.creator = nbt.getString("creator");
NBTTagList blockList = nbt.getTagList("blocks");
for (int i = 0; i < blockList.tagCount(); i++) {
NBTTagCompound blockNBT = (NBTTagCompound) blockList.tagAt(i);
BlockSchematic block = BlockSchematic.readFromNBT(blockNBT);
blueprint.blocks[block.x][block.y][block.z] = block;
}
return blueprint;
}
/**
* @return the creator
*/
public String getCreator() {
return creator;
}
/**
* @param creator the creator to set
*/
public void setCreator(String creator) {
this.creator = creator;
}
}

View file

@ -0,0 +1,132 @@
/**
* Copyright (c) SpaceToad, 2011-2012
* 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.builder;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class BlueprintDatabase {
public static File configFolder;
private static Map<UUID, Blueprint> blueprints = new HashMap<UUID, Blueprint>();
public static Blueprint getBlueprint(UUID uuid) {
Blueprint blueprint = blueprints.get(uuid);
if (blueprint == null) {
blueprint = loadBlueprint(uuid);
addBlueprint(blueprint);
}
return blueprint;
}
public static void addBlueprint(Blueprint blueprint) {
if (blueprint == null)
return;
blueprints.put(blueprint.getUUID(), blueprint);
}
private static File getBlueprintFolder() {
File blueprintFolder = new File(configFolder, "buildcraft/blueprints/");
if (!blueprintFolder.exists()) {
blueprintFolder.mkdirs();
}
return blueprintFolder;
}
private static String uuidToString(UUID uuid) {
return String.format(Locale.ENGLISH, "%x%x", uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
}
public static void saveBlueprint(Blueprint blueprint) {
NBTTagCompound nbt = new NBTTagCompound();
blueprint.writeToNBT(nbt);
File blueprintFile = new File(getBlueprintFolder(), String.format(Locale.ENGLISH, "%x%x-%s.nbt", uuidToString(blueprint.getUUID()), blueprint.getName()));
if (blueprintFile.exists())
return;
try {
CompressedStreamTools.write(nbt, blueprintFile);
} catch (IOException ex) {
Logger.getLogger("Buildcraft").log(Level.WARNING, "Failed to save Blueprint file: {0} {1}", new Object[]{blueprintFile.getName(), ex.getMessage()});
}
}
public static void saveBlueprints() {
for (Blueprint blueprint : blueprints.values()) {
saveBlueprint(blueprint);
}
}
private static Blueprint loadBlueprint(final UUID uuid) {
FilenameFilter filter = new FilenameFilter() {
private String uuidString = uuidToString(uuid);
@Override
public boolean accept(File dir, String name) {
return name.startsWith(uuidString);
}
};
NBTTagCompound nbt = null;
File blueprintFolder = getBlueprintFolder();
for (File blueprintFile : blueprintFolder.listFiles(filter)) {
try {
nbt = CompressedStreamTools.read(blueprintFile);
break;
} catch (IOException ex) {
Logger.getLogger("Buildcraft").log(Level.WARNING, "Failed to load Blueprint file: {0} {1}", new Object[]{blueprintFile.getName(), ex.getMessage()});
}
}
if (nbt == null) {
return null;
}
return Blueprint.readFromNBT(nbt);
}
public static void loadBlueprints() {
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".nbt");
}
};
File blueprintFolder = getBlueprintFolder();
for (File blueprintFile : blueprintFolder.listFiles(filter)) {
try {
NBTTagCompound nbt = CompressedStreamTools.read(blueprintFile);
addBlueprint(Blueprint.readFromNBT(nbt));
} catch (IOException ex) {
Logger.getLogger("Buildcraft").log(Level.WARNING, "Failed to load Blueprint file: {0} {1}", new Object[]{blueprintFile.getName(), ex.getMessage()});
}
}
}
@SideOnly(Side.CLIENT)
public static void sendBlueprintsToServer() {
// TODO
}
}

View file

@ -41,7 +41,7 @@ public class BlockBuilder extends BlockContainer {
public BlockBuilder(int i) {
super(i, Material.iron);
setHardness(0.7F);
//setCreativeTab(CreativeTabBuildCraft.tabBuildCraft);
setCreativeTab(CreativeTabBuildCraft.tabBuildCraft);
}
@Override

View file

@ -1,12 +1,10 @@
/**
* Copyright (c) SpaceToad, 2011
* 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
/**
* Copyright (c) SpaceToad, 2011 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.builders;
import java.util.Collection;
@ -50,18 +48,12 @@ import buildcraft.core.utils.Utils;
public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IPowerReceptor, IMachine {
private final ItemStack items[] = new ItemStack[28];
private BptBuilderBase bluePrintBuilder;
public @TileNetworkData
Box box = new Box();
private IPowerProvider powerProvider;
private LinkedList<BlockIndex> path;
private LinkedList<EntityLaser> pathLasers;
private EntityRobot builderRobot;
private class PathIterator {
@ -170,9 +162,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
return true;
}
}
public PathIterator currentPathIterator;
private PathIterator currentPathIterator;
private boolean done = true;
public TileBuilder() {
@ -287,7 +277,6 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
iterateBpt();
/* Temp fix to make Builders impotent as the World Destroyers they are
if (bluePrintBuilder != null && !bluePrintBuilder.done) {
if (!box.isInitialized()) {
box.initialize(bluePrintBuilder);
@ -300,10 +289,8 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
box.createLasers(worldObj, LaserKind.Stripes);
builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, new SurroundingInventory(worldObj, xCoord, yCoord, zCoord)),
bluePrintBuilder.getContext());
builderRobot.scheduleContruction(bluePrintBuilder.getNextBlock(worldObj, this), bluePrintBuilder.getContext());
}
*/
}
public void iterateBpt() {
@ -347,10 +334,8 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
if (bluePrintBuilder != null) {
box.deleteLasers();
box.reset();
/*
box.initialize(bluePrintBuilder);
box.createLasers(worldObj, LaserKind.Stripes);
*/
}
if (builderRobot != null) {
@ -443,11 +428,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
// TODO Auto-generated method stub
return false;
return true;
}
@Override
@ -559,12 +543,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
@Override
public void openChest() {
}
@Override
public void closeChest() {
}
@Override