diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index 057580bef..fc696e274 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -45,8 +45,6 @@ public class DecIris implements DecreeExecutor { private DecObject object; - private DecWhat what; - @Decree(description = "Create a new world", aliases = "+") public void create( @Param(aliases = "world-name", description = "The name of the world to create") diff --git a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java index b117652e8..37af6c9a7 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -18,6 +18,7 @@ package com.volmit.iris.core.decrees; +import com.google.gson.Gson; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.gui.NoiseExplorerGUI; @@ -27,12 +28,14 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.core.service.ConversionSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.biome.IrisBiomePaletteLayer; import com.volmit.iris.engine.object.common.IrisScript; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.object.entity.IrisEntity; +import com.volmit.iris.engine.object.feature.IrisFeaturePositional; import com.volmit.iris.engine.object.loot.IrisLootTable; import com.volmit.iris.engine.object.meta.InventorySlotType; import com.volmit.iris.engine.object.noise.IrisGenerator; @@ -40,9 +43,11 @@ import com.volmit.iris.engine.object.noise.IrisInterpolator; import com.volmit.iris.engine.object.noise.IrisNoiseGenerator; import com.volmit.iris.engine.object.noise.NoiseStyle; import com.volmit.iris.engine.object.objects.IrisObject; +import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; +import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.data.B; import com.volmit.iris.util.decree.DecreeExecutor; import com.volmit.iris.util.decree.DecreeOrigin; @@ -56,7 +61,9 @@ import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.json.JSONArray; import com.volmit.iris.util.json.JSONObject; +import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; +import com.volmit.iris.util.math.Spiraler; import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.scheduling.J; @@ -66,16 +73,26 @@ import com.volmit.iris.util.scheduling.jobs.Job; import com.volmit.iris.util.scheduling.jobs.JobCollection; import com.volmit.iris.util.scheduling.jobs.QueueJob; import com.volmit.iris.util.scheduling.jobs.SingleJob; +import io.papermc.lib.PaperLib; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.Inventory; +import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; import java.awt.*; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.attribute.FileTime; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.Date; +import java.util.Objects; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.function.Supplier; @@ -786,6 +803,201 @@ public class DecStudio implements DecreeExecutor { } } + @Decree(aliases = {"find-features", "nf"}, description = "Get the noise feature data in your chunk") + public void features() { + + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "Iris worlds only"); + return; + } + + int n = 0; + + for (IrisFeaturePositional irisFeaturePositional : engine().getMantle().getFeaturesInChunk(player().getLocation().getChunk())) { + sender().sendMessage("#" + n++ + " " + new JSONObject(new Gson().toJson(irisFeaturePositional)).toString(4)); + } + } + + @Decree(aliases = "find-objects", description = "Get information about nearby structures") + public void objects() { + if (!IrisToolbelt.isIrisWorld(player().getWorld())){ + sender().sendMessage(C.RED + "You must be in an Iris world"); + return; + } + + World world = player().getWorld(); + + if (!IrisToolbelt.isIrisWorld(world)) { + sender().sendMessage("You must be in an iris world."); + return; + } + KList chunks = new KList<>(); + int bx = player().getLocation().getChunk().getX(); + int bz = player().getLocation().getChunk().getZ(); + + try { + Location l = player().getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); + + int cx = l.getChunk().getX(); + int cz = l.getChunk().getZ(); + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); + } catch (Throwable e) { + Iris.reportError(e); + } + + new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + bx, z + bz))).drain(); + sender().sendMessage("Capturing IGenData from " + chunks.size() + " nearby chunks."); + try { + File ff = Iris.instance.getDataFile("reports/" + M.ms() + ".txt"); + PrintWriter pw = new PrintWriter(ff); + pw.println("=== Iris Chunk Report ==="); + pw.println("== General Info =="); + pw.println("Iris Version: " + Iris.instance.getDescription().getVersion()); + pw.println("Bukkit Version: " + Bukkit.getBukkitVersion()); + pw.println("MC Version: " + Bukkit.getVersion()); + pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!")); + pw.println("Report Captured At: " + new Date()); + pw.println("Chunks: (" + chunks.size() + "): "); + + for (Chunk i : chunks) { + pw.println("- [" + i.getX() + ", " + i.getZ() + "]"); + } + + int regions = 0; + long size = 0; + String age = "No idea..."; + + try { + for (File i : Objects.requireNonNull(new File(world.getWorldFolder(), "region").listFiles())) { + if (i.isFile()) { + size += i.length(); + } + } + } catch (Throwable e) { + Iris.reportError(e); + } + + try { + FileTime creationTime = (FileTime) Files.getAttribute(world.getWorldFolder().toPath(), "creationTime"); + age = hrf(Duration.of(M.ms() - creationTime.toMillis(), ChronoUnit.MILLIS)); + } catch (IOException e) { + Iris.reportError(e); + } + + KList biomes = new KList<>(); + KList caveBiomes = new KList<>(); + KMap>> objects = new KMap<>(); + + for (Chunk i : chunks) { + for (int j = 0; j < 16; j += 3) { + + for (int k = 0; k < 16; k += 3) { + + assert engine() != null; + IrisBiome bb = engine().getSurfaceBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + IrisBiome bxf = engine().getCaveBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); + biomes.addIfMissing(bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"); + caveBiomes.addIfMissing(bxf.getName() + " (" + bxf.getLoadFile().getName() + ")"); + exportObjects(bb, pw, engine(), objects); + exportObjects(bxf, pw, engine(), objects); + } + } + } + + regions = Objects.requireNonNull(new File(world.getWorldFolder().getPath() + "/region").list()).length; + + pw.println(); + pw.println("== World Info =="); + pw.println("World Name: " + world.getName()); + pw.println("Age: " + age); + pw.println("Folder: " + world.getWorldFolder().getPath()); + pw.println("Regions: " + Form.f(regions)); + pw.println("Chunks: max. " + Form.f(regions * 32 * 32)); + pw.println("World Size: min. " + Form.fileSize(size)); + pw.println(); + pw.println("== Biome Info =="); + pw.println("Found " + biomes.size() + " Biome(s): "); + + for (String i : biomes) { + pw.println("- " + i); + } + pw.println(); + + pw.println("== Object Info =="); + + for (String i : objects.k()) { + pw.println("- " + i); + + for (String j : objects.get(i).k()) { + pw.println(" @ " + j); + + for (String k : objects.get(i).get(j)) { + pw.println(" * " + k); + } + } + } + + pw.println(); + pw.close(); + + sender().sendMessage("Reported to: " + ff.getPath()); + } catch (FileNotFoundException e) { + e.printStackTrace(); + Iris.reportError(e); + } + } + + private void exportObjects(IrisBiome bb, PrintWriter pw, Engine g, KMap>> objects) { + String n1 = bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"; + int m = 0; + KSet stop = new KSet<>(); + for (IrisObjectPlacement f : bb.getObjects()) { + m++; + String n2 = "Placement #" + m + " (" + f.getPlace().size() + " possible objects)"; + + for (String i : f.getPlace()) { + String nn3 = i + ": [ERROR] Failed to find object!"; + + try { + if (stop.contains(i)) { + continue; + } + + File ff = g.getData().getObjectLoader().findFile(i); + BlockVector sz = IrisObject.sampleSize(ff); + nn3 = i + ": size=[" + sz.getBlockX() + "," + sz.getBlockY() + "," + sz.getBlockZ() + "] location=[" + ff.getPath() + "]"; + stop.add(i); + } catch (Throwable e) { + Iris.reportError(e); + } + + String n3 = nn3; + + objects.compute(n1, (k1, v1) -> + { + //noinspection ReplaceNullCheck + if (v1 == null) { + return new KMap<>(); + } + + return v1; + }).compute(n2, (k, v) -> + { + if (v == null) { + return new KList().qaddIfMissing(n3); + } + + v.addIfMissing(n3); + return v; + }); + } + } + } + + public static String hrf(Duration duration) { + return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); + } + /** * @return true if server GUIs are not enabled */ diff --git a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java b/src/main/java/com/volmit/iris/core/decrees/DecWhat.java deleted file mode 100644 index 2349ab703..000000000 --- a/src/main/java/com/volmit/iris/core/decrees/DecWhat.java +++ /dev/null @@ -1,258 +0,0 @@ -package com.volmit.iris.core.decrees; - -import com.google.gson.Gson; -import com.volmit.iris.Iris; -import com.volmit.iris.core.nms.INMS; -import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.biome.IrisBiome; -import com.volmit.iris.engine.object.feature.IrisFeaturePositional; -import com.volmit.iris.engine.object.objects.IrisObject; -import com.volmit.iris.engine.object.objects.IrisObjectPlacement; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.collection.KSet; -import com.volmit.iris.util.data.B; -import com.volmit.iris.util.decree.DecreeExecutor; -import com.volmit.iris.util.decree.DecreeOrigin; -import com.volmit.iris.util.decree.annotations.Decree; -import com.volmit.iris.util.decree.annotations.Param; -import com.volmit.iris.util.format.C; -import com.volmit.iris.util.format.Form; -import com.volmit.iris.util.json.JSONObject; -import com.volmit.iris.util.math.M; -import com.volmit.iris.util.math.Spiraler; -import com.volmit.iris.util.plugin.VolmitSender; -import io.papermc.lib.PaperLib; -import org.bukkit.*; -import org.bukkit.block.Biome; -import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; -import org.bukkit.util.BlockVector; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.PrintWriter; -import java.nio.file.Files; -import java.nio.file.attribute.FileTime; -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.Objects; - -@Decree(name = "what", aliases = "?", description = "Find information on the world around you", origin = DecreeOrigin.PLAYER) -public class DecWhat implements DecreeExecutor { - - @Decree(aliases = "nf", description = "Get the noise feature data in your chunk") - public void features() { - - if (!IrisToolbelt.isIrisWorld(player().getWorld())){ - sender().sendMessage(C.RED + "Iris worlds only"); - return; - } - - int n = 0; - - for (IrisFeaturePositional irisFeaturePositional : engine().getMantle().getFeaturesInChunk(player().getLocation().getChunk())) { - sender().sendMessage("#" + n++ + " " + new JSONObject(new Gson().toJson(irisFeaturePositional)).toString(4)); - } - } - - @Decree(description = "Get information about the world around you", aliases = "location", studio = true) - public void me( - @Param(description = "Whether or not to show dimension information", defaultValue = "true") - boolean dimension, - @Param(description = "Whether or not to show region information", defaultValue = "true") - boolean region, - @Param(description = "Whether or not to show biome information", defaultValue = "true") - boolean biome, - @Param(description = "Whether or not to show information about the block you are looking at", defaultValue = "true") - boolean look, - @Param(description = "Whether or not to show information about the block you are holding", defaultValue = "true") - boolean hand - ) { - new DecStudio().what(dimension, region, biome, look, hand); - } - - @Decree(aliases = "capture", description = "Get information about nearby structures") - public void objects() { - if (!IrisToolbelt.isIrisWorld(player().getWorld())){ - sender().sendMessage(C.RED + "You must be in an Iris world"); - return; - } - - World world = player().getWorld(); - - if (!IrisToolbelt.isIrisWorld(world)) { - sender().sendMessage("You must be in an iris world."); - return; - } - KList chunks = new KList<>(); - int bx = player().getLocation().getChunk().getX(); - int bz = player().getLocation().getChunk().getZ(); - - try { - Location l = player().getTargetBlockExact(48, FluidCollisionMode.NEVER).getLocation(); - - int cx = l.getChunk().getX(); - int cz = l.getChunk().getZ(); - new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + cx, z + cz))).drain(); - } catch (Throwable e) { - Iris.reportError(e); - } - - new Spiraler(3, 3, (x, z) -> chunks.addIfMissing(world.getChunkAt(x + bx, z + bz))).drain(); - sender().sendMessage("Capturing IGenData from " + chunks.size() + " nearby chunks."); - try { - File ff = Iris.instance.getDataFile("reports/" + M.ms() + ".txt"); - PrintWriter pw = new PrintWriter(ff); - pw.println("=== Iris Chunk Report ==="); - pw.println("== General Info =="); - pw.println("Iris Version: " + Iris.instance.getDescription().getVersion()); - pw.println("Bukkit Version: " + Bukkit.getBukkitVersion()); - pw.println("MC Version: " + Bukkit.getVersion()); - pw.println("PaperSpigot: " + (PaperLib.isPaper() ? "Yup!" : "Nope!")); - pw.println("Report Captured At: " + new Date()); - pw.println("Chunks: (" + chunks.size() + "): "); - - for (Chunk i : chunks) { - pw.println("- [" + i.getX() + ", " + i.getZ() + "]"); - } - - int regions = 0; - long size = 0; - String age = "No idea..."; - - try { - for (File i : Objects.requireNonNull(new File(world.getWorldFolder(), "region").listFiles())) { - if (i.isFile()) { - size += i.length(); - } - } - } catch (Throwable e) { - Iris.reportError(e); - } - - try { - FileTime creationTime = (FileTime) Files.getAttribute(world.getWorldFolder().toPath(), "creationTime"); - age = hrf(Duration.of(M.ms() - creationTime.toMillis(), ChronoUnit.MILLIS)); - } catch (IOException e) { - Iris.reportError(e); - } - - KList biomes = new KList<>(); - KList caveBiomes = new KList<>(); - KMap>> objects = new KMap<>(); - - for (Chunk i : chunks) { - for (int j = 0; j < 16; j += 3) { - - for (int k = 0; k < 16; k += 3) { - - assert engine() != null; - IrisBiome bb = engine().getSurfaceBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); - IrisBiome bxf = engine().getCaveBiome((i.getX() * 16) + j, (i.getZ() * 16) + k); - biomes.addIfMissing(bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"); - caveBiomes.addIfMissing(bxf.getName() + " (" + bxf.getLoadFile().getName() + ")"); - exportObjects(bb, pw, engine(), objects); - exportObjects(bxf, pw, engine(), objects); - } - } - } - - regions = Objects.requireNonNull(new File(world.getWorldFolder().getPath() + "/region").list()).length; - - pw.println(); - pw.println("== World Info =="); - pw.println("World Name: " + world.getName()); - pw.println("Age: " + age); - pw.println("Folder: " + world.getWorldFolder().getPath()); - pw.println("Regions: " + Form.f(regions)); - pw.println("Chunks: max. " + Form.f(regions * 32 * 32)); - pw.println("World Size: min. " + Form.fileSize(size)); - pw.println(); - pw.println("== Biome Info =="); - pw.println("Found " + biomes.size() + " Biome(s): "); - - for (String i : biomes) { - pw.println("- " + i); - } - pw.println(); - - pw.println("== Object Info =="); - - for (String i : objects.k()) { - pw.println("- " + i); - - for (String j : objects.get(i).k()) { - pw.println(" @ " + j); - - for (String k : objects.get(i).get(j)) { - pw.println(" * " + k); - } - } - } - - pw.println(); - pw.close(); - - sender().sendMessage("Reported to: " + ff.getPath()); - } catch (FileNotFoundException e) { - e.printStackTrace(); - Iris.reportError(e); - } - } - - private void exportObjects(IrisBiome bb, PrintWriter pw, Engine g, KMap>> objects) { - String n1 = bb.getName() + " [" + Form.capitalize(bb.getInferredType().name().toLowerCase()) + "] " + " (" + bb.getLoadFile().getName() + ")"; - int m = 0; - KSet stop = new KSet<>(); - for (IrisObjectPlacement f : bb.getObjects()) { - m++; - String n2 = "Placement #" + m + " (" + f.getPlace().size() + " possible objects)"; - - for (String i : f.getPlace()) { - String nn3 = i + ": [ERROR] Failed to find object!"; - - try { - if (stop.contains(i)) { - continue; - } - - File ff = g.getData().getObjectLoader().findFile(i); - BlockVector sz = IrisObject.sampleSize(ff); - nn3 = i + ": size=[" + sz.getBlockX() + "," + sz.getBlockY() + "," + sz.getBlockZ() + "] location=[" + ff.getPath() + "]"; - stop.add(i); - } catch (Throwable e) { - Iris.reportError(e); - } - - String n3 = nn3; - - objects.compute(n1, (k1, v1) -> - { - //noinspection ReplaceNullCheck - if (v1 == null) { - return new KMap<>(); - } - - return v1; - }).compute(n2, (k, v) -> - { - if (v == null) { - return new KList().qaddIfMissing(n3); - } - - v.addIfMissing(n3); - return v; - }); - } - } - } - - public static String hrf(Duration duration) { - return duration.toString().substring(2).replaceAll("(\\d[HMS])(?!$)", "$1 ").toLowerCase(); - } -}