From fccd1db045f37af95b45143ec8fedf603117ce01 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 31 Mar 2021 14:18:11 -0500 Subject: [PATCH] Add the ability to select and deselect worlds --- .../com/backsun/lod/objects/LodWorld.java | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/backsun/lod/objects/LodWorld.java b/src/main/java/com/backsun/lod/objects/LodWorld.java index 381ee5c74..df14c8d6c 100644 --- a/src/main/java/com/backsun/lod/objects/LodWorld.java +++ b/src/main/java/com/backsun/lod/objects/LodWorld.java @@ -9,33 +9,56 @@ import net.minecraft.world.DimensionType; * This stores all LODs for a given world. * * @author James Seibel - * @version 02-22-2021 + * @version 03-31-2021 */ public class LodWorld { - public String worldName; + private String worldName; - /** - * Key = Dimension id (as an int) - */ private Map lodDimensions; - public LodWorld(String newWorldName) + public LodWorld() + { + worldName = "No world loaded"; + } + + /** + * Set up the LodWorld with the given newWorldName.
+ * This should be done whenever loading a new world. + * @param newWorldName + */ + public void selectWorld(String newWorldName) { worldName = newWorldName; lodDimensions = new Hashtable(); } + /** + * Set the worldName to "No world loaded" + * and clear the lodDimensions Map.
+ * This should be done whenever unloaded a world. + */ + public void deselectWorld() + { + worldName = "No world loaded"; + lodDimensions = null; + } public void addLodDimension(LodDimension newStorage) { + if (lodDimensions == null) + throw new IllegalStateException("LodWorld hasn't been given a world yet."); + lodDimensions.put(newStorage.dimension, newStorage); } public LodDimension getLodDimension(DimensionType dimension) { + if (lodDimensions == null) + throw new IllegalStateException("LodWorld hasn't been given a world yet."); + return lodDimensions.get(dimension); } @@ -45,21 +68,23 @@ public class LodWorld */ public void resizeDimensionRegionWidth(int newWidth) { + if (lodDimensions == null) + throw new IllegalStateException("LodWorld hasn't been given a world yet."); + for(DimensionType key : lodDimensions.keySet()) lodDimensions.get(key).setRegionWidth(newWidth); } + public String getWorldName() + { + return worldName; + } + @Override public String toString() { - String s = ""; - - s += worldName + "\t - dimensions: "; - for(DimensionType key : lodDimensions.keySet()) - s += lodDimensions.get(key).dimension.toString() + ", "; - - return s; + return "World name: " + worldName; } }