Pocket placement preparation and schematic saving
-Prepared code accessibility for placement of Pockets -Added method to save schematic nbt to a GZip file on disk. Todo: -Discovered that Schematics don't get the correct names for their blocks upon writing themselves to NBT.
This commit is contained in:
parent
21a008c11f
commit
d0af9178f0
4 changed files with 51 additions and 15 deletions
|
@ -19,7 +19,7 @@ import net.minecraft.nbt.NBTTagString;
|
|||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
class Pocket {
|
||||
public class Pocket {
|
||||
|
||||
private int ID; //this gets reset every server-load
|
||||
private final int size; //in chunks
|
||||
|
|
|
@ -194,9 +194,9 @@ public class PocketRegistry {
|
|||
private PocketTemplate getRandomPocketTemplate(EnumPocketType typeID, int depth, int maxPocketSize) {
|
||||
switch (typeID) {
|
||||
case PRIVATE:
|
||||
return SchematicHandler.Instance.getPersonalPocketSchematic(maxPocketSize);
|
||||
return SchematicHandler.Instance.getPersonalPocketTemplate();
|
||||
case PUBLIC:
|
||||
return SchematicHandler.Instance.getPublicPocketSchematic(maxPocketSize);
|
||||
return SchematicHandler.Instance.getPublicPocketTemplate();
|
||||
case DUNGEON:
|
||||
default:
|
||||
return SchematicHandler.Instance.getRandomDungeonPocketTemplate(depth, maxPocketSize);
|
||||
|
|
|
@ -19,7 +19,7 @@ import net.minecraft.world.WorldServer;
|
|||
*
|
||||
* @author Robijnvogel
|
||||
*/
|
||||
class PocketTemplate { //there is exactly one pocket placer for each different schematic that is loaded into the game (a Json might load several schematics though)
|
||||
public class PocketTemplate { //there is exactly one pocket placer for each different schematic that is loaded into the game (a Json might load several schematics though)
|
||||
|
||||
//generation parameters
|
||||
private Schematic schematic;
|
||||
|
@ -71,7 +71,7 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
|
|||
return variantName;
|
||||
}
|
||||
|
||||
Object getSchematic() {
|
||||
Schematic getSchematic() {
|
||||
return schematic;
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,8 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
|
|||
this.schematic = schematic;
|
||||
}
|
||||
|
||||
Pocket place(int shortenedX, int yBase, int shortenedZ, int gridSize, int dimID, int pocketID, int depth, EnumPocketType pocketTypeID) { //returns the riftID of the entrance DimDoor
|
||||
//@todo make sure that the "pocketID" parameter gets used, or remove it.
|
||||
public Pocket place(int shortenedX, int yBase, int shortenedZ, int gridSize, int dimID, int pocketID, int depth, EnumPocketType pocketTypeID) { //returns the riftID of the entrance DimDoor
|
||||
int xBase = shortenedX * gridSize * 16;
|
||||
int zBase = shortenedZ * gridSize * 16;
|
||||
|
||||
|
@ -122,7 +123,7 @@ class PocketTemplate { //there is exactly one pocket placer for each different s
|
|||
rift.setIsInPocket();
|
||||
riftIDs.add(rift.getRiftID());
|
||||
}
|
||||
|
||||
|
||||
return new Pocket(size, depth, pocketTypeID, shortenedX, shortenedZ, riftIDs);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,10 @@ import com.google.gson.JsonObject;
|
|||
import com.google.gson.JsonParser;
|
||||
import com.zixiken.dimdoors.DimDoors;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
|
@ -27,6 +29,7 @@ import java.util.Random;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
@ -43,14 +46,6 @@ public class SchematicHandler {
|
|||
private List<PocketTemplate> dungeonTemplates;
|
||||
//@todo, sort templates by depth over here? that'd mean that that doesn't have to be done on pocket placement each and every time
|
||||
|
||||
PocketTemplate getPersonalPocketSchematic(int maxPocketSize) {
|
||||
return personalPocketTemplate;
|
||||
}
|
||||
|
||||
PocketTemplate getPublicPocketSchematic(int maxPocketSize) {
|
||||
return publicPocketTemplate;
|
||||
}
|
||||
|
||||
PocketTemplate getRandomDungeonPocketTemplate(int depth, int maxPocketSize) {
|
||||
List<PocketTemplate> validTemplates = new ArrayList();
|
||||
int totalWeight = 0;
|
||||
|
@ -250,4 +245,44 @@ public class SchematicHandler {
|
|||
|
||||
return pocketTemplates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the personalPocketTemplate
|
||||
*/
|
||||
public PocketTemplate getPersonalPocketTemplate() {
|
||||
return personalPocketTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the publicPocketTemplate
|
||||
*/
|
||||
public PocketTemplate getPublicPocketTemplate() {
|
||||
return publicPocketTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dungeonTemplates
|
||||
*/
|
||||
public List<PocketTemplate> getDungeonTemplates() {
|
||||
return dungeonTemplates;
|
||||
}
|
||||
|
||||
public void saveSchematic(Schematic schematic, String name) {
|
||||
NBTTagCompound schematicNBT = Schematic.saveToNBT(schematic);
|
||||
File saveFolder = new File(DDConfig.configurationFolder, "/Schematics/Saved");
|
||||
if (!saveFolder.exists()) {
|
||||
saveFolder.mkdirs();
|
||||
}
|
||||
|
||||
File saveFile = new File(saveFolder.getAbsolutePath() + "/" + name + ".schem");
|
||||
try {
|
||||
saveFile.createNewFile();
|
||||
GZIPOutputStream schematicZipStream = new GZIPOutputStream(new FileOutputStream(saveFile));
|
||||
CompressedStreamTools.write(schematicNBT, new DataOutputStream(schematicZipStream));
|
||||
schematicZipStream.flush();
|
||||
schematicZipStream.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue