Fixed extension for templates, and added templates support in the library.
Close #1614
This commit is contained in:
parent
fb6a7b740f
commit
a4205745fc
7 changed files with 75 additions and 16 deletions
|
@ -31,7 +31,7 @@ public abstract class TileAbstractBuilder extends TileBuildCraft implements ITil
|
||||||
public static final double BUILD_ENERGY = 20;
|
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
|
* plus a safeguard. That's a nice way to evaluate maximum amount of energy
|
||||||
* that need to be in a builder.
|
* that need to be in a builder.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,6 +19,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
import buildcraft.api.core.NetworkData;
|
import buildcraft.api.core.NetworkData;
|
||||||
import buildcraft.builders.blueprints.BlueprintId;
|
import buildcraft.builders.blueprints.BlueprintId;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintId.Kind;
|
||||||
import buildcraft.core.TileBuildCraft;
|
import buildcraft.core.TileBuildCraft;
|
||||||
import buildcraft.core.blueprints.BlueprintBase;
|
import buildcraft.core.blueprints.BlueprintBase;
|
||||||
import buildcraft.core.inventory.InvUtils;
|
import buildcraft.core.inventory.InvUtils;
|
||||||
|
@ -250,12 +251,17 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
|
||||||
|
|
||||||
@RPC (RPCSide.CLIENT)
|
@RPC (RPCSide.CLIENT)
|
||||||
public void requestSelectedBlueprint () {
|
public void requestSelectedBlueprint () {
|
||||||
|
if (isOuputConsistent()) {
|
||||||
if (selected > -1 && selected < currentPage.size()) {
|
if (selected > -1 && selected < currentPage.size()) {
|
||||||
BlueprintBase bpt = BuildCraftBuilders.clientDB.load(currentPage.get(selected));
|
BlueprintBase bpt = BuildCraftBuilders.clientDB
|
||||||
|
.load(currentPage.get(selected));
|
||||||
|
|
||||||
RPCHandler.rpcServer(this, "uploadBlueprintToServer", bpt.id, bpt.getData());
|
RPCHandler.rpcServer(this, "uploadBlueprintToServer", bpt.id,
|
||||||
|
bpt.getData());
|
||||||
} else {
|
} else {
|
||||||
RPCHandler.rpcServer(this, "uploadBlueprintToServer", null, null);
|
RPCHandler.rpcServer(this, "uploadBlueprintToServer", null,
|
||||||
|
null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -301,4 +307,15 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
|
||||||
public void selectBlueprint (int index) {
|
public void selectBlueprint (int index) {
|
||||||
selected = 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,13 @@ import java.util.logging.Logger;
|
||||||
import net.minecraft.nbt.CompressedStreamTools;
|
import net.minecraft.nbt.CompressedStreamTools;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintId.Kind;
|
||||||
import buildcraft.core.blueprints.BlueprintBase;
|
import buildcraft.core.blueprints.BlueprintBase;
|
||||||
|
|
||||||
public class BlueprintDatabase {
|
public class BlueprintDatabase {
|
||||||
private final int bufferSize = 8192;
|
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 File blueprintFolder;
|
||||||
private final static int PAGE_SIZE = 12;
|
private final static int PAGE_SIZE = 12;
|
||||||
|
|
||||||
|
@ -69,7 +71,7 @@ public class BlueprintDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteBlueprint (BlueprintId id) {
|
public void deleteBlueprint (BlueprintId id) {
|
||||||
File blueprintFile = new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + fileExt, id.toString()));
|
File blueprintFile = getBlueprintFile(id);
|
||||||
blueprintFile.delete();
|
blueprintFile.delete();
|
||||||
blueprintIds.remove(id);
|
blueprintIds.remove(id);
|
||||||
pages = new BlueprintId [blueprintIds.size()];
|
pages = new BlueprintId [blueprintIds.size()];
|
||||||
|
@ -80,8 +82,7 @@ public class BlueprintDatabase {
|
||||||
blueprint.id.generateUniqueId(blueprint.getData());
|
blueprint.id.generateUniqueId(blueprint.getData());
|
||||||
|
|
||||||
BlueprintId id = blueprint.id;
|
BlueprintId id = blueprint.id;
|
||||||
|
File blueprintFile = getBlueprintFile (id);
|
||||||
File blueprintFile = new File(blueprintFolder, String.format(Locale.ENGLISH, "%s" + fileExt, id.toString()));
|
|
||||||
|
|
||||||
if (!blueprintFile.exists()) {
|
if (!blueprintFile.exists()) {
|
||||||
OutputStream gzOs = null;
|
OutputStream gzOs = null;
|
||||||
|
@ -103,11 +104,19 @@ public class BlueprintDatabase {
|
||||||
return id;
|
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() {
|
private void loadIndex() {
|
||||||
FilenameFilter filter = new FilenameFilter() {
|
FilenameFilter filter = new FilenameFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File dir, String name) {
|
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();
|
BlueprintId id = new BlueprintId();
|
||||||
id.name = prefix;
|
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)) {
|
if (!blueprintIds.contains(id)) {
|
||||||
blueprintIds.add(id);
|
blueprintIds.add(id);
|
||||||
|
@ -140,8 +156,7 @@ public class BlueprintDatabase {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
File blueprintFile = new File(blueprintFolder, String.format(
|
File blueprintFile = getBlueprintFile(id);
|
||||||
Locale.ENGLISH, "%s" + fileExt, id.toString()));
|
|
||||||
|
|
||||||
if (blueprintFile.exists()) {
|
if (blueprintFile.exists()) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -21,12 +21,17 @@ import buildcraft.api.core.NetworkData;
|
||||||
|
|
||||||
public final class BlueprintId implements Comparable<BlueprintId> {
|
public final class BlueprintId implements Comparable<BlueprintId> {
|
||||||
|
|
||||||
|
public enum Kind {Template, Blueprint};
|
||||||
|
|
||||||
@NetworkData
|
@NetworkData
|
||||||
public byte[] uniqueId;
|
public byte[] uniqueId;
|
||||||
|
|
||||||
@NetworkData
|
@NetworkData
|
||||||
public String name = "";
|
public String name = "";
|
||||||
|
|
||||||
|
@NetworkData
|
||||||
|
public Kind kind = Kind.Blueprint;
|
||||||
|
|
||||||
public String completeId;
|
public String completeId;
|
||||||
|
|
||||||
public BlueprintId() {
|
public BlueprintId() {
|
||||||
|
@ -46,11 +51,13 @@ public final class BlueprintId implements Comparable<BlueprintId> {
|
||||||
public void write (NBTTagCompound nbt) {
|
public void write (NBTTagCompound nbt) {
|
||||||
nbt.setByteArray("uniqueBptId", uniqueId);
|
nbt.setByteArray("uniqueBptId", uniqueId);
|
||||||
nbt.setString("name", name);
|
nbt.setString("name", name);
|
||||||
|
nbt.setByte("kind", (byte) kind.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read (NBTTagCompound nbt) {
|
public void read (NBTTagCompound nbt) {
|
||||||
uniqueId = nbt.getByteArray("uniqueBptId");
|
uniqueId = nbt.getByteArray("uniqueBptId");
|
||||||
name = nbt.getString("name");
|
name = nbt.getString("name");
|
||||||
|
kind = Kind.values()[nbt.getByte("kind")];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.lwjgl.opengl.GL11;
|
||||||
import buildcraft.BuildCraftBuilders;
|
import buildcraft.BuildCraftBuilders;
|
||||||
import buildcraft.builders.TileBlueprintLibrary;
|
import buildcraft.builders.TileBlueprintLibrary;
|
||||||
import buildcraft.builders.blueprints.BlueprintId;
|
import buildcraft.builders.blueprints.BlueprintId;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintId.Kind;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.gui.GuiBuildCraft;
|
import buildcraft.core.gui.GuiBuildCraft;
|
||||||
import buildcraft.core.utils.StringUtils;
|
import buildcraft.core.utils.StringUtils;
|
||||||
|
@ -77,10 +78,20 @@ public class GuiBlueprintLibrary extends GuiBuildCraft {
|
||||||
if (c == library.selected) {
|
if (c == library.selected) {
|
||||||
int l1 = 8;
|
int l1 = 8;
|
||||||
int i2 = 24;
|
int i2 = 24;
|
||||||
|
|
||||||
|
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);
|
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++;
|
c++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import buildcraft.api.blueprints.SchematicEntity;
|
||||||
import buildcraft.api.blueprints.SchematicRegistry;
|
import buildcraft.api.blueprints.SchematicRegistry;
|
||||||
import buildcraft.api.blueprints.Translation;
|
import buildcraft.api.blueprints.Translation;
|
||||||
import buildcraft.api.core.BCLog;
|
import buildcraft.api.core.BCLog;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintId.Kind;
|
||||||
import buildcraft.core.utils.NBTUtils;
|
import buildcraft.core.utils.NBTUtils;
|
||||||
|
|
||||||
public class Blueprint extends BlueprintBase {
|
public class Blueprint extends BlueprintBase {
|
||||||
|
@ -31,10 +32,14 @@ public class Blueprint extends BlueprintBase {
|
||||||
|
|
||||||
public Blueprint() {
|
public Blueprint() {
|
||||||
super ();
|
super ();
|
||||||
|
|
||||||
|
id.kind = Kind.Blueprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Blueprint(int sizeX, int sizeY, int sizeZ) {
|
public Blueprint(int sizeX, int sizeY, int sizeZ) {
|
||||||
super(sizeX, sizeY, sizeZ);
|
super(sizeX, sizeY, sizeZ);
|
||||||
|
|
||||||
|
id.kind = Kind.Blueprint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -16,6 +16,7 @@ import buildcraft.BuildCraftBuilders;
|
||||||
import buildcraft.api.blueprints.IBuilderContext;
|
import buildcraft.api.blueprints.IBuilderContext;
|
||||||
import buildcraft.api.blueprints.SchematicMask;
|
import buildcraft.api.blueprints.SchematicMask;
|
||||||
import buildcraft.api.core.BuildCraftAPI;
|
import buildcraft.api.core.BuildCraftAPI;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintId.Kind;
|
||||||
import buildcraft.core.utils.NBTUtils;
|
import buildcraft.core.utils.NBTUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,10 +25,13 @@ import buildcraft.core.utils.NBTUtils;
|
||||||
public class Template extends BlueprintBase {
|
public class Template extends BlueprintBase {
|
||||||
|
|
||||||
public Template() {
|
public Template() {
|
||||||
|
id.kind = Kind.Template;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Template(int sizeX, int sizeY, int sizeZ) {
|
public Template(int sizeX, int sizeY, int sizeZ) {
|
||||||
super(sizeX, sizeY, sizeZ);
|
super(sizeX, sizeY, sizeZ);
|
||||||
|
|
||||||
|
id.kind = Kind.Template;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue