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:
parent
45c9487874
commit
9f33aac2b8
4 changed files with 97 additions and 69 deletions
|
@ -27,6 +27,7 @@ public class DDConfig {
|
|||
private static int maxPocketSize = 4;
|
||||
private static int privatePocketSize = 3;
|
||||
private static int publicPocketSize = 2;
|
||||
private static int baseDimID = 684;
|
||||
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) {
|
||||
|
@ -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.");
|
||||
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
|
||||
config.save();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.google.gson.JsonParser;
|
|||
import com.zixiken.dimdoors.DimDoors;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
|
@ -163,14 +164,16 @@ public class SchematicHandler {
|
|||
}
|
||||
} else if (schematicFile.exists()) {
|
||||
try {
|
||||
schematicNBT = CompressedStreamTools.read(schematicFile);
|
||||
GZIPInputStream schematicZipStream = new GZIPInputStream(new FileInputStream(schematicFile));
|
||||
schematicNBT = CompressedStreamTools.read(new DataInputStream(schematicZipStream));
|
||||
schematic = Schematic.loadFromNBT(schematicNBT);
|
||||
} catch (IOException 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()) {
|
||||
try {
|
||||
schematicNBT = CompressedStreamTools.read(oldVersionSchematicFile);
|
||||
GZIPInputStream schematicZipStream = new GZIPInputStream(new FileInputStream(oldVersionSchematicFile));
|
||||
schematicNBT = CompressedStreamTools.read(new DataInputStream(schematicZipStream));
|
||||
schematic = Schematic.loadFromNBT(schematicNBT);
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(SchematicHandler.class.getName()).log(Level.SEVERE, "Schematic file " + template.getName() + ".schematic did not load correctly from config folder.", ex);
|
||||
|
|
|
@ -201,6 +201,11 @@ public class BlockRift extends Block implements ITileEntityProvider {
|
|||
world.removeTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean causesSuffocation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public DDTileEntityBase getRiftTile(World world, BlockPos pos, IBlockState state) {
|
||||
return (DDTileEntityBase) world.getTileEntity(pos);
|
||||
}
|
||||
|
|
|
@ -27,41 +27,27 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
|||
*/
|
||||
public class Schematic {
|
||||
|
||||
private static final String[] oldDimDoorBlockNames = new String[]{
|
||||
"Fabric of RealityPerm",
|
||||
private static final String[] OLDDIMDOORBLOCKNAMES = new String[]{
|
||||
"Dimensional Door",
|
||||
"Fabric of Reality",
|
||||
"Warp Door",
|
||||
"Dummy",
|
||||
"Dummy",
|
||||
"Dummy",
|
||||
"Dummy",
|
||||
"Dummy",
|
||||
"Dummy",
|
||||
"Dummy",
|
||||
"Dummy"};
|
||||
"transientDoor", //only used in the two old Overworld gateway (worldgen) structures
|
||||
"Warp Door"};
|
||||
|
||||
private static final String[] newDimDoorBlockNames = new String[]{
|
||||
"blockDoorQuartz",
|
||||
"blockDoorGold",
|
||||
"blockDimDoorPersonal",
|
||||
"blockDimDoorTransient",
|
||||
"blockDimDoorWarp",
|
||||
"blockDimDoorGold",
|
||||
"blockDimDoorChaos",
|
||||
private static final String[] NEWDIMDOORBLOCKNAMES = new String[]{
|
||||
"blockDimDoor",
|
||||
"blockDimHatch",
|
||||
"blockDimWall",
|
||||
"blockRift"}; //@todo make these lists complete, possibly with specific blockstate as well?
|
||||
"blockDimWall", //I think [type=fabric] is the default blockstate
|
||||
"blockDimDoorTransient",
|
||||
"blockDimDoorWarp"}; //@todo make these lists complete, possibly with specific blockstate as well?
|
||||
|
||||
int version;
|
||||
String author;
|
||||
String schematicName;
|
||||
int version = Integer.parseInt("1"); //@todo set in build.gradle ${spongeSchematicVersion}
|
||||
String author = "DimDoors"; //@todo set in build.gradle ${modID}
|
||||
String schematicName = "Unknown";
|
||||
long creationDate;
|
||||
String[] requiredMods;
|
||||
String[] requiredMods = new String[0];
|
||||
short width;
|
||||
short height;
|
||||
short length;
|
||||
int[] offset = new int[3];
|
||||
int[] offset = new int[]{0, 0, 0};
|
||||
int paletteMax;
|
||||
List<IBlockState> pallette = new ArrayList();
|
||||
int[][][] blockData; //[x][y][z]
|
||||
|
@ -71,37 +57,49 @@ public class Schematic {
|
|||
}
|
||||
|
||||
public static Schematic loadFromNBT(NBTTagCompound nbt) {
|
||||
if (!nbt.hasKey("Metadata")) {
|
||||
if (!nbt.hasKey("Version")) {
|
||||
return loadOldDimDoorSchematicFromNBT(nbt);
|
||||
}
|
||||
|
||||
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(".");
|
||||
if (nbt.hasKey("Author")) { //Author is not required
|
||||
schematic.author = metadataCompound.getString("Author");
|
||||
}
|
||||
if (nbt.hasKey("Name")) { //Name is not required
|
||||
schematic.schematicName = metadataCompound.getString("Name");
|
||||
}
|
||||
if (nbt.hasKey("Date")) { //Date is not required
|
||||
schematic.creationDate = metadataCompound.getLong("Date");
|
||||
}
|
||||
if (nbt.hasKey("RequiredMods")) { //RequiredMods is not required (ironically)
|
||||
NBTTagList requiredModsTagList = ((NBTTagList) metadataCompound.getTag("RequiredMods"));
|
||||
schematic.requiredMods = new String[requiredModsTagList.tagCount()];
|
||||
for (int i = 0; i < requiredModsTagList.tagCount(); i++) {
|
||||
schematic.requiredMods[i] = requiredModsTagList.getStringTagAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//@todo, check if the needed mods are loade; otherwise abort
|
||||
schematic.width = nbt.getShort("Width");
|
||||
schematic.height = nbt.getShort("Height");
|
||||
schematic.length = nbt.getShort("Length");
|
||||
//@todo, check if the required mods are loaded, otherwise abort
|
||||
schematic.width = nbt.getShort("Width"); //Width is required
|
||||
schematic.height = nbt.getShort("Height"); //Height is required
|
||||
schematic.length = nbt.getShort("Length"); //Length is required
|
||||
if (nbt.hasKey("Offset")) { //Offset is not required
|
||||
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();
|
||||
for (String key : paletteNBT.getKeySet()) {
|
||||
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);
|
||||
char lastBlockStateStringChar = blockStateString.charAt(blockStateString.length() - 1);
|
||||
String blockString;
|
||||
|
@ -120,13 +118,18 @@ public class Schematic {
|
|||
IBlockState blockstate = block.getDefaultState();
|
||||
if (!stateString.equals("")) {
|
||||
String[] properties = stateString.split(",");
|
||||
blockstate = getBlockStateWithProperties(block, properties); //@todo get the blockState from string
|
||||
blockstate = getBlockStateWithProperties(block, properties);
|
||||
} else {
|
||||
}
|
||||
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];
|
||||
for (int x = 0; x < schematic.width; x++) {
|
||||
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");
|
||||
for (int i = 0; i < tileEntitiesTagList.tagCount(); i++) {
|
||||
NBTTagCompound tileEntityTagCompound = tileEntitiesTagList.getCompoundTagAt(i);
|
||||
schematic.tileEntities.add(tileEntityTagCompound);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
Schematic schematic = new Schematic();
|
||||
|
||||
schematic.version = Integer.parseInt("1"); //@todo set in build.gradle ${spongeSchematicVersion}
|
||||
schematic.author = "Robijnvogel";
|
||||
//schematic.version = 1; //already the default value
|
||||
//schematic.author = "DimDoors"; //already the default value
|
||||
schematic.schematicName = "This schematic was converted from an MC 1.7.10 DimDoors schematic";
|
||||
schematic.creationDate = System.currentTimeMillis();
|
||||
schematic.requiredMods = new String[0];
|
||||
schematic.requiredMods = new String[]{DimDoors.MODID};
|
||||
|
||||
schematic.width = nbt.getShort("Width");
|
||||
schematic.height = nbt.getShort("Height");
|
||||
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");
|
||||
for (int i = 0; i <= paletteNBT.tagCount(); i++) {
|
||||
String blockString = paletteNBT.getStringTagAt(i);
|
||||
boolean isAncientFabric = false;
|
||||
if (blockString.startsWith("dimdoors")) {
|
||||
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);
|
||||
blockString = "dimdoors:" + dimdoorsBlockName;
|
||||
}
|
||||
}
|
||||
IBlockState blockstate;
|
||||
if (!isAncientFabric) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -361,22 +377,21 @@ public class Schematic {
|
|||
}
|
||||
|
||||
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.");
|
||||
return null;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (; i < oldDimDoorBlockNames.length; i++) {
|
||||
if (oldDimDoorBlockNames[i].equals(dimdoorsBlockName)) {
|
||||
break;
|
||||
for (; i < OLDDIMDOORBLOCKNAMES.length; i++) {
|
||||
if (OLDDIMDOORBLOCKNAMES[i].equals(dimdoorsBlockName)) {
|
||||
return NEWDIMDOORBLOCKNAMES[i];
|
||||
} else {
|
||||
if (i == oldDimDoorBlockNames.length - 1) {
|
||||
if (i == OLDDIMDOORBLOCKNAMES.length - 1) {
|
||||
DimDoors.warn(Schematic.class, dimdoorsBlockName + " as an old dimdoors block name is unknown.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return newDimDoorBlockNames[i];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue