Wrote backbone for the Pocket Placement

-Added a configs class to handle the configs
-Rewrote some of the save handling of the RiftRegistry

Still needed:
-Some dimensions to place pockets in
-Actual loading of json and schematic files into memory
-Actual placement of the pockets (+ door placement and stuff)

Repo does not compile right now!¡!
This commit is contained in:
Mathijs Riezebos 2017-01-20 12:34:33 +01:00
parent 8a36c6b1c0
commit c7535030a4
9 changed files with 476 additions and 63 deletions

View file

@ -0,0 +1,82 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.zixiken.dimdoors;
import java.util.ArrayList;
import java.util.List;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
/**
*
* @author Robijnvogel
*/
public class DDConfig {
private static int pocketGridSize = 8;
private static int maxPocketSize = 4;
private static int privatePocketSize = 3;
private static int publicPocketSize = 2;
private static String[] dungeonSchematicNames = {"", ""}; //@todo set default dungeon names
public static void loadConfig(FMLPreInitializationEvent event) {
// Load config
Configuration config = new Configuration(event.getSuggestedConfigurationFile());
config.load();
// Setup general
//@todo a comment in the config files about how these values only influence new worlds
Property prop = config.get(Configuration.CATEGORY_GENERAL, "pocketGridSize", pocketGridSize,
"Sets how many chunks apart all pockets in pocket dimensions should be placed. [min: 4, max: 16, default: 8]", 4, 8);
pocketGridSize = prop.getInt(pocketGridSize);
prop = config.get(Configuration.CATEGORY_GENERAL, "maxPocketSize", maxPocketSize,
"Sets how many deep and wide any pocket can be. [min: 1, max: pocketGridSize/2, default: 4]", 1, (int) (((double) pocketGridSize / 2) - 0.5));
maxPocketSize = prop.getInt(maxPocketSize);
prop = config.get(Configuration.CATEGORY_GENERAL, "privatePocketSize", privatePocketSize,
"Sets how many deep and wide any personal pocket can be. [min: 1, max: maxPocketsSize, default: 3]", 1, maxPocketSize);
privatePocketSize = prop.getInt(privatePocketSize);
prop = config.get(Configuration.CATEGORY_GENERAL, "publicPocketSize", publicPocketSize,
"Sets how many deep and wide any public pocket can be. [min: 1, max: maxPocketsSize, default: 2]", 1, maxPocketSize);
publicPocketSize = prop.getInt(publicPocketSize);
prop = config.get(Configuration.CATEGORY_GENERAL, "dungeonSchematicNames", dungeonSchematicNames,
"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();
// Save config
config.save();
}
public static int getPocketGridSize() {
return pocketGridSize;
}
public static int getMaxPocketsSize() {
return maxPocketSize;
}
public static int getPrivatePocketSize() {
return privatePocketSize;
}
public static int getPublicPocketSize() {
return publicPocketSize;
}
public static List<String> getDungeonSchematicNames() {
List<String> dungeonSchematicNamesArrayList = new ArrayList();
for (String dungeonSchematicName : dungeonSchematicNames) {
dungeonSchematicNamesArrayList.add(dungeonSchematicName);
}
return dungeonSchematicNamesArrayList;
}
}

View file

@ -40,6 +40,7 @@ public class DimDoors {
@Mod.EventHandler
public void onPreInitialization(FMLPreInitializationEvent event) {
proxy.onPreInitialization(event);
DDConfig.loadConfig(event);
}
@Mod.EventHandler

View file

@ -9,6 +9,9 @@ import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
/**
*
@ -16,30 +19,66 @@ import net.minecraft.nbt.NBTTagCompound;
*/
class Pocket {
private int ID;
private int size; //in chunks
private int depth;
private int typeID;
private Object coords; //0,0 should be 0,0, 1,1 should be 128,128 etc
private final int ID;
private final int size; //in chunks
private final int depth;
private final int typeID; // dungeon, pocket, or personal pocket
private final int x; //pocket-relative 0 coordinate, should be at x * PocketRegistry.Instance.gridSize * 16
private final int z; //pocket-relative 0 coordinate, should be at z * PocketRegistry.Instance.gridSize * 16
private final List<String> playerUUIDs;
private final List<Integer> doorIDs;
private final List<Integer> doorIDs; //first one of these should be the entrance door? Does that even matter?
private final int entranceDoorID;
//when adding any new variables, don't forget to add them to the write and load functions
Pocket() {
public Pocket(int ID, int size, int depth, int typeID, int x, int z, int entranceDoorID) {
this.ID = ID;
this.size = size;
this.depth = depth;
this.typeID = typeID;
this.x = x;
this.z = z;
this.entranceDoorID = entranceDoorID; //keeping this stored after pocket generation for personal pocket dimensions mostly
playerUUIDs = new ArrayList();
doorIDs = new ArrayList();
}
static Pocket readFromNBT(int ID, NBTTagCompound pocketNBT) {
Pocket pocket = new Pocket();
pocket.ID = ID;
pocket.size = pocketNBT.getInteger("size");
pocket.depth = pocketNBT.getInteger("depth");
pocket.typeID = pocketNBT.getInteger("typeID");
public int getID() {
return ID;
}
public int getX() {
return x;
}
public int getZ() {
return z;
}
//@todo pocket.coords = pocketNBT.get;
NBTTagCompound playersNBT = pocketNBT.getCompoundTag("players");
NBTTagCompound doorsNBT = pocketNBT.getCompoundTag("doors");
//@todo iterate through above two compound tags
int getEntranceDoorID() {
return entranceDoorID;
}
static Pocket readFromNBT(NBTTagCompound pocketNBT) {
int ID = pocketNBT.getInteger("ID");;
int size = pocketNBT.getInteger("size");
int depth = pocketNBT.getInteger("depth");
int typeID = pocketNBT.getInteger("typeID");
int x = pocketNBT.getInteger("x");
int z = pocketNBT.getInteger("z");
int entranceDoorID = pocketNBT.getInteger("entranceDoorID");
Pocket pocket = new Pocket(ID, size, depth, typeID, x, z, entranceDoorID);
NBTTagList playersTagList = (NBTTagList) pocketNBT.getTag("playerUUIDs");
for (int i = 0; i < playersTagList.tagCount(); i++) {
String playerUUID = playersTagList.getStringTagAt(i);
pocket.playerUUIDs.add(playerUUID);
}
NBTTagList doorsTagList = (NBTTagList) pocketNBT.getTag("doorIDs");
for (int i = 0; i < doorsTagList.tagCount(); i++) {
int doorID = doorsTagList.getIntAt(i);
pocket.doorIDs.add(doorID);
}
return pocket;
}
@ -47,8 +86,28 @@ class Pocket {
static NBTBase writeToNBT(Pocket pocket) {
NBTTagCompound pocketNBT = new NBTTagCompound();
//@todo implement shit;
pocketNBT.setInteger("ID", pocket.ID);
pocketNBT.setInteger("size", pocket.size);
pocketNBT.setInteger("depth", pocket.depth);
pocketNBT.setInteger("typeID", pocket.typeID);
pocketNBT.setInteger("x", pocket.x);
pocketNBT.setInteger("z", pocket.z);
pocketNBT.setInteger("entranceDoorID", pocket.entranceDoorID);
NBTTagList playersTagList = new NBTTagList();
for (int i = 0; i < pocket.playerUUIDs.size(); i++) {
NBTTagString playerTag = new NBTTagString(pocket.playerUUIDs.get(i));
playersTagList.appendTag(playerTag);
}
pocketNBT.setTag("playerUUIDs", playersTagList);
NBTTagList doorsTagList = new NBTTagList();
for (int i = 0; i < pocket.doorIDs.size(); i++) {
NBTTagInt doorTag = new NBTTagInt(pocket.doorIDs.get(i));
doorsTagList.appendTag(doorTag);
}
pocketNBT.setTag("doorIDs", doorsTagList);
return pocketNBT;
}
}

View file

@ -0,0 +1,27 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.zixiken.dimdoors.shared;
/**
*
* @author Robijnvogel
*/
class PocketPlacer { //there is exactly one pocket placer for each different schematic that is loaded into the game
int size;
//@todo about everything
//this class should contain the actual schematic info, as well as some of the Json info (placement of Rifts and stuff)
int getSize() {
return size;
}
int place(int x, int y, int z, int dimID) { //actual coords
//@todo generate a "bedrock" wall around the pocket and start generating the contents of the pocket at (1, 0, 1)
//so pocket with size 1 is 14 * 14, size 2 is 30 * 30, size 3 is 46 * 46 etc.
}
}

View file

@ -5,10 +5,12 @@
*/
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.DDConfig;
import com.zixiken.dimdoors.DimDoors;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.nbt.NBTTagList;
/**
*
@ -19,62 +21,195 @@ public class PocketRegistry {
public static final PocketRegistry Instance = new PocketRegistry();
// Privates
private int nextUnusedID;
private int gridSize; //determines how much pockets in their dimension are spaced
private int maxPocketSize;
private int privatePocketSize;
private int publicPocketSize;
private int nextUnusedID = -1;
private final Map<Integer, Pocket> pocketList;
//when adding any new variables, don't forget to add them to the write and load functions
// Methods
public PocketRegistry() {
nextUnusedID = 0;
private PocketRegistry() {
pocketList = new HashMap();
}
public int getGridSize() {
return gridSize;
}
public int getMaxPocketSize() {
return maxPocketSize;
}
public int getPrivatePocketSize() {
return privatePocketSize;
}
public int getPublicPocketSize() {
return publicPocketSize;
}
public void reset() {
nextUnusedID = 0;
pocketList.clear();
gridSize = DDConfig.getPocketGridSize();
maxPocketSize = DDConfig.getMaxPocketsSize();
privatePocketSize = DDConfig.getPrivatePocketSize();
publicPocketSize = DDConfig.getPublicPocketSize();
PocketSavedData.get(DimDoors.getDefWorld()).markDirty();
}
public void readFromNBT(NBTTagCompound nbt) {
nextUnusedID = nbt.getInteger("nextUnusedID");
if (nbt.hasKey("pocketData")) {
NBTTagCompound pocketsNBT = nbt.getCompoundTag("pocketData");
int i = 1;
String tag = "" + i;
while (pocketsNBT.hasKey(tag)) {
NBTTagCompound pocketNBT = pocketsNBT.getCompoundTag(tag);
Pocket pocket = Pocket.readFromNBT(i, pocketNBT);
pocketList.put(i, pocket);
i++;
tag = "" + i;
if (nbt.hasKey("gridSize")) { //if this info has been saved before
gridSize = nbt.getInteger("gridSize");
maxPocketSize = nbt.getInteger("maxPocketSize");
privatePocketSize = nbt.getInteger("privatePocketSize");
publicPocketSize = nbt.getInteger("publicPocketSize");
nextUnusedID = nbt.getInteger("nextUnusedID");
if (nbt.hasKey("pocketData")) {
NBTTagList pocketTagList = (NBTTagList) nbt.getTag("pocketData");
for (int i = 0; i < pocketTagList.tagCount(); i++) {
NBTTagCompound pocketTag = pocketTagList.getCompoundTagAt(i);
Pocket pocket = Pocket.readFromNBT(pocketTag);
pocketList.put(pocket.getID(), pocket);
}
}
} else { //load privates from config
reset();
}
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("gridSize", gridSize);
nbt.setInteger("maxPocketSize", maxPocketSize);
nbt.setInteger("privatePocketSize", privatePocketSize);
nbt.setInteger("publicPocketSize", publicPocketSize);
nbt.setInteger("nextUnusedID", nextUnusedID);
NBTTagCompound pocketsNBT = new NBTTagCompound();
NBTTagList pocketTagList = new NBTTagList();
for (Map.Entry<Integer, Pocket> entry : pocketList.entrySet()) {
pocketsNBT.setTag("" + entry.getKey(), Pocket.writeToNBT(entry.getValue()));
pocketTagList.appendTag(Pocket.writeToNBT(entry.getValue()));
}
nbt.setTag("pocketData", pocketsNBT);
nbt.setTag("pocketData", pocketTagList);
}
public int registerNewPocket(Pocket pocket, World world) {
public int registerNewPocket(Pocket pocket) {
pocketList.put(nextUnusedID, pocket);
nextUnusedID++;
PocketSavedData.get(world).markDirty(); //Notify that this needs to be saved on world save
PocketSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
return nextUnusedID - 1;
}
public void removePocket(int pocketID, World world) {
public void removePocket(int pocketID) {
if (pocketList.containsKey(pocketID)) {
pocketList.remove(pocketID);
PocketSavedData.get(world).markDirty(); //Notify that this needs to be saved on world save
PocketSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
}
}
public Pocket getPocket(int ID) {
return pocketList.get(ID);
}
public int getEntranceDoorIDOfNewPocket(int typeID, int depth) {//should return the riftID of the entrance door of the newly generated pocket
Location shortenedLocation = getGenerationlocation(nextUnusedID, typeID);
int x = shortenedLocation.getPos().getX();
int z = shortenedLocation.getPos().getZ();
Pocket pocket = generateRandomPocketAt(typeID, depth, shortenedLocation);
registerNewPocket(pocket);
nextUnusedID++;
int entranceDoorID = pocket.getEntranceDoorID();
return entranceDoorID;
}
private Pocket generateRandomPocketAt(int typeID, int depth, Location shortenedLocation) {
int x = shortenedLocation.getPos().getX();
int z = shortenedLocation.getPos().getZ();
int actualX = x * gridSize * 16;
int actualZ = z * gridSize * 16;
int dimID = shortenedLocation.getDimensionID();
PocketPlacer pocketPlacer = getPocketPlacer(typeID, depth, maxPocketSize);
int entranceDoorID = pocketPlacer.place(actualX, 0, actualZ, dimID);
Pocket pocket = new Pocket(nextUnusedID, pocketPlacer.getSize(), depth, typeID, x, z, entranceDoorID);
return pocket;
}
public int getPrivateDimDoorID(String playerUUID) {
throw new UnsupportedOperationException("Not supported yet."); //@todo
}
private Location getGenerationlocation(int nextUnusedID, int typeID) { //typeID is for determining the dimension
int x = getSimpleX(nextUnusedID);
int y = 0;
int z = getSimpleZ(nextUnusedID);;
int dimID = 0; //@todo should be fetched using typeID
Location location = new Location(x, y, z, dimID);
return location;
}
private PocketPlacer getPocketPlacer(int typeID, int depth, int maxPocketSize) {
if (typeID == 0) {
return SchematicHandler.Instance.getPersonalPocketSchematic(maxPocketSize);
} else if (typeID == 1) {
return SchematicHandler.Instance.getPublicPocketSchematic(maxPocketSize);
} else {
return SchematicHandler.Instance.getRandomDungeonSchematic(depth, maxPocketSize);
}
}
private int getSimpleX(int ID) { //we can get the previous x from the last entry of the PocketRegistry :D
if (ID == 0) {
return 0;
} else {
int baseX = pocketList.get(ID - 1).getX();
int group = getDiffToPreviousGroup(ID);
if (group % 2 == 0) {//even
return baseX;
} else { //uneven
if (group % 4 == 1) { //power of four + 1
return baseX + 1;
} else { //power of four - 1
return baseX - 1;
}
}
}
}
private int getSimpleZ(int ID) {
if (ID == 0) {
return 0;
} else {
int baseZ = pocketList.get(ID - 1).getZ();
int group = getDiffToPreviousGroup(ID);
if (group % 2 == 1) {//uneven
return baseZ;
} else { //uneven
if (group % 4 == 0) { //power of four
return baseZ - 1;
} else { //"4-uneven"
return baseZ + 1;
}
}
}
}
private int getDiffToPreviousGroup(int ID) {
int temp = 0;
int group;
for (group = 1; temp <= ID; group++) {
temp += group * 2;
}
if (temp - group < ID) {
group *= 2;
} else {
group = (group * 2) - 1;
}
return group;
}
}

View file

@ -5,7 +5,6 @@
*/
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.DimDoors;
import java.io.File;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
@ -50,7 +49,6 @@ public class PocketSavedData extends DDSavedData {
PocketRegistry.Instance.writeToNBT(pockets);
pocketnbt.setTag("pockets", pockets);
//@todo? saveNBTToPath(getSaveLocation(DimDoors.getDefWorld()), pocketnbt);
return pocketnbt;
}

View file

@ -14,6 +14,7 @@ import java.util.Map;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -23,17 +24,18 @@ import net.minecraft.world.World;
*/
public class RiftRegistry {
private int maximumDungeonDepth = 2;
private DDTileEntityBase lastBrokenRift = null; //@todo, redo this functionality in a more refined way
public static final RiftRegistry Instance = new RiftRegistry();
// Privates
private int nextRiftID;
private int maximumDungeonDepth = 2;
private final Map<Integer, Location> riftList; //maps all rifts in the world to their ID
//@todo somehow remove rifts from this list even if they are removed in creative
private final Map<Integer, Location> unpairedRiftList; //maps of all rifts in the world that are not paired to their ID
private final List<Map<Integer, Location>> unpairedDepthRiftList; //List of all "unpairedRiftList s" per Dungeon Depth. Depth 0 is almost anything outside the dungeon dimension
//@todo, once we have a dungeon dimension this List should be implemented (for determining what doors an unpaired door can link to)
//when adding any new variables, don't forget to add them to the write and load functions
// Methods
private RiftRegistry() {
@ -58,30 +60,82 @@ public class RiftRegistry {
public void readFromNBT(NBTTagCompound nbt) {
nextRiftID = nbt.getInteger("nextUnusedID");
if (nbt.hasKey("riftData")) {
NBTTagCompound riftsNBT = nbt.getCompoundTag("riftData");
int i = 0;
String tag = "" + i;
while (riftsNBT.hasKey(tag)) {
NBTTagCompound riftNBT = riftsNBT.getCompoundTag(tag);
Location riftLocation = Location.readFromNBT(riftNBT);
riftList.put(i, riftLocation);
i++;
tag = "" + i;
if (nbt.hasKey("riftList")) {
NBTTagList riftsNBT = (NBTTagList) nbt.getTag("riftList");
for (int i = 0; i < riftsNBT.tagCount(); i++) {
NBTTagCompound riftTag = riftsNBT.getCompoundTagAt(i);
int riftID = riftTag.getInteger("riftID");
NBTTagCompound locationTag = riftTag.getCompoundTag("location");
Location riftLocation = Location.readFromNBT(locationTag);
riftList.put(riftID, riftLocation);
}
}
if (nbt.hasKey("unpairedRiftList")) {
NBTTagList riftsNBT = (NBTTagList) nbt.getTag("unpairedRiftList");
for (int i = 0; i < riftsNBT.tagCount(); i++) {
NBTTagCompound riftTag = riftsNBT.getCompoundTagAt(i);
int riftID = riftTag.getInteger("riftID");
NBTTagCompound locationTag = riftTag.getCompoundTag("location");
Location riftLocation = Location.readFromNBT(locationTag);
unpairedRiftList.put(riftID, riftLocation);
}
}
if (nbt.hasKey("unpairedDepthRiftList")) {
unpairedDepthRiftList.clear(); //because its "maximum depth" (or in other words, "size()") could be re-determined by this action
NBTTagList riftListsNBT = (NBTTagList) nbt.getTag("unpairedDepthRiftList");
maximumDungeonDepth = riftListsNBT.tagCount(); //makes sure both are synched
for (int i = 0; i < riftListsNBT.tagCount(); i++) {
unpairedDepthRiftList.add(new HashMap());
NBTTagList riftsNBT = (NBTTagList) riftListsNBT.get(i);
for (int j = 0; j < riftsNBT.tagCount(); j++) {
NBTTagCompound riftTag = riftsNBT.getCompoundTagAt(j);
int riftID = riftTag.getInteger("riftID");
NBTTagCompound locationTag = riftTag.getCompoundTag("location");
Location riftLocation = Location.readFromNBT(locationTag);
unpairedDepthRiftList.get(i).put(riftID, riftLocation);
}
}
}
//@todo code for loading the other rift lists
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setInteger("maximumDungeonDepth", maximumDungeonDepth);
nbt.setInteger("nextUnusedID", nextRiftID);
NBTTagCompound riftsNBT = new NBTTagCompound();
NBTTagList riftsNBT = new NBTTagList();
for (Map.Entry<Integer, Location> entry : riftList.entrySet()) {
riftsNBT.setTag("" + entry.getKey(), Location.writeToNBT(entry.getValue()));
NBTTagCompound riftTag = new NBTTagCompound();
riftTag.setInteger("riftID", entry.getKey());
riftTag.setTag("location", Location.writeToNBT(entry.getValue()));
riftsNBT.appendTag(riftTag);
}
nbt.setTag("riftData", riftsNBT);
//@todo code for loading the other rift lists
nbt.setTag("riftList", riftsNBT);
NBTTagList unpairedRiftsNBT = new NBTTagList();
for (Map.Entry<Integer, Location> entry : unpairedRiftList.entrySet()) {
NBTTagCompound riftTag = new NBTTagCompound();
riftTag.setInteger("riftID", entry.getKey());
riftTag.setTag("location", Location.writeToNBT(entry.getValue()));
unpairedRiftsNBT.appendTag(riftTag);
}
nbt.setTag("unpairedRiftList", unpairedRiftsNBT);
NBTTagList unpairedRiftListsNBT = new NBTTagList();
for (Map<Integer, Location> arrayEntry : unpairedDepthRiftList) {
NBTTagList unpairedRiftsNBT2 = new NBTTagList();
for (Map.Entry<Integer, Location> mapEntry : arrayEntry.entrySet()) {
NBTTagCompound riftTag = new NBTTagCompound();
riftTag.setInteger("riftID", mapEntry.getKey());
riftTag.setTag("location", Location.writeToNBT(mapEntry.getValue()));
unpairedRiftsNBT2.appendTag(riftTag);
}
unpairedRiftListsNBT.appendTag(unpairedRiftsNBT2);
}
nbt.setTag("unpairedDepthRiftList", unpairedRiftListsNBT);
}
public int registerNewRift(DDTileEntityBase rift) {
@ -95,8 +149,9 @@ public class RiftRegistry {
return nextRiftID - 1;
}
public void unregisterRift(int riftID, World world) {
public void unregisterRift(int riftID) {
if (riftList.containsKey(riftID)) {
unpair(riftID);
riftList.remove(riftID);
RiftSavedData.get(DimDoors.getDefWorld()).markDirty(); //Notify that this needs to be saved on world save
}

View file

@ -48,8 +48,7 @@ public class RiftSavedData extends DDSavedData {
NBTTagCompound rifts = new NBTTagCompound();
RiftRegistry.Instance.writeToNBT(rifts);
riftnbt.setTag("rifts", rifts);
//@todo? saveNBTToPath(getSaveLocation(DimDoors.getDefWorld()), riftnbt);
return riftnbt;
}

View file

@ -0,0 +1,57 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.zixiken.dimdoors.shared;
import com.zixiken.dimdoors.DDConfig;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Robijnvogel
*/
public class SchematicHandler {
public static final SchematicHandler Instance = new SchematicHandler();
private PocketPlacer personalPocketSchematic;
private PocketPlacer publicPocketSchematic;
private List<PocketPlacer> dungeonSchematics;
private SchematicHandler() {
loadSchematics();
}
PocketPlacer getPersonalPocketSchematic(int maxPocketSize) {
return personalPocketSchematic;
}
PocketPlacer getPublicPocketSchematic(int maxPocketSize) {
return publicPocketSchematic;
}
PocketPlacer getRandomDungeonSchematic(int depth, int maxPocketSize) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private void loadSchematics() {
personalPocketSchematic = loadSchematic("defaultPersonal", PocketRegistry.Instance.getPrivatePocketSize());
publicPocketSchematic = loadSchematic("defaultPublic", PocketRegistry.Instance.getPublicPocketSize());
dungeonSchematics = new ArrayList();
List<String> dungeonSchematicNameStrings = DDConfig.getDungeonSchematicNames(); //@todo load default dungeon schematics AND user-added schematics
for (String nameString : dungeonSchematicNameStrings) {
PocketPlacer schematic = loadSchematic(nameString, PocketRegistry.Instance.getMaxPocketSize()); //should keep in mind the globally set maximum schematic size
if (schematic != null) {
dungeonSchematics.add(schematic);
}
}
}
private PocketPlacer loadSchematic(String nameString, int maxPocketSize) {
//check for json files in both directories (inside the mod jar, and inside the dimdoors config folder)
//check if the json has a "variant" with the correct pocket size, if it doesn't, pick the largest smaller variant. If there's only bigger variants, cancel
}
}