diff --git a/src/main/java/com/volmit/iris/ProjectManager.java b/src/main/java/com/volmit/iris/ProjectManager.java index 7136a77bc..f9af759e0 100644 --- a/src/main/java/com/volmit/iris/ProjectManager.java +++ b/src/main/java/com/volmit/iris/ProjectManager.java @@ -61,31 +61,41 @@ import com.volmit.iris.util.Required; import lombok.Data; @Data -public class ProjectManager { +public class ProjectManager +{ private IrisChunkGenerator currentProject; - public ProjectManager() { + public ProjectManager() + { } - public boolean isProjectOpen() { + public boolean isProjectOpen() + { return currentProject != null; } - public void open(MortarSender sender, String dimm) { - open(sender, dimm, () -> { + public void open(MortarSender sender, String dimm) + { + open(sender, dimm, () -> + { }); } - public void open(MortarSender sender, String dimm, Runnable onDone) { + public void open(MortarSender sender, String dimm, Runnable onDone) + { Iris.globaldata.dump(); IrisDimension d = Iris.globaldata.getDimensionLoader().load(dimm); - J.attemptAsync(() -> { - try { + J.attemptAsync(() -> + { + try + { File f = d.getLoadFile().getParentFile().getParentFile(); - for (File i : f.listFiles()) { - if (i.getName().endsWith(".code-workspace")) { + for(File i : f.listFiles()) + { + if(i.getName().endsWith(".code-workspace")) + { sender.sendMessage("Updating Workspace"); updateWorkspace(i); Desktop.getDesktop().open(i); @@ -94,16 +104,19 @@ public class ProjectManager { } } - catch (Throwable e) { + catch(Throwable e) + { e.printStackTrace(); } }); - if (d == null) { + if(d == null) + { sender.sendMessage("Can't find dimension: " + dimm); return; } - if (isProjectOpen()) { + if(isProjectOpen()) + { sender.sendMessage("Please Wait. Closing Current Project..."); close(); } @@ -117,45 +130,52 @@ public class ProjectManager { O done = new O(); done.set(false); - J.a(() -> { + J.a(() -> + { double last = 0; int req = 740; - while (!done.get()) { + while(!done.get()) + { boolean derp = false; double v = (double) gx.getGenerated() / (double) req; - if (last > v || v > 1) { + if(last > v || v > 1) + { derp = true; v = last; } - else { + else + { last = v; } sender.sendMessage("Generating " + Form.pc(v) + (derp ? " (Waiting on Server...)" : "")); J.sleep(3000); - if (gx.isFailing()) { + if(gx.isFailing()) + { sender.sendMessage("Generation Failed!"); return; } } }); - World world = Bukkit.createWorld(new WorldCreator("iris/" + UUID.randomUUID()).seed(1337).generator(gx) - .generateStructures(false).type(WorldType.NORMAL).environment(d.getEnvironment())); + World world = Bukkit.createWorld(new WorldCreator("iris/" + UUID.randomUUID()).seed(1337).generator(gx).generateStructures(false).type(WorldType.NORMAL).environment(d.getEnvironment())); done.set(true); sender.sendMessage("Generating 100%"); - if (sender.isPlayer()) { + if(sender.isPlayer()) + { sender.player().teleport(new Location(world, 150, 150, 275)); } - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> { + Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> + { sender.sendMessage("Hotloading Active! Change any files and watch them appear as you load new chunks!"); - if (sender.isPlayer()) { + if(sender.isPlayer()) + { sender.player().setGameMode(GameMode.SPECTATOR); } @@ -163,8 +183,10 @@ public class ProjectManager { }, 0); } - public void close() { - if (isProjectOpen()) { + public void close() + { + if(isProjectOpen()) + { currentProject.close(); File folder = currentProject.getWorld().getWorldFolder(); Bukkit.unloadWorld(currentProject.getWorld(), false); @@ -174,7 +196,8 @@ public class ProjectManager { } } - public File compilePackage(MortarSender sender, String dim, boolean obfuscate) { + public File compilePackage(MortarSender sender, String dim, boolean obfuscate) + { Iris.globaldata.dump(); String dimm = dim; IrisDimension dimension = Iris.globaldata.getDimensionLoader().load(dimm); @@ -196,13 +219,17 @@ public class ProjectManager { StringBuilder c = new StringBuilder(); sender.sendMessage("Serializing Objects"); - for (IrisStructure i : structures) { - for (IrisStructureTile j : i.getTiles()) { + for(IrisStructure i : structures) + { + for(IrisStructureTile j : i.getTiles()) + { b.append(j.hashCode()); KList newNames = new KList<>(); - for (String k : j.getObjects()) { - if (renameObjects.containsKey(k)) { + for(String k : j.getObjects()) + { + if(renameObjects.containsKey(k)) + { newNames.add(renameObjects.get(k)); continue; } @@ -217,13 +244,17 @@ public class ProjectManager { } } - for (IrisBiome i : biomes) { - for (IrisObjectPlacement j : i.getObjects()) { + for(IrisBiome i : biomes) + { + for(IrisObjectPlacement j : i.getObjects()) + { b.append(j.hashCode()); KList newNames = new KList<>(); - for (String k : j.getPlace()) { - if (renameObjects.containsKey(k)) { + for(String k : j.getPlace()) + { + if(renameObjects.containsKey(k)) + { newNames.add(renameObjects.get(k)); continue; } @@ -238,13 +269,17 @@ public class ProjectManager { } } - for (IrisBiomeMutation i : dimension.getMutations()) { - for (IrisObjectPlacement j : i.getObjects()) { + for(IrisBiomeMutation i : dimension.getMutations()) + { + for(IrisObjectPlacement j : i.getObjects()) + { b.append(j.hashCode()); KList newNames = new KList<>(); - for (String k : j.getPlace()) { - if (renameObjects.containsKey(k)) { + for(String k : j.getPlace()) + { + if(renameObjects.containsKey(k)) + { newNames.add(renameObjects.get(k)); continue; } @@ -264,59 +299,71 @@ public class ProjectManager { ChronoLatch cl = new ChronoLatch(1000); O ggg = new O(); ggg.set(0); - biomes.forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) -> { - try { + biomes.forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) -> + { + try + { File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0)); IO.copyFile(f, new File(folder, "objects/" + k + ".iob")); gb.append(IO.hash(f)); ggg.set(ggg.get() + 1); - if (cl.flip()) { + if(cl.flip()) + { int g = ggg.get(); ggg.set(0); sender.sendMessage("Wrote another " + g + " Objects"); } } - catch (Throwable e) { + catch(Throwable e) + { } }))); - structures.forEach((i) -> i.getTiles().forEach((j) -> j.getObjects().forEach((k) -> { - try { + structures.forEach((i) -> i.getTiles().forEach((j) -> j.getObjects().forEach((k) -> + { + try + { File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0)); IO.copyFile(f, new File(folder, "objects/" + k + ".iob")); gb.append(IO.hash(f)); ggg.set(ggg.get() + 1); - if (cl.flip()) { + if(cl.flip()) + { int g = ggg.get(); ggg.set(0); sender.sendMessage("Wrote another " + g + " Objects"); } } - catch (Throwable e) { + catch(Throwable e) + { } }))); - dimension.getMutations().forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) -> { - try { + dimension.getMutations().forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) -> + { + try + { File f = Iris.globaldata.getObjectLoader().findFile(lookupObjects.get(k).get(0)); IO.copyFile(f, new File(folder, "objects/" + k + ".iob")); gb.append(IO.hash(f)); ggg.set(ggg.get() + 1); - if (cl.flip()) { + if(cl.flip()) + { int g = ggg.get(); ggg.set(0); sender.sendMessage("Wrote another " + g + " Objects"); } } - catch (Throwable e) { + catch(Throwable e) + { } }))); @@ -327,12 +374,14 @@ public class ProjectManager { Iris.info("Writing Dimensional Scaffold"); - try { + try + { a = new JSONObject(new Gson().toJson(dimension)).toString(0); IO.writeAll(new File(folder, "dimensions/" + dimension.getLoadKey() + ".json"), a); b.append(IO.hash(a)); - for (IrisGenerator i : generators) { + for(IrisGenerator i : generators) + { a = new JSONObject(new Gson().toJson(i)).toString(0); IO.writeAll(new File(folder, "generators/" + i.getLoadKey() + ".json"), a); b.append(IO.hash(a)); @@ -341,19 +390,22 @@ public class ProjectManager { c.append(IO.hash(b.toString())); b = new StringBuilder(); - for (IrisRegion i : regions) { + for(IrisRegion i : regions) + { a = new JSONObject(new Gson().toJson(i)).toString(0); IO.writeAll(new File(folder, "regions/" + i.getLoadKey() + ".json"), a); b.append(IO.hash(a)); } - for (IrisStructure i : structures) { + for(IrisStructure i : structures) + { a = new JSONObject(new Gson().toJson(i)).toString(0); IO.writeAll(new File(folder, "structures/" + i.getLoadKey() + ".json"), a); b.append(IO.hash(a)); } - for (IrisBiome i : biomes) { + for(IrisBiome i : biomes) + { a = new JSONObject(new Gson().toJson(i)).toString(0); IO.writeAll(new File(folder, "biomes/" + i.getLoadKey() + ".json"), a); b.append(IO.hash(a)); @@ -376,20 +428,22 @@ public class ProjectManager { return p; } - catch (Throwable e) { + catch(Throwable e) + { e.printStackTrace(); } sender.sendMessage("Failed!"); return null; } - public void create(MortarSender sender, String s) { + public void create(MortarSender sender, String s) + { IrisDimension dimension = new IrisDimension(); dimension.setLoadKey(s); dimension.setName(Form.capitalizeWords(s.replaceAll("\\Q-\\E", " "))); - if (Iris.instance.getDataFile("packs", dimension.getLoadKey(), "dimensions", dimension.getLoadKey() + ".json") - .exists()) { + if(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "dimensions", dimension.getLoadKey() + ".json").exists()) + { sender.sendMessage("Project Already Exists! Open it instead!"); return; } @@ -454,46 +508,29 @@ public class ProjectManager { exampleRegion.getSeaBiomes().add(exampleOcean1.getLoadKey()); dimension.getRegions().add(exampleRegion.getLoadKey()); - try { + try + { JSONObject ws = newWorkspaceConfig(); - IO.writeAll( - Iris.instance.getDataFile("packs", dimension.getLoadKey(), "dimensions", - dimension.getLoadKey() + ".json"), - new JSONObject(new Gson().toJson(dimension)).toString(4)); - IO.writeAll( - Iris.instance.getDataFile("packs", dimension.getLoadKey(), "regions", - exampleRegion.getLoadKey() + ".json"), - new JSONObject(new Gson().toJson(exampleRegion)).toString(4)); - IO.writeAll( - Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", - exampleLand1.getLoadKey() + ".json"), - new JSONObject(new Gson().toJson(exampleLand1)).toString(4)); - IO.writeAll( - Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", - exampleLand2.getLoadKey() + ".json"), - new JSONObject(new Gson().toJson(exampleLand2)).toString(4)); - IO.writeAll( - Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", - exampleShore1.getLoadKey() + ".json"), - new JSONObject(new Gson().toJson(exampleShore1)).toString(4)); - IO.writeAll( - Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", - exampleOcean1.getLoadKey() + ".json"), - new JSONObject(new Gson().toJson(exampleOcean1)).toString(4)); - IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "generators", - gen.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(gen)).toString(4)); - IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), - dimension.getLoadKey() + ".code-workspace"), ws.toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "dimensions", dimension.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(dimension)).toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "regions", exampleRegion.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(exampleRegion)).toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", exampleLand1.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(exampleLand1)).toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", exampleLand2.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(exampleLand2)).toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", exampleShore1.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(exampleShore1)).toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "biomes", exampleOcean1.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(exampleOcean1)).toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), "generators", gen.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(gen)).toString(4)); + IO.writeAll(Iris.instance.getDataFile("packs", dimension.getLoadKey(), dimension.getLoadKey() + ".code-workspace"), ws.toString(4)); Iris.proj.open(sender, dimension.getName()); } - catch (JSONException | IOException e) { + catch(JSONException | IOException e) + { sender.sendMessage("Failed! Check the console."); e.printStackTrace(); } } - private JSONObject newWorkspaceConfig() { + private JSONObject newWorkspaceConfig() + { JSONObject ws = new JSONObject(); JSONArray folders = new JSONArray(); JSONObject folder = new JSONObject(); @@ -515,12 +552,15 @@ public class ProjectManager { return ws; } - public File getWorkspaceFile(String dim) { + public File getWorkspaceFile(String dim) + { return Iris.instance.getDataFile("packs", dim, dim + ".code-workspace"); } - public void updateWorkspace(File ws) { - try { + public void updateWorkspace(File ws) + { + try + { J.attemptAsync(() -> writeDocs(ws.getParentFile())); JSONObject j = new JSONObject(IO.readAll(ws)); JSONObject s = j.getJSONObject("settings"); @@ -546,21 +586,24 @@ public class ProjectManager { Iris.info("Updating Project " + ws.getAbsolutePath()); } - catch (Throwable e) { - Iris.warn("Project invalid: " + ws.getAbsolutePath() - + " Re-creating. You may loose some vs-code workspace settings! But not your actual project!"); + catch(Throwable e) + { + Iris.warn("Project invalid: " + ws.getAbsolutePath() + " Re-creating. You may loose some vs-code workspace settings! But not your actual project!"); - try { + try + { IO.writeAll(ws, newWorkspaceConfig()); } - catch (IOException e1) { + catch(IOException e1) + { e1.printStackTrace(); } } } - private JSONArray buildSchemas() { + private JSONArray buildSchemas() + { JSONArray schemas = new JSONArray(); schemas.put(getSchemaEntry(IrisDimension.class, "/dimensions/*.json")); schemas.put(getSchemaEntry(IrisBiome.class, "/biomes/*.json")); @@ -570,7 +613,8 @@ public class ProjectManager { return schemas; } - public JSONObject getSchemaEntry(Class i, String... fileMatch) { + public JSONObject getSchemaEntry(Class i, String... fileMatch) + { JSONObject o = new JSONObject(); o.put("fileMatch", new JSONArray(fileMatch)); o.put("schema", getSchemaFor(i)); @@ -578,11 +622,13 @@ public class ProjectManager { return o; } - public JSONObject getSchemaFor(Class i) { + public JSONObject getSchemaFor(Class i) + { KMap def = new KMap<>(); JSONObject s = getSchemaFor(i, 7, def); JSONObject defx = new JSONObject(); - for (String v : def.k()) { + for(String v : def.k()) + { defx.put(v, def.get(v)); } @@ -591,15 +637,18 @@ public class ProjectManager { return s; } - public JSONObject getSchemaFor(Class i, int step, KMap def) { - if (step <= 0) { + public JSONObject getSchemaFor(Class i, int step, KMap def) + { + if(step <= 0) + { JSONObject m = new JSONObject(); m.put("properties", new JSONObject()); return m; } JSONObject schema = new JSONObject(); - if (i.isAnnotationPresent(Desc.class)) { + if(i.isAnnotationPresent(Desc.class)) + { schema.put("$schema", "http://json-schema.org/draft-07/schema#"); schema.put("$id", "http://volmit.com/iris-schema/" + i.getSimpleName().toLowerCase() + ".json"); schema.put("title", i.getSimpleName().replaceAll("\\QIris\\E", "")); @@ -612,135 +661,166 @@ public class ProjectManager { JSONArray req = new JSONArray(); JSONObject deps = new JSONObject(); - for (java.lang.reflect.Field k : i.getDeclaredFields()) { + for(java.lang.reflect.Field k : i.getDeclaredFields()) + { JSONObject prop = new JSONObject(); - if (k.isAnnotationPresent(Desc.class)) { + if(k.isAnnotationPresent(Desc.class)) + { - if (k.isAnnotationPresent(DependsOn.class)) { + if(k.isAnnotationPresent(DependsOn.class)) + { deps.put(k.getName(), new JSONArray(k.getDeclaredAnnotation(DependsOn.class).value())); } String tp = "object"; - if (k.getType().equals(int.class) || k.getType().equals(long.class)) { + if(k.getType().equals(int.class) || k.getType().equals(long.class)) + { tp = "integer"; - if (k.isAnnotationPresent(MinNumber.class)) { + if(k.isAnnotationPresent(MinNumber.class)) + { prop.put("minimum", (int) k.getDeclaredAnnotation(MinNumber.class).value()); } - if (k.isAnnotationPresent(MaxNumber.class)) { + if(k.isAnnotationPresent(MaxNumber.class)) + { prop.put("maximum", (int) k.getDeclaredAnnotation(MaxNumber.class).value()); } } - if (k.getType().equals(double.class) || k.getType().equals(float.class)) { + if(k.getType().equals(double.class) || k.getType().equals(float.class)) + { tp = "number"; - if (k.isAnnotationPresent(MinNumber.class)) { + if(k.isAnnotationPresent(MinNumber.class)) + { prop.put("minimum", k.getDeclaredAnnotation(MinNumber.class).value()); } - if (k.isAnnotationPresent(MaxNumber.class)) { + if(k.isAnnotationPresent(MaxNumber.class)) + { prop.put("maximum", k.getDeclaredAnnotation(MaxNumber.class).value()); } } - if (k.getType().equals(boolean.class)) { + if(k.getType().equals(boolean.class)) + { tp = "boolean"; } - if (k.getType().equals(String.class)) { + if(k.getType().equals(String.class)) + { tp = "string"; - if (k.isAnnotationPresent(MinNumber.class)) { + if(k.isAnnotationPresent(MinNumber.class)) + { prop.put("minLength", (int) k.getDeclaredAnnotation(MinNumber.class).value()); } - if (k.isAnnotationPresent(MaxNumber.class)) { + if(k.isAnnotationPresent(MaxNumber.class)) + { prop.put("maxLength", (int) k.getDeclaredAnnotation(MaxNumber.class).value()); } } - if (k.getType().equals(String.class)) { + if(k.getType().equals(String.class)) + { tp = "string"; } - if (k.getType().isEnum()) { + if(k.getType().isEnum()) + { tp = "string"; JSONArray a = new JSONArray(); - for (Object gg : k.getType().getEnumConstants()) { + for(Object gg : k.getType().getEnumConstants()) + { a.put(((Enum) gg).name()); } prop.put("enum", a); } - if (k.getType().equals(String.class) && k.getName().equals("potionEffect")) { + if(k.getType().equals(String.class) && k.getName().equals("potionEffect")) + { tp = "string"; JSONArray a = new JSONArray(); - for (PotionEffectType gg : PotionEffectType.values()) { + for(PotionEffectType gg : PotionEffectType.values()) + { a.put(gg.getName().toUpperCase().replaceAll("\\Q \\E", "_")); } prop.put("enum", a); } - if (k.getType().equals(KList.class)) { + if(k.getType().equals(KList.class)) + { tp = "array"; } - if (k.isAnnotationPresent(Required.class)) { + if(k.isAnnotationPresent(Required.class)) + { req.put(k.getName()); } - if (tp.equals("object")) { - if (k.getType().isAnnotationPresent(Desc.class)) { + if(tp.equals("object")) + { + if(k.getType().isAnnotationPresent(Desc.class)) + { prop.put("additionalProperties", false); - prop.put("properties", - getSchemaFor(k.getType(), step - 1, def).getJSONObject("properties")); + prop.put("properties", getSchemaFor(k.getType(), step - 1, def).getJSONObject("properties")); } } - if (tp.equals("array")) { + if(tp.equals("array")) + { ArrayType t = k.getDeclaredAnnotation(ArrayType.class); - if (t.min() > 0) { + if(t.min() > 0) + { prop.put("minItems", t.min()); } - if (t != null) { + if(t != null) + { String tx = "object"; - if (t.type().equals(int.class) || k.getType().equals(long.class)) { + if(t.type().equals(int.class) || k.getType().equals(long.class)) + { tx = "integer"; } - if (t.type().equals(double.class) || k.getType().equals(float.class)) { + if(t.type().equals(double.class) || k.getType().equals(float.class)) + { tx = "number"; } - if (t.type().equals(boolean.class)) { + if(t.type().equals(boolean.class)) + { tx = "boolean"; } - if (t.type().equals(String.class)) { + if(t.type().equals(String.class)) + { tx = "string"; } - if (t.type().isEnum()) { + if(t.type().isEnum()) + { tx = "string"; JSONArray a = new JSONArray(); - for (Object gg : t.type().getEnumConstants()) { + for(Object gg : t.type().getEnumConstants()) + { a.put(((Enum) gg).name()); } String name = "enum" + t.type().getSimpleName().toLowerCase(); - if (!def.containsKey(name)) { + if(!def.containsKey(name)) + { JSONObject deff = new JSONObject(); deff.put("type", tx); deff.put("enum", a); @@ -752,27 +832,34 @@ public class ProjectManager { prop.put("items", items); } - if (t.type().isEnum()) { + if(t.type().isEnum()) + { tx = "string"; } - if (t.type().equals(KList.class)) { + if(t.type().equals(KList.class)) + { tx = "array"; } JSONObject items = new JSONObject(); - if (tx.equals("object")) { - if (t.type().isAnnotationPresent(Desc.class)) { + if(tx.equals("object")) + { + if(t.type().isAnnotationPresent(Desc.class)) + { String name = t.type().getSimpleName().toLowerCase(); - if (!def.containsKey(name)) { + if(!def.containsKey(name)) + { JSONObject deff = new JSONObject(); JSONObject scv = getSchemaFor(t.type(), step - 1, def); deff.put("type", tx); deff.put("description", t.type().getDeclaredAnnotation(Desc.class).value()); + deff.put("additionalProperties", false); deff.put("properties", scv.getJSONObject("properties")); - if (scv.has("required")) { + if(scv.has("required")) + { deff.put("required", scv.getJSONArray("required")); } def.put(name, deff); @@ -781,21 +868,23 @@ public class ProjectManager { items.put("$ref", "#/definitions/" + name); } - else { + else + { items.put("type", tx); } } - else { + else + { items.put("type", tx); } prop.put("items", items); } - if (tp.getClass().isAnnotationPresent(Desc.class)) { - prop.put("properties", - getSchemaFor(tp.getClass(), step - 1, def).getJSONObject("properties")); + if(tp.getClass().isAnnotationPresent(Desc.class)) + { + prop.put("properties", getSchemaFor(tp.getClass(), step - 1, def).getJSONObject("properties")); } } @@ -814,32 +903,40 @@ public class ProjectManager { return schema; } - public KList analyzeFolder(File folder, String fn, Object t) { + public KList analyzeFolder(File folder, String fn, Object t) + { KList a = new KList(); - if (!new File(folder, fn).exists()) { + if(!new File(folder, fn).exists()) + { return a; } - if (!new File(folder, fn).isDirectory()) { + if(!new File(folder, fn).isDirectory()) + { a.add("ERROR: " + new File(folder, fn).getAbsolutePath() + " must be a folder, not a file!"); return a; } - for (File i : new File(folder, fn).listFiles()) { - if (i.isFile() && i.getName().endsWith(".json")) { - if (!i.getName().toLowerCase().equals(i.getName())) { + for(File i : new File(folder, fn).listFiles()) + { + if(i.isFile() && i.getName().endsWith(".json")) + { + if(!i.getName().toLowerCase().equals(i.getName())) + { a.add("WARN: " + i.getAbsolutePath() + " has upper case letters in the file name."); } - if (i.getName().contains(" ")) { + if(i.getName().contains(" ")) + { a.add("WARN: " + i.getAbsolutePath() + " has spaces in the file name."); } Object o; JSONObject j; - try { + try + { j = new JSONObject(IO.readAll(i)); o = new Gson().fromJson(j.toString(), t.getClass()); a.addAll(analyze(o, i)); @@ -847,12 +944,14 @@ public class ProjectManager { verify(j, o, a, i); } - catch (Throwable e) { + catch(Throwable e) + { a.add("ERROR: Failed to read " + i.getAbsolutePath() + ": " + e.getMessage()); } } - else { + else + { a.add("WARN: " + i.getAbsolutePath() + " should not be in this directory."); } } @@ -860,43 +959,50 @@ public class ProjectManager { return a; } - private void verify(JSONObject j, Object o, KList a, File m) { - for (String i : j.keySet()) { - try { + private void verify(JSONObject j, Object o, KList a, File m) + { + for(String i : j.keySet()) + { + try + { JSONObject jj = j.getJSONObject(i); - try { + try + { Field f = o.getClass().getDeclaredField(i); - if (f.isEnumConstant() || f.getType().isEnum() || f.getType().isPrimitive()) { - a.add("ERROR: Unexptected type: " + i + " into " + f.getType() - + " expected. Got a jsonObject in " + o.getClass() + " in " + m.getAbsolutePath()); + if(f.isEnumConstant() || f.getType().isEnum() || f.getType().isPrimitive()) + { + a.add("ERROR: Unexptected type: " + i + " into " + f.getType() + " expected. Got a jsonObject in " + o.getClass() + " in " + m.getAbsolutePath()); continue; } f.setAccessible(true); Object oo = f.get(o); - if (oo == null) { + if(oo == null) + { a.add("WARN: Incorrect injection on " + o.getClass() + "." + i); } verify(jj, oo, a, m); } - catch (Throwable e) { - a.add("WARN: Unexptected Field: " + i + " in " + o.getClass().getSimpleName() + " from " - + m.getAbsolutePath() + " " + e.getClass().getSimpleName() + " " + e.getMessage()); + catch(Throwable e) + { + a.add("WARN: Unexptected Field: " + i + " in " + o.getClass().getSimpleName() + " from " + m.getAbsolutePath() + " " + e.getClass().getSimpleName() + " " + e.getMessage()); } } - catch (Throwable enn) { + catch(Throwable enn) + { } } } - public KList analyze(File project) { + public KList analyze(File project) + { KList a = new KList(); a.addAll(analyzeFolder(project, "dimensions", new IrisDimension())); @@ -908,116 +1014,134 @@ public class ProjectManager { return a; } - public KList analyze(Object o, File file) { + public KList analyze(Object o, File file) + { KList a = new KList(); String t; - try { + try + { t = IO.readAll(file); - } catch (IOException e1) { + } + catch(IOException e1) + { a.add("ERROR: Unable to read " + file.getAbsolutePath() + ": " + e1.getMessage()); return a; } JSONObject j; - try { + try + { j = new JSONObject(t); } - catch (Throwable e) { + catch(Throwable e) + { a.add("ERROR: Unable to parse json " + file.getAbsolutePath() + ": " + e.getMessage()); return a; } - for (String i : j.keySet()) { - try { + for(String i : j.keySet()) + { + try + { Field f = o.getClass().getDeclaredField(i); - if (f == null) { + if(f == null) + { throw new NullPointerException(); } } - catch (Throwable e) { - a.add("WARN: Unreconized Field (key): " + i + " in " + file.getAbsolutePath() - + ". Delete this key/value pair: " + o.getClass().getSimpleName()); + catch(Throwable e) + { + a.add("WARN: Unreconized Field (key): " + i + " in " + file.getAbsolutePath() + ". Delete this key/value pair: " + o.getClass().getSimpleName()); } } return a; } - public void writeDocs(File folder) - throws IOException, JSONException, InstantiationException, IllegalAccessException, IllegalArgumentException, - InvocationTargetException, NoSuchMethodException, SecurityException { + public void writeDocs(File folder) throws IOException, JSONException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException + { File of = new File(folder, "_docs"); KList m = new KList<>(); - for (Biome i : Biome.values()) { + for(Biome i : Biome.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "biomes.txt"), m.toString("\n")); m = new KList<>(); - for (Particle i : Particle.values()) { + for(Particle i : Particle.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "particles.txt"), m.toString("\n")); m = new KList<>(); - for (NoiseStyle i : NoiseStyle.values()) { + for(NoiseStyle i : NoiseStyle.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "noise-style.txt"), m.toString("\n")); m = new KList<>(); - for (DecorationPart i : DecorationPart.values()) { + for(DecorationPart i : DecorationPart.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "decoration-part.txt"), m.toString("\n")); m = new KList<>(); - for (Envelope i : Envelope.values()) { + for(Envelope i : Envelope.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "envelope.txt"), m.toString("\n")); m = new KList<>(); - for (Environment i : Environment.values()) { + for(Environment i : Environment.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "environment.txt"), m.toString("\n")); m = new KList<>(); - for (StructureTileCondition i : StructureTileCondition.values()) { + for(StructureTileCondition i : StructureTileCondition.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "structure-tile-condition.txt"), m.toString("\n")); m = new KList<>(); - for (InterpolationMethod i : InterpolationMethod.values()) { + for(InterpolationMethod i : InterpolationMethod.values()) + { m.add(i.name()); } IO.writeAll(new File(of, "interpolation-method.txt"), m.toString("\n")); m = new KList<>(); - for (Class i : Iris.postProcessors) { + for(Class i : Iris.postProcessors) + { m.add(i.getDeclaredAnnotation(Post.class).value()); } IO.writeAll(new File(of, "post-processors.txt"), m.toString("\n")); m = new KList<>(); - for (PotionEffectType i : PotionEffectType.values()) { + for(PotionEffectType i : PotionEffectType.values()) + { m.add(i.getName().toUpperCase().replaceAll("\\Q \\E", "_")); } } diff --git a/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java b/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java index bc5f7cc8e..ba2de4812 100644 --- a/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/BiomeChunkGenerator.java @@ -25,7 +25,8 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public abstract class BiomeChunkGenerator extends DimensionChunkGenerator { +public abstract class BiomeChunkGenerator extends DimensionChunkGenerator +{ protected IrisLock regLock; private KMap generators; private KMap ceilingGenerators; @@ -33,14 +34,16 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator { protected CNG masterFracture; protected ChronoLatch cwarn = new ChronoLatch(1000); - public BiomeChunkGenerator(String dimensionName) { + public BiomeChunkGenerator(String dimensionName) + { super(dimensionName); generators = new KMap<>(); ceilingGenerators = new KMap<>(); regLock = new IrisLock("BiomeChunkGenerator"); } - public void onInit(World world, RNG rng) { + public void onInit(World world, RNG rng) + { super.onInit(world, rng); loadGenerators(); glBiome = new GenLayerBiome(this, masterRandom.nextParallelRNG(1)); @@ -48,17 +51,20 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator { } @Override - public void onHotload() { + public void onHotload() + { super.onHotload(); loadGenerators(); glBiome = new GenLayerBiome(this, masterRandom.nextParallelRNG(1)); } - public void registerGenerator(IrisGenerator g, IrisDimension dim) { + public void registerGenerator(IrisGenerator g, IrisDimension dim) + { KMap generators = dim.isInverted() ? ceilingGenerators : this.generators; regLock.lock(); - if (g.getLoadKey() == null || generators.containsKey(g.getLoadKey())) { + if(g.getLoadKey() == null || generators.containsKey(g.getLoadKey())) + { regLock.unlock(); return; } @@ -67,83 +73,100 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator { generators.put(g.getLoadKey(), g); } - protected KMap getGenerators() { + protected KMap getGenerators() + { return getDimension().isInverted() ? ceilingGenerators : generators; } - protected double getBiomeHeight(double rx, double rz, int x, int z) { + protected double getBiomeHeight(double rx, double rz, int x, int z) + { double h = 0; - for (IrisGenerator i : getGenerators().values()) { + for(IrisGenerator i : getGenerators().values()) + { h += interpolateGenerator(rx, rz, i); } return h; } - protected double interpolateGenerator(double rx, double rz, IrisGenerator gen) { - double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), - (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> { - try { - IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); - - for (IrisBiomeGeneratorLink i : b.getGenerators()) { - if (i.getGenerator().equals(gen.getLoadKey())) { - return i.getMax(); - } - } + protected double interpolateGenerator(double rx, double rz, IrisGenerator gen) + { + double hi = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> + { + try + { + IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); + for(IrisBiomeGeneratorLink i : b.getGenerators()) + { + if(i.getGenerator().equals(gen.getLoadKey())) + { + return i.getMax(); } + } - catch (Throwable e) { - Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " - + gen.getLoadKey()); + } + + catch(Throwable e) + { + e.printStackTrace(); + Iris.warn("Failed to sample hi biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey()); + } + return 0; + }); + + double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> + { + try + { + IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); + + for(IrisBiomeGeneratorLink i : b.getGenerators()) + { + if(i.getGenerator().equals(gen.getLoadKey())) + { + return i.getMin(); } - return 0; - }); + } + } - double lo = IrisInterpolation.getNoise(gen.getInterpolationFunction(), (int) Math.round(rx), - (int) Math.round(rz), gen.getInterpolationScale(), (xx, zz) -> { - try { - IrisBiome b = sampleBiome((int) xx, (int) zz).getBiome(); + catch(Throwable e) + { + e.printStackTrace(); + Iris.warn("Failed to sample lo biome at " + rx + " " + rz + " using the generator " + gen.getLoadKey()); + } - for (IrisBiomeGeneratorLink i : b.getGenerators()) { - if (i.getGenerator().equals(gen.getLoadKey())) { - return i.getMin(); - } - } - } - - catch (Throwable e) { - Iris.warn("Failed to sample biome at " + rx + " " + rz + " using the generator " - + gen.getLoadKey()); - } - - return 0; - }); + return 0; + }); return M.lerp(lo, hi, gen.getHeight(rx, rz, world.getSeed() + 239945)); } - protected void loadGenerators() { + protected void loadGenerators() + { generators.clear(); ceilingGenerators.clear(); loadGenerators(((CeilingChunkGenerator) this).getFloorDimension()); loadGenerators(((CeilingChunkGenerator) this).getCeilingDimension()); } - protected void loadGenerators(IrisDimension dim) { - if (dim == null) { + protected void loadGenerators(IrisDimension dim) + { + if(dim == null) + { return; } KList touch = new KList<>(); KList loadQueue = new KList<>(); - for (String i : dim.getRegions()) { + for(String i : dim.getRegions()) + { IrisRegion r = loadRegion(i); - if (r != null) { + if(r != null) + { loadQueue.addAll(r.getLandBiomes()); loadQueue.addAll(r.getSeaBiomes()); loadQueue.addAll(r.getShoreBiomes()); @@ -152,10 +175,12 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator { } } - while (!loadQueue.isEmpty()) { + while(!loadQueue.isEmpty()) + { String next = loadQueue.pop(); - if (!touch.contains(next)) { + if(!touch.contains(next)) + { touch.add(next); IrisBiome biome = loadBiome(next); biome.getGenerators().forEach((i) -> registerGenerator(i.getCachedGenerator(this), dim)); @@ -164,32 +189,40 @@ public abstract class BiomeChunkGenerator extends DimensionChunkGenerator { } } - public IrisRegion sampleRegion(int x, int z) { + public IrisRegion sampleRegion(int x, int z) + { double wx = getModifiedX(x, z); double wz = getModifiedZ(x, z); return glBiome.getRegion(wx, wz); } - public BiomeResult sampleBiome(int x, int z) { - return getCache().getRawBiome(x, z, () -> { - if (!getDimension().getFocus().equals("")) { + public BiomeResult sampleBiome(int x, int z) + { + return getCache().getRawBiome(x, z, () -> + { + if(!getDimension().getFocus().equals("")) + { IrisBiome biome = loadBiome(getDimension().getFocus()); - for (String i : getDimension().getRegions()) { + for(String i : getDimension().getRegions()) + { IrisRegion reg = loadRegion(i); - if (reg.getLandBiomes().contains(biome.getLoadKey())) { + if(reg.getLandBiomes().contains(biome.getLoadKey())) + { biome.setInferredType(InferredType.LAND); break; } - if (reg.getSeaBiomes().contains(biome.getLoadKey())) { + if(reg.getSeaBiomes().contains(biome.getLoadKey())) + { biome.setInferredType(InferredType.SEA); break; } - if (reg.getShoreBiomes().contains(biome.getLoadKey())) { + if(reg.getShoreBiomes().contains(biome.getLoadKey())) + { biome.setInferredType(InferredType.SHORE); break; } diff --git a/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java b/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java index 6de5b3601..7c2398809 100644 --- a/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/ContextualChunkGenerator.java @@ -46,7 +46,8 @@ import net.md_5.bungee.api.ChatColor; @Data @EqualsAndHashCode(callSuper = false) -public abstract class ContextualChunkGenerator extends ChunkGenerator implements Listener { +public abstract class ContextualChunkGenerator extends ChunkGenerator implements Listener +{ private AtomicMulticache cache; private IrisDataManager data; protected boolean failing; @@ -65,8 +66,10 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements protected long hlast; private boolean fastPregen = false; protected boolean pregenDone; + private volatile boolean hotloadable = false; - public ContextualChunkGenerator() { + public ContextualChunkGenerator() + { pushLatch = new ChronoLatch(3000); tickLatch = new ChronoLatch(650); perSecond = new ChronoLatch(1000); @@ -101,57 +104,72 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements protected abstract void onPlayerLeft(Player p); - public IrisRegion loadRegion(String i) { + public IrisRegion loadRegion(String i) + { return getData().getRegionLoader().load(i); } - public IrisBiome loadBiome(String i) { + public IrisBiome loadBiome(String i) + { return getData().getBiomeLoader().load(i); } - public IrisStructure loadStructure(String i) { + public IrisStructure loadStructure(String i) + { return getData().getStructureLoader().load(i); } - public IrisObject loadObject(String i) { + public IrisObject loadObject(String i) + { return getData().getObjectLoader().load(i); } - public IrisDimension loadDimension(String i) { + public IrisDimension loadDimension(String i) + { return (getData() == null ? Iris.globaldata : getData()).getDimensionLoader().load(i); } - public IrisGenerator loadGenerator(String i) { + public IrisGenerator loadGenerator(String i) + { return getData().getGeneratorLoader().load(i); } - public IrisDataManager getData() { + public IrisDataManager getData() + { return isDev() ? Iris.globaldata : data; } - private void init(World world, RNG rng) { - if (initialized) { + private void init(World world, RNG rng) + { + if(initialized) + { return; } - data = new IrisDataManager(getWorld().getWorldFolder()); this.world = world; + data = new IrisDataManager(getWorld().getWorldFolder()); this.masterRandom = new RNG(world.getSeed()); metrics = new IrisMetrics(128); initialized = true; Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance); task = Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, this::tick, 0, 0); onInit(world, masterRandom); + setHotloadable(true); } - private void tick() { - if (dev) { - if (perSecond.flip()) { - if (generated > (fastPregen ? 1950 : 770)) { + private void tick() + { + if(dev) + { + if(perSecond.flip()) + { + if(generated > (fastPregen ? 1950 : 770)) + { pregenDone = true; } - if (pregenDone) { + if(pregenDone) + { metrics.getPerSecond().put(generated); generated = 0; } @@ -160,7 +178,8 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements } } - else { + else + { pregenDone = true; fastPregen = false; } @@ -169,80 +188,100 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements } @EventHandler - public void on(PlayerTeleportEvent e) { - if (e.getFrom().getWorld().equals(world) && !e.getTo().getWorld().equals(world)) { + public void on(PlayerTeleportEvent e) + { + if(e.getFrom().getWorld().equals(world) && !e.getTo().getWorld().equals(world)) + { tick(); onPlayerLeft(e.getPlayer()); } - if (!e.getFrom().getWorld().equals(world) && e.getTo().getWorld().equals(world)) { + if(!e.getFrom().getWorld().equals(world) && e.getTo().getWorld().equals(world)) + { tick(); onPlayerJoin(e.getPlayer()); } } @EventHandler - public void on(PlayerQuitEvent e) { - if (e.getPlayer().getWorld().equals(world)) { + public void on(PlayerQuitEvent e) + { + if(e.getPlayer().getWorld().equals(world)) + { tick(); onPlayerLeft(e.getPlayer()); } } @EventHandler - public void on(PlayerJoinEvent e) { - if (e.getPlayer().getWorld().equals(world)) { + public void on(PlayerJoinEvent e) + { + if(e.getPlayer().getWorld().equals(world)) + { tick(); onPlayerJoin(e.getPlayer()); } } @EventHandler - public void on(ChunkLoadEvent e) { - if (e.getWorld().equals(world)) { + public void on(ChunkLoadEvent e) + { + if(e.getWorld().equals(world)) + { tick(); onChunkLoaded(e.getChunk()); } } @EventHandler - public void on(ChunkUnloadEvent e) { - if (e.getWorld().equals(world)) { + public void on(ChunkUnloadEvent e) + { + if(e.getWorld().equals(world)) + { tick(); onChunkUnloaded(e.getChunk()); } } @EventHandler - public void on(WorldUnloadEvent e) { - if (world != null && e.getWorld().equals(world)) { + public void on(WorldUnloadEvent e) + { + if(world != null && e.getWorld().equals(world)) + { close(); } } - public void close() { + public void close() + { HandlerList.unregisterAll(this); Bukkit.getScheduler().cancelTask(getTask()); onClose(); } @Override - public boolean canSpawn(World world, int x, int z) { + public boolean canSpawn(World world, int x, int z) + { return super.canSpawn(world, x, z); } - protected ChunkData generateChunkDataFailure(World world, Random no, int x, int z, BiomeGrid biomeGrid) { + protected ChunkData generateChunkDataFailure(World world, Random no, int x, int z, BiomeGrid biomeGrid) + { ChunkData c = Bukkit.createChunkData(world); - for (int i = 0; i < 16; i++) { - for (int j = 0; j < 16; j++) { + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { int h = 0; - if (j == i || j + i == 16) { + if(j == i || j + i == 16) + { c.setBlock(i, h, j, B.getBlockData("RED_TERRACOTTA")); } - else { + else + { c.setBlock(i, h, j, B.getBlockData("BLACK_TERRACOTTA")); } } @@ -251,18 +290,23 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements return c; } - protected ChunkData generateChunkFastPregen(World world, Random no, int x, int z, BiomeGrid biomeGrid) { + protected ChunkData generateChunkFastPregen(World world, Random no, int x, int z, BiomeGrid biomeGrid) + { ChunkData c = Bukkit.createChunkData(world); - for (int i = 0; i < 16; i++) { - for (int j = 0; j < 16; j++) { + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { int h = 0; - if (j == i || j + i == 16) { + if(j == i || j + i == 16) + { c.setBlock(i, h, j, B.getBlockData("BLUE_TERRACOTTA")); } - else { + else + { c.setBlock(i, h, j, B.getBlockData("WHITE_TERRACOTTA")); } } @@ -272,33 +316,39 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements } @Override - public ChunkData generateChunkData(World world, Random no, int x, int z, BiomeGrid biomeGrid) { + public ChunkData generateChunkData(World world, Random no, int x, int z, BiomeGrid biomeGrid) + { hlock.lock(); - if (!dev) { + setHotloadable(false); + if(!dev) + { pregenDone = true; fastPregen = false; } PrecisionStopwatch sx = PrecisionStopwatch.start(); - if (failing) { + if(failing) + { hlock.unlock(); return generateChunkDataFailure(world, no, x, z, biomeGrid); } - try { - checkHotload(world); + try + { PrecisionStopwatch s = PrecisionStopwatch.start(); RNG random = new RNG(world.getSeed()); init(world, random.nextParallelRNG(0)); ChunkData c = Bukkit.createChunkData(world); - if (!pregenDone && fastPregen) { + if(!pregenDone && fastPregen) + { c = generateChunkFastPregen(world, no, x, z, biomeGrid); } - else { + else + { onGenerate(random, x, z, c, biomeGrid); } @@ -308,69 +358,85 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements CNG.hits = 0; Iris.instance.hit(hits); metrics.getLoss().put(sx.getMilliseconds() - s.getMilliseconds()); + setHotloadable(true); hlock.unlock(); return c; } - catch (Throwable e) { + catch(Throwable e) + { fail(e); } + setHotloadable(true); hlock.unlock(); return generateChunkDataFailure(world, no, x, z, biomeGrid); } - public void checkHotload() { - if (M.ms() - hlast < 1000) { + public void checkHotload() + { + if(M.ms() - hlast < 1000) + { return; } hlock.lock(); - if (world != null) { + if(world != null) + { checkHotload(world); } hlock.unlock(); } - private void checkHotload(World world) { - if (pushLatch.flip()) { + private void checkHotload(World world) + { + if(!isHotloadable()) + { + return; + } - if (this.world == null) { + if(pushLatch.flip()) + { + if(this.world == null) + { this.world = world; } Iris.hotloader.check((IrisContext) this); - if (this instanceof IrisContext) { + if(this instanceof IrisContext) + { IrisContext.pushContext((IrisContext) this); } } } - public void onHotload() { + public void onHotload() + { hlast = M.ms(); } - protected void fail(Throwable e) { - if (failing) { + protected void fail(Throwable e) + { + if(failing) + { return; } failing = true; e.printStackTrace(); - J.a(() -> { + J.a(() -> + { J.sleep(1000); - Iris.error( - "---------------------------------------------------------------------------------------------------------"); + Iris.error("---------------------------------------------------------------------------------------------------------"); e.printStackTrace(); - Iris.error( - "---------------------------------------------------------------------------------------------------------"); + Iris.error("---------------------------------------------------------------------------------------------------------"); Iris.error("ERROR! Failed to generate chunk! Iris has entered a failed state!"); - Iris.error( - "---------------------------------------------------------------------------------------------------------"); + Iris.error("---------------------------------------------------------------------------------------------------------"); - for (Player i : world.getPlayers()) { + for(Player i : world.getPlayers()) + { Iris.instance.imsg(i, ChatColor.DARK_RED + "Iris Generator has crashed!"); Iris.instance.imsg(i, ChatColor.RED + "- Check the console for the error."); Iris.instance.imsg(i, ChatColor.RED + "- To Regen, use /iris std open "); @@ -382,17 +448,20 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements } @Override - public List getDefaultPopulators(World world) { + public List getDefaultPopulators(World world) + { return super.getDefaultPopulators(world); } @Override - public Location getFixedSpawnLocation(World world, Random random) { + public Location getFixedSpawnLocation(World world, Random random) + { return super.getFixedSpawnLocation(world, random); } @Override - public boolean isParallelCapable() { + public boolean isParallelCapable() + { return true; } } diff --git a/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java b/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java index d113463ec..508391060 100644 --- a/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java +++ b/src/main/java/com/volmit/iris/gen/IrisChunkGenerator.java @@ -4,6 +4,7 @@ import java.awt.Color; import java.io.IOException; import java.lang.reflect.Method; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -28,94 +29,114 @@ import lombok.EqualsAndHashCode; @Data @EqualsAndHashCode(callSuper = false) -public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisContext { +public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisContext +{ private Method initLighting; private IrisLock lock; private IrisBiome hb = null; private IrisRegion hr = null; private KMap b = new KMap<>(); - public IrisChunkGenerator(String dimensionName, int threads) { + public IrisChunkGenerator(String dimensionName, int threads) + { super(dimensionName, threads); lock = new IrisLock("IrisChunkGenerator"); } - public IrisChunkGenerator(String dimensionName) { + public IrisChunkGenerator(String dimensionName) + { super(dimensionName, 16); lock = new IrisLock("IrisChunkGenerator"); } - public IrisChunkGenerator(int tc) { + public IrisChunkGenerator(int tc) + { super("", tc); lock = new IrisLock("IrisChunkGenerator"); } - public void hotload() { + public void hotload() + { onHotload(); } - public void retry() { - if (failing) { + public void retry() + { + if(failing) + { failing = false; hotload(); } } @Override - protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) { + protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) + { lock.lock(); super.onGenerate(random, x, z, data, grid); lock.unlock(); } - public void onInit(World world, RNG rng) { - try { + public void onInit(World world, RNG rng) + { + try + { super.onInit(world, rng); } - catch (Throwable e) { + catch(Throwable e) + { fail(e); } } @Override - public BiomeResult getBiome(int x, int z) { + public BiomeResult getBiome(int x, int z) + { return sampleBiome(x, z); } @Override - public IrisRegion getRegion(int x, int z) { + public IrisRegion getRegion(int x, int z) + { return sampleRegion(x, z); } @Override - public int getHeight(int x, int z) { + public int getHeight(int x, int z) + { return sampleHeight(x, z); } @Override - public void onTick(int ticks) { + public void onTick(int ticks) + { super.onTick(ticks); - for (Player i : getWorld().getPlayers()) { + for(Player i : getWorld().getPlayers()) + { Location l = i.getLocation(); IrisRegion r = sampleRegion(l.getBlockX(), l.getBlockZ()); IrisBiome b = sampleTrueBiome(l.getBlockX(), l.getBlockY(), l.getBlockZ()).getBiome(); - for (IrisEffect j : r.getEffects()) { + for(IrisEffect j : r.getEffects()) + { j.apply(i, this); } - for (IrisEffect j : b.getEffects()) { + for(IrisEffect j : b.getEffects()) + { j.apply(i, this); } } } @Override - protected void onClose() { + protected void onClose() + { super.onClose(); - try { + try + { parallaxMap.saveAll(); ceilingParallaxMap.saveAll(); parallaxMap.getLoadedChunks().clear(); @@ -124,7 +145,8 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon ceilingParallaxMap.getLoadedRegions().clear(); } - catch (IOException e) { + catch(IOException e) + { e.printStackTrace(); } @@ -135,45 +157,61 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon } @Override - protected void onFailure(Throwable e) { + protected void onFailure(Throwable e) + { } @Override - protected void onChunkLoaded(Chunk c) { + protected void onChunkLoaded(Chunk c) + { } @Override - protected void onChunkUnloaded(Chunk c) { + protected void onChunkUnloaded(Chunk c) + { } @Override - protected void onPlayerJoin(Player p) { + protected void onPlayerJoin(Player p) + { } @Override - public void onPlayerLeft(Player p) { + public void onPlayerLeft(Player p) + { super.onPlayerLeft(p); } @Override - public void onHotloaded() { + public void onHotloaded() + { + if(!isHotloadable()) + { + Iris.warn("Hotload skipped (During Chunk Gen). Retrying."); + Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, this::onHotloaded); + return; + } + CNG.creates = 0; getData().dump(); onHotload(); } - public long guessMemoryUsage() { + public long guessMemoryUsage() + { long bytes = 1024 * 1024 * (8 + (getThreads() / 3)); - for (AtomicRegionData i : parallaxMap.getLoadedRegions().values()) { + for(AtomicRegionData i : parallaxMap.getLoadedRegions().values()) + { bytes += i.guessMemoryUsage(); } - for (AtomicRegionData i : ceilingParallaxMap.getLoadedRegions().values()) { + for(AtomicRegionData i : ceilingParallaxMap.getLoadedRegions().values()) + { bytes += i.guessMemoryUsage(); } @@ -186,34 +224,41 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon } @Override - public boolean shouldGenerateCaves() { + public boolean shouldGenerateCaves() + { return false; } @Override - public boolean shouldGenerateDecorations() { + public boolean shouldGenerateDecorations() + { return false; } @Override - public boolean shouldGenerateMobs() { + public boolean shouldGenerateMobs() + { return true; } @Override - public boolean shouldGenerateStructures() { - if (!isInitialized()) { + public boolean shouldGenerateStructures() + { + if(!isInitialized()) + { return false; } return getDimension().isVanillaStructures(); } - public Function2 createRenderer() { + public Function2 createRenderer() + { return (x, z) -> render(x, z); } - private Color render(double x, double z) { + private Color render(double x, double z) + { int ix = (int) x; int iz = (int) z; double height = getTerrainHeight(ix, iz); @@ -225,22 +270,24 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon shift -= shift2; float sat = 0; - if (hr.getLoadKey().equals(region.getLoadKey())) { + if(hr.getLoadKey().equals(region.getLoadKey())) + { sat += 0.2; } - if (hb.getLoadKey().equals(biome.getLoadKey())) { + if(hb.getLoadKey().equals(biome.getLoadKey())) + { sat += 0.3; } - Color c = Color.getHSBColor((biome.isLand() ? 0.233f : 0.644f) - shift, 0.25f + shift + sat, - (float) (Math.max(0, Math.min(height + getFluidHeight(), 255)) / 255)); + Color c = Color.getHSBColor((biome.isLand() ? 0.233f : 0.644f) - shift, 0.25f + shift + sat, (float) (Math.max(0, Math.min(height + getFluidHeight(), 255)) / 255)); return c; } - public String textFor(double x, double z) { + public String textFor(double x, double z) + { int ix = (int) x; int iz = (int) z; @@ -249,8 +296,6 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon IrisBiome biome = sampleTrueBiome(ix, iz, height).getBiome(); hb = biome; hr = region; - return biome.getName() + " (" - + Form.capitalizeWords(biome.getInferredType().name().toLowerCase().replaceAll("\\Q_\\E", " ") + ") in " - + region.getName() + "\nY: " + (int) height); + return biome.getName() + " (" + Form.capitalizeWords(biome.getInferredType().name().toLowerCase().replaceAll("\\Q_\\E", " ") + ") in " + region.getName() + "\nY: " + (int) height); } } diff --git a/src/main/java/com/volmit/iris/gen/layer/BiomeDataProvider.java b/src/main/java/com/volmit/iris/gen/layer/BiomeDataProvider.java index 95c01f602..5f913f494 100644 --- a/src/main/java/com/volmit/iris/gen/layer/BiomeDataProvider.java +++ b/src/main/java/com/volmit/iris/gen/layer/BiomeDataProvider.java @@ -4,7 +4,6 @@ import com.volmit.iris.gen.ContextualChunkGenerator; import com.volmit.iris.noise.CNG; import com.volmit.iris.object.InferredType; import com.volmit.iris.object.IrisRegion; -import com.volmit.iris.object.NoiseStyle; import com.volmit.iris.util.BiomeResult; import com.volmit.iris.util.RNG; @@ -21,7 +20,7 @@ public class BiomeDataProvider { this.type = type; this.layer = layer; - generator = NoiseStyle.CELLULAR_IRIS_DOUBLE.create(rng.nextParallelRNG(4645079 + (type.ordinal() * 23845))); + generator = layer.getIris().getDimension().getBiomeStyle(type).create(rng.nextParallelRNG(4645079 + (type.ordinal() * 23845))); } public BiomeResult generatePureData(ContextualChunkGenerator g, double bx, double bz, int rawX, int rawZ, IrisRegion regionData) diff --git a/src/main/java/com/volmit/iris/noise/CNG.java b/src/main/java/com/volmit/iris/noise/CNG.java index c7239e96a..1c6ea3ba7 100644 --- a/src/main/java/com/volmit/iris/noise/CNG.java +++ b/src/main/java/com/volmit/iris/noise/CNG.java @@ -8,19 +8,20 @@ import com.volmit.iris.util.KList; import com.volmit.iris.util.NoiseInjector; import com.volmit.iris.util.RNG; -public class CNG { +public class CNG +{ public static long hits = 0; public static long creates = 0; - public static final NoiseInjector ADD = (s, v) -> new double[] { s + v, 1 }; - public static final NoiseInjector SRC_SUBTRACT = (s, v) -> new double[] { s - v < 0 ? 0 : s - v, -1 }; - public static final NoiseInjector DST_SUBTRACT = (s, v) -> new double[] { v - s < 0 ? 0 : s - v, -1 }; - public static final NoiseInjector MULTIPLY = (s, v) -> new double[] { s * v, 0 }; - public static final NoiseInjector MAX = (s, v) -> new double[] { Math.max(s, v), 0 }; - public static final NoiseInjector MIN = (s, v) -> new double[] { Math.min(s, v), 0 }; - public static final NoiseInjector SRC_MOD = (s, v) -> new double[] { s % v, 0 }; - public static final NoiseInjector SRC_POW = (s, v) -> new double[] { Math.pow(s, v), 0 }; - public static final NoiseInjector DST_MOD = (s, v) -> new double[] { v % s, 0 }; - public static final NoiseInjector DST_POW = (s, v) -> new double[] { Math.pow(v, s), 0 }; + public static final NoiseInjector ADD = (s, v) -> new double[] {s + v, 1}; + public static final NoiseInjector SRC_SUBTRACT = (s, v) -> new double[] {s - v < 0 ? 0 : s - v, -1}; + public static final NoiseInjector DST_SUBTRACT = (s, v) -> new double[] {v - s < 0 ? 0 : s - v, -1}; + public static final NoiseInjector MULTIPLY = (s, v) -> new double[] {s * v, 0}; + public static final NoiseInjector MAX = (s, v) -> new double[] {Math.max(s, v), 0}; + public static final NoiseInjector MIN = (s, v) -> new double[] {Math.min(s, v), 0}; + public static final NoiseInjector SRC_MOD = (s, v) -> new double[] {s % v, 0}; + public static final NoiseInjector SRC_POW = (s, v) -> new double[] {Math.pow(s, v), 0}; + public static final NoiseInjector DST_MOD = (s, v) -> new double[] {v % s, 0}; + public static final NoiseInjector DST_POW = (s, v) -> new double[] {Math.pow(v, s), 0}; private double scale; private double bakedScale; private double fscale; @@ -36,31 +37,38 @@ public class CNG { private double down; private double power; - public NoiseGenerator getGen() { + public NoiseGenerator getGen() + { return generator; } - public static CNG signature(RNG rng) { + public static CNG signature(RNG rng) + { return signature(rng, NoiseType.SIMPLEX); } - public static CNG signatureHalf(RNG rng) { + public static CNG signatureHalf(RNG rng) + { return signatureHalf(rng, NoiseType.SIMPLEX); } - public static CNG signatureThick(RNG rng) { + public static CNG signatureThick(RNG rng) + { return signatureThick(rng, NoiseType.SIMPLEX); } - public static CNG signatureDouble(RNG rng) { + public static CNG signatureDouble(RNG rng) + { return signatureDouble(rng, NoiseType.SIMPLEX); } - public static CNG signatureDouble(RNG rng, NoiseType t) { + public static CNG signatureDouble(RNG rng, NoiseType t) + { return signatureThick(rng, t).fractureWith(signature(rng.nextParallelRNG(4956)), 93); } - public static CNG signature(RNG rng, NoiseType t) { + public static CNG signature(RNG rng, NoiseType t) + { // @builder return new CNG(rng.nextParallelRNG(17), t, 1D, 1) .fractureWith( @@ -72,7 +80,8 @@ public class CNG { // @done } - public static CNG signatureThick(RNG rng, NoiseType t) { + public static CNG signatureThick(RNG rng, NoiseType t) + { // @builder return new CNG(rng.nextParallelRNG(133), t, 1D, 1) .fractureWith( @@ -84,7 +93,8 @@ public class CNG { // @done } - public static CNG signatureHalf(RNG rng, NoiseType t) { + public static CNG signatureHalf(RNG rng, NoiseType t) + { // @builder return new CNG(rng.nextParallelRNG(127), t, 1D, 1) .fractureWith( @@ -96,19 +106,23 @@ public class CNG { // @done } - public CNG(RNG random) { + public CNG(RNG random) + { this(random, 1); } - public CNG(RNG random, int octaves) { + public CNG(RNG random, int octaves) + { this(random, 1D, octaves); } - public CNG(RNG random, double opacity, int octaves) { + public CNG(RNG random, double opacity, int octaves) + { this(random, NoiseType.SIMPLEX, opacity, octaves); } - public CNG(RNG random, NoiseType t, double opacity, int octaves) { + public CNG(RNG random, NoiseType t, double opacity, int octaves) + { creates++; this.oct = octaves; this.rng = random; @@ -124,19 +138,23 @@ public class CNG { this.opacity = opacity; this.injector = ADD; - if (generator instanceof OctaveNoise) { + if(generator instanceof OctaveNoise) + { ((OctaveNoise) generator).setOctaves(octaves); } } - public CNG bake() { + public CNG bake() + { bakedScale *= scale; scale = 1; return this; } - public CNG child(CNG c) { - if (children == null) { + public CNG child(CNG c) + { + if(children == null) + { children = new KList<>(); } @@ -145,114 +163,141 @@ public class CNG { } @Deprecated - public RNG nextRNG() { + public RNG nextRNG() + { return getRNG().nextRNG(); } - public RNG getRNG() { + public RNG getRNG() + { return rng; } - public CNG fractureWith(CNG c, double scale) { + public CNG fractureWith(CNG c, double scale) + { fracture = c; fscale = scale; return this; } - public CNG scale(double c) { + public CNG scale(double c) + { scale = c; return this; } - public CNG patch(double c) { + public CNG patch(double c) + { patch = c; return this; } - public CNG up(double c) { + public CNG up(double c) + { up = c; return this; } - public CNG down(double c) { + public CNG down(double c) + { down = c; return this; } - public CNG injectWith(NoiseInjector i) { + public CNG injectWith(NoiseInjector i) + { injector = i; return this; } - public T fitRarity(KList b, double... dim) { - if (b.size() == 0) { + public T fitRarity(KList b, double... dim) + { + if(b.size() == 0) + { return null; } - if (b.size() == 1) { + if(b.size() == 1) + { return b.get(0); } KList rarityMapped = new KList<>(); boolean o = false; int max = 1; - for (T i : b) { - if (i.getRarity() > max) { + for(T i : b) + { + if(i.getRarity() > max) + { max = i.getRarity(); } } max++; - for (T i : b) { - for (int j = 0; j < max - i.getRarity(); j++) { - if (o = !o) { + for(T i : b) + { + for(int j = 0; j < max - i.getRarity(); j++) + { + if(o = !o) + { rarityMapped.add(i); } - else { + else + { rarityMapped.add(0, i); } } } - if (rarityMapped.size() == 1) { + if(rarityMapped.size() == 1) + { return rarityMapped.get(0); } - if (rarityMapped.isEmpty()) { + if(rarityMapped.isEmpty()) + { throw new RuntimeException("BAD RARITY MAP! RELATED TO: " + b.toString(", or possibly ")); } return fit(rarityMapped, dim); } - public T fit(T[] v, double... dim) { - if (v.length == 0) { + public T fit(T[] v, double... dim) + { + if(v.length == 0) + { return null; } - if (v.length == 1) { + if(v.length == 1) + { return v[0]; } return v[fit(0, v.length - 1, dim)]; } - public T fit(List v, double... dim) { - if (v.size() == 0) { + public T fit(List v, double... dim) + { + if(v.size() == 0) + { return null; } - if (v.size() == 1) { + if(v.size() == 1) + { return v.get(0); } return v.get(fit(0, v.size() - 1, dim)); } - public int fit(int min, int max, double... dim) { - if (min == max) { + public int fit(int min, int max, double... dim) + { + if(min == max) + { return min; } @@ -261,8 +306,10 @@ public class CNG { return (int) Math.round(IrisInterpolation.lerp(min, max, noise)); } - public int fit(double min, double max, double... dim) { - if (min == max) { + public int fit(double min, double max, double... dim) + { + if(min == max) + { return (int) Math.round(min); } @@ -271,8 +318,10 @@ public class CNG { return (int) Math.round(IrisInterpolation.lerp(min, max, noise)); } - public double fitDouble(double min, double max, double... dim) { - if (min == max) { + public double fitDouble(double min, double max, double... dim) + { + if(min == max) + { return min; } @@ -281,21 +330,24 @@ public class CNG { return IrisInterpolation.lerp(min, max, noise); } - public double noise(double... dim) { + public double noise(double... dim) + { double scale = this.bakedScale * this.scale; - double f = fracture != null ? (fracture.noise(dim) - 0.5) * fscale : 0D; + double f = (fracture != null ? (fracture.noise(dim) - 0.5) * fscale : 0D); double x = dim.length > 0 ? dim[0] + f : 0D; - double y = dim.length > 1 ? dim[1] - f : 0D; - double z = dim.length > 2 ? dim[2] + f : 0D; + double z = dim.length > 1 ? dim[1] - f : 0D; + double y = dim.length > 2 ? dim[2] + f : 0D; double n = generator.noise(x * scale, y * scale, z * scale) * opacity; n = power != 1D ? Math.pow(n, power) : n; double m = 1; hits += oct; - if (children == null) { + if(children == null) + { return (n - down + up) * patch; } - for (CNG i : children) { + for(CNG i : children) + { double[] r = injector.combine(n, i.noise(dim)); n = r[0]; m += r[1]; @@ -304,17 +356,20 @@ public class CNG { return ((n / m) - down + up) * patch; } - public CNG pow(double power) { + public CNG pow(double power) + { this.power = power; return this; } - public CNG oct(int octaves) { + public CNG oct(int octaves) + { oct = octaves; return this; } - public double getScale() { + public double getScale() + { return scale; } } diff --git a/src/main/java/com/volmit/iris/object/IrisBiome.java b/src/main/java/com/volmit/iris/object/IrisBiome.java index edfcb44db..d131bfd21 100644 --- a/src/main/java/com/volmit/iris/object/IrisBiome.java +++ b/src/main/java/com/volmit/iris/object/IrisBiome.java @@ -26,7 +26,8 @@ import lombok.EqualsAndHashCode; @Desc("Represents a biome in iris. Biomes are placed inside of regions and hold objects.") @Data @EqualsAndHashCode(callSuper = false) -public class IrisBiome extends IrisRegistrant implements IRare { +public class IrisBiome extends IrisRegistrant implements IRare +{ @MinNumber(2) @Required @DontObfuscate @@ -39,13 +40,13 @@ public class IrisBiome extends IrisRegistrant implements IRare { private KList effects = new KList<>(); @DontObfuscate - @DependsOn({ "biomeStyle", "biomeZoom", "biomeScatter" }) + @DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"}) @Desc("This changes the dispersion of the biome colors if multiple derivatives are chosen.") private IrisGeneratorStyle biomeStyle = NoiseStyle.SIMPLEX.style(); @MinNumber(0.0001) @DontObfuscate - @DependsOn({ "biomeStyle", "biomeZoom", "biomeScatter" }) + @DependsOn({"biomeStyle", "biomeZoom", "biomeScatter"}) @Desc("This zooms in the biome colors if multiple derivatives are chosen") private double biomeZoom = 1; @@ -75,12 +76,12 @@ public class IrisBiome extends IrisRegistrant implements IRare { private KList biomeSkyScatter = new KList<>(); @DontObfuscate - @DependsOn({ "children" }) + @DependsOn({"children"}) @Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, how much smaller will it be (inside of this biome). Higher values means a smaller biome relative to this biome's size. Set higher than 1.0 and below 3.0 for best results.") private double childShrinkFactor = 1.5; @DontObfuscate - @DependsOn({ "children" }) + @DependsOn({"children"}) @Desc("If this biome has children biomes, and the gen layer chooses one of this biomes children, How will it be shaped?") private IrisGeneratorStyle childStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); @@ -122,8 +123,7 @@ public class IrisBiome extends IrisRegistrant implements IRare { @ArrayType(min = 1, type = IrisBiomeGeneratorLink.class) @DontObfuscate @Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.") - private KList generators = new KList() - .qadd(new IrisBiomeGeneratorLink()); + private KList generators = new KList().qadd(new IrisBiomeGeneratorLink()); @ArrayType(min = 1, type = IrisStructurePlacement.class) @DontObfuscate @@ -143,67 +143,80 @@ public class IrisBiome extends IrisRegistrant implements IRare { private transient AtomicCache> layerHeightGenerators = new AtomicCache<>(); private transient AtomicCache> layerSeaHeightGenerators = new AtomicCache<>(); - public IrisBiome() { + public IrisBiome() + { } - public double getHeight(ContextualChunkGenerator xg, double x, double z, long seed) { + public double getHeight(ContextualChunkGenerator xg, double x, double z, long seed) + { double height = 0; - for (IrisBiomeGeneratorLink i : generators) { + for(IrisBiomeGeneratorLink i : generators) + { height += i.getHeight(xg, x, z, seed); } return Math.max(0, Math.min(height, 255)); } - public CNG getBiomeGenerator(RNG random) { - return biomeGenerator.aquire(() -> { + public CNG getBiomeGenerator(RNG random) + { + return biomeGenerator.aquire(() -> + { return biomeStyle.create(random.nextParallelRNG(213949 + 228888 + getRarity() + getName().length())); }); } - public CNG getChildrenGenerator(RNG random, int sig, double scale) { - return childrenCell - .aquire(() -> getChildStyle().create(random.nextParallelRNG(sig * 2137)).bake().scale(scale).bake()); + public CNG getChildrenGenerator(RNG random, int sig, double scale) + { + return childrenCell.aquire(() -> getChildStyle().create(random.nextParallelRNG(sig * 2137)).bake().scale(scale).bake()); } - public KList generateLayers(double wx, double wz, RNG random, int maxDepth, int height) { - if (isLockLayers()) { + public KList generateLayers(double wx, double wz, RNG random, int maxDepth, int height) + { + if(isLockLayers()) + { return generateLockedLayers(wx, wz, random, maxDepth, height); } KList data = new KList<>(); - if (maxDepth <= 0) { + if(maxDepth <= 0) + { return data; } - for (int i = 0; i < layers.size(); i++) { + for(int i = 0; i < layers.size(); i++) + { CNG hgen = getLayerHeightGenerators(random).get(i); - int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(), - wz / layers.get(i).getZoom()); + int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(), wz / layers.get(i).getZoom()); - if (d < 0) { + if(d < 0) + { continue; } - for (int j = 0; j < d; j++) { - if (data.size() >= maxDepth) { + for(int j = 0; j < d; j++) + { + if(data.size() >= maxDepth) + { break; } - try { - data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(), - j, (wz - j) / layers.get(i).getZoom())); + try + { + data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(), j, (wz - j) / layers.get(i).getZoom())); } - catch (Throwable e) { + catch(Throwable e) + { e.printStackTrace(); } } - if (data.size() >= maxDepth) { + if(data.size() >= maxDepth) + { break; } } @@ -211,40 +224,47 @@ public class IrisBiome extends IrisRegistrant implements IRare { return data; } - public KList generateLockedLayers(double wx, double wz, RNG random, int maxDepth, int height) { + public KList generateLockedLayers(double wx, double wz, RNG random, int maxDepth, int height) + { KList data = new KList<>(); KList real = new KList<>(); - if (maxDepth <= 0) { + if(maxDepth <= 0) + { return data; } - for (int i = 0; i < layers.size(); i++) { + for(int i = 0; i < layers.size(); i++) + { CNG hgen = getLayerHeightGenerators(random).get(i); - int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(), - wz / layers.get(i).getZoom()); + int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(), wz / layers.get(i).getZoom()); - if (d < 0) { + if(d < 0) + { continue; } - for (int j = 0; j < d; j++) { - try { - data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(), - j, (wz - j) / layers.get(i).getZoom())); + for(int j = 0; j < d; j++) + { + try + { + data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(), j, (wz - j) / layers.get(i).getZoom())); } - catch (Throwable e) { + catch(Throwable e) + { e.printStackTrace(); } } } - if (data.isEmpty()) { + if(data.isEmpty()) + { return real; } - for (int i = 0; i < maxDepth; i++) { + for(int i = 0; i < maxDepth; i++) + { int offset = (getMaxHeight() - height) - i; int index = offset % data.size(); real.add(data.get(index < 0 ? 0 : index)); @@ -253,11 +273,14 @@ public class IrisBiome extends IrisRegistrant implements IRare { return real; } - private int getMaxHeight() { - return maxHeight.aquire(() -> { + private int getMaxHeight() + { + return maxHeight.aquire(() -> + { int maxHeight = 0; - for (IrisBiomeGeneratorLink i : getGenerators()) { + for(IrisBiomeGeneratorLink i : getGenerators()) + { maxHeight += i.getMax(); } @@ -265,39 +288,46 @@ public class IrisBiome extends IrisRegistrant implements IRare { }); } - public IrisBiome infer(InferredType t, InferredType type) { + public IrisBiome infer(InferredType t, InferredType type) + { setInferredType(t.equals(InferredType.DEFER) ? type : t); return this; } - public KList generateSeaLayers(double wx, double wz, RNG random, int maxDepth) { + public KList generateSeaLayers(double wx, double wz, RNG random, int maxDepth) + { KList data = new KList<>(); - for (int i = 0; i < seaLayers.size(); i++) { + for(int i = 0; i < seaLayers.size(); i++) + { CNG hgen = getLayerSeaHeightGenerators(random).get(i); - int d = hgen.fit(seaLayers.get(i).getMinHeight(), seaLayers.get(i).getMaxHeight(), - wx / seaLayers.get(i).getZoom(), wz / seaLayers.get(i).getZoom()); + int d = hgen.fit(seaLayers.get(i).getMinHeight(), seaLayers.get(i).getMaxHeight(), wx / seaLayers.get(i).getZoom(), wz / seaLayers.get(i).getZoom()); - if (d < 0) { + if(d < 0) + { continue; } - for (int j = 0; j < d; j++) { - if (data.size() >= maxDepth) { + for(int j = 0; j < d; j++) + { + if(data.size() >= maxDepth) + { break; } - try { - data.add(getSeaLayers().get(i).get(random.nextParallelRNG(i + j), - (wx + j) / seaLayers.get(i).getZoom(), j, (wz - j) / seaLayers.get(i).getZoom())); + try + { + data.add(getSeaLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / seaLayers.get(i).getZoom(), j, (wz - j) / seaLayers.get(i).getZoom())); } - catch (Throwable e) { + catch(Throwable e) + { e.printStackTrace(); } } - if (data.size() >= maxDepth) { + if(data.size() >= maxDepth) + { break; } } @@ -305,13 +335,16 @@ public class IrisBiome extends IrisRegistrant implements IRare { return data; } - public KList getLayerHeightGenerators(RNG rng) { - return layerHeightGenerators.aquire(() -> { + public KList getLayerHeightGenerators(RNG rng) + { + return layerHeightGenerators.aquire(() -> + { KList layerHeightGenerators = new KList<>(); int m = 7235; - for (IrisBiomePaletteLayer i : getLayers()) { + for(IrisBiomePaletteLayer i : getLayers()) + { layerHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m))); } @@ -319,13 +352,16 @@ public class IrisBiome extends IrisRegistrant implements IRare { }); } - public KList getLayerSeaHeightGenerators(RNG rng) { - return layerSeaHeightGenerators.aquire(() -> { + public KList getLayerSeaHeightGenerators(RNG rng) + { + return layerSeaHeightGenerators.aquire(() -> + { KList layerSeaHeightGenerators = new KList<>(); int m = 7735; - for (IrisBiomePaletteLayer i : getSeaLayers()) { + for(IrisBiomePaletteLayer i : getSeaLayers()) + { layerSeaHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m))); } @@ -333,45 +369,57 @@ public class IrisBiome extends IrisRegistrant implements IRare { }); } - public boolean isLand() { - if (inferredType == null) { + public boolean isLand() + { + if(inferredType == null) + { return true; } return inferredType.equals(InferredType.LAND); } - public boolean isSea() { - if (inferredType == null) { + public boolean isSea() + { + if(inferredType == null) + { return false; } return inferredType.equals(InferredType.SEA); } - public boolean isShore() { - if (inferredType == null) { + public boolean isShore() + { + if(inferredType == null) + { return false; } return inferredType.equals(InferredType.SHORE); } - public Biome getSkyBiome(RNG rng, double x, double y, double z) { - if (biomeSkyScatter.size() == 1) { + public Biome getSkyBiome(RNG rng, double x, double y, double z) + { + if(biomeSkyScatter.size() == 1) + { return biomeSkyScatter.get(0); } - if (biomeSkyScatter.isEmpty()) { + if(biomeSkyScatter.isEmpty()) + { return getGroundBiome(rng, x, y, z); } return biomeSkyScatter.get(getBiomeGenerator(rng).fit(0, biomeSkyScatter.size() - 1, x, y, z)); } - public KList getRealChildren(ContextualChunkGenerator g) { - return realChildren.aquire(() -> { + public KList getRealChildren(ContextualChunkGenerator g) + { + return realChildren.aquire(() -> + { KList realChildren = new KList<>(); - for (String i : getChildren()) { + for(String i : getChildren()) + { realChildren.add(g != null ? g.loadBiome(i) : Iris.globaldata.getBiomeLoader().load(i)); } @@ -379,13 +427,16 @@ public class IrisBiome extends IrisRegistrant implements IRare { }); } - public KList getAllChildren(ContextualChunkGenerator g, int limit) { + public KList getAllChildren(ContextualChunkGenerator g, int limit) + { KSet m = new KSet<>(); m.addAll(getChildren()); limit--; - if (limit > 0) { - for (String i : getChildren()) { + if(limit > 0) + { + for(String i : getChildren()) + { IrisBiome b = g != null ? g.loadBiome(i) : Iris.globaldata.getBiomeLoader().load(i); int l = limit; m.addAll(b.getAllChildren(g, l)); @@ -395,12 +446,15 @@ public class IrisBiome extends IrisRegistrant implements IRare { return new KList(m); } - public Biome getGroundBiome(RNG rng, double x, double y, double z) { - if (biomeSkyScatter.isEmpty()) { + public Biome getGroundBiome(RNG rng, double x, double y, double z) + { + if(biomeSkyScatter.isEmpty()) + { return getDerivative(); } - if (biomeScatter.size() == 1) { + if(biomeScatter.size() == 1) + { return biomeScatter.get(0); } diff --git a/src/main/java/com/volmit/iris/object/IrisBiomeDecorator.java b/src/main/java/com/volmit/iris/object/IrisBiomeDecorator.java index ba312dcf5..a56bd84fe 100644 --- a/src/main/java/com/volmit/iris/object/IrisBiomeDecorator.java +++ b/src/main/java/com/volmit/iris/object/IrisBiomeDecorator.java @@ -20,14 +20,15 @@ import lombok.Data; @Desc("A biome decorator is used for placing flowers, grass, cacti and so on") @Data -public class IrisBiomeDecorator { +public class IrisBiomeDecorator +{ @DontObfuscate @Desc("The varience dispersion is used when multiple blocks are put in the palette. Scatter scrambles them, Wispy shows streak-looking varience") private IrisGeneratorStyle variance = NoiseStyle.STATIC.style(); @DontObfuscate @Desc("Dispersion is used to pick places to spawn. Scatter randomly places them (vanilla) or Wispy for a streak like patch system.") - private IrisGeneratorStyle dispersion = NoiseStyle.STATIC.style(); + private IrisGeneratorStyle style = NoiseStyle.STATIC.style(); @DependsOn({"stackMin", "stackMax"}) @DontObfuscate @@ -86,64 +87,78 @@ public class IrisBiomeDecorator { private transient AtomicCache heightGenerator = new AtomicCache<>(); private transient AtomicCache> blockData = new AtomicCache<>(); - public int getHeight(RNG rng, double x, double z) { - if (stackMin == stackMax) { + public int getHeight(RNG rng, double x, double z) + { + if(stackMin == stackMax) + { return stackMin; } return getHeightGenerator(rng).fit(stackMin, stackMax, x / verticalZoom, z / verticalZoom); } - public CNG getHeightGenerator(RNG rng) { - return heightGenerator.aquire(() -> { + public CNG getHeightGenerator(RNG rng) + { + return heightGenerator.aquire(() -> + { return heightVariance.create(rng.nextParallelRNG(getBlockData().size() + stackMax + stackMin)); }); } - public CNG getGenerator(RNG rng) { + public CNG getGenerator(RNG rng) + { long key = rng.nextParallelRNG(1).nextLong(); - if (layerGenerators == null) { + if(layerGenerators == null) + { layerGenerators = new KMap<>(); } - if (!layerGenerators.containsKey(key)) { - layerGenerators.put(key, dispersion.create(rng.nextParallelRNG((int) (getBlockData().size() + key)))); + if(!layerGenerators.containsKey(key)) + { + layerGenerators.put(key, style.create(rng.nextParallelRNG((int) (getBlockData().size() + key)))); } return layerGenerators.get(key); } - public CNG getVarianceGenerator(RNG rng) { + public CNG getVarianceGenerator(RNG rng) + { long key = rng.nextParallelRNG(4).nextLong(); - if (layerVarianceGenerators == null) { + if(layerVarianceGenerators == null) + { layerVarianceGenerators = new KMap<>(); } - if (!layerVarianceGenerators.containsKey(key)) { - layerVarianceGenerators.put(key, - variance.create(rng.nextParallelRNG((int) (getBlockData().size() + key))).scale(1D / varianceZoom)); + if(!layerVarianceGenerators.containsKey(key)) + { + layerVarianceGenerators.put(key, variance.create(rng.nextParallelRNG((int) (getBlockData().size() + key))).scale(1D / varianceZoom)); } return layerVarianceGenerators.get(key); } - public KList add(String b) { + public KList add(String b) + { palette.add(b); return palette; } - public BlockData getBlockData(RNG rng, double x, double z) { - if (getGenerator(rng) == null) { + public BlockData getBlockData(RNG rng, double x, double z) + { + if(getGenerator(rng) == null) + { return null; } - if (getBlockData() == null) { + if(getBlockData() == null) + { return null; } - if (getBlockData().isEmpty()) { + if(getBlockData().isEmpty()) + { return null; } @@ -152,8 +167,10 @@ public class IrisBiomeDecorator { xx /= getZoom(); zz /= getZoom(); - if (getGenerator(rng).fitDouble(0D, 1D, xx, zz) <= chance) { - if (getBlockData().size() == 1) { + if(getGenerator(rng).fitDouble(0D, 1D, xx, zz) <= chance) + { + if(getBlockData().size() == 1) + { return getBlockData().get(0); } @@ -163,12 +180,16 @@ public class IrisBiomeDecorator { return null; } - public KList getBlockData() { - return blockData.aquire(() -> { + public KList getBlockData() + { + return blockData.aquire(() -> + { KList blockData = new KList<>(); - for (String i : palette) { + for(String i : palette) + { BlockData bx = B.getBlockData(i); - if (bx != null) { + if(bx != null) + { blockData.add(bx); } } diff --git a/src/main/java/com/volmit/iris/object/IrisDimension.java b/src/main/java/com/volmit/iris/object/IrisDimension.java index 4ed3a1f61..99efbaf9f 100644 --- a/src/main/java/com/volmit/iris/object/IrisDimension.java +++ b/src/main/java/com/volmit/iris/object/IrisDimension.java @@ -29,7 +29,8 @@ import lombok.EqualsAndHashCode; @Desc("Represents a dimension") @Data @EqualsAndHashCode(callSuper = false) -public class IrisDimension extends IrisRegistrant { +public class IrisDimension extends IrisRegistrant +{ public static final BlockData STONE = Material.STONE.createBlockData(); public static final BlockData WATER = Material.WATER.createBlockData(); @@ -66,8 +67,28 @@ public class IrisDimension extends IrisRegistrant { private IrisGeneratorStyle continentalStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); @DontObfuscate - @Desc("The placement style of land/sea") - private IrisGeneratorStyle coordinateFracture = NoiseStyle.FLAT.style(); + @Desc("The placement style of biomes") + private IrisGeneratorStyle landBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + + @DontObfuscate + @Desc("The placement style of biomes") + private IrisGeneratorStyle shoreBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + + @DontObfuscate + @Desc("The placement style of biomes") + private IrisGeneratorStyle seaBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + + @DontObfuscate + @Desc("The placement style of biomes") + private IrisGeneratorStyle caveBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + + @DontObfuscate + @Desc("The placement style of biomes") + private IrisGeneratorStyle islandBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); + + @DontObfuscate + @Desc("The placement style of biomes") + private IrisGeneratorStyle skylandBiomeStyle = NoiseStyle.CELLULAR_IRIS_DOUBLE.style(); @MinNumber(-256) @MaxNumber(256) @@ -277,29 +298,33 @@ public class IrisDimension extends IrisRegistrant { private transient AtomicCache rad = new AtomicCache<>(); private transient boolean inverted = false; - public KList getPostBlockProcessors(PostBlockChunkGenerator g) { - return cacheFilters.aquire(() -> { + public KList getPostBlockProcessors(PostBlockChunkGenerator g) + { + return cacheFilters.aquire(() -> + { KList cacheFilters = new KList<>(); - for (IrisPostProcessor i : getPostProcessors()) { + for(IrisPostProcessor i : getPostProcessors()) + { cacheFilters.add(g.createProcessor(i.getProcessor(), i.getPhase())); } g.setMinPhase(0); g.setMaxPhase(0); - for (IrisPostBlockFilter i : cacheFilters) { + for(IrisPostBlockFilter i : cacheFilters) + { g.setMinPhase(Math.min(g.getMinPhase(), i.getPhase())); g.setMaxPhase(Math.max(g.getMaxPhase(), i.getPhase())); } - Iris.info("Post Processing: " + cacheFilters.size() + " filters. Phases: " + g.getMinPhase() + " - " - + g.getMaxPhase()); + Iris.info("Post Processing: " + cacheFilters.size() + " filters. Phases: " + g.getMinPhase() + " - " + g.getMaxPhase()); return cacheFilters; }); } - public static KList getDefaultCompatability() { + public static KList getDefaultCompatability() + { KList filters = new KList<>(); // Below 1.16 @@ -438,15 +463,18 @@ public class IrisDimension extends IrisRegistrant { return filters; } - public CNG getCoordFracture(RNG rng, int signature) { - return coordFracture.aquire(() -> { + public CNG getCoordFracture(RNG rng, int signature) + { + return coordFracture.aquire(() -> + { CNG coordFracture = CNG.signature(rng.nextParallelRNG(signature)); coordFracture.scale(0.012 / coordFractureZoom); return coordFracture; }); } - private KList getDefaultPostProcessors() { + private KList getDefaultPostProcessors() + { KList p = new KList(); p.add(new IrisPostProcessor("wall-painter")); @@ -456,32 +484,40 @@ public class IrisDimension extends IrisRegistrant { return p; } - public BlockData getRock(RNG rng, double x, double y, double z) { - if (getRockData().isEmpty()) { + public BlockData getRock(RNG rng, double x, double y, double z) + { + if(getRockData().isEmpty()) + { return STONE; } - if (getRockData().size() == 1) { + if(getRockData().size() == 1) + { return getRockData().get(0); } return getRockGenerator(rng).fit(getRockData(), x, y, z); } - public CNG getRockGenerator(RNG rng) { - return rockLayerGenerator.aquire(() -> { - RNG rngx = rng.nextParallelRNG( - (int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357)); + public CNG getRockGenerator(RNG rng) + { + return rockLayerGenerator.aquire(() -> + { + RNG rngx = rng.nextParallelRNG((int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357)); return rockStyle.create(rngx); }); } - public KList getRockData() { - return rockData.aquire(() -> { + public KList getRockData() + { + return rockData.aquire(() -> + { KList rockData = new KList<>(); - for (String ix : rockPalette) { + for(String ix : rockPalette) + { BlockData bx = B.getBlockData(ix); - if (bx != null) { + if(bx != null) + { rockData.add(bx); } } @@ -490,32 +526,40 @@ public class IrisDimension extends IrisRegistrant { }); } - public BlockData getFluid(RNG rng, double x, double y, double z) { - if (getFluidData().isEmpty()) { + public BlockData getFluid(RNG rng, double x, double y, double z) + { + if(getFluidData().isEmpty()) + { return WATER; } - if (getFluidData().size() == 1) { + if(getFluidData().size() == 1) + { return getFluidData().get(0); } return getFluidGenerator(rng).fit(getFluidData(), x, y, z); } - public CNG getFluidGenerator(RNG rng) { - return fluidLayerGenerator.aquire(() -> { - RNG rngx = rng.nextParallelRNG(getFluidData().size() - * (int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357)); + public CNG getFluidGenerator(RNG rng) + { + return fluidLayerGenerator.aquire(() -> + { + RNG rngx = rng.nextParallelRNG(getFluidData().size() * (int) (getRockData().size() * getRegions().size() * getCaveScale() * getLandZoom() * 10357)); return fluidStyle.create(rngx); }); } - public KList getFluidData() { - return fluidData.aquire(() -> { + public KList getFluidData() + { + return fluidData.aquire(() -> + { KList fluidData = new KList<>(); - for (String ix : fluidPalette) { + for(String ix : fluidPalette) + { BlockData bx = B.getBlockData(ix); - if (bx != null) { + if(bx != null) + { fluidData.add(bx); } } @@ -524,40 +568,49 @@ public class IrisDimension extends IrisRegistrant { }); } - public double getDimensionAngle() { + public double getDimensionAngle() + { return rad.aquire(() -> Math.toRadians(dimensionAngleDeg)); } - public double sinRotate() { + public double sinRotate() + { return sinr.aquire(() -> Math.sin(getDimensionAngle())); } - public double cosRotate() { + public double cosRotate() + { return cosr.aquire(() -> Math.cos(getDimensionAngle())); } - public KList getAllRegions(ContextualChunkGenerator g) { + public KList getAllRegions(ContextualChunkGenerator g) + { KList r = new KList<>(); - for (String i : getRegions()) { + for(String i : getRegions()) + { r.add(g != null ? g.loadRegion(i) : Iris.globaldata.getRegionLoader().load(i)); } return r; } - public KList getAllBiomes(ContextualChunkGenerator g) { + public KList getAllBiomes(ContextualChunkGenerator g) + { KList r = new KList<>(); - for (IrisRegion i : getAllRegions(g)) { + for(IrisRegion i : getAllRegions(g)) + { r.addAll(i.getAllBiomes(g)); } return r; } - public ChunkPosition getParallaxSize(ContextualChunkGenerator g) { - return parallaxSize.aquire(() -> { + public ChunkPosition getParallaxSize(ContextualChunkGenerator g) + { + return parallaxSize.aquire(() -> + { int x = 0; int z = 0; @@ -565,40 +618,50 @@ public class IrisDimension extends IrisRegistrant { KList r = getAllRegions(g); KList b = getAllBiomes(g); - for (IrisBiome i : b) { - for (IrisObjectPlacement j : i.getObjects()) { + for(IrisBiome i : b) + { + for(IrisObjectPlacement j : i.getObjects()) + { objects.addAll(j.getPlace()); } } - for (String i : objects) { - try { + for(String i : objects) + { + try + { BlockVector bv = IrisObject.sampleSize(g.getData().getObjectLoader().findFile(i)); x = bv.getBlockX() > x ? bv.getBlockX() : x; z = bv.getBlockZ() > z ? bv.getBlockZ() : z; } - catch (Throwable e) { + catch(Throwable e) + { } } - for (IrisDepositGenerator i : getDeposits()) { + for(IrisDepositGenerator i : getDeposits()) + { int max = i.getMaxDimension(); x = max > x ? max : x; z = max > z ? max : z; } - for (IrisRegion v : r) { - for (IrisDepositGenerator i : v.getDeposits()) { + for(IrisRegion v : r) + { + for(IrisDepositGenerator i : v.getDeposits()) + { int max = i.getMaxDimension(); x = max > x ? max : x; z = max > z ? max : z; } } - for (IrisBiome v : b) { - for (IrisDepositGenerator i : v.getDeposits()) { + for(IrisBiome v : b) + { + for(IrisDepositGenerator i : v.getDeposits()) + { int max = i.getMaxDimension(); x = max > x ? max : x; z = max > z ? max : z; @@ -614,13 +677,39 @@ public class IrisDimension extends IrisRegistrant { }); } - public BlockData resolve(String bd) { - for (IrisCompatabilityFilter i : getCompatability()) { - if (i.getWhen().equalsIgnoreCase(bd)) { + public BlockData resolve(String bd) + { + for(IrisCompatabilityFilter i : getCompatability()) + { + if(i.getWhen().equalsIgnoreCase(bd)) + { return i.getReplace(); } } return null; } + + public IrisGeneratorStyle getBiomeStyle(InferredType type) + { + switch(type) + { + case CAVE: + return caveBiomeStyle; + case ISLAND: + return islandBiomeStyle; + case LAND: + return landBiomeStyle; + case SEA: + return seaBiomeStyle; + case SHORE: + return shoreBiomeStyle; + case SKYLAND: + return skylandBiomeStyle; + default: + break; + } + + return landBiomeStyle; + } } diff --git a/src/main/java/com/volmit/iris/util/ResourceLoader.java b/src/main/java/com/volmit/iris/util/ResourceLoader.java index 2df6da8a2..bcda74e60 100644 --- a/src/main/java/com/volmit/iris/util/ResourceLoader.java +++ b/src/main/java/com/volmit/iris/util/ResourceLoader.java @@ -9,7 +9,8 @@ import com.volmit.iris.object.IrisRegistrant; import lombok.Data; @Data -public class ResourceLoader { +public class ResourceLoader +{ protected File root; protected String folderName; protected String resourceTypeName; @@ -21,7 +22,8 @@ public class ResourceLoader { protected IrisLock lock; protected String preferredFolder = null; - public ResourceLoader(File root, String folderName, String resourceTypeName, Class objectClass) { + public ResourceLoader(File root, String folderName, String resourceTypeName, Class objectClass) + { lock = new IrisLock("Res"); folderMapCache = new KMap<>(); this.objectClass = objectClass; @@ -32,12 +34,15 @@ public class ResourceLoader { loadCache = new KMap<>(); } - public long count() { + public long count() + { return loadCache.size(); } - protected T loadFile(File j, String key, String name) { - try { + protected T loadFile(File j, String key, String name) + { + try + { T t = new Gson().fromJson(IO.readAll(j), objectClass); loadCache.put(key, t); Iris.hotloader.track(j); @@ -48,32 +53,39 @@ public class ResourceLoader { return t; } - catch (Throwable e) { + catch(Throwable e) + { lock.unlock(); Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage()); return null; } } - public T load(String name) { + public T load(String name) + { String key = name + "-" + cname; - if (loadCache.containsKey(key)) { + if(loadCache.containsKey(key)) + { T t = loadCache.get(key); return t; } lock.lock(); - for (File i : getFolders(name)) { - for (File j : i.listFiles()) { - if (j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name)) { + for(File i : getFolders(name)) + { + for(File j : i.listFiles()) + { + if(j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name)) + { return loadFile(j, key, name); } } File file = new File(i, name + ".json"); - if (file.exists()) { + if(file.exists()) + { return loadFile(file, key, name); } } @@ -84,15 +96,21 @@ public class ResourceLoader { return null; } - public KList getFolders() { + public KList getFolders() + { lock.lock(); - if (folderCache == null) { + if(folderCache == null) + { folderCache = new KList<>(); - for (File i : root.listFiles()) { - if (i.isDirectory()) { - for (File j : i.listFiles()) { - if (j.isDirectory() && j.getName().equals(folderName)) { + for(File i : root.listFiles()) + { + if(i.isDirectory()) + { + for(File j : i.listFiles()) + { + if(j.isDirectory() && j.getName().equals(folderName)) + { folderCache.add(j); break; } @@ -100,9 +118,12 @@ public class ResourceLoader { } } - if (preferredFolder != null) { - for (File i : folderCache.copy()) { - if (i.getParentFile().getName().equals(preferredFolder)) { + if(preferredFolder != null) + { + for(File i : folderCache.copy()) + { + if(i.getParentFile().getName().equals(preferredFolder)) + { folderCache.remove(i); folderCache.add(0, i); } @@ -114,12 +135,16 @@ public class ResourceLoader { return folderCache; } - public KList getFolders(String rc) { + public KList getFolders(String rc) + { KList folders = getFolders().copy(); - if (rc.contains(":")) { - for (File i : folders.copy()) { - if (!rc.startsWith(i.getName() + ":")) { + if(rc.contains(":")) + { + for(File i : folders.copy()) + { + if(!rc.startsWith(i.getName() + ":")) + { folders.remove(i); } } @@ -128,23 +153,28 @@ public class ResourceLoader { return folders; } - public void clearCache() { + public void clearCache() + { loadCache.clear(); folderCache = null; } - public File fileFor(T b) { - for (File i : getFolders()) { - for (File j : i.listFiles()) { - if (j.isFile() && j.getName().endsWith(".json") - && j.getName().split("\\Q.\\E")[0].equals(b.getLoadKey())) { + public File fileFor(T b) + { + for(File i : getFolders()) + { + for(File j : i.listFiles()) + { + if(j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(b.getLoadKey())) + { return j; } } File file = new File(i, b.getLoadKey() + ".json"); - if (file.exists()) { + if(file.exists()) + { return file; } } @@ -152,11 +182,13 @@ public class ResourceLoader { return null; } - public boolean isLoaded(String next) { + public boolean isLoaded(String next) + { return loadCache.containsKey(next); } - public void preferFolder(String name) { + public void preferFolder(String name) + { preferredFolder = name; } }