From 90846401a5656e442784046363b7540cfce0fa02 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Tue, 14 Jan 2020 01:16:33 -0500 Subject: [PATCH] Tweaking carves --- .../java/ninja/bytecode/iris/CommandIris.java | 1 + .../java/ninja/bytecode/iris/CommandIsh.java | 4 +- src/main/java/ninja/bytecode/iris/Iris.java | 9 +- .../java/ninja/bytecode/iris/Settings.java | 6 +- .../bytecode/iris/command/CommandIsh.java | 4 +- .../iris/controller/DebugController.java | 2 +- .../iris/controller/PackController.java | 117 +++++++++++--- .../iris/controller/WorldController.java | 6 +- .../iris/generator/IrisGenerator.java | 31 ++-- .../iris/generator/genobject/GenObject.java | 52 ++---- .../genobject/GenObjectDecorator.java | 20 +-- .../generator/genobject/GenObjectGroup.java | 136 ++++++++-------- .../iris/generator/layer/GenLayerCarving.java | 56 +++++-- .../generator/layer/GenLayerLayeredNoise.java | 6 +- .../bytecode/iris/pack/CompiledDimension.java | 152 ++++++++++++++++++ .../ninja/bytecode/iris/pack/IrisBiome.java | 12 +- .../bytecode/iris/pack/IrisDimension.java | 55 +++---- .../ninja/bytecode/iris/pack/IrisPack.java | 4 +- 18 files changed, 449 insertions(+), 224 deletions(-) create mode 100644 src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java diff --git a/src/main/java/ninja/bytecode/iris/CommandIris.java b/src/main/java/ninja/bytecode/iris/CommandIris.java index 788da8384..3af6ce029 100644 --- a/src/main/java/ninja/bytecode/iris/CommandIris.java +++ b/src/main/java/ninja/bytecode/iris/CommandIris.java @@ -9,6 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import mortar.api.nms.NMP; +import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.controller.TimingsController; import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.pack.IrisBiome; diff --git a/src/main/java/ninja/bytecode/iris/CommandIsh.java b/src/main/java/ninja/bytecode/iris/CommandIsh.java index f502b9626..3c0078280 100644 --- a/src/main/java/ninja/bytecode/iris/CommandIsh.java +++ b/src/main/java/ninja/bytecode/iris/CommandIsh.java @@ -72,7 +72,7 @@ public class CommandIsh implements CommandExecutor try { FileOutputStream fos = new FileOutputStream(f); - s.write(fos); + s.write(fos, true); msg(p, "Saved " + args[1] + " (" + F.f(s.getSchematic().size()) + " Entries)"); p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f); } @@ -96,7 +96,7 @@ public class CommandIsh implements CommandExecutor try { FileInputStream fin = new FileInputStream(f); - s.read(fin); + s.read(fin, true); boolean cursor = false; for(String i : args) diff --git a/src/main/java/ninja/bytecode/iris/Iris.java b/src/main/java/ninja/bytecode/iris/Iris.java index 93c345881..a4eff0fd8 100644 --- a/src/main/java/ninja/bytecode/iris/Iris.java +++ b/src/main/java/ninja/bytecode/iris/Iris.java @@ -46,10 +46,10 @@ public class Iris extends JavaPlugin implements Listener getServer().getPluginManager().registerEvents((Listener) this, this); getCommand("iris").setExecutor(new CommandIris()); getCommand("ish").setExecutor(new CommandIsh()); - + if(!settings.performance.debugMode) { - getController(PackController.class).loadContent(); + getController(PackController.class).compile(); } } @@ -59,10 +59,11 @@ public class Iris extends JavaPlugin implements Listener HandlerList.unregisterAll((Plugin) this); Bukkit.getScheduler().cancelTasks(this); } - + public void reload() { - Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> { + Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> + { onDisable(); onEnable(); }); diff --git a/src/main/java/ninja/bytecode/iris/Settings.java b/src/main/java/ninja/bytecode/iris/Settings.java index 673ae3c54..11421d6a3 100644 --- a/src/main/java/ninja/bytecode/iris/Settings.java +++ b/src/main/java/ninja/bytecode/iris/Settings.java @@ -9,7 +9,7 @@ public class Settings public static class PerformanceSettings { - public PerformanceMode performanceMode = PerformanceMode.HALF_CPU; + public PerformanceMode performanceMode = PerformanceMode.MATCH_CPU; public boolean fastDecoration = true; public int threadPriority = Thread.MIN_PRIORITY; public int compilerPriority = Thread.MIN_PRIORITY; @@ -27,7 +27,7 @@ public class Settings public double beachScale = 76; public double landScale = 0.325; public double landChance = 0.62; - public double roughness = 1; + public double roughness = 1.25; public double heightMultiplier = 0.806; public double heightExponentBase = 1; public double heightExponentMultiplier = 1.41; @@ -41,7 +41,7 @@ public class Settings public boolean flatBedrock = false; public boolean genObjects = true; public int minCarvingHeight = 75; - public int maxCarvingHeight = 175; + public int maxCarvingHeight = 155; public double carvingChance = 0.6; } } diff --git a/src/main/java/ninja/bytecode/iris/command/CommandIsh.java b/src/main/java/ninja/bytecode/iris/command/CommandIsh.java index 75eb72fd9..e9adbe44d 100644 --- a/src/main/java/ninja/bytecode/iris/command/CommandIsh.java +++ b/src/main/java/ninja/bytecode/iris/command/CommandIsh.java @@ -73,7 +73,7 @@ public class CommandIsh implements CommandExecutor try { FileOutputStream fos = new FileOutputStream(f); - s.write(fos); + s.write(fos, true); msg(p, "Saved " + args[1] + " (" + F.f(s.getSchematic().size()) + " Entries)"); p.playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 0.45f); } @@ -97,7 +97,7 @@ public class CommandIsh implements CommandExecutor try { FileInputStream fin = new FileInputStream(f); - s.read(fin); + s.read(fin, true); boolean cursor = false; for(String i : args) diff --git a/src/main/java/ninja/bytecode/iris/controller/DebugController.java b/src/main/java/ninja/bytecode/iris/controller/DebugController.java index b19480f0b..730e41a07 100644 --- a/src/main/java/ninja/bytecode/iris/controller/DebugController.java +++ b/src/main/java/ninja/bytecode/iris/controller/DebugController.java @@ -71,7 +71,7 @@ public class DebugController implements IrisController } }, 1); }); - Iris.getController(PackController.class).loadContent(); + Iris.getController(PackController.class).compile(); }); } }, 1); diff --git a/src/main/java/ninja/bytecode/iris/controller/PackController.java b/src/main/java/ninja/bytecode/iris/controller/PackController.java index 028d4feca..29e0ca524 100644 --- a/src/main/java/ninja/bytecode/iris/controller/PackController.java +++ b/src/main/java/ninja/bytecode/iris/controller/PackController.java @@ -1,14 +1,21 @@ package ninja.bytecode.iris.controller; +import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.security.DigestOutputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import mortar.logic.queue.ChronoLatch; import net.md_5.bungee.api.ChatColor; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.generator.genobject.GenObject; import ninja.bytecode.iris.generator.genobject.GenObjectGroup; +import ninja.bytecode.iris.pack.CompiledDimension; import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.pack.IrisDimension; import ninja.bytecode.iris.pack.IrisPack; @@ -16,24 +23,29 @@ import ninja.bytecode.iris.util.IrisController; import ninja.bytecode.shuriken.bench.PrecisionStopwatch; import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GMap; +import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.execution.TaskExecutor; import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.format.F; import ninja.bytecode.shuriken.io.IO; +import ninja.bytecode.shuriken.io.VoidOutputStream; import ninja.bytecode.shuriken.json.JSONException; import ninja.bytecode.shuriken.json.JSONObject; import ninja.bytecode.shuriken.logging.L; public class PackController implements IrisController { + private GMap compiledDimensions; private GMap dimensions; private GMap biomes; private GMap genObjectGroups; + private ChronoLatch ll = new ChronoLatch(3000); private boolean ready; @Override public void onStart() { + compiledDimensions = new GMap<>(); dimensions = new GMap<>(); biomes = new GMap<>(); genObjectGroups = new GMap<>(); @@ -51,14 +63,43 @@ public class PackController implements IrisController return ready; } - public void loadContent() + public GList getFiles(File folder) + { + GList buf = new GList(); + + if(!folder.exists()) + { + return buf; + } + + if(folder.isDirectory()) + { + for(File i : folder.listFiles()) + { + if(i.isFile()) + { + buf.add(i); + } + + else if(i.isDirectory()) + { + buf.addAll(getFiles(folder)); + } + } + } + + return buf; + } + + public void compile() { dimensions = new GMap<>(); biomes = new GMap<>(); genObjectGroups = new GMap<>(); ready = false; PrecisionStopwatch p = PrecisionStopwatch.start(); - L.i("Loading Content"); + File dims = new File(Iris.instance.getDataFolder(), "dimensions"); + dims.mkdirs(); try { @@ -75,29 +116,64 @@ public class PackController implements IrisController TaskExecutor exf = new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Compiler"); TaskGroup gg = exf.startWork(); - for(GenObjectGroup i : getGenObjectGroups().v()) + for(GenObjectGroup i : genObjectGroups.v()) { gg.queue(i::processVariants); } gg.execute(); exf.close(); - int m = 0; - for(GenObjectGroup i : getGenObjectGroups().v()) + for(String i : dimensions.k()) { - m += i.size(); + IrisDimension id = dimensions.get(i); + CompiledDimension d = new CompiledDimension(id); + + for(IrisBiome j : id.getBiomes()) + { + d.registerBiome(j); + GList g = j.getSchematicGroups().k(); + g.sort(); + + for(String k : g) + { + d.registerObject(genObjectGroups.get(k)); + + if(j.isSnowy()) + { + GenObjectGroup ggx = genObjectGroups.get(k).copy("-snowy-" + j.getSnow()); + ggx.applySnowFilter((int) (j.getSnow() * 4)); + d.registerObject(ggx); + } + } + } + + d.sort(); + compiledDimensions.put(i, d); } - L.i(ChatColor.LIGHT_PURPLE + "Dimensions: " + ChatColor.WHITE + getDimensions().size()); - L.i(ChatColor.LIGHT_PURPLE + "Biomes: " + ChatColor.WHITE + getBiomes().size()); - L.i(ChatColor.LIGHT_PURPLE + "Object Groups: " + ChatColor.WHITE + F.f(getGenObjectGroups().size())); - L.i(ChatColor.LIGHT_PURPLE + "Objects: " + ChatColor.WHITE + F.f(m)); + for(String i : compiledDimensions.k()) + { + CompiledDimension d = compiledDimensions.get(i); + L.i(ChatColor.GREEN + i + ChatColor.WHITE + " (" + d.getEnvironment().toString().toLowerCase() + ")"); + L.i(ChatColor.DARK_GREEN + " Biomes: " + ChatColor.GRAY + F.f(d.getBiomes().size())); + L.i(ChatColor.DARK_GREEN + " Objects: " + ChatColor.GRAY + F.f(d.countObjects())); + L.flush(); + } + + L.i(""); L.i(ChatColor.LIGHT_PURPLE + "Compilation Time: " + ChatColor.WHITE + F.duration(p.getMilliseconds(), 2)); - L.flush(); L.i(ChatColor.GREEN + "Iris Dimensions Successfully Compiled!"); + L.i(""); + L.flush(); + ready = true; } + + public CompiledDimension getDimension(String name) + { + return compiledDimensions.get(name); + } public IrisDimension loadDimension(String s) throws JSONException, IOException { @@ -118,7 +194,7 @@ public class PackController implements IrisController if(g != null) { - Iris.getController(PackController.class).getGenObjectGroups().put(s, g); + Iris.getController(PackController.class).genObjectGroups.put(s, g); return g; } @@ -163,13 +239,13 @@ public class PackController implements IrisController else { L.f(ChatColor.RED + "Cannot find Resource: " + ChatColor.YELLOW + internal.getAbsolutePath()); - + if(internal.getName().equals("manifest.json")) { L.f(ChatColor.RED + "Reloading Iris to fix manifest jar issues"); Iris.instance.reload(); } - + return null; } } @@ -184,18 +260,19 @@ public class PackController implements IrisController return new File(System.getProperty("java.io.tmpdir") + "/Iris/" + resource); } - public GMap getDimensions() + public void registerBiome(String name, IrisBiome biome) { - return dimensions; + biomes.put(name, biome); } - public GMap getBiomes() + public void registerDimension(String i, IrisDimension d) { - return biomes; + dimensions.put(i, d); } - public GMap getGenObjectGroups() + public void invalidate() { - return genObjectGroups; + J.attempt(() -> new File(Iris.instance.getDataFolder(), "dimensions").delete()); + compiledDimensions.clear(); } } diff --git a/src/main/java/ninja/bytecode/iris/controller/WorldController.java b/src/main/java/ninja/bytecode/iris/controller/WorldController.java index 36dfe5855..e970ddd69 100644 --- a/src/main/java/ninja/bytecode/iris/controller/WorldController.java +++ b/src/main/java/ninja/bytecode/iris/controller/WorldController.java @@ -9,7 +9,7 @@ import org.bukkit.WorldCreator; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.generator.IrisGenerator; -import ninja.bytecode.iris.pack.IrisDimension; +import ninja.bytecode.iris.pack.CompiledDimension; import ninja.bytecode.iris.util.IrisController; import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.io.IO; @@ -42,11 +42,11 @@ public class WorldController implements IrisController } - public World createIrisWorld(IrisDimension dimension, long seed, boolean temp) + public World createIrisWorld(CompiledDimension dimension, long seed, boolean temp) { if(dimension == null) { - dimension = Iris.getController(PackController.class).getDimensions().get("overworld"); + dimension = Iris.getController(PackController.class).getDimension("overworld"); } //@builder diff --git a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java index d3337509d..867c691f0 100644 --- a/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java +++ b/src/main/java/ninja/bytecode/iris/generator/IrisGenerator.java @@ -8,6 +8,7 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; +import net.md_5.bungee.api.ChatColor; import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.generator.genobject.GenObjectDecorator; @@ -19,8 +20,8 @@ import ninja.bytecode.iris.generator.layer.GenLayerCaves; import ninja.bytecode.iris.generator.layer.GenLayerLayeredNoise; import ninja.bytecode.iris.generator.layer.GenLayerRidge; import ninja.bytecode.iris.generator.layer.GenLayerSnow; +import ninja.bytecode.iris.pack.CompiledDimension; import ninja.bytecode.iris.pack.IrisBiome; -import ninja.bytecode.iris.pack.IrisDimension; import ninja.bytecode.iris.util.AtomicChunkData; import ninja.bytecode.iris.util.ChunkPlan; import ninja.bytecode.iris.util.IrisInterpolation; @@ -64,21 +65,16 @@ public class IrisGenerator extends ParallelChunkGenerator private GenLayerCarving glCarving; private GenLayerSnow glSnow; private RNG rTerrain; - private IrisDimension dim; + private CompiledDimension dim; private World world; private GMap schematicCache = new GMap<>(); public IrisGenerator() { - this(Iris.getController(PackController.class).getDimensions().get("overworld")); + this(Iris.getController(PackController.class).getDimension("overworld")); } - public GList getLoadedBiomes() - { - return internal; - } - - public IrisGenerator(IrisDimension dim) + public IrisGenerator(CompiledDimension dim) { this.dim = dim; L.i("Preparing Dimension: " + dim.getName() + " With " + dim.getBiomes().size() + " Biomes..."); @@ -91,7 +87,7 @@ public class IrisGenerator extends ParallelChunkGenerator if(j.getName().equals(i.getName())) { internal.remove(j); - L.i("Internal Biome: " + j.getName() + " overwritten by dimension " + dim.getName()); + L.i(ChatColor.LIGHT_PURPLE + "Internal Biome: " + ChatColor.WHITE+ j.getName() + ChatColor.LIGHT_PURPLE + " overwritten by dimension " + ChatColor.WHITE + dim.getName()); } } } @@ -104,6 +100,11 @@ public class IrisGenerator extends ParallelChunkGenerator } } + public GList getLoadedBiomes() + { + return internal; + } + @Override public void onInit(World world, Random random) { @@ -273,11 +274,6 @@ public class IrisGenerator extends ParallelChunkGenerator return p; } - public GenObjectGroup loadSchematics(String folder) - { - return Iris.getController(PackController.class).getGenObjectGroups().get(folder); - } - private double getBiomedHeight(int x, int z, ChunkPlan plan) { double xh = plan.getHeight(x, z); @@ -321,4 +317,9 @@ public class IrisGenerator extends ParallelChunkGenerator { return glBase; } + + public CompiledDimension getDimension() + { + return dim; + } } \ No newline at end of file diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java index 50badd190..11c01b761 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java @@ -15,7 +15,6 @@ import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; import mortar.compute.math.M; -import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.generator.placer.NMSPlacer; import ninja.bytecode.iris.util.Direction; import ninja.bytecode.iris.util.IPlacer; @@ -38,14 +37,12 @@ public class GenObject private BlockVector mount; private int mountHeight; private BlockVector shift; - private boolean cascading; public GenObject(int w, int h, int d) { this.w = w; this.h = h; this.d = d; - cascading = false; shift = new BlockVector(); s = new GMap<>(); centeredHeight = false; @@ -137,40 +134,21 @@ public class GenObject return d; } - public int getAntiCascadeWidth() + public void read(InputStream in, boolean gzip) throws IOException { - if(isCascading()) - { - return -1; - } - - return 16 - w; - } - - public int getAntiCascadeDepth() - { - if(isCascading()) - { - return -1; - } - - return 16 - d; - } - - public boolean isCascading() - { - return cascading; + @SuppressWarnings("resource") + GZIPInputStream gzi = gzip ? new GZIPInputStream(in) : null; + DataInputStream din = new DataInputStream(gzip ? gzi : in); + readDirect(din); + din.close(); } @SuppressWarnings("deprecation") - public void read(InputStream in) throws IOException + public void readDirect(DataInputStream din) throws IOException { - GZIPInputStream gzi = new GZIPInputStream(in); - DataInputStream din = new DataInputStream(gzi); w = din.readInt(); h = din.readInt(); d = din.readInt(); - cascading = w > Iris.settings.performance.cascadeLimit || d > Iris.settings.performance.cascadeLimit; int l = din.readInt(); clear(); @@ -178,15 +156,11 @@ public class GenObject { s.put(new BlockVector(din.readInt(), din.readInt(), din.readInt()), new MB(Material.getMaterial((int) din.readInt()), din.readInt())); } - - din.close(); } @SuppressWarnings("deprecation") - public void write(OutputStream out) throws IOException + public void writeDirect(DataOutputStream dos) throws IOException { - CustomOutputStream cos = new CustomOutputStream(out, 9); - DataOutputStream dos = new DataOutputStream(cos); dos.writeInt(w); dos.writeInt(h); dos.writeInt(d); @@ -200,7 +174,13 @@ public class GenObject dos.writeInt(s.get(i).material.getId()); dos.writeInt(s.get(i).data); } + } + public void write(OutputStream out, boolean gzip) throws IOException + { + CustomOutputStream cos = gzip ? new CustomOutputStream(out, 9) : null; + DataOutputStream dos = new DataOutputStream(gzip ? cos : out); + writeDirect(dos); dos.close(); } @@ -319,7 +299,7 @@ public class GenObject public static GenObject load(InputStream in) throws IOException { GenObject s = new GenObject(1, 1, 1); - s.read(in); + s.read(in, true); return s; } @@ -329,7 +309,7 @@ public class GenObject GenObject s = new GenObject(1, 1, 1); s.name = f.getName().replaceAll("\\Q.ish\\E", ""); FileInputStream fin = new FileInputStream(f); - s.read(fin); + s.read(fin, true); return s; } diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java index bda00a39e..36a96f79e 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java @@ -47,25 +47,13 @@ public class GenObjectDecorator extends BlockPopulator for(String j : i.getSchematicGroups().k()) { + double c = i.getSchematicGroups().get(j); + try { - GenObjectGroup g = Iris.getController(PackController.class).getGenObjectGroups().get(j); + GenObjectGroup g = generator.getDimension().getObjectGroup(j); - if(i.isSnowy()) - { - String v = g.getName() + "-" + i.getSnow(); - - if(!snowCache.containsKey(v)) - { - GenObjectGroup gog = g.copy("-snowy-" + i.getSnow()); - gog.applySnowFilter((int) (i.getSnow() * 4)); - snowCache.put(v, gog); - } - - g = snowCache.get(v); - } - - gc.put(g, i.getSchematicGroups().get(j)); + gc.put(g, c); } catch(Throwable e) diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java index 9f604f1a5..c853549cb 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java @@ -1,8 +1,13 @@ package ninja.bytecode.iris.generator.genobject; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import java.util.concurrent.locks.ReentrantLock; +import java.util.function.Consumer; import net.md_5.bungee.api.ChatColor; import ninja.bytecode.iris.Iris; @@ -20,21 +25,75 @@ public class GenObjectGroup private GList schematics; private GList flags; private String name; - private int priority; - private boolean noCascade; public GenObjectGroup(String name) { this.schematics = new GList<>(); this.flags = new GList<>(); - priority = 0; this.name = name; - this.noCascade = false; + } + + public void read(DataInputStream din) throws IOException + { + flags.clear(); + schematics.clear(); + name = din.readUTF(); + int fl = din.readInt(); + int sc = din.readInt(); + + for(int i = 0; i < fl; i++) + { + flags.add(din.readUTF()); + } + + for(int i = 0; i < sc; i++) + { + GenObject g = new GenObject(0, 0, 0); + g.readDirect(din); + schematics.add(g); + } + } + + public void write(DataOutputStream dos, Consumer progress) throws IOException + { + dos.writeUTF(name); + dos.writeInt(flags.size()); + dos.writeInt(schematics.size()); + + for(String i : flags) + { + dos.writeUTF(i); + } + + int of = 0; + + if(progress != null) + { + progress.accept((double) of / (double) schematics.size()); + } + + for(GenObject i : schematics) + { + i.writeDirect(dos); + of++; + + if(progress != null) + { + progress.accept((double) of / (double) schematics.size()); + } + } } public void applySnowFilter(int factor) { + if(flags.contains("no snow")) + { + L.i(ChatColor.DARK_AQUA + "Skipping Snow Filter for " + ChatColor.GRAY + getName()); + return; + } + L.i(ChatColor.AQUA + "Applying Snow Filter to " + ChatColor.WHITE + getName()); + for(GenObject i : schematics) { i.applySnowFilter(factor); @@ -46,8 +105,6 @@ public class GenObjectGroup GenObjectGroup gog = new GenObjectGroup(name + suffix); gog.schematics = new GList<>(); gog.flags = flags.copy(); - gog.priority = priority; - gog.noCascade = noCascade; for(GenObject i : schematics) { @@ -89,16 +146,6 @@ public class GenObjectGroup this.flags = flags; } - public int getPriority() - { - return priority; - } - - public void setPriority(int priority) - { - this.priority = priority; - } - public int size() { return getSchematics().size(); @@ -192,62 +239,7 @@ public class GenObjectGroup gg.execute(); ex.close(); - noCascade = true; - for(GenObject i : getSchematics()) - { - if(i.isCascading()) - { - noCascade = false; - break; - } - } - - L.i(ChatColor.LIGHT_PURPLE + "Processed " + ChatColor.WHITE + F.f(schematics.size()) + ChatColor.LIGHT_PURPLE + " Schematics in " + ChatColor.WHITE + name + (noCascade ? ChatColor.AQUA + "*" : ChatColor.YELLOW + "^")); - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + ((flags == null) ? 0 : flags.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + priority; - return result; - } - - @Override - public boolean equals(Object obj) - { - if(this == obj) - return true; - if(obj == null) - return false; - if(getClass() != obj.getClass()) - return false; - GenObjectGroup other = (GenObjectGroup) obj; - if(flags == null) - { - if(other.flags != null) - return false; - } - else if(!flags.equals(other.flags)) - return false; - if(name == null) - { - if(other.name != null) - return false; - } - else if(!name.equals(other.name)) - return false; - if(priority != other.priority) - return false; - return true; - } - - public boolean isCascading() - { - return !noCascade; + L.i(ChatColor.LIGHT_PURPLE + "Processed " + ChatColor.WHITE + F.f(schematics.size()) + ChatColor.LIGHT_PURPLE + " Schematics in " + ChatColor.WHITE + name); } } diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java index eaa7a1d16..bb0301850 100644 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java +++ b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerCarving.java @@ -25,25 +25,25 @@ public class GenLayerCarving extends GenLayer super(iris, world, random, rng); //@builder carver = new CNG(rng.nextParallelRNG(116), 1D, 3) - .scale(0.0135) + .scale(0.0285) .amp(0.5) .freq(1.1) .fractureWith(new CNG(rng.nextParallelRNG(18), 1, 3) - .scale(0.018) + .scale(0.005) .child(new CNG(rng.nextParallelRNG(19), 0.745, 2) .scale(0.1)) .fractureWith(new CNG(rng.nextParallelRNG(20), 1, 3) - .scale(0.15), 24), 44); + .scale(0.08), 12), 33); clipper = new CNG(rng.nextParallelRNG(117), 1D, 1) - .scale(0.005) - .amp(0.5) + .scale(0.0009) + .amp(0.0) .freq(1.1) .fractureWith(new CNG(rng.nextParallelRNG(18), 1, 3) - .scale(0.018) + .scale(0.005) .child(new CNG(rng.nextParallelRNG(19), 0.745, 2) .scale(0.1)) .fractureWith(new CNG(rng.nextParallelRNG(20), 1, 3) - .scale(0.15), 24), 44); + .scale(0.08), 12), 33); //@done } @@ -87,7 +87,7 @@ public class GenLayerCarving extends GenLayer continue; } - if(carver.noise(wxx, i, wzx) < IrisInterpolation.lerpBezier(0.01, 0.465, hill)) + if(carver.noise(wxx, i, wzx) < IrisInterpolation.lerpBezier(0.01, 0.425, hill)) { carved++; g.setBlock(x, i, z, Material.AIR); @@ -97,6 +97,8 @@ public class GenLayerCarving extends GenLayer if(carved > 4) { + boolean fail = false; + for(int i = Iris.settings.gen.maxCarvingHeight; i > Iris.settings.gen.minCarvingHeight; i--) { Material m = g.getType(x, i, z); @@ -106,14 +108,44 @@ public class GenLayerCarving extends GenLayer if(hit == 1) { - MB mb = biome.getSurface(wxx, wzx, g.getRTerrain()); - g.setBlock(x, i, z, mb.material, mb.data); + fail = false; + + if(i > 5) + { + for(int j = i; j > i - 5; j--) + { + if(g.getType(x, j, z).equals(Material.AIR)) + { + fail = true; + break; + } + } + } + + if(!fail) + { + MB mb = biome.getSurface(wxx, wzx, g.getRTerrain()); + g.setBlock(x, i, z, mb.material, mb.data); + } + + else + { + g.setBlock(x, i, z, Material.AIR); + } } else if(hit > 1 && hit < g.getGlBase().scatterInt(x, i, z, 4) + 3) { - MB mb = biome.getDirtRNG(); - g.setBlock(x, i, z, mb.material, mb.data); + if(!fail) + { + MB mb = biome.getDirtRNG(); + g.setBlock(x, i, z, mb.material, mb.data); + } + + else + { + g.setBlock(x, i, z, Material.AIR); + } } } diff --git a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java index b14af16fa..2233fd763 100644 --- a/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java +++ b/src/main/java/ninja/bytecode/iris/generator/layer/GenLayerLayeredNoise.java @@ -18,12 +18,12 @@ public class GenLayerLayeredNoise extends GenLayer { //@builder super(iris, world, random, rng); - fract = new CNG(rng.nextParallelRNG(16), 1D, 3).scale(0.0181); - gen = new CNG(rng.nextParallelRNG(17), 0.19D, 6) + fract = new CNG(rng.nextParallelRNG(16), 1D, 9).scale(0.0181); + gen = new CNG(rng.nextParallelRNG(17), 0.19D, 12) .scale(0.012) .amp(0.5) .freq(1.1) - .fractureWith(new CNG(rng.nextParallelRNG(18), 1, 3) + .fractureWith(new CNG(rng.nextParallelRNG(18), 1, 5) .scale(0.018) .child(new CNG(rng.nextParallelRNG(19), 0.745, 2) .scale(0.1)) diff --git a/src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java b/src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java new file mode 100644 index 000000000..47d66b25a --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/pack/CompiledDimension.java @@ -0,0 +1,152 @@ +package ninja.bytecode.iris.pack; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.function.Consumer; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +import org.bukkit.World.Environment; +import org.bukkit.block.Biome; + +import ninja.bytecode.iris.generator.genobject.GenObjectGroup; +import ninja.bytecode.shuriken.collections.GList; +import ninja.bytecode.shuriken.collections.GMap; +import ninja.bytecode.shuriken.io.CustomOutputStream; +import ninja.bytecode.shuriken.json.JSONObject; +import ninja.bytecode.shuriken.reaction.O; + +public class CompiledDimension +{ + private IrisDimension dimension; + private GList biomes; + private GMap objects; + + public CompiledDimension(IrisDimension dimension) + { + this.dimension = dimension; + biomes = new GList<>(); + objects = new GMap<>(); + } + + public void read(InputStream in) throws IOException + { + GZIPInputStream gin = new GZIPInputStream(in); + DataInputStream din = new DataInputStream(gin); + dimension = new IrisDimension(); + dimension.fromJSON(new JSONObject(din.readUTF()), false); + int bi = din.readInt(); + int ob = din.readInt(); + + for(int i = 0; i < bi; i++) + { + IrisBiome b = new IrisBiome("Loading", Biome.VOID); + b.fromJSON(new JSONObject(din.readUTF()), false); + } + + for(int i = 0; i < ob; i++) + { + GenObjectGroup g = new GenObjectGroup("Loading"); + g.read(din); + } + } + + public void write(OutputStream out, Consumer progress) throws IOException + { + GZIPOutputStream gzo = new CustomOutputStream(out, 1); + DataOutputStream dos = new DataOutputStream(gzo); + dos.writeUTF(dimension.toJSON().toString(0)); + dos.writeInt(biomes.size()); + dos.writeInt(objects.size()); + + for(IrisBiome i : biomes) + { + dos.writeUTF(i.toJSON().toString(0)); + } + + O tc = new O<>(); + O oc = new O<>(); + O cc = new O<>(); + tc.set(0); + oc.set(0); + cc.set(0); + + for(GenObjectGroup i : objects.v()) + { + tc.set(tc.get() + i.size()); + } + + for(GenObjectGroup i : objects.v().shuffle()) + { + i.write(dos, (o) -> + { + cc.set((int) (o * i.size())); + + if(progress != null) + { + progress.accept((double) (oc.get() + cc.get()) / (double) tc.get()); + } + }); + + oc.set(oc.get() + cc.get()); + cc.set(0); + } + + dos.close(); + } + + public void registerBiome(IrisBiome j) + { + biomes.add(j); + } + + public void registerObject(GenObjectGroup g) + { + if(g.getName().startsWith("pack/objects/")) + { + g.setName(g.getName().replaceFirst("\\Qpack/objects/\\E", "")); + } + + objects.put(g.getName(), g); + } + + public String getName() + { + return dimension.getName(); + } + + public GList getBiomes() + { + return biomes; + } + + public Environment getEnvironment() + { + return dimension.getEnvironment(); + } + + public GenObjectGroup getObjectGroup(String j) + { + return objects.get(j); + } + + public int countObjects() + { + int m = 0; + + for(GenObjectGroup i : objects.v()) + { + m += i.size(); + } + + return m; + } + + public void sort() + { + biomes.sort(); + } +} diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java index 7ed6f22df..042cda5e9 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisBiome.java @@ -158,6 +158,11 @@ public class IrisBiome } public void fromJSON(JSONObject o) + { + fromJSON(o, true); + } + + public void fromJSON(JSONObject o, boolean chain) { name = o.getString("name"); realBiome = Biome.valueOf(o.getString("derivative").toUpperCase().replaceAll(" ", "_")); @@ -173,9 +178,12 @@ public class IrisBiome { schematicGroups = strFromJSON(o.getJSONArray("objects")); - for(String i : schematicGroups.k()) + if(chain) { - Iris.getController(PackController.class).loadSchematicGroup(i); + for(String i : schematicGroups.k()) + { + Iris.getController(PackController.class).loadSchematicGroup(i); + } } }); } diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java b/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java index 5227da0cc..4f459d6cc 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java @@ -20,93 +20,86 @@ public class IrisDimension private String name; private Environment environment; GList biomes; - + public IrisDimension(JSONObject o) throws JSONException, IOException { this(); fromJSON(o); } - + public IrisDimension() { biomes = new GList(); environment = Environment.NORMAL; } - + public void fromJSON(JSONObject o) throws JSONException, IOException + { + fromJSON(o, true); + } + + public void fromJSON(JSONObject o, boolean chain) throws JSONException, IOException { name = o.getString("name"); J.attempt(() -> environment = Environment.valueOf(o.getString("environment").toUpperCase().replaceAll(" ", "_"))); - + try { - biomes = biomesFromArray(o.getJSONArray("biomes")); + biomes = chain ? biomesFromArray(o.getJSONArray("biomes")) : new GList<>(); } - + catch(Throwable e) { e.printStackTrace(); } - - if(o.has("focus")) - { - String focus = o.getString("focus"); - - for(IrisBiome i : biomes.copy()) - { - if(!i.getName().toLowerCase().replaceAll(" ", "_").equals(focus)) - { - biomes.remove(i); - } - } - } } - + public JSONObject toJSON() { JSONObject o = new JSONObject(); - + o.put("name", name); o.put("environment", environment.name().toLowerCase().replaceAll("_", " ")); o.put("biomes", biomesToArray(biomes)); - + return o; } - + private GList biomesFromArray(JSONArray a) throws JSONException, IOException { GList b = new GList<>(); - TaskExecutor ex= new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Loader"); + TaskExecutor ex = new TaskExecutor(Iris.settings.performance.compilerThreads, Iris.settings.performance.compilerPriority, "Iris Loader"); TaskGroup g = ex.startWork(); ReentrantLock lock = new ReentrantLock(); - + for(int i = 0; i < a.length(); i++) { int ii = i; - g.queue(() -> { + g.queue(() -> + { IrisBiome bb = Iris.getController(PackController.class).loadBiome(a.getString(ii)); lock.lock(); - Iris.getController(PackController.class).getBiomes().put(a.getString(ii), bb); + Iris.getController(PackController.class).registerBiome(a.getString(ii), bb); b.add(bb); lock.unlock(); }); } - + g.execute(); ex.close(); - + return b; } private JSONArray biomesToArray(GList b) { JSONArray a = new JSONArray(); - + for(IrisBiome i : b) { a.put(i.getName().toLowerCase().replaceAll(" ", "_")); } - + return a; } diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisPack.java b/src/main/java/ninja/bytecode/iris/pack/IrisPack.java index a9dd5df2b..5365471cb 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisPack.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisPack.java @@ -75,13 +75,13 @@ public class IrisPack for(String i : dimensions) { IrisDimension d = Iris.getController(PackController.class).loadDimension(i); - Iris.getController(PackController.class).getDimensions().put(i, d); + Iris.getController(PackController.class).registerDimension(i, d); } } public void loadBiome(String s) throws JSONException, IOException { IrisBiome b = Iris.getController(PackController.class).loadBiome(s); - Iris.getController(PackController.class).getBiomes().put(s, b); + Iris.getController(PackController.class).registerBiome(s, b); } }