Skip to content

Commit b7aab95

Browse files
committed
Convert the schematics
1 parent 9350b91 commit b7aab95

File tree

242 files changed

+18
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+18
-32
lines changed

src/main/java/org/dimdev/dimdoors/shared/commands/CommandSaveSchem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void execute(MinecraftServer server, ICommandSender sender, String[] args
4343
schematic.name = args[0];
4444
schematic.author = player.getName();
4545

46-
SchematicHandler.INSTANCE.saveSchematic(schematic, args[0]);
46+
SchematicHandler.INSTANCE.saveSchematicForEditing(schematic, args[0]);
4747
notifyCommandListener(sender, this, "commands.saveschem.success", args[0]);
4848
}
4949
}

src/main/java/org/dimdev/dimdoors/shared/pockets/PocketTemplate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void replacePlaceholders() { // TODO: it should be possible to place a sc
7777
rift.setDestination(DefaultDungeonDestinations.deeperDungeonDestination);
7878
newNBT = rift.serializeNBT();
7979
break;
80-
case "shallower_depth_door":
80+
case "less_deep_depth_door":
8181
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
8282
rift.setPos(new BlockPos(x, y, z));
8383
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);
@@ -91,7 +91,7 @@ public void replacePlaceholders() { // TODO: it should be possible to place a sc
9191
rift.setDestination(DefaultDungeonDestinations.overworldDestination);
9292
newNBT = rift.serializeNBT();
9393
break;
94-
case "pocket_entrance_door":
94+
case "entrance_door":
9595
/*TileEntityEntranceRift*/ rift = (TileEntityEntranceRift) state.getBlock().createTileEntity(null, state);
9696
rift.setPos(new BlockPos(x, y, z));
9797
rift.setProperties(DefaultDungeonDestinations.pocketLinkProperties);

src/main/java/org/dimdev/dimdoors/shared/pockets/SchematicHandler.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.stream.Collectors;
2424

2525
import org.dimdev.dimdoors.shared.ModConfig;
26-
import org.dimdev.dimdoors.shared.tools.SchematicConverter;
2726
import net.minecraft.nbt.NBTTagCompound;
2827
import net.minecraft.nbt.CompressedStreamTools;
2928
import org.apache.commons.io.IOUtils;
@@ -114,47 +113,31 @@ private static List<PocketTemplate> loadTemplatesFromJson(String jsonString) {
114113

115114
//Initialising the possible locations/formats for the schematic file
116115
InputStream schematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + extendedTemplatelocation + ".schem");
117-
InputStream oldVersionSchematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + extendedTemplatelocation + ".schematic"); //@todo also check for other schematics
118116
File schematicFile = new File(schematicFolder, "/" + extendedTemplatelocation + ".schem");
119-
File oldVersionSchematicFile = new File(schematicFolder, "/" + extendedTemplatelocation + ".schematic");
120117

121118
//determine which location to load the schematic file from (and what format)
122119
DataInputStream schematicDataStream = null;
123120
boolean streamOpened = false;
124121
if (schematicStream != null) {
125122
schematicDataStream = new DataInputStream(schematicStream);
126123
streamOpened = true;
127-
} else if (oldVersionSchematicStream != null) {
128-
schematicDataStream = new DataInputStream(oldVersionSchematicStream);
129-
streamOpened = true;
130124
} else if (schematicFile.exists()) {
131125
try {
132126
schematicDataStream = new DataInputStream(new FileInputStream(schematicFile));
133127
streamOpened = true;
134128
} catch (FileNotFoundException ex) {
135129
DimDoors.log.error("Schematic file " + template.getId() + ".schem did not load correctly from config folder.", ex);
136130
}
137-
} else if (oldVersionSchematicFile.exists()) {
138-
try {
139-
schematicDataStream = new DataInputStream(new FileInputStream(oldVersionSchematicFile));
140-
streamOpened = true;
141-
} catch (FileNotFoundException ex) {
142-
DimDoors.log.error("Schematic file " + template.getId() + ".schematic did not load correctly from config folder.", ex);
143-
}
144131
} else {
145-
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.");
132+
DimDoors.log.error("Schematic \"" + template.getId() + "\".schem was not found in the jar or config directory.");
146133
}
147134

148135
NBTTagCompound schematicNBT;
149136
Schematic schematic = null;
150137
if (streamOpened) {
151138
try {
152139
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
153-
if (!schematicNBT.hasKey("Version")) {
154-
schematic = SchematicConverter.convertSchematic(schematicNBT, template.getId(), template.getAuthor());
155-
} else {
156-
schematic = Schematic.loadFromNBT(schematicNBT);
157-
}
140+
schematic = Schematic.loadFromNBT(schematicNBT);
158141
schematicDataStream.close();
159142
} catch (IOException ex) {
160143
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 PocketTemplate getPublicPocketTemplate() {
294277
return getRandomTemplate("public", -1, ModConfig.pockets.basePublicPocketSize, true);
295278
}
296279

297-
public void saveSchematic(Schematic schematic, String id) {
280+
public static void saveSchematic(Schematic schematic, String id) {
298281
NBTTagCompound schematicNBT = schematic.saveToNBT();
299282
File saveFolder = new File(DimDoors.getConfigurationFolder(), "/schematics/saved");
300283
if (!saveFolder.exists()) {
@@ -303,6 +286,7 @@ public void saveSchematic(Schematic schematic, String id) {
303286

304287
File saveFile = new File(saveFolder.getAbsolutePath() + "/" + id + ".schem");
305288
try {
289+
saveFile.getParentFile().mkdirs();
306290
saveFile.createNewFile();
307291
DataOutputStream schematicDataStream = new DataOutputStream(new FileOutputStream(saveFile));
308292
CompressedStreamTools.writeCompressed(schematicNBT, schematicDataStream);
@@ -311,6 +295,10 @@ public void saveSchematic(Schematic schematic, String id) {
311295
} catch (IOException ex) {
312296
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Something went wrong while saving " + saveFile.getAbsolutePath() + " to disk.", ex);
313297
}
298+
}
299+
300+
public void saveSchematicForEditing(Schematic schematic, String id) {
301+
saveSchematic(schematic, id);
314302

315303
if (!nameMap.containsKey(SAVED_POCKETS_GROUP_NAME)) {
316304
nameMap.put(SAVED_POCKETS_GROUP_NAME, new HashMap<>());

src/main/java/org/dimdev/dimdoors/shared/tools/SchematicConverter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@
2828
import java.util.ArrayList;
2929
import java.util.List;
3030

31+
@Deprecated
3132
public final class SchematicConverter {
3233

3334
private final static int LOCKED_CHEST_ID = 95;
3435
private final static int POTION_ID = 373;
3536
private final static int WRITTEN_BOOK_ID = 387;
3637

37-
public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId, String author) {
38+
public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId, String author, String group) {
3839
Schematic schematic = new Schematic(nbt.getShort("Width"), nbt.getShort("Height"), nbt.getShort("Length"));
3940

4041
schematic.name = schematicId;
@@ -160,7 +161,6 @@ public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId,
160161
byte[] addIdArray = nbt.getByteArray("AddBlocks");
161162
byte[] metaArray = nbt.getByteArray("Data");
162163
IBlockState lastWasSandstone;
163-
int entranceCount = 0;
164164
for (int x = 0; x < schematic.width; x++) {
165165
for (int z = 0; z < schematic.length; z++) {
166166
lastWasSandstone = null;
@@ -216,8 +216,7 @@ public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId,
216216
if (lastWasSandstone != null) {
217217
riftPlaceholder.setString("placeholder", "overworld_door");
218218
} else {
219-
riftPlaceholder.setString("placeholder", "pocket_entrance_door");
220-
entranceCount++;
219+
riftPlaceholder.setString("placeholder", "entrance_door");
221220
}
222221
} else if (block == ModBlocks.DIMENSIONAL_PORTAL) {
223222
riftPlaceholder.setString("placeholder", "gateway_portal");

src/main/java/org/dimdev/dimdoors/shared/world/gateways/BaseSchematicGateway.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.dimdev.dimdoors.DimDoors;
44
import org.dimdev.ddutils.schem.Schematic;
5-
import org.dimdev.dimdoors.shared.tools.SchematicConverter;
65
import net.minecraft.nbt.CompressedStreamTools;
76
import net.minecraft.nbt.NBTTagCompound;
87
import net.minecraft.world.World;
@@ -18,13 +17,13 @@ public BaseSchematicGateway(String id) {
1817
String schematicJarDirectory = "/assets/dimdoors/gateways/";
1918

2019
//Initialising the possible locations/formats for the schematic file
21-
InputStream oldVersionSchematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + id + ".schematic"); //@todo also check for other schematics
20+
InputStream schematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + id + ".schem");
2221

2322
//determine which location to load the schematic file from (and what format)
2423
DataInputStream schematicDataStream = null;
2524
boolean streamOpened = false;
26-
if (oldVersionSchematicStream != null) {
27-
schematicDataStream = new DataInputStream(oldVersionSchematicStream);
25+
if (schematicStream != null) {
26+
schematicDataStream = new DataInputStream(schematicStream);
2827
streamOpened = true;
2928
} else {
3029
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 BaseSchematicGateway(String id) {
3534
if (streamOpened) {
3635
try {
3736
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
38-
schematic = SchematicConverter.convertSchematic(schematicNBT, id, null);
37+
schematic = Schematic.loadFromNBT(schematicNBT);
3938
schematicDataStream.close();
4039
} catch (IOException ex) {
4140
DimDoors.log.error("Schematic file for " + id + " could not be read as a valid schematic NBT file.", ex);
439 Bytes
Binary file not shown.
Binary file not shown.
337 Bytes
Binary file not shown.
-268 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)