Convert the schematics

This commit is contained in:
Runemoro 2018-01-27 05:09:36 -05:00
parent 9350b913ff
commit b7aab958ac
242 changed files with 18 additions and 32 deletions

View file

@ -43,7 +43,7 @@ public class CommandSaveSchem extends CommandBase {
schematic.name = args[0];
schematic.author = player.getName();
SchematicHandler.INSTANCE.saveSchematic(schematic, args[0]);
SchematicHandler.INSTANCE.saveSchematicForEditing(schematic, args[0]);
notifyCommandListener(sender, this, "commands.saveschem.success", args[0]);
}
}

View file

@ -77,7 +77,7 @@ public class PocketTemplate {
rift.setDestination(DefaultDungeonDestinations.deeperDungeonDestination);
newNBT = rift.serializeNBT();
break;
case "shallower_depth_door":
case "less_deep_depth_door":
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
@ -91,7 +91,7 @@ public class PocketTemplate {
rift.setDestination(DefaultDungeonDestinations.overworldDestination);
newNBT = rift.serializeNBT();
break;
case "pocket_entrance_door":
case "entrance_door":
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
rift.setPos(new BlockPos(x, y, z));
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);

View file

@ -23,7 +23,6 @@ import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.dimdev.dimdoors.shared.ModConfig;
import org.dimdev.dimdoors.shared.tools.SchematicConverter;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.CompressedStreamTools;
import org.apache.commons.io.IOUtils;
@ -114,9 +113,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
//Initialising the possible locations/formats for the schematic file
InputStream schematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + extendedTemplatelocation + ".schem");
InputStream oldVersionSchematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + extendedTemplatelocation + ".schematic"); //@todo also check for other schematics
File schematicFile = new File(schematicFolder, "/" + extendedTemplatelocation + ".schem");
File oldVersionSchematicFile = new File(schematicFolder, "/" + extendedTemplatelocation + ".schematic");
//determine which location to load the schematic file from (and what format)
DataInputStream schematicDataStream = null;
@ -124,9 +121,6 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
if (schematicStream != null) {
schematicDataStream = new DataInputStream(schematicStream);
streamOpened = true;
} else if (oldVersionSchematicStream != null) {
schematicDataStream = new DataInputStream(oldVersionSchematicStream);
streamOpened = true;
} else if (schematicFile.exists()) {
try {
schematicDataStream = new DataInputStream(new FileInputStream(schematicFile));
@ -134,15 +128,8 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
} catch (FileNotFoundException ex) {
DimDoors.log.error("Schematic file " + template.getId() + ".schem did not load correctly from config folder.", ex);
}
} else if (oldVersionSchematicFile.exists()) {
try {
schematicDataStream = new DataInputStream(new FileInputStream(oldVersionSchematicFile));
streamOpened = true;
} catch (FileNotFoundException ex) {
DimDoors.log.error("Schematic file " + template.getId() + ".schematic did not load correctly from config folder.", ex);
}
} else {
DimDoors.log.error("Schematic \"" + template.getId() + "\" was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
DimDoors.log.error("Schematic \"" + template.getId() + "\".schem was not found in the jar or config directory.");
}
NBTTagCompound schematicNBT;
@ -150,11 +137,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
if (streamOpened) {
try {
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
if (!schematicNBT.hasKey("Version")) {
schematic = SchematicConverter.convertSchematic(schematicNBT, template.getId(), template.getAuthor());
} else {
schematic = Schematic.loadFromNBT(schematicNBT);
}
schematic = Schematic.loadFromNBT(schematicNBT);
schematicDataStream.close();
} catch (IOException ex) {
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file for " + template.getId() + " could not be read as a valid schematic NBT file.", ex); // TODO: consistently use one type of logger for this.
@ -294,7 +277,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
return getRandomTemplate("public", -1, ModConfig.pockets.basePublicPocketSize, true);
}
public void saveSchematic(Schematic schematic, String id) {
public static void saveSchematic(Schematic schematic, String id) {
NBTTagCompound schematicNBT = schematic.saveToNBT();
File saveFolder = new File(DimDoors.getConfigurationFolder(), "/schematics/saved");
if (!saveFolder.exists()) {
@ -303,6 +286,7 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
File saveFile = new File(saveFolder.getAbsolutePath() + "/" + id + ".schem");
try {
saveFile.getParentFile().mkdirs();
saveFile.createNewFile();
DataOutputStream schematicDataStream = new DataOutputStream(new FileOutputStream(saveFile));
CompressedStreamTools.writeCompressed(schematicNBT, schematicDataStream);
@ -311,6 +295,10 @@ public class SchematicHandler { // TODO: parts of this should be moved to the or
} catch (IOException ex) {
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Something went wrong while saving " + saveFile.getAbsolutePath() + " to disk.", ex);
}
}
public void saveSchematicForEditing(Schematic schematic, String id) {
saveSchematic(schematic, id);
if (!nameMap.containsKey(SAVED_POCKETS_GROUP_NAME)) {
nameMap.put(SAVED_POCKETS_GROUP_NAME, new HashMap<>());

View file

@ -28,13 +28,14 @@ import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
@Deprecated
public final class SchematicConverter {
private final static int LOCKED_CHEST_ID = 95;
private final static int POTION_ID = 373;
private final static int WRITTEN_BOOK_ID = 387;
public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId, String author) {
public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId, String author, String group) {
Schematic schematic = new Schematic(nbt.getShort("Width"), nbt.getShort("Height"), nbt.getShort("Length"));
schematic.name = schematicId;
@ -160,7 +161,6 @@ public final class SchematicConverter {
byte[] addIdArray = nbt.getByteArray("AddBlocks");
byte[] metaArray = nbt.getByteArray("Data");
IBlockState lastWasSandstone;
int entranceCount = 0;
for (int x = 0; x < schematic.width; x++) {
for (int z = 0; z < schematic.length; z++) {
lastWasSandstone = null;
@ -216,8 +216,7 @@ public final class SchematicConverter {
if (lastWasSandstone != null) {
riftPlaceholder.setString("placeholder", "overworld_door");
} else {
riftPlaceholder.setString("placeholder", "pocket_entrance_door");
entranceCount++;
riftPlaceholder.setString("placeholder", "entrance_door");
}
} else if (block == ModBlocks.DIMENSIONAL_PORTAL) {
riftPlaceholder.setString("placeholder", "gateway_portal");

View file

@ -2,7 +2,6 @@ package org.dimdev.dimdoors.shared.world.gateways;
import org.dimdev.dimdoors.DimDoors;
import org.dimdev.ddutils.schem.Schematic;
import org.dimdev.dimdoors.shared.tools.SchematicConverter;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
@ -18,13 +17,13 @@ public abstract class BaseSchematicGateway extends BaseGateway {
String schematicJarDirectory = "/assets/dimdoors/gateways/";
//Initialising the possible locations/formats for the schematic file
InputStream oldVersionSchematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + id + ".schematic"); //@todo also check for other schematics
InputStream schematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + id + ".schem");
//determine which location to load the schematic file from (and what format)
DataInputStream schematicDataStream = null;
boolean streamOpened = false;
if (oldVersionSchematicStream != null) {
schematicDataStream = new DataInputStream(oldVersionSchematicStream);
if (schematicStream != null) {
schematicDataStream = new DataInputStream(schematicStream);
streamOpened = true;
} else {
DimDoors.log.warn("Schematic '" + id + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
@ -35,7 +34,7 @@ public abstract class BaseSchematicGateway extends BaseGateway {
if (streamOpened) {
try {
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
schematic = SchematicConverter.convertSchematic(schematicNBT, id, null);
schematic = Schematic.loadFromNBT(schematicNBT);
schematicDataStream.close();
} catch (IOException ex) {
DimDoors.log.error("Schematic file for " + id + " could not be read as a valid schematic NBT file.", ex);

Some files were not shown because too many files have changed in this diff Show more