Several small features

-BlockRift doesn't cause suffocation damage anymore
-Added config option for Dimension ID's
-Added correct method for opening schematic files from File
-Finished "dictionary" for converting dimdoors blocks from the old
schematics to new schematics.
-Added a special "translation-case" for Ancient Fabric, because I am not
going to write a complete method just because one block deviates.
-Added "null-checks" for each non-required field in schematics (new
format) while reading them from NBT and set some corresponding default
values for the fields that can be "null"
This commit is contained in:
Mathijs Riezebos 2017-01-28 13:28:04 +01:00
parent 45c9487874
commit 9f33aac2b8
4 changed files with 97 additions and 69 deletions

View file

@ -27,6 +27,7 @@ public class DDConfig {
private static int maxPocketSize = 4; private static int maxPocketSize = 4;
private static int privatePocketSize = 3; private static int privatePocketSize = 3;
private static int publicPocketSize = 2; private static int publicPocketSize = 2;
private static int baseDimID = 684;
private static String[] dungeonSchematicNames = {}; //@todo set default dungeon names private static String[] dungeonSchematicNames = {}; //@todo set default dungeon names
private static int setConfigIntWithMaxAndMin(Configuration config, String category, String key, int defaultValue, String comment, int minValue, int maxValue) { private static int setConfigIntWithMaxAndMin(Configuration config, String category, String key, int defaultValue, String comment, int minValue, int maxValue) {
@ -72,6 +73,10 @@ public class DDConfig {
"List of names of Pockets' jSon- and Schematic file names excluding extention. Custom json and schematic files can be dropped in the corresponding folders."); "List of names of Pockets' jSon- and Schematic file names excluding extention. Custom json and schematic files can be dropped in the corresponding folders.");
dungeonSchematicNames = prop.getStringList(); dungeonSchematicNames = prop.getStringList();
prop = config.get(Configuration.CATEGORY_GENERAL, "baseDimID", baseDimID,
"Dimension ID of the first Dimensional Doors pocket-containing dimension. Other pocket-containing dimensions will use consecutive IDs. [default: 684]");
baseDimID = prop.getInt(baseDimID);
// Save config // Save config
config.save(); config.save();
} }

View file

@ -13,6 +13,7 @@ import com.google.gson.JsonParser;
import com.zixiken.dimdoors.DimDoors; import com.zixiken.dimdoors.DimDoors;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringWriter; import java.io.StringWriter;
@ -163,14 +164,16 @@ public class SchematicHandler {
} }
} else if (schematicFile.exists()) { } else if (schematicFile.exists()) {
try { try {
schematicNBT = CompressedStreamTools.read(schematicFile); GZIPInputStream schematicZipStream = new GZIPInputStream(new FileInputStream(schematicFile));
schematicNBT = CompressedStreamTools.read(new DataInputStream(schematicZipStream));
schematic = Schematic.loadFromNBT(schematicNBT); schematic = Schematic.loadFromNBT(schematicNBT);
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schem did not load correctly from config folder.", ex); Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schem did not load correctly from config folder.", ex);
} }
} else if (oldVersionSchematicFile.exists()) { } else if (oldVersionSchematicFile.exists()) {
try { try {
schematicNBT = CompressedStreamTools.read(oldVersionSchematicFile); GZIPInputStream schematicZipStream = new GZIPInputStream(new FileInputStream(oldVersionSchematicFile));
schematicNBT = CompressedStreamTools.read(new DataInputStream(schematicZipStream));
schematic = Schematic.loadFromNBT(schematicNBT); schematic = Schematic.loadFromNBT(schematicNBT);
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schematic did not load correctly from config folder.", ex); Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schematic did not load correctly from config folder.", ex);

View file

@ -201,6 +201,11 @@ public class BlockRift extends Block implements ITileEntityProvider {
world.removeTileEntity(pos); world.removeTileEntity(pos);
} }
@Override
public boolean causesSuffocation() {
return false;
}
public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) { public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) {
return (DDTileEntityBase) world.getTileEntity(pos); return (DDTileEntityBase) world.getTileEntity(pos);
} }

View file

@ -27,41 +27,27 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
*/ */
public class Schematic { public class Schematic {
private static final String[] oldDimDoorBlockNames = new String[]{ private static final String[] OLDDIMDOORBLOCKNAMES = new String[]{
"Fabric of RealityPerm", "Dimensional Door",
"Fabric of Reality", "Fabric of Reality",
"Warp Door", "transientDoor", //only used in the two old Overworld gateway (worldgen) structures
"Dummy", "Warp Door"};
"Dummy",
"Dummy",
"Dummy",
"Dummy",
"Dummy",
"Dummy",
"Dummy"};
private static final String[] newDimDoorBlockNames = new String[]{ private static final String[] NEWDIMDOORBLOCKNAMES = new String[]{
"blockDoorQuartz",
"blockDoorGold",
"blockDimDoorPersonal",
"blockDimDoorTransient",
"blockDimDoorWarp",
"blockDimDoorGold",
"blockDimDoorChaos",
"blockDimDoor", "blockDimDoor",
"blockDimHatch", "blockDimWall", //I think [type=fabric] is the default blockstate
"blockDimWall", "blockDimDoorTransient",
"blockRift"}; //@todo make these lists complete, possibly with specific blockstate as well? "blockDimDoorWarp"}; //@todo make these lists complete, possibly with specific blockstate as well?
int version; int version = Integer.parseInt("1"); //@todo set in build.gradle ${spongeSchematicVersion}
String author; String author = "DimDoors"; //@todo set in build.gradle ${modID}
String schematicName; String schematicName = "Unknown";
long creationDate; long creationDate;
String[] requiredMods; String[] requiredMods = new String[0];
short width; short width;
short height; short height;
short length; short length;
int[] offset = new int[3]; int[] offset = new int[]{0, 0, 0};
int paletteMax; int paletteMax;
List<IBlockState> pallette = new ArrayList(); List<IBlockState> pallette = new ArrayList();
int[][][] blockData; //[x][y][z] int[][][] blockData; //[x][y][z]
@ -71,37 +57,49 @@ public class Schematic {
} }
public static Schematic loadFromNBT(NBTTagCompound nbt) { public static Schematic loadFromNBT(NBTTagCompound nbt) {
if (!nbt.hasKey("Metadata")) { if (!nbt.hasKey("Version")) {
return loadOldDimDoorSchematicFromNBT(nbt); return loadOldDimDoorSchematicFromNBT(nbt);
} }
Schematic schematic = new Schematic(); Schematic schematic = new Schematic();
schematic.version = nbt.getInteger("Version"); //Version is required
schematic.version = nbt.getInteger("Version"); schematic.creationDate = System.currentTimeMillis();
if (nbt.hasKey("Metadata")) { //Metadata is not required
NBTTagCompound metadataCompound = nbt.getCompoundTag("Metadata").getCompoundTag("."); NBTTagCompound metadataCompound = nbt.getCompoundTag("Metadata").getCompoundTag(".");
if (nbt.hasKey("Author")) { //Author is not required
schematic.author = metadataCompound.getString("Author"); schematic.author = metadataCompound.getString("Author");
}
if (nbt.hasKey("Name")) { //Name is not required
schematic.schematicName = metadataCompound.getString("Name"); schematic.schematicName = metadataCompound.getString("Name");
}
if (nbt.hasKey("Date")) { //Date is not required
schematic.creationDate = metadataCompound.getLong("Date"); schematic.creationDate = metadataCompound.getLong("Date");
}
if (nbt.hasKey("RequiredMods")) { //RequiredMods is not required (ironically)
NBTTagList requiredModsTagList = ((NBTTagList) metadataCompound.getTag("RequiredMods")); NBTTagList requiredModsTagList = ((NBTTagList) metadataCompound.getTag("RequiredMods"));
schematic.requiredMods = new String[requiredModsTagList.tagCount()]; schematic.requiredMods = new String[requiredModsTagList.tagCount()];
for (int i = 0; i < requiredModsTagList.tagCount(); i++) { for (int i = 0; i < requiredModsTagList.tagCount(); i++) {
schematic.requiredMods[i] = requiredModsTagList.getStringTagAt(i); schematic.requiredMods[i] = requiredModsTagList.getStringTagAt(i);
} }
}
}
//@todo, check if the needed mods are loade; otherwise abort //@todo, check if the required mods are loaded, otherwise abort
schematic.width = nbt.getShort("Width"); schematic.width = nbt.getShort("Width"); //Width is required
schematic.height = nbt.getShort("Height"); schematic.height = nbt.getShort("Height"); //Height is required
schematic.length = nbt.getShort("Length"); schematic.length = nbt.getShort("Length"); //Length is required
if (nbt.hasKey("Offset")) { //Offset is not required
schematic.offset = nbt.getIntArray("Offset"); schematic.offset = nbt.getIntArray("Offset");
schematic.paletteMax = nbt.getInteger("PaletteMax"); }
NBTTagCompound paletteNBT = nbt.getCompoundTag("Palette"); NBTTagCompound paletteNBT = nbt.getCompoundTag("Palette"); //Palette is not required, however since we assume that the schematic contains at least some blocks, we can also assume that thee has to be a Palette
Map<Integer, String> paletteMap = new HashMap(); Map<Integer, String> paletteMap = new HashMap();
for (String key : paletteNBT.getKeySet()) { for (String key : paletteNBT.getKeySet()) {
int paletteID = paletteNBT.getInteger(key); int paletteID = paletteNBT.getInteger(key);
paletteMap.put(paletteID, key); //basically use the reversed order paletteMap.put(paletteID, key); //basically use the reversed order (key becomes value and value becomes key)
} }
for (int i = 0; i <= schematic.paletteMax; i++) { for (int i = 0; i <= paletteMap.size(); i++) {
String blockStateString = paletteMap.get(i); String blockStateString = paletteMap.get(i);
char lastBlockStateStringChar = blockStateString.charAt(blockStateString.length() - 1); char lastBlockStateStringChar = blockStateString.charAt(blockStateString.length() - 1);
String blockString; String blockString;
@ -120,13 +118,18 @@ public class Schematic {
IBlockState blockstate = block.getDefaultState(); IBlockState blockstate = block.getDefaultState();
if (!stateString.equals("")) { if (!stateString.equals("")) {
String[] properties = stateString.split(","); String[] properties = stateString.split(",");
blockstate = getBlockStateWithProperties(block, properties); //@todo get the blockState from string blockstate = getBlockStateWithProperties(block, properties);
} else { } else {
} }
schematic.pallette.add(blockstate); schematic.pallette.add(blockstate);
} }
if (nbt.hasKey("PaletteMax")) { //PaletteMax is not required
schematic.paletteMax = nbt.getInteger("PaletteMax");
} else {
schematic.paletteMax = schematic.pallette.size() - 1;
}
byte[] blockDataIntArray = nbt.getByteArray("BlockData"); byte[] blockDataIntArray = nbt.getByteArray("BlockData"); //BlockData is required
schematic.blockData = new int[schematic.width][schematic.height][schematic.length]; schematic.blockData = new int[schematic.width][schematic.height][schematic.length];
for (int x = 0; x < schematic.width; x++) { for (int x = 0; x < schematic.width; x++) {
for (int y = 0; y < schematic.height; y++) { for (int y = 0; y < schematic.height; y++) {
@ -136,11 +139,13 @@ public class Schematic {
} }
} }
if (nbt.hasKey("TileEntities")) { //TileEntities is not required
NBTTagList tileEntitiesTagList = (NBTTagList) nbt.getTag("TileEntities"); NBTTagList tileEntitiesTagList = (NBTTagList) nbt.getTag("TileEntities");
for (int i = 0; i < tileEntitiesTagList.tagCount(); i++) { for (int i = 0; i < tileEntitiesTagList.tagCount(); i++) {
NBTTagCompound tileEntityTagCompound = tileEntitiesTagList.getCompoundTagAt(i); NBTTagCompound tileEntityTagCompound = tileEntitiesTagList.getCompoundTagAt(i);
schematic.tileEntities.add(tileEntityTagCompound); schematic.tileEntities.add(tileEntityTagCompound);
} }
}
return schematic; return schematic;
} }
@ -298,27 +303,38 @@ public class Schematic {
public static Schematic loadOldDimDoorSchematicFromNBT(NBTTagCompound nbt) { //@todo, maybe make this a separate class, so values can be final so they HAVE TO be set in a newly designed constructor public static Schematic loadOldDimDoorSchematicFromNBT(NBTTagCompound nbt) { //@todo, maybe make this a separate class, so values can be final so they HAVE TO be set in a newly designed constructor
Schematic schematic = new Schematic(); Schematic schematic = new Schematic();
schematic.version = Integer.parseInt("1"); //@todo set in build.gradle ${spongeSchematicVersion} //schematic.version = 1; //already the default value
schematic.author = "Robijnvogel"; //schematic.author = "DimDoors"; //already the default value
schematic.schematicName = "This schematic was converted from an MC 1.7.10 DimDoors schematic"; schematic.schematicName = "This schematic was converted from an MC 1.7.10 DimDoors schematic";
schematic.creationDate = System.currentTimeMillis(); schematic.creationDate = System.currentTimeMillis();
schematic.requiredMods = new String[0]; schematic.requiredMods = new String[]{DimDoors.MODID};
schematic.width = nbt.getShort("Width"); schematic.width = nbt.getShort("Width");
schematic.height = nbt.getShort("Height"); schematic.height = nbt.getShort("Height");
schematic.length = nbt.getShort("Length"); schematic.length = nbt.getShort("Length");
schematic.offset = new int[]{0, 0, 0}; //schematic.offset = new int[]{0, 0, 0}; //already the default value
NBTTagList paletteNBT = (NBTTagList) nbt.getTag("Palette"); NBTTagList paletteNBT = (NBTTagList) nbt.getTag("Palette");
for (int i = 0; i <= paletteNBT.tagCount(); i++) { for (int i = 0; i <= paletteNBT.tagCount(); i++) {
String blockString = paletteNBT.getStringTagAt(i); String blockString = paletteNBT.getStringTagAt(i);
boolean isAncientFabric = false;
if (blockString.startsWith("dimdoors")) { if (blockString.startsWith("dimdoors")) {
String dimdoorsBlockName = blockString.split(":")[1]; String dimdoorsBlockName = blockString.split(":")[1];
if (dimdoorsBlockName.equals("Fabric of RealityPerm")) { //only special case, because this is now another state of another block
isAncientFabric = true;
} else {
dimdoorsBlockName = convertOldDimDoorsBlockNameToNewDimDoorsBlockName(dimdoorsBlockName); dimdoorsBlockName = convertOldDimDoorsBlockNameToNewDimDoorsBlockName(dimdoorsBlockName);
blockString = "dimdoors:" + dimdoorsBlockName; blockString = "dimdoors:" + dimdoorsBlockName;
} }
}
IBlockState blockstate;
if (!isAncientFabric) {
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockString)); Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockString));
IBlockState blockstate = block.getDefaultState(); blockstate = block.getDefaultState();
} else {
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("blockDimWall"));
blockstate = getBlockStateWithProperties(block, new String[]{"type=ancient"});
}
schematic.pallette.add(blockstate); schematic.pallette.add(blockstate);
} }
@ -361,22 +377,21 @@ public class Schematic {
} }
private static String convertOldDimDoorsBlockNameToNewDimDoorsBlockName(String dimdoorsBlockName) { private static String convertOldDimDoorsBlockNameToNewDimDoorsBlockName(String dimdoorsBlockName) {
if (oldDimDoorBlockNames.length != newDimDoorBlockNames.length) { if (OLDDIMDOORBLOCKNAMES.length != NEWDIMDOORBLOCKNAMES.length) {
DimDoors.warn(Schematic.class, "The array of old dimdoors block names, somehow isn't the same length as the array of new names, therefore the dimdoors blocks in this schematic will not be loaded."); DimDoors.warn(Schematic.class, "The array of old dimdoors block names, somehow isn't the same length as the array of new names, therefore the dimdoors blocks in this schematic will not be loaded.");
return null; return null;
} }
int i = 0; int i = 0;
for (; i < oldDimDoorBlockNames.length; i++) { for (; i < OLDDIMDOORBLOCKNAMES.length; i++) {
if (oldDimDoorBlockNames[i].equals(dimdoorsBlockName)) { if (OLDDIMDOORBLOCKNAMES[i].equals(dimdoorsBlockName)) {
break; return NEWDIMDOORBLOCKNAMES[i];
} else { } else {
if (i == oldDimDoorBlockNames.length - 1) { if (i == OLDDIMDOORBLOCKNAMES.length - 1) {
DimDoors.warn(Schematic.class, dimdoorsBlockName + " as an old dimdoors block name is unknown."); DimDoors.warn(Schematic.class, dimdoorsBlockName + " as an old dimdoors block name is unknown.");
}
}
}
return null; return null;
} }
}
}
return newDimDoorBlockNames[i];
}
} }