From 3b76bb64a9d1fba767d241324f629b2cec3008c2 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Sat, 1 Aug 2020 04:36:57 -0400 Subject: [PATCH] Oh the commands --- src/main/java/com/volmit/iris/Iris.java | 710 +----------------- .../com/volmit/iris/IrisHotloadManager.java | 18 +- .../java/com/volmit/iris/IrisSettings.java | 4 +- .../com/volmit/iris/command/CommandIris.java | 9 + .../volmit/iris/command/CommandIrisGoto.java | 135 ++++ .../iris/command/CommandIrisMetrics.java | 55 ++ .../iris/command/CommandIrisObject.java | 61 ++ .../command/CommandIrisObjectContract.java | 62 ++ .../iris/command/CommandIrisObjectExpand.java | 62 ++ .../iris/command/CommandIrisObjectP1.java | 66 ++ .../iris/command/CommandIrisObjectP2.java | 66 ++ .../iris/command/CommandIrisObjectPaste.java | 91 +++ .../iris/command/CommandIrisObjectSave.java | 61 ++ .../iris/command/CommandIrisObjectShift.java | 63 ++ .../iris/command/CommandIrisObjectWand.java | 40 + .../iris/command/CommandIrisObjectXAY.java | 91 +++ .../iris/command/CommandIrisObjectXPY.java | 79 ++ .../iris/command/CommandIrisStudio.java | 4 + .../iris/command/CommandIrisStudioClose.java | 1 + .../iris/command/CommandIrisStudioCreate.java | 1 + .../iris/command/CommandIrisStudioList.java | 1 + .../iris/command/CommandIrisStudioOpen.java | 1 + .../command/CommandIrisStudioPackage.java | 141 ++++ .../volmit/iris/command/CommandIrisWhat.java | 63 ++ .../iris/command/CommandIrisWhatBlock.java | 46 ++ .../iris/command/CommandIrisWhatHand.java | 46 ++ .../volmit/iris/command/CommandIrisWorld.java | 39 + .../iris/command/util/MortarCommand.java | 2 +- .../generator/ParallaxChunkGenerator.java | 42 -- .../iris/generator/TerrainChunkGenerator.java | 37 +- .../iris/object/IrisDepositGenerator.java | 87 ++- .../com/volmit/iris/object/IrisObject.java | 4 +- .../iris/object/atomics/AtomicWorldData.java | 17 +- .../com/volmit/iris/util/BlockDataTools.java | 14 +- 34 files changed, 1427 insertions(+), 792 deletions(-) create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisGoto.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisMetrics.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObject.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectContract.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectExpand.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectP1.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectP2.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectSave.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectShift.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectWand.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectXAY.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisObjectXPY.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisStudioPackage.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisWhat.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisWhatHand.java create mode 100644 src/main/java/com/volmit/iris/command/CommandIrisWorld.java diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 9a5216ff4..f66a757ab 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -3,31 +3,17 @@ package com.volmit.iris; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; import java.util.List; -import java.util.Set; -import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.FluidCollisionMode; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; import org.bukkit.World; -import org.bukkit.WorldCreator; -import org.bukkit.WorldType; -import org.bukkit.block.data.BlockData; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; -import org.bukkit.util.Vector; -import org.zeroturnaround.zip.ZipUtil; import com.google.gson.Gson; import com.volmit.iris.command.CommandIris; @@ -42,22 +28,13 @@ import com.volmit.iris.layer.post.PostSlabber; import com.volmit.iris.layer.post.PostWallPatcher; import com.volmit.iris.layer.post.PostWaterlogger; import com.volmit.iris.object.IrisBiome; -import com.volmit.iris.object.IrisDimension; -import com.volmit.iris.object.IrisGenerator; -import com.volmit.iris.object.IrisObject; -import com.volmit.iris.object.IrisObjectPlacement; -import com.volmit.iris.object.IrisRegion; import com.volmit.iris.util.BiomeResult; -import com.volmit.iris.util.BlockDataTools; import com.volmit.iris.util.BoardManager; import com.volmit.iris.util.BoardProvider; import com.volmit.iris.util.BoardSettings; import com.volmit.iris.util.CNG; import com.volmit.iris.util.ChronoLatch; -import com.volmit.iris.util.Cuboid; -import com.volmit.iris.util.Cuboid.CuboidDirection; import com.volmit.iris.util.Desc; -import com.volmit.iris.util.Direction; import com.volmit.iris.util.Form; import com.volmit.iris.util.GroupedExecutor; import com.volmit.iris.util.IO; @@ -68,9 +45,6 @@ import com.volmit.iris.util.JSONObject; import com.volmit.iris.util.JarScanner; import com.volmit.iris.util.KList; import com.volmit.iris.util.KMap; -import com.volmit.iris.util.KSet; -import com.volmit.iris.util.O; -import com.volmit.iris.util.RNG; import com.volmit.iris.util.RollingSequence; import com.volmit.iris.util.ScoreDirection; import com.volmit.iris.wand.WandController; @@ -87,6 +61,8 @@ public class Iris extends MortarPlugin implements BoardProvider private BoardManager manager; private String mem = "..."; private ChronoLatch cl = new ChronoLatch(1000); + private ChronoLatch clf = new ChronoLatch(1000); + private KList lines = new KList<>(); public RollingSequence hits = new RollingSequence(20); public RollingSequence tp = new RollingSequence(100); public static KList> postProcessors; @@ -178,8 +154,13 @@ public class Iris extends MortarPlugin implements BoardProvider @Override public List getLines(Player player) { + if(!clf.flip()) + { + return lines; + } + World world = player.getWorld(); - List lines = new ArrayList<>(); + lines.clear(); if(world.getGenerator() instanceof IrisChunkGenerator) { @@ -281,684 +262,9 @@ public class Iris extends MortarPlugin implements BoardProvider } } - @SuppressWarnings("deprecation") @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(super.onCommand(sender, command, label, args)) - { - return true; - } - - if(command.getName().equals("iris")) - { - if(args.length == 0) - { - imsg(sender, "/iris dev [dimension] - Create a new dev world"); - imsg(sender, "/iris what - Data about items & blocks"); - imsg(sender, "/iris goto [other-biome] [-cave] - Fast goto biome"); - imsg(sender, "/iris wand [?] - Get a wand / help"); - imsg(sender, "/iris save - Save object"); - imsg(sender, "/iris load - Load & place object"); - } - - if(args.length >= 1) - { - if(args[0].equalsIgnoreCase("goto") && args.length >= 2) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - World world = p.getWorld(); - IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator(); - int tries = 10000; - boolean cave = false; - IrisBiome biome2 = null; - if(args.length > 2) - { - if(args[2].equalsIgnoreCase("-cave")) - { - cave = true; - } - - else - { - biome2 = data.getBiomeLoader().load(args[2]); - - if(biome2 == null) - { - sender.sendMessage(args[2] + " is not a biome. Use the file name (without extension)"); - return true; - } - } - } - - for(String i : args) - { - if(i.equalsIgnoreCase("-cave")) - { - cave = true; - } - } - - IrisBiome biome = data.getBiomeLoader().load(args[1]); - - if(biome == null) - { - sender.sendMessage(args[1] + " is not a biome. Use the file name (without extension)"); - return true; - } - - while(tries > 0) - { - tries--; - - int xx = (int) (RNG.r.i(-29999970, 29999970)); - int zz = (int) (RNG.r.i(-29999970, 29999970)); - if((cave ? g.sampleCaveBiome(xx, zz) : g.sampleTrueBiome(xx, zz)).getBiome().getLoadKey().equals(biome.getLoadKey())) - { - if(biome2 != null) - { - for(int i = 0; i < 64; i++) - { - int ax = xx + RNG.r.i(-64, 32); - int az = zz + RNG.r.i(-64, 32); - - if((cave ? g.sampleCaveBiome(ax, az) : g.sampleTrueBiome(ax, az)).getBiome().getLoadKey().equals(biome2.getLoadKey())) - { - tries--; - p.teleport(new Location(world, xx, world.getHighestBlockYAt(xx, zz), zz)); - sender.sendMessage("Found border in " + (10000 - tries) + " tries!"); - return true; - } - } - } - - else - { - p.teleport(new Location(world, xx, world.getHighestBlockYAt(xx, zz), zz)); - sender.sendMessage("Found in " + (10000 - tries) + " tries!"); - return true; - } - } - } - - sender.sendMessage("Tried to find " + biome.getName() + " looked in 10,000 places no dice."); - - return true; - } - } - - if(args[0].equalsIgnoreCase("metrics")) - { - if(sender instanceof Player) - { - Player p = (Player) sender; - World world = p.getWorld(); - IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator(); - IrisMetrics m = g.getMetrics(); - - imsg(sender, "Thread Count: " + ChatColor.BOLD + "" + ChatColor.WHITE + g.getThreads()); - imsg(sender, "Total : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTotal().getAverage(), 2)); - imsg(sender, " Terrain : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTerrain().getAverage(), 2)); - imsg(sender, " Parallax: " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getParallax().getAverage(), 2)); - imsg(sender, " Post : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getPost().getAverage(), 2)); - - return true; - } - } - - if(args[0].equalsIgnoreCase("what")) - { - if(args.length != 2) - { - imsg(sender, "/iris what - Data about items & blocks"); - return true; - } - - BlockData bd = null; - - try - { - if(args[1].toLowerCase().startsWith("h")) - { - bd = BlockDataTools.getBlockData(((Player) sender).getInventory().getItemInMainHand().getType().name()); - } - - else - { - bd = ((Player) sender).getTargetBlockExact(128, FluidCollisionMode.NEVER).getBlockData(); - } - - } - - catch(Throwable e) - { - - } - - if(bd == null) - { - imsg(sender, "No data found."); - return true; - } - - imsg(sender, "Material: " + ChatColor.GREEN + bd.getMaterial().name()); - imsg(sender, "Full: " + ChatColor.WHITE + bd.getAsString(true)); - - return true; - } - - if(args[0].equalsIgnoreCase("wand")) - { - if(args.length == 1) - { - ((Player) sender).getInventory().addItem(WandController.createWand()); - } - - else if(args[1].equalsIgnoreCase("x+y")) - { - Player p = (Player) sender; - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - b[0].add(new Vector(0, 1, 0)); - b[1].add(new Vector(0, 1, 0)); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - b[0] = a1; - a2 = b[1]; - cursor = new Cuboid(a1, a2); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); - } - - else if(args[1].equalsIgnoreCase("x&y")) - { - Player p = (Player) sender; - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Location a1x = b[0].clone(); - Location a2x = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Cuboid cursorx = new Cuboid(a1, a2); - - while(!cursor.containsOnly(Material.AIR)) - { - a1.add(new Vector(0, 1, 0)); - a2.add(new Vector(0, 1, 0)); - cursor = new Cuboid(a1, a2); - } - - a1.add(new Vector(0, -1, 0)); - a2.add(new Vector(0, -1, 0)); - - while(!cursorx.containsOnly(Material.AIR)) - { - a1x.add(new Vector(0, -1, 0)); - a2x.add(new Vector(0, -1, 0)); - cursorx = new Cuboid(a1x, a2x); - } - - a1x.add(new Vector(0, 1, 0)); - a2x.add(new Vector(0, 1, 0)); - b[0] = a1; - b[1] = a2x; - cursor = new Cuboid(b[0], b[1]); - cursor = cursor.contract(CuboidDirection.North); - cursor = cursor.contract(CuboidDirection.South); - cursor = cursor.contract(CuboidDirection.East); - cursor = cursor.contract(CuboidDirection.West); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); - } - - else if(args[1].equalsIgnoreCase(">") && args.length > 2) - { - Player p = (Player) sender; - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - int amt = Integer.valueOf(args[2]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - a1.add(d.toVector().multiply(amt)); - a2.add(d.toVector().multiply(amt)); - Cuboid cursor = new Cuboid(a1, a2); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); - } - - else if(args[1].equalsIgnoreCase("+") && args.length > 2) - { - Player p = (Player) sender; - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - int amt = Integer.valueOf(args[2]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - cursor = cursor.expand(d, amt); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); - } - - else if(args[1].equalsIgnoreCase("-") && args.length > 2) - { - Player p = (Player) sender; - - if(!WandController.isWand(p)) - { - sender.sendMessage("Ready your Wand."); - return true; - } - - int amt = Integer.valueOf(args[2]); - Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); - Location a1 = b[0].clone(); - Location a2 = b[1].clone(); - Cuboid cursor = new Cuboid(a1, a2); - Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); - cursor = cursor.expand(d, -amt); - b[0] = cursor.getLowerNE(); - b[1] = cursor.getUpperSW(); - p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); - p.updateInventory(); - p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); - } - - else if(args[1].equalsIgnoreCase("p1")) - { - ItemStack wand = ((Player) sender).getInventory().getItemInMainHand(); - if(WandController.isWand(wand)) - { - Location[] g = WandController.getCuboid(wand); - g[0] = ((Player) sender).getLocation().getBlock().getLocation().clone().add(0, -1, 0); - ((Player) sender).setItemInHand(WandController.createWand(g[0], g[1])); - } - } - - else if(args[1].equalsIgnoreCase("p2")) - { - ItemStack wand = ((Player) sender).getInventory().getItemInMainHand(); - if(WandController.isWand(wand)) - { - Location[] g = WandController.getCuboid(wand); - g[1] = ((Player) sender).getLocation().getBlock().getLocation().clone().add(0, -1, 0); - ((Player) sender).setItemInHand(WandController.createWand(g[0], g[1])); - } - } - - else if(args[1].equalsIgnoreCase("l1")) - { - ItemStack wand = ((Player) sender).getInventory().getItemInMainHand(); - if(WandController.isWand(wand)) - { - Location[] g = WandController.getCuboid(wand); - g[0] = ((Player) sender).getTargetBlock((Set) null, 256).getLocation().clone(); - ((Player) sender).setItemInHand(WandController.createWand(g[0], g[1])); - } - } - - else if(args[1].equalsIgnoreCase("l2")) - { - ItemStack wand = ((Player) sender).getInventory().getItemInMainHand(); - if(WandController.isWand(wand)) - { - Location[] g = WandController.getCuboid(wand); - g[1] = ((Player) sender).getTargetBlock((Set) null, 256).getLocation().clone(); - ((Player) sender).setItemInHand(WandController.createWand(g[0], g[1])); - } - } - - else - { - imsg(sender, "/iris wand x+y - Expand up and out"); - imsg(sender, "/iris wand x&y - Expand up and down and out"); - imsg(sender, "/iris wand > - Shift in looking direction"); - imsg(sender, "/iris wand + - Expand in looking direction"); - imsg(sender, "/iris wand - - Contract in looking direction"); - imsg(sender, "/iris wand p1 - Set wand pos 1 where standing"); - imsg(sender, "/iris wand p2 - Set wand pos 2 where standing"); - imsg(sender, "/iris wand l1 - Set wand pos 1 where looking"); - imsg(sender, "/iris wand l2 - Set wand pos 2 where looking"); - } - } - - if(args[0].equalsIgnoreCase("save") && args.length >= 2) - { - ItemStack wand = ((Player) sender).getInventory().getItemInMainHand(); - IrisObject o = WandController.createSchematic(wand); - try - { - o.write(new File(getDataFolder(), "objects/" + args[1] + ".iob")); - imsg(sender, "Saved " + "objects/" + args[1] + ".iob"); - ((Player) sender).getWorld().playSound(((Player) sender).getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); - } - - catch(IOException e) - { - imsg(sender, "Failed to save " + "objects/" + args[1] + ".iob"); - - e.printStackTrace(); - } - } - - if(args[0].equalsIgnoreCase("load") && args.length >= 2) - { - File file = new File(getDataFolder(), "objects/" + args[1] + ".iob"); - boolean intoWand = false; - - for(String i : args) - { - if(i.equalsIgnoreCase("-edit")) - { - intoWand = true; - } - } - - if(!file.exists()) - { - imsg(sender, "Can't find " + "objects/" + args[1] + ".iob"); - } - - ItemStack wand = ((Player) sender).getInventory().getItemInMainHand(); - IrisObject o = new IrisObject(0, 0, 0); - - try - { - o.read(new File(getDataFolder(), "objects/" + args[1] + ".iob")); - imsg(sender, "Loaded " + "objects/" + args[1] + ".iob"); - - ((Player) sender).getWorld().playSound(((Player) sender).getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); - Location block = ((Player) sender).getTargetBlock((Set) null, 256).getLocation().clone().add(0, 1, 0); - - if(intoWand && WandController.isWand(wand)) - { - wand = WandController.createWand(block.clone().subtract(o.getCenter()).add(o.getW() - 1, o.getH(), o.getD() - 1), block.clone().subtract(o.getCenter())); - ((Player) sender).getInventory().setItemInMainHand(wand); - imsg(sender, "Updated wand for " + "objects/" + args[1] + ".iob"); - } - - WandController.pasteSchematic(o, block); - imsg(sender, "Placed " + "objects/" + args[1] + ".iob"); - } - - catch(IOException e) - { - imsg(sender, "Failed to load " + "objects/" + args[1] + ".iob"); - e.printStackTrace(); - } - } - - if(args[0].equalsIgnoreCase("package") || args[0].equalsIgnoreCase("pkg")) - { - String dim = "overworld"; - - if(args.length > 1) - { - dim = args[1]; - } - - String dimm = dim; - IrisDimension dimension = data.getDimensionLoader().load(dimm); - File folder = new File(getDataFolder(), "exports/" + dimension.getLoadKey()); - folder.mkdirs(); - Iris.info("Packaging Dimension " + dimension.getName()); - KSet regions = new KSet<>(); - KSet biomes = new KSet<>(); - KSet generators = new KSet<>(); - dimension.getRegions().forEach((i) -> regions.add(data.getRegionLoader().load(i))); - regions.forEach((i) -> biomes.addAll(i.getAllBiomes())); - biomes.forEach((i) -> i.getGenerators().forEach((j) -> generators.add(j.getCachedGenerator()))); - KMap renameObjects = new KMap<>(); - - for(IrisBiome i : biomes) - { - for(IrisObjectPlacement j : i.getObjects()) - { - KList newNames = new KList<>(); - - for(String k : j.getPlace()) - { - if(renameObjects.containsKey(k)) - { - newNames.add(renameObjects.get(k)); - continue; - } - - String name = UUID.randomUUID().toString().replaceAll("-", ""); - newNames.add(name); - renameObjects.put(k, name); - } - - j.setPlace(newNames); - } - } - - KMap> lookupObjects = renameObjects.flip(); - - biomes.forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) -> - { - try - { - Iris.info("- " + k + " (Object)"); - IO.copyFile(Iris.data.getObjectLoader().findFile(lookupObjects.get(k).get(0)), new File(folder, "objects/" + k + ".iob")); - } - - catch(Throwable e) - { - - } - }))); - - try - { - IO.writeAll(new File(folder, "dimensions/" + dimension.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(dimension)).toString(0)); - - for(IrisGenerator i : generators) - { - Iris.info("- " + i.getLoadKey() + " (Generator)"); - IO.writeAll(new File(folder, "generators/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0)); - } - - for(IrisRegion i : regions) - { - Iris.info("- " + i.getName() + " (Region)"); - IO.writeAll(new File(folder, "regions/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0)); - } - - for(IrisBiome i : biomes) - { - Iris.info("- " + i.getName() + " (Biome)"); - IO.writeAll(new File(folder, "biomes/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0)); - } - - ZipUtil.pack(folder, new File(getDataFolder(), "exports/" + dimension.getLoadKey() + ".iris"), 9); - IO.delete(folder); - } - - catch(Throwable e) - { - e.printStackTrace(); - } - - sender.sendMessage("Done!"); - } - - if(args[0].equalsIgnoreCase("dev")) - { - String dim = "overworld"; - - boolean fast = false; - boolean first = true; - int tc = (int) Math.max(Runtime.getRuntime().availableProcessors(), 4); - for(String i : args) - { - if(first) - { - first = false; - continue; - } - - if(i.startsWith("-t:")) - { - tc = Integer.valueOf(i.split("\\Q:\\E")[1]); - continue; - } - - if(i.equals("--fast") || i.equals("-f")) - { - fast = true; - continue; - } - - dim = i; - } - - String dimm = dim; - int tcc = tc; - boolean ff = fast; - Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> - { - for(World i : Bukkit.getWorlds()) - { - if(i.getName().startsWith("iris/")) - { - for(Player j : Bukkit.getOnlinePlayers()) - { - imsg(j, "Unloading " + i.getName()); - } - - Bukkit.unloadWorld(i, false); - } - } - - IrisDimension d = data.getDimensionLoader().load(dimm); - - if(d == null) - { - imsg(sender, "Can't find dimension: " + dimm); - return; - } - - for(Player i : Bukkit.getOnlinePlayers()) - { - imsg(i, "Creating Iris " + dimm + "..."); - } - - IrisChunkGenerator gx = new IrisChunkGenerator(dimm, tcc); - gx.setDev(true); - gx.setFastPregen(ff); - - info("Generating with " + tcc + " threads per chunk"); - O done = new O(); - done.set(false); - - J.a(() -> - { - double last = 0; - int req = 740; - while(!done.get()) - { - boolean derp = false; - double v = (double) gx.getGenerated() / (double) req; - - if(last > v || v > 1) - { - derp = true; - v = last; - } - - else - { - last = v; - } - - for(Player i : Bukkit.getOnlinePlayers()) - { - imsg(i, "Generating " + Form.pc(v) + (derp ? " (Waiting on Server...)" : "")); - } - J.sleep(3000); - } - }); - World world = Bukkit.createWorld(new WorldCreator("iris/" + UUID.randomUUID()).seed(1337).generator(gx).generateStructures(false).type(WorldType.NORMAL).environment(d.getEnvironment())); - done.set(true); - - for(Player i : Bukkit.getOnlinePlayers()) - { - imsg(i, "Generating 100%"); - } - - for(Player i : Bukkit.getOnlinePlayers()) - { - i.teleport(new Location(world, 150, 150, 275)); - - Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> - { - imsg(i, "Have Fun!"); - i.setGameMode(GameMode.SPECTATOR); - }, 5); - } - }); - } - } - - return true; - } - return super.onCommand(sender, command, label, args); } diff --git a/src/main/java/com/volmit/iris/IrisHotloadManager.java b/src/main/java/com/volmit/iris/IrisHotloadManager.java index 4d33520c9..92f70b01f 100644 --- a/src/main/java/com/volmit/iris/IrisHotloadManager.java +++ b/src/main/java/com/volmit/iris/IrisHotloadManager.java @@ -31,16 +31,24 @@ public class IrisHotloadManager boolean modified = false; int c = 0; - for(FileWatcher i : watchers) + try { - if(i.checkModified()) + for(FileWatcher i : watchers) { - c++; - Iris.info("File Modified: " + i.getFile().getPath()); - modified = true; + if(i.checkModified()) + { + c++; + Iris.info("File Modified: " + i.getFile().getPath()); + modified = true; + } } } + catch(Throwable e) + { + + } + if(modified) { watchers.clear(); diff --git a/src/main/java/com/volmit/iris/IrisSettings.java b/src/main/java/com/volmit/iris/IrisSettings.java index 58ea1b1f6..2e6c85132 100644 --- a/src/main/java/com/volmit/iris/IrisSettings.java +++ b/src/main/java/com/volmit/iris/IrisSettings.java @@ -9,7 +9,7 @@ public class IrisSettings @DontObfuscate @Desc("Iris generator threads (must be 2 or higher).") - public int threads = 8; + public int threads = 16; @DontObfuscate @Desc("Compress parallax data in memory to reduce memory usage in exchange for more cpu usage.") @@ -17,7 +17,7 @@ public class IrisSettings @DontObfuscate @Desc("Compression level (0-9) lower is faster, but is not as good compression. Best results around 3-5") - public int parallaxCompressionLevel = 9; + public int parallaxCompressionLevel = 3; public static IrisSettings get() { diff --git a/src/main/java/com/volmit/iris/command/CommandIris.java b/src/main/java/com/volmit/iris/command/CommandIris.java index 82b4e2757..264c31ec2 100644 --- a/src/main/java/com/volmit/iris/command/CommandIris.java +++ b/src/main/java/com/volmit/iris/command/CommandIris.java @@ -10,6 +10,15 @@ public class CommandIris extends MortarCommand @Command private CommandIrisStudio studio; + @Command + private CommandIrisWorld world; + + @Command + private CommandIrisWhat what; + + @Command + private CommandIrisObject object; + public CommandIris() { super("iris", "ir", "irs"); diff --git a/src/main/java/com/volmit/iris/command/CommandIrisGoto.java b/src/main/java/com/volmit/iris/command/CommandIrisGoto.java new file mode 100644 index 000000000..72407a6b3 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisGoto.java @@ -0,0 +1,135 @@ +package com.volmit.iris.command; + +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.generator.IrisChunkGenerator; +import com.volmit.iris.object.IrisBiome; +import com.volmit.iris.util.RNG; + +public class CommandIrisGoto extends MortarCommand +{ + public CommandIrisGoto() + { + super("goto", "find"); + setDescription("Find any biome or a biome border"); + requiresPermission(Iris.perm.studio); + setCategory("World"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(args.length <= 1) + { + sender.sendMessage("/iris world goto " + getArgsUsage()); + return true; + } + + if(sender.isPlayer()) + { + Player p = sender.player(); + World world = p.getWorld(); + + if(!(world.getGenerator() instanceof IrisChunkGenerator)) + { + sender.sendMessage("You must be in an iris world."); + return true; + } + + IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator(); + int tries = 10000; + boolean cave = false; + IrisBiome biome2 = null; + if(args.length > 2) + { + if(args[2].equalsIgnoreCase("-cave")) + { + cave = true; + } + + else + { + biome2 = Iris.data.getBiomeLoader().load(args[2]); + + if(biome2 == null) + { + sender.sendMessage(args[2] + " is not a biome. Use the file name (without extension)"); + return true; + } + } + } + + for(String i : args) + { + if(i.equalsIgnoreCase("-cave")) + { + cave = true; + } + } + + IrisBiome biome = Iris.data.getBiomeLoader().load(args[1]); + + if(biome == null) + { + sender.sendMessage(args[1] + " is not a biome. Use the file name (without extension)"); + return true; + } + + while(tries > 0) + { + tries--; + + int xx = (int) (RNG.r.i(-29999970, 29999970)); + int zz = (int) (RNG.r.i(-29999970, 29999970)); + if((cave ? g.sampleCaveBiome(xx, zz) : g.sampleTrueBiome(xx, zz)).getBiome().getLoadKey().equals(biome.getLoadKey())) + { + if(biome2 != null) + { + for(int i = 0; i < 64; i++) + { + int ax = xx + RNG.r.i(-64, 32); + int az = zz + RNG.r.i(-64, 32); + + if((cave ? g.sampleCaveBiome(ax, az) : g.sampleTrueBiome(ax, az)).getBiome().getLoadKey().equals(biome2.getLoadKey())) + { + tries--; + p.teleport(new Location(world, xx, world.getHighestBlockYAt(xx, zz), zz)); + sender.sendMessage("Found border in " + (10000 - tries) + " tries!"); + return true; + } + } + } + + else + { + p.teleport(new Location(world, xx, world.getHighestBlockYAt(xx, zz), zz)); + sender.sendMessage("Found in " + (10000 - tries) + " tries!"); + return true; + } + } + } + + sender.sendMessage("Tried to find " + biome.getName() + " looked in 10,000 places no dice."); + + return true; + } + + else + { + sender.sendMessage("Players only."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[biome] [otherbiome] [-cave]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisMetrics.java b/src/main/java/com/volmit/iris/command/CommandIrisMetrics.java new file mode 100644 index 000000000..cbcdf86c9 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisMetrics.java @@ -0,0 +1,55 @@ +package com.volmit.iris.command; + +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.IrisMetrics; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.generator.IrisChunkGenerator; +import com.volmit.iris.util.Form; + +public class CommandIrisMetrics extends MortarCommand +{ + public CommandIrisMetrics() + { + super("metrics", "stats", "mt"); + setDescription("Get timings for this world"); + requiresPermission(Iris.perm.studio); + setCategory("Metrics"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(sender.isPlayer()) + { + Player p = (Player) sender; + World world = p.getWorld(); + IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator(); + IrisMetrics m = g.getMetrics(); + sender.sendMessage("Thread Count: " + ChatColor.BOLD + "" + ChatColor.WHITE + g.getThreads()); + sender.sendMessage("Total : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTotal().getAverage(), 2)); + sender.sendMessage(" Terrain : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTerrain().getAverage(), 2)); + sender.sendMessage(" Parallax: " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getParallax().getAverage(), 2)); + sender.sendMessage(" Post : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getPost().getAverage(), 2)); + + return true; + } + + else + { + sender.sendMessage("Players only."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObject.java b/src/main/java/com/volmit/iris/command/CommandIrisObject.java new file mode 100644 index 000000000..46f555c62 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObject.java @@ -0,0 +1,61 @@ +package com.volmit.iris.command; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.Command; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; + +public class CommandIrisObject extends MortarCommand +{ + @Command + private CommandIrisObjectWand wand; + + @Command + private CommandIrisObjectXPY xpy; + + @Command + private CommandIrisObjectXAY xay; + + @Command + private CommandIrisObjectShift shift; + + @Command + private CommandIrisObjectExpand expand; + + @Command + private CommandIrisObjectContract contract; + + @Command + private CommandIrisObjectP1 p1; + + @Command + private CommandIrisObjectP2 p2; + + @Command + private CommandIrisObjectSave save; + + @Command + private CommandIrisObjectPaste paste; + + public CommandIrisObject() + { + super("object", "iob", "o"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Object Commands"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + sender.sendMessage("Iris Object Commands"); + printHelp(sender); + return true; + } + + @Override + protected String getArgsUsage() + { + return "[subcommand]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectContract.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectContract.java new file mode 100644 index 000000000..4c2e86df5 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectContract.java @@ -0,0 +1,62 @@ +package com.volmit.iris.command; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.util.Cuboid; +import com.volmit.iris.util.Direction; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectContract extends MortarCommand +{ + public CommandIrisObjectContract() + { + super("-"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Contract a selection based on your lookign direction"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + int amt = Integer.valueOf(args[2]); + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); + cursor = cursor.expand(d, -amt); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[amt]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectExpand.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectExpand.java new file mode 100644 index 000000000..4e7e7a841 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectExpand.java @@ -0,0 +1,62 @@ +package com.volmit.iris.command; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.util.Cuboid; +import com.volmit.iris.util.Direction; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectExpand extends MortarCommand +{ + public CommandIrisObjectExpand() + { + super("+"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Expand based on looking direction"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + int amt = Integer.valueOf(args[2]); + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); + cursor = cursor.expand(d, amt); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[amt]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectP1.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectP1.java new file mode 100644 index 000000000..6f0b8bec1 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectP1.java @@ -0,0 +1,66 @@ +package com.volmit.iris.command; + +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectP1 extends MortarCommand +{ + public CommandIrisObjectP1() + { + super("p1"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Set point 1 to pos (or look)"); + } + + @SuppressWarnings("deprecation") + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + ItemStack wand = p.getInventory().getItemInMainHand(); + + if(WandController.isWand(wand)) + { + Location[] g = WandController.getCuboid(wand); + g[0] = p.getLocation().getBlock().getLocation().clone().add(0, -1, 0); + + if(args.length == 1 && args[0].equals("-l")) + { + g[0] = p.getTargetBlock((Set) null, 256).getLocation().clone(); + } + + p.setItemInHand(WandController.createWand(g[0], g[1])); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[-l]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectP2.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectP2.java new file mode 100644 index 000000000..b579ba0d5 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectP2.java @@ -0,0 +1,66 @@ +package com.volmit.iris.command; + +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectP2 extends MortarCommand +{ + public CommandIrisObjectP2() + { + super("p2"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Set point 1 to pos (or look)"); + } + + @SuppressWarnings("deprecation") + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + ItemStack wand = p.getInventory().getItemInMainHand(); + + if(WandController.isWand(wand)) + { + Location[] g = WandController.getCuboid(wand); + g[1] = p.getLocation().getBlock().getLocation().clone().add(0, -1, 0); + + if(args.length == 1 && args[0].equals("-l")) + { + g[1] = p.getTargetBlock((Set) null, 256).getLocation().clone(); + } + + p.setItemInHand(WandController.createWand(g[0], g[1])); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[-l]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java new file mode 100644 index 000000000..ca0397e9b --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectPaste.java @@ -0,0 +1,91 @@ +package com.volmit.iris.command; + +import java.io.File; +import java.io.IOException; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.object.IrisObject; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectPaste extends MortarCommand +{ + public CommandIrisObjectPaste() + { + super("paste", "pasta"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Paste an object"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + File file = new File(Iris.instance.getDataFolder(), "objects/" + args[1] + ".iob"); + boolean intoWand = false; + + for(String i : args) + { + if(i.equalsIgnoreCase("-edit")) + { + intoWand = true; + } + } + + if(!file.exists()) + { + sender.sendMessage("Can't find " + "objects/" + args[1] + ".iob"); + } + + ItemStack wand = ((Player) sender).getInventory().getItemInMainHand(); + IrisObject o = new IrisObject(0, 0, 0); + + try + { + o.read(new File(Iris.instance.getDataFolder(), "objects/" + args[1] + ".iob")); + sender.sendMessage("Loaded " + "objects/" + args[1] + ".iob"); + + ((Player) sender).getWorld().playSound(((Player) sender).getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + Location block = ((Player) sender).getTargetBlock((Set) null, 256).getLocation().clone().add(0, 1, 0); + + if(intoWand && WandController.isWand(wand)) + { + wand = WandController.createWand(block.clone().subtract(o.getCenter()).add(o.getW() - 1, o.getH(), o.getD() - 1), block.clone().subtract(o.getCenter())); + p.getInventory().setItemInMainHand(wand); + sender.sendMessage("Updated wand for " + "objects/" + args[1] + ".iob"); + } + + WandController.pasteSchematic(o, block); + sender.sendMessage("Placed " + "objects/" + args[1] + ".iob"); + } + + catch(IOException e) + { + sender.sendMessage("Failed to load " + "objects/" + args[1] + ".iob"); + e.printStackTrace(); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[name] [-edit]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectSave.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectSave.java new file mode 100644 index 000000000..b9bab497c --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectSave.java @@ -0,0 +1,61 @@ +package com.volmit.iris.command; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.object.IrisObject; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectSave extends MortarCommand +{ + public CommandIrisObjectSave() + { + super("save"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Save an object"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + ItemStack wand = p.getInventory().getItemInMainHand(); + IrisObject o = WandController.createSchematic(wand); + + try + { + o.write(new File(Iris.instance.getDataFolder(), "objects/" + args[1] + ".iob")); + sender.sendMessage("Saved " + "objects/" + args[1] + ".iob"); + p.getWorld().playSound(p.getLocation(), Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f); + } + + catch(IOException e) + { + sender.sendMessage("Failed to save " + "objects/" + args[1] + ".iob. Are you holding your wand?"); + + e.printStackTrace(); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[name]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectShift.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectShift.java new file mode 100644 index 000000000..42ce35c95 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectShift.java @@ -0,0 +1,63 @@ +package com.volmit.iris.command; + +import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.util.Cuboid; +import com.volmit.iris.util.Direction; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectShift extends MortarCommand +{ + public CommandIrisObjectShift() + { + super(">"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Shift selection based on direction"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + int amt = Integer.valueOf(args[2]); + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Direction d = Direction.closest(p.getLocation().getDirection()).reverse(); + a1.add(d.toVector().multiply(amt)); + a2.add(d.toVector().multiply(amt)); + Cuboid cursor = new Cuboid(a1, a2); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[amt]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectWand.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectWand.java new file mode 100644 index 000000000..9547ad72f --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectWand.java @@ -0,0 +1,40 @@ +package com.volmit.iris.command; + +import org.bukkit.Sound; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectWand extends MortarCommand +{ + public CommandIrisObjectWand() + { + super("wand", "w"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Get an Iris Wand for selecting objects"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have an inventory"); + return true; + } + + sender.player().getInventory().addItem(WandController.createWand()); + sender.player().playSound(sender.player().getLocation(), Sound.ITEM_ARMOR_EQUIP_NETHERITE, 1f, 1.5f); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[subcommand]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectXAY.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectXAY.java new file mode 100644 index 000000000..1a679b010 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectXAY.java @@ -0,0 +1,91 @@ +package com.volmit.iris.command; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.util.Cuboid; +import com.volmit.iris.util.Cuboid.CuboidDirection; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectXAY extends MortarCommand +{ + public CommandIrisObjectXAY() + { + super("x&y"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Auto select up, down and out"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Location a1x = b[0].clone(); + Location a2x = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + Cuboid cursorx = new Cuboid(a1, a2); + + while(!cursor.containsOnly(Material.AIR)) + { + a1.add(new Vector(0, 1, 0)); + a2.add(new Vector(0, 1, 0)); + cursor = new Cuboid(a1, a2); + } + + a1.add(new Vector(0, -1, 0)); + a2.add(new Vector(0, -1, 0)); + + while(!cursorx.containsOnly(Material.AIR)) + { + a1x.add(new Vector(0, -1, 0)); + a2x.add(new Vector(0, -1, 0)); + cursorx = new Cuboid(a1x, a2x); + } + + a1x.add(new Vector(0, 1, 0)); + a2x.add(new Vector(0, 1, 0)); + b[0] = a1; + b[1] = a2x; + cursor = new Cuboid(b[0], b[1]); + cursor = cursor.contract(CuboidDirection.North); + cursor = cursor.contract(CuboidDirection.South); + cursor = cursor.contract(CuboidDirection.East); + cursor = cursor.contract(CuboidDirection.West); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[subcommand]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisObjectXPY.java b/src/main/java/com/volmit/iris/command/CommandIrisObjectXPY.java new file mode 100644 index 000000000..7d0ad43e3 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisObjectXPY.java @@ -0,0 +1,79 @@ +package com.volmit.iris.command; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.util.Vector; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.util.Cuboid; +import com.volmit.iris.util.Cuboid.CuboidDirection; +import com.volmit.iris.wand.WandController; + +public class CommandIrisObjectXPY extends MortarCommand +{ + public CommandIrisObjectXPY() + { + super("x+y"); + requiresPermission(Iris.perm); + setCategory("Object"); + setDescription("Auto select up and out"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(!sender.isPlayer()) + { + sender.sendMessage("You don't have a wand"); + return true; + } + + Player p = sender.player(); + + if(!WandController.isWand(p)) + { + sender.sendMessage("Ready your Wand."); + return true; + } + Location[] b = WandController.getCuboid(p.getInventory().getItemInMainHand()); + b[0].add(new Vector(0, 1, 0)); + b[1].add(new Vector(0, 1, 0)); + Location a1 = b[0].clone(); + Location a2 = b[1].clone(); + Cuboid cursor = new Cuboid(a1, a2); + + while(!cursor.containsOnly(Material.AIR)) + { + a1.add(new Vector(0, 1, 0)); + a2.add(new Vector(0, 1, 0)); + cursor = new Cuboid(a1, a2); + } + + a1.add(new Vector(0, -1, 0)); + a2.add(new Vector(0, -1, 0)); + b[0] = a1; + a2 = b[1]; + cursor = new Cuboid(a1, a2); + cursor = cursor.contract(CuboidDirection.North); + cursor = cursor.contract(CuboidDirection.South); + cursor = cursor.contract(CuboidDirection.East); + cursor = cursor.contract(CuboidDirection.West); + b[0] = cursor.getLowerNE(); + b[1] = cursor.getUpperSW(); + p.getInventory().setItemInMainHand(WandController.createWand(b[0], b[1])); + p.updateInventory(); + p.playSound(p.getLocation(), Sound.ENTITY_ITEM_FRAME_ROTATE_ITEM, 1f, 0.55f); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[subcommand]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudio.java b/src/main/java/com/volmit/iris/command/CommandIrisStudio.java index 66ec6d3d4..6e0786e2d 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudio.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudio.java @@ -16,6 +16,9 @@ public class CommandIrisStudio extends MortarCommand @Command private CommandIrisStudioClose close; + @Command + private CommandIrisStudioPackage pkg; + @Command private CommandIrisStudioList list; @@ -23,6 +26,7 @@ public class CommandIrisStudio extends MortarCommand { super("studio", "std"); requiresPermission(Iris.perm.studio); + setCategory("Studio"); } @Override diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioClose.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioClose.java index 76a648c56..e2e37607c 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioClose.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioClose.java @@ -15,6 +15,7 @@ public class CommandIrisStudioClose extends MortarCommand super("close", "x"); requiresPermission(Iris.perm.studio); setDescription("Close the existing dimension"); + setCategory("Studio"); } @Override diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioCreate.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioCreate.java index b68c58d4a..9a2c820ec 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioCreate.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioCreate.java @@ -27,6 +27,7 @@ public class CommandIrisStudioCreate extends MortarCommand super("create", "new"); requiresPermission(Iris.perm.studio); setDescription("Create a new project & open it."); + setCategory("Studio"); } @Override diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioList.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioList.java index 1f1ed9c0a..1afbf9d32 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioList.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioList.java @@ -14,6 +14,7 @@ public class CommandIrisStudioList extends MortarCommand super("list", "l"); requiresPermission(Iris.perm.studio); setDescription("List projects that can be opened."); + setCategory("Studio"); } @Override diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioOpen.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioOpen.java index 98fa783ab..6d36f08d7 100644 --- a/src/main/java/com/volmit/iris/command/CommandIrisStudioOpen.java +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioOpen.java @@ -11,6 +11,7 @@ public class CommandIrisStudioOpen extends MortarCommand super("open", "o"); requiresPermission(Iris.perm.studio); setDescription("Create a new temporary world to design a dimension."); + setCategory("Studio"); } @Override diff --git a/src/main/java/com/volmit/iris/command/CommandIrisStudioPackage.java b/src/main/java/com/volmit/iris/command/CommandIrisStudioPackage.java new file mode 100644 index 000000000..c6abdb87d --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisStudioPackage.java @@ -0,0 +1,141 @@ +package com.volmit.iris.command; + +import java.io.File; +import java.util.UUID; + +import org.zeroturnaround.zip.ZipUtil; + +import com.google.gson.Gson; +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.object.IrisBiome; +import com.volmit.iris.object.IrisDimension; +import com.volmit.iris.object.IrisGenerator; +import com.volmit.iris.object.IrisObjectPlacement; +import com.volmit.iris.object.IrisRegion; +import com.volmit.iris.util.IO; +import com.volmit.iris.util.J; +import com.volmit.iris.util.JSONObject; +import com.volmit.iris.util.KList; +import com.volmit.iris.util.KMap; +import com.volmit.iris.util.KSet; + +public class CommandIrisStudioPackage extends MortarCommand +{ + public CommandIrisStudioPackage() + { + super("package", "pkg"); + requiresPermission(Iris.perm.studio); + setDescription("Package your dimension into a compressed format."); + setCategory("Studio"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + + J.a(() -> + { + String dim = "overworld"; + + if(args.length > 1) + { + dim = args[1]; + } + + String dimm = dim; + IrisDimension dimension = Iris.data.getDimensionLoader().load(dimm); + File folder = new File(Iris.instance.getDataFolder(), "exports/" + dimension.getLoadKey()); + folder.mkdirs(); + Iris.info("Packaging Dimension " + dimension.getName()); + KSet regions = new KSet<>(); + KSet biomes = new KSet<>(); + KSet generators = new KSet<>(); + dimension.getRegions().forEach((i) -> regions.add(Iris.data.getRegionLoader().load(i))); + regions.forEach((i) -> biomes.addAll(i.getAllBiomes())); + biomes.forEach((i) -> i.getGenerators().forEach((j) -> generators.add(j.getCachedGenerator()))); + KMap renameObjects = new KMap<>(); + + for(IrisBiome i : biomes) + { + for(IrisObjectPlacement j : i.getObjects()) + { + KList newNames = new KList<>(); + + for(String k : j.getPlace()) + { + if(renameObjects.containsKey(k)) + { + newNames.add(renameObjects.get(k)); + continue; + } + + String name = UUID.randomUUID().toString().replaceAll("-", ""); + newNames.add(name); + renameObjects.put(k, name); + } + + j.setPlace(newNames); + } + } + + KMap> lookupObjects = renameObjects.flip(); + + biomes.forEach((i) -> i.getObjects().forEach((j) -> j.getPlace().forEach((k) -> + { + try + { + Iris.info("- " + k + " (Object)"); + IO.copyFile(Iris.data.getObjectLoader().findFile(lookupObjects.get(k).get(0)), new File(folder, "objects/" + k + ".iob")); + } + + catch(Throwable e) + { + + } + }))); + + try + { + IO.writeAll(new File(folder, "dimensions/" + dimension.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(dimension)).toString(0)); + + for(IrisGenerator i : generators) + { + Iris.info("- " + i.getLoadKey() + " (Generator)"); + IO.writeAll(new File(folder, "generators/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0)); + } + + for(IrisRegion i : regions) + { + Iris.info("- " + i.getName() + " (Region)"); + IO.writeAll(new File(folder, "regions/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0)); + } + + for(IrisBiome i : biomes) + { + Iris.info("- " + i.getName() + " (Biome)"); + IO.writeAll(new File(folder, "biomes/" + i.getLoadKey() + ".json"), new JSONObject(new Gson().toJson(i)).toString(0)); + } + + ZipUtil.pack(folder, new File(Iris.instance.getDataFolder(), "exports/" + dimension.getLoadKey() + ".iris"), 9); + IO.delete(folder); + } + + catch(Throwable e) + { + e.printStackTrace(); + } + + sender.sendMessage("Done!"); + }); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[dimension] [-o]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisWhat.java b/src/main/java/com/volmit/iris/command/CommandIrisWhat.java new file mode 100644 index 000000000..359a3a702 --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisWhat.java @@ -0,0 +1,63 @@ +package com.volmit.iris.command; + +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.IrisMetrics; +import com.volmit.iris.command.util.Command; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; +import com.volmit.iris.generator.IrisChunkGenerator; +import com.volmit.iris.util.Form; + +public class CommandIrisWhat extends MortarCommand +{ + @Command + private CommandIrisWhatBlock block; + + @Command + private CommandIrisWhatHand hand; + + public CommandIrisWhat() + { + super("what", "w", "?"); + setDescription("Get timings for this world"); + requiresPermission(Iris.perm.studio); + setCategory("Wut"); + setDescription("Figure out what stuff is"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(sender.isPlayer()) + { + Player p = (Player) sender; + World world = p.getWorld(); + IrisChunkGenerator g = (IrisChunkGenerator) world.getGenerator(); + IrisMetrics m = g.getMetrics(); + sender.sendMessage("Thread Count: " + ChatColor.BOLD + "" + ChatColor.WHITE + g.getThreads()); + sender.sendMessage("Total : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTotal().getAverage(), 2)); + sender.sendMessage(" Terrain : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getTerrain().getAverage(), 2)); + sender.sendMessage(" Parallax: " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getParallax().getAverage(), 2)); + sender.sendMessage(" Post : " + ChatColor.BOLD + "" + ChatColor.WHITE + Form.duration(m.getPost().getAverage(), 2)); + + return true; + } + + else + { + sender.sendMessage("Players only."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java b/src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java new file mode 100644 index 000000000..7b0e76c0c --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisWhatBlock.java @@ -0,0 +1,46 @@ +package com.volmit.iris.command; + +import org.bukkit.ChatColor; +import org.bukkit.FluidCollisionMode; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; + +public class CommandIrisWhatBlock extends MortarCommand +{ + public CommandIrisWhatBlock() + { + super("block", "b"); + setDescription("Get the block data for looking."); + requiresPermission(Iris.perm.studio); + setCategory("Wut"); + setDescription("WAILA,WAWLA etc"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(sender.isPlayer()) + { + BlockData bd = ((Player) sender).getTargetBlockExact(128, FluidCollisionMode.NEVER).getBlockData(); + sender.sendMessage("Material: " + ChatColor.GREEN + bd.getMaterial().name()); + sender.sendMessage("Full: " + ChatColor.WHITE + bd.getAsString(true)); + } + + else + { + sender.sendMessage("Players only."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisWhatHand.java b/src/main/java/com/volmit/iris/command/CommandIrisWhatHand.java new file mode 100644 index 000000000..bbc67d2ba --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisWhatHand.java @@ -0,0 +1,46 @@ +package com.volmit.iris.command; + +import org.bukkit.ChatColor; +import org.bukkit.FluidCollisionMode; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; + +public class CommandIrisWhatHand extends MortarCommand +{ + public CommandIrisWhatHand() + { + super("hand", "h"); + setDescription("Get the block data for holding."); + requiresPermission(Iris.perm.studio); + setCategory("Wut"); + setDescription("What block holding"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + if(sender.isPlayer()) + { + BlockData bd = ((Player) sender).getTargetBlockExact(128, FluidCollisionMode.NEVER).getBlockData(); + sender.sendMessage("Material: " + ChatColor.GREEN + bd.getMaterial().name()); + sender.sendMessage("Full: " + ChatColor.WHITE + bd.getAsString(true)); + } + + else + { + sender.sendMessage("Players only."); + } + + return true; + } + + @Override + protected String getArgsUsage() + { + return ""; + } +} diff --git a/src/main/java/com/volmit/iris/command/CommandIrisWorld.java b/src/main/java/com/volmit/iris/command/CommandIrisWorld.java new file mode 100644 index 000000000..58c86d97d --- /dev/null +++ b/src/main/java/com/volmit/iris/command/CommandIrisWorld.java @@ -0,0 +1,39 @@ +package com.volmit.iris.command; + +import com.volmit.iris.Iris; +import com.volmit.iris.command.util.Command; +import com.volmit.iris.command.util.MortarCommand; +import com.volmit.iris.command.util.MortarSender; + +public class CommandIrisWorld extends MortarCommand +{ + @Command + private CommandIrisGoto got0; + + @Command + private CommandIrisMetrics metrics; + + public CommandIrisWorld() + { + super("world", "wrld"); + setDescription("Commands while in an iris world."); + requiresPermission(Iris.perm.studio); + setCategory("World"); + setDescription("Worldly commands"); + } + + @Override + public boolean handle(MortarSender sender, String[] args) + { + sender.sendMessage("Iris In-World Commands"); + printHelp(sender); + + return true; + } + + @Override + protected String getArgsUsage() + { + return "[biome] [otherbiome] [-cave]"; + } +} diff --git a/src/main/java/com/volmit/iris/command/util/MortarCommand.java b/src/main/java/com/volmit/iris/command/util/MortarCommand.java index be0a90d58..7e03db0ca 100644 --- a/src/main/java/com/volmit/iris/command/util/MortarCommand.java +++ b/src/main/java/com/volmit/iris/command/util/MortarCommand.java @@ -55,7 +55,7 @@ public abstract class MortarCommand implements ICommand } } b = true; - sender.sendMessage("/" + ChatColor.GREEN + i.getAllNodes().toString(",") + " " + ChatColor.WHITE + getArgsUsage() + ChatColor.GRAY + " - " + getDescription()); + sender.sendMessage(ChatColor.GREEN + i.getNode() + " " + ChatColor.WHITE + i.getArgsUsage() + ChatColor.GRAY + " - " + i.getDescription()); } if(!b) diff --git a/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java b/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java index edc1df3a8..bd5d72a61 100644 --- a/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/ParallaxChunkGenerator.java @@ -9,9 +9,7 @@ import org.bukkit.block.data.BlockData; import com.volmit.iris.Iris; import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisBiomeMutation; -import com.volmit.iris.object.IrisDepositGenerator; import com.volmit.iris.object.IrisObjectPlacement; -import com.volmit.iris.object.IrisRegion; import com.volmit.iris.object.atomics.AtomicSliver; import com.volmit.iris.object.atomics.AtomicSliverMap; import com.volmit.iris.object.atomics.AtomicWorldData; @@ -254,7 +252,6 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple getAccelerant().queue(key, () -> { IrisBiome b = sampleTrueBiome((i * 16) + 7, (j * 16) + 7).getBiome(); - IrisRegion r = sampleRegion((i * 16) + 7, (j * 16) + 7); RNG ro = random.nextParallelRNG(496888 + i + j); int g = 1; @@ -300,45 +297,6 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple lockq.unlock(); } - for(IrisDepositGenerator k : getDimension().getDeposits()) - { - for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) - { - lockq.lock(); - q.add(() -> - { - k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); - }); - lockq.unlock(); - } - } - - for(IrisDepositGenerator k : r.getDeposits()) - { - for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) - { - lockq.lock(); - q.add(() -> - { - k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); - }); - lockq.unlock(); - } - } - - for(IrisDepositGenerator k : b.getDeposits()) - { - for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) - { - lockq.lock(); - q.add(() -> - { - k.generate((i * 16) + ro.nextInt(16), (j * 16) + ro.nextInt(16), ro, this); - }); - lockq.unlock(); - } - } - if(getDimension().isCaves()) { int bx = (i * 16) + ro.nextInt(16); diff --git a/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java b/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java index 5f3052ae5..0a0c5142a 100644 --- a/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java +++ b/src/main/java/com/volmit/iris/generator/TerrainChunkGenerator.java @@ -15,6 +15,7 @@ import com.volmit.iris.object.DecorationPart; import com.volmit.iris.object.InferredType; import com.volmit.iris.object.IrisBiome; import com.volmit.iris.object.IrisBiomeDecorator; +import com.volmit.iris.object.IrisDepositGenerator; import com.volmit.iris.object.IrisRegion; import com.volmit.iris.object.atomics.AtomicSliver; import com.volmit.iris.util.BiomeMap; @@ -64,12 +65,6 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator return glCave.genCaves(x, z, x & 15, z & 15, null); } - @Override - protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) - { - super.onGenerate(random, x, z, data, grid); - } - @Override protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, int onlyY) { @@ -256,6 +251,36 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator } } + @Override + protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) + { + super.onGenerate(random, x, z, data, grid); + RNG ro = random.nextParallelRNG((x * x * x) - z); + IrisRegion region = sampleRegion((x * 16) + 7, (z * 16) + 7); + IrisBiome biome = sampleTrueBiome((x * 16) + 7, (z * 16) + 7).getBiome(); + + for(IrisDepositGenerator k : getDimension().getDeposits()) + { + k.generate(data, ro, this); + } + + for(IrisDepositGenerator k : region.getDeposits()) + { + for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) + { + k.generate(data, ro, this); + } + } + + for(IrisDepositGenerator k : biome.getDeposits()) + { + for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) + { + k.generate(data, ro, this); + } + } + } + protected boolean canPlace(Material mat, Material onto) { if(onto.equals(Material.GRASS_PATH)) diff --git a/src/main/java/com/volmit/iris/object/IrisDepositGenerator.java b/src/main/java/com/volmit/iris/object/IrisDepositGenerator.java index 529dd8e57..d2b950f5e 100644 --- a/src/main/java/com/volmit/iris/object/IrisDepositGenerator.java +++ b/src/main/java/com/volmit/iris/object/IrisDepositGenerator.java @@ -3,9 +3,10 @@ package com.volmit.iris.object; import java.util.concurrent.locks.ReentrantLock; import org.bukkit.block.data.BlockData; +import org.bukkit.generator.ChunkGenerator.ChunkData; import org.bukkit.util.BlockVector; -import com.volmit.iris.generator.ParallaxChunkGenerator; +import com.volmit.iris.generator.TerrainChunkGenerator; import com.volmit.iris.util.BlockDataTools; import com.volmit.iris.util.Desc; import com.volmit.iris.util.DontObfuscate; @@ -99,13 +100,13 @@ public class IrisDepositGenerator public int getMaxDimension() { - return (int) Math.round(Math.pow(maxSize, 1D / 3D)); + return Math.min(11, (int) Math.round(Math.pow(maxSize, 1D / 3D))); } private IrisObject generateClumpObject(RNG rngv) { int s = rngv.i(minSize, maxSize); - int dim = (int) Math.round(Math.pow(s, 1D / 3D)); + int dim = Math.min(11, (int) Math.round(Math.pow(maxSize, 1D / 3D))); int w = dim / 2; IrisObject o = new IrisObject(dim, dim, dim); @@ -157,31 +158,65 @@ public class IrisDepositGenerator return blockData; } - public void generate(int x, int z, RNG rng, ParallaxChunkGenerator g) + public void generate(ChunkData data, RNG rng, TerrainChunkGenerator g) { - IrisObject clump = getClump(rng); - int height = (int) (Math.round(g.getTerrainHeight(x, z))) - 5; - - if(height < 0) + for(int l = 0; l < rng.i(getMinPerChunk(), getMaxPerChunk()); l++) { - return; + IrisObject clump = getClump(rng); + + int af = (int) Math.ceil(clump.getW() / 2D); + int bf = (int) Math.floor(16D - (clump.getW() / 2D)); + + if(af > bf || af < 0 || bf > 15 || af > 15 || bf < 0) + { + af = 6; + bf = 9; + } + + int x = rng.i(af, bf); + int z = rng.i(af, bf); + int height = (int) (Math.round(g.getTerrainHeight(x, z))) - 5; + + if(height <= 0) + { + return; + } + + int i = Math.max(0, minHeight); + int a = Math.min(height, Math.min(256, maxHeight)); + + if(i >= a) + { + return; + } + + int h = rng.i(i, a); + + if(h > maxHeight || h < minHeight) + { + return; + } + + for(BlockVector j : clump.getBlocks().keySet()) + { + int nx = j.getBlockX() + x; + int ny = j.getBlockY() + h; + int nz = j.getBlockZ() + z; + + if(nx > 15 || nx < 0 || ny > 255 || ny < 0 || nz < 0 || nz > 15) + { + continue; + } + + BlockData b = data.getBlockData(nx, ny, nz); + + if(!b.getMaterial().isSolid()) + { + continue; + } + + data.setBlock(nx, ny, nz, clump.getBlocks().get(j)); + } } - - int i = Math.max(0, minHeight); - int a = Math.min(height, Math.min(256, maxHeight)); - - if(i >= a) - { - return; - } - - int h = rng.i(i, a); - - if(h > maxHeight || h < minHeight) - { - return; - } - - clump.place(x, h, z, g, config, rng); } } diff --git a/src/main/java/com/volmit/iris/object/IrisObject.java b/src/main/java/com/volmit/iris/object/IrisObject.java index 244309ecd..c010f7b01 100644 --- a/src/main/java/com/volmit/iris/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/object/IrisObject.java @@ -143,7 +143,7 @@ public class IrisObject extends IrisRegistrant } } - for(BlockVector g : blocks.k()) + for(BlockVector g : blocks.keySet()) { BlockVector i = g.clone(); i = config.getRotation().rotate(i.clone(), yf, xf, spinx, spiny, spinz).clone(); @@ -217,7 +217,7 @@ public class IrisObject extends IrisRegistrant public void place(Location at) { - for(BlockVector i : blocks.k()) + for(BlockVector i : blocks.keySet()) { at.clone().add(0, getCenter().getY(), 0).add(i).getBlock().setBlockData(blocks.get(i), false); } diff --git a/src/main/java/com/volmit/iris/object/atomics/AtomicWorldData.java b/src/main/java/com/volmit/iris/object/atomics/AtomicWorldData.java index 6878bdd5e..55553d780 100644 --- a/src/main/java/com/volmit/iris/object/atomics/AtomicWorldData.java +++ b/src/main/java/com/volmit/iris/object/atomics/AtomicWorldData.java @@ -8,7 +8,6 @@ import java.io.IOException; import org.bukkit.World; import com.volmit.iris.Iris; -import com.volmit.iris.util.ChronoLatch; import com.volmit.iris.util.ChunkPosition; import com.volmit.iris.util.KList; import com.volmit.iris.util.KMap; @@ -23,8 +22,8 @@ public class AtomicWorldData private KMap lastChunk; private KList unloadRegions; private KList unloadChunks; + private long last = M.ms(); private String prefix; - private ChronoLatch cl = new ChronoLatch(333); public AtomicWorldData(World world, String prefix) { @@ -267,7 +266,7 @@ public class AtomicWorldData public void clean(int j) { - if(!cl.flip()) + if(M.ms() - last < getUnloadBatchSpeed()) { return; } @@ -309,7 +308,7 @@ public class AtomicWorldData for(ChunkPosition i : lastChunk.keySet()) { - if(m > 7) + if(m > getUnloadBatchSize()) { break; } @@ -336,4 +335,14 @@ public class AtomicWorldData unloadChunks.clear(); } + + private int getUnloadBatchSize() + { + return Math.max(3, getLoadedRegions().size() / 125); + } + + private int getUnloadBatchSpeed() + { + return Math.max(250, 2000 - getLoadedRegions().size()); + } } diff --git a/src/main/java/com/volmit/iris/util/BlockDataTools.java b/src/main/java/com/volmit/iris/util/BlockDataTools.java index 73d24d4be..38af4076d 100644 --- a/src/main/java/com/volmit/iris/util/BlockDataTools.java +++ b/src/main/java/com/volmit/iris/util/BlockDataTools.java @@ -25,6 +25,15 @@ public class BlockDataTools if(bdx == null) { Iris.warn("Unknown Block Data '" + bd + "'"); + try + { + throw new RuntimeException("Unknown Block Data"); + } + + catch(Throwable e) + { + e.printStackTrace(); + } nulls.add(bd); return bdx; } @@ -33,12 +42,13 @@ public class BlockDataTools return bdx; } - + catch(Throwable e) { Iris.warn("Unknown Block Data '" + bd + "'"); + e.printStackTrace(); } - + return null; }