Fixed extension for templates, and added templates support in the library.

Close #1614
This commit is contained in:
SpaceToad 2014-04-27 17:44:37 +02:00
parent fb6a7b740f
commit a4205745fc
7 changed files with 75 additions and 16 deletions

View file

@ -31,7 +31,7 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
public static final double BUILD_ENERGY = 20;
/**
* Computes the maximym amount of energy required to build a full chest,
* Computes the maximum amount of energy required to build a full chest,
* plus a safeguard. That's a nice way to evaluate maximum amount of energy
* that need to be in a builder.
*/

View file

@ -19,6 +19,7 @@ import net.minecraft.nbt.NBTTagCompound;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.core.NetworkData;
import buildcraft.builders.blueprints.BlueprintId;
import buildcraft.builders.blueprints.BlueprintId.Kind;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.BlueprintBase;
import buildcraft.core.inventory.InvUtils;
@ -250,12 +251,17 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
@RPC (RPCSide.CLIENT)
public void requestSelectedBlueprint () {
if (selected > -1 && selected < currentPage.size()) {
BlueprintBase bpt = BuildCraftBuilders.clientDB.load(currentPage.get(selected));
if (isOuputConsistent()) {
if (selected > -1 && selected < currentPage.size()) {
BlueprintBase bpt = BuildCraftBuilders.clientDB
.load(currentPage.get(selected));
RPCHandler.rpcServer(this, "uploadBlueprintToServer", bpt.id, bpt.getData());
} else {
RPCHandler.rpcServer(this, "uploadBlueprintToServer", null, null);
RPCHandler.rpcServer(this, "uploadBlueprintToServer", bpt.id,
bpt.getData());
} else {
RPCHandler.rpcServer(this, "uploadBlueprintToServer", null,
null);
}
}
}
@ -301,4 +307,15 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
public void selectBlueprint (int index) {
selected = index;
}
private boolean isOuputConsistent () {
if (selected == -1 || stack [2] == null) {
return false;
}
return (stack [2].getItem() instanceof ItemBlueprintStandard
&& currentPage.get(selected).kind == Kind.Blueprint) ||
(stack [2].getItem() instanceof ItemBlueprintTemplate
&& currentPage.get(selected).kind == Kind.Template);
}
}

View file

@ -25,11 +25,13 @@ import java.util.logging.Logger;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.BuildCraftBuilders;
import buildcraft.builders.blueprints.BlueprintId.Kind;
import buildcraft.core.blueprints.BlueprintBase;
public class BlueprintDatabase {
private final int bufferSize = 8192;
private final String fileExt = ".bpt";
private final static String BPT_EXTENSION = ".bpt";
private final static String TPL_EXTENSION = ".tpl";
private File blueprintFolder;
private final static int PAGE_SIZE = 12;
@ -69,7 +71,7 @@ public class BlueprintDatabase {
}
public void deleteBlueprint (BlueprintId id) {
File blueprintFile = new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + fileExt, id.toString()));
File blueprintFile = getBlueprintFile(id);
blueprintFile.delete();
blueprintIds.remove(id);
pages = new BlueprintId [blueprintIds.size()];
@ -80,8 +82,7 @@ public class BlueprintDatabase {
blueprint.id.generateUniqueId(blueprint.getData());
BlueprintId id = blueprint.id;
File blueprintFile = new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + fileExt, id.toString()));
File blueprintFile = getBlueprintFile (id);
if (!blueprintFile.exists()) {
OutputStream gzOs = null;
@ -103,11 +104,19 @@ public class BlueprintDatabase {
return id;
}
private File getBlueprintFile(BlueprintId id) {
if (id.kind == Kind.Blueprint) {
return new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + BPT_EXTENSION, id.toString()));
} else {
return new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + TPL_EXTENSION, id.toString()));
}
}
private void loadIndex() {
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(fileExt);
return name.endsWith(BPT_EXTENSION) || name.endsWith(TPL_EXTENSION);
}
};
@ -121,7 +130,14 @@ public class BlueprintDatabase {
BlueprintId id = new BlueprintId();
id.name = prefix;
id.uniqueId = BlueprintId.toBytes (suffix.replaceAll(".bpt", ""));
if (suffix.contains(BPT_EXTENSION)) {
id.uniqueId = BlueprintId.toBytes (suffix.replaceAll(BPT_EXTENSION, ""));
id.kind = Kind.Blueprint;
} else {
id.uniqueId = BlueprintId.toBytes (suffix.replaceAll(TPL_EXTENSION, ""));
id.kind = Kind.Template;
}
if (!blueprintIds.contains(id)) {
blueprintIds.add(id);
@ -140,8 +156,7 @@ public class BlueprintDatabase {
return null;
}
File blueprintFile = new File(blueprintFolder, String.format(
Locale.ENGLISH, "%s" + fileExt, id.toString()));
File blueprintFile = getBlueprintFile(id);
if (blueprintFile.exists()) {
try {

View file

@ -21,12 +21,17 @@ import buildcraft.api.core.NetworkData;
public final class BlueprintId implements Comparable<BlueprintId> {
public enum Kind {Template, Blueprint};
@NetworkData
public byte[] uniqueId;
@NetworkData
public String name = "";
@NetworkData
public Kind kind = Kind.Blueprint;
public String completeId;
public BlueprintId() {
@ -46,11 +51,13 @@ public final class BlueprintId implements Comparable<BlueprintId> {
public void write (NBTTagCompound nbt) {
nbt.setByteArray("uniqueBptId", uniqueId);
nbt.setString("name", name);
nbt.setByte("kind", (byte) kind.ordinal());
}
public void read (NBTTagCompound nbt) {
uniqueId = nbt.getByteArray("uniqueBptId");
name = nbt.getString("name");
kind = Kind.values()[nbt.getByte("kind")];
}
@Override

View file

@ -17,6 +17,7 @@ import org.lwjgl.opengl.GL11;
import buildcraft.BuildCraftBuilders;
import buildcraft.builders.TileBlueprintLibrary;
import buildcraft.builders.blueprints.BlueprintId;
import buildcraft.builders.blueprints.BlueprintId.Kind;
import buildcraft.core.DefaultProps;
import buildcraft.core.gui.GuiBuildCraft;
import buildcraft.core.utils.StringUtils;
@ -77,10 +78,20 @@ public class GuiBlueprintLibrary extends GuiBuildCraft {
if (c == library.selected) {
int l1 = 8;
int i2 = 24;
drawGradientRect(l1, i2 + 9 * c, l1 + 88, i2 + 9 * (c + 1), 0x80ffffff, 0x80ffffff);
if (bpt.kind == Kind.Blueprint) {
drawGradientRect(l1, i2 + 9 * c, l1 + 88, i2 + 9 * (c + 1), 0xFFA0A0FF, 0xFFA0A0FF);
} else {
drawGradientRect(l1, i2 + 9 * c, l1 + 88, i2 + 9 * (c + 1), 0x80ffffff, 0x80ffffff);
}
}
if (bpt.kind == Kind.Blueprint) {
fontRendererObj.drawString(name, 9, 25 + 9 * c, 0x1000FF);
} else {
fontRendererObj.drawString(name, 9, 25 + 9 * c, 0x000000);
}
fontRendererObj.drawString(name, 9, 25 + 9 * c, 0x404040);
c++;
}
}

View file

@ -24,6 +24,7 @@ import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.blueprints.Translation;
import buildcraft.api.core.BCLog;
import buildcraft.builders.blueprints.BlueprintId.Kind;
import buildcraft.core.utils.NBTUtils;
public class Blueprint extends BlueprintBase {
@ -31,10 +32,14 @@ public class Blueprint extends BlueprintBase {
public Blueprint() {
super ();
id.kind = Kind.Blueprint;
}
public Blueprint(int sizeX, int sizeY, int sizeZ) {
super(sizeX, sizeY, sizeZ);
id.kind = Kind.Blueprint;
}
@Override

View file

@ -16,6 +16,7 @@ import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.builders.blueprints.BlueprintId.Kind;
import buildcraft.core.utils.NBTUtils;
/**
@ -24,10 +25,13 @@ import buildcraft.core.utils.NBTUtils;
public class Template extends BlueprintBase {
public Template() {
id.kind = Kind.Template;
}
public Template(int sizeX, int sizeY, int sizeZ) {
super(sizeX, sizeY, sizeZ);
id.kind = Kind.Template;
}
@Override