diff --git a/src/main/java/ninja/bytecode/iris/CommandIris.java b/src/main/java/ninja/bytecode/iris/CommandIris.java index 354191602..6f90cbff6 100644 --- a/src/main/java/ninja/bytecode/iris/CommandIris.java +++ b/src/main/java/ninja/bytecode/iris/CommandIris.java @@ -15,7 +15,6 @@ import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.util.BiomeLayer; import ninja.bytecode.shuriken.format.F; -import ninja.bytecode.shuriken.logging.L; public class CommandIris implements CommandExecutor { diff --git a/src/main/java/ninja/bytecode/iris/CommandIsh.java b/src/main/java/ninja/bytecode/iris/CommandIsh.java index 3c0078280..f9e2fdcbf 100644 --- a/src/main/java/ninja/bytecode/iris/CommandIsh.java +++ b/src/main/java/ninja/bytecode/iris/CommandIsh.java @@ -15,6 +15,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import mortar.util.text.C; import ninja.bytecode.iris.controller.WandController; import ninja.bytecode.iris.generator.genobject.GenObject; import ninja.bytecode.iris.util.Cuboid; @@ -99,6 +100,9 @@ public class CommandIsh implements CommandExecutor s.read(fin, true); boolean cursor = false; + Direction df = null; + Direction dt = null; + for(String i : args) { if(i.equalsIgnoreCase("cursor")) @@ -106,6 +110,22 @@ public class CommandIsh implements CommandExecutor cursor = true; break; } + + if(i.startsWith("from:")) + { + df = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); + } + + if(i.startsWith("to:")) + { + dt = Direction.valueOf(i.split("\\Q:\\E")[1].toUpperCase().substring(0, 1)); + } + } + + if(dt != null && df != null) + { + msg(sender, "Rotating " + C.WHITE + df + C.GRAY + " to " + C.WHITE + dt); + s.rotate(df, dt); } Location at = p.getLocation(); diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java index af9c327bb..62ac1f567 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObject.java @@ -7,10 +7,18 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.function.Consumer; +import java.util.function.Supplier; import java.util.zip.GZIPInputStream; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.material.Directional; +import org.bukkit.material.Ladder; +import org.bukkit.material.MaterialData; +import org.bukkit.material.Stairs; +import org.bukkit.material.Vine; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; @@ -231,7 +239,11 @@ public class GenObject public Location place(Location l) { - return place(l, new NMSPlacer(l.getWorld())); + NMSPlacer p; + Location ll = place(l, p = new NMSPlacer(l.getWorld())); + p.flush(); + + return ll; } public Location place(Location l, IPlacer placer) @@ -263,12 +275,6 @@ public class GenObject for(SBlockVector i : s.keySet()) { MB b = getSchematic().get(i); - - if(b.material.equals(Material.CONCRETE_POWDER)) - { - continue; - } - Location f = start.clone().add(i.toBlockVector()); Material m = placer.get(f.clone().subtract(0, 1, 0)).material; @@ -343,13 +349,124 @@ public class GenObject for(SBlockVector i : g.keySet()) { - MB mb = g.get(i); + MB mb = rotate(from, to, g.get(i)); s.put(new SBlockVector(VectorMath.rotate(from, to, i.toBlockVector()).toBlockVector()), mb); } name = name + "-rt" + to.name(); } + @SuppressWarnings("deprecation") + private MB rotate(Direction from, Direction to, MB mb) + { + try + { + Material t = mb.material; + int i = t.getId(); + byte d = mb.data; + MaterialData data = t.getData().getConstructor(int.class, byte.class).newInstance(i, d); + + if(data instanceof Directional) + { + Directional dir = (Directional) data; + Supplier get = dir::getFacing; + Consumer set = dir::setFacingDirection; + + if(dir instanceof Ladder) + { + get = ((Ladder) dir)::getAttachedFace; + set = ((Ladder) dir)::setFacingDirection; + } + + if(dir instanceof Stairs) + { + get = ((Stairs) dir)::getAscendingDirection; + set = ((Stairs) dir)::setFacingDirection; + } + + BlockFace fac = get.get(); + set.accept(rotate(from, to, fac)); + d = data.getData(); + t = data.getItemType(); + return MB.of(t, d); + } + + else if(data instanceof Vine) + { + Vine vin = (Vine) data; + Vine vif = new Vine(); + + for(Direction j : Direction.news()) + { + if(vin.isOnFace(j.getFace())) + { + vif.putOnFace(rotate(from, to, j.getFace())); + } + } + + d = vif.getData(); + t = vif.getItemType(); + return MB.of(t, d); + } + + else if(i >= 235 && i <= 250) + { + BlockFace fac = getGlazedTCDir(d); + d = toGlazedTCDir(Direction.getDirection(rotate(from, to, fac)).getFace()); + t = data.getItemType(); + return MB.of(t, d); + } + } + + catch(Throwable e) + { + e.printStackTrace(); + } + + return mb; + } + + private byte toGlazedTCDir(BlockFace b) + { + switch(b) + { + case NORTH: + return 0; + case EAST: + return 1; + case SOUTH: + return 2; + case WEST: + return 3; + default: + break; + } + + return 0; + } + + private BlockFace getGlazedTCDir(byte d2) + { + switch(d2) + { + case 0: + return BlockFace.NORTH; + case 1: + return BlockFace.EAST; + case 2: + return BlockFace.SOUTH; + case 3: + return BlockFace.WEST; + } + + return BlockFace.NORTH; + } + + private BlockFace rotate(Direction from, Direction to, BlockFace face) + { + return Direction.getDirection(from.angle(Direction.getDirection(face).toVector(), to)).getFace(); + } + public void computeFlag(String j) { try @@ -379,6 +496,12 @@ public class GenObject int downshift = Integer.valueOf(j.split("\\Q \\E")[1]); shift.subtract(new Vector(0, downshift, 0)); } + + if(j.startsWith("raise ")) + { + int downshift = Integer.valueOf(j.split("\\Q \\E")[1]); + shift.add(new Vector(0, downshift, 0)); + } } catch(Throwable e) diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java index f2f4b0dbe..5911907fb 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectDecorator.java @@ -1,6 +1,6 @@ package ninja.bytecode.iris.generator.genobject; -import java.lang.Thread.State; +import java.util.Collections; import java.util.Random; import java.util.concurrent.Executor; import java.util.concurrent.Executors; @@ -18,21 +18,21 @@ import mortar.logic.format.F; import mortar.util.text.C; import net.md_5.bungee.api.ChatColor; import ninja.bytecode.iris.Iris; -import ninja.bytecode.iris.controller.TimingsController; import ninja.bytecode.iris.generator.IrisGenerator; import ninja.bytecode.iris.generator.placer.BukkitPlacer; import ninja.bytecode.iris.generator.placer.NMSPlacer; import ninja.bytecode.iris.pack.IrisBiome; import ninja.bytecode.iris.util.IPlacer; +import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.collections.GMap; import ninja.bytecode.shuriken.collections.GSet; import ninja.bytecode.shuriken.execution.ChronoLatch; -import ninja.bytecode.shuriken.execution.J; import ninja.bytecode.shuriken.logging.L; import ninja.bytecode.shuriken.math.M; public class GenObjectDecorator extends BlockPopulator { + private GMap> orderCache; private GMap> populationCache; private IPlacer placer; private Executor ex; @@ -43,11 +43,13 @@ public class GenObjectDecorator extends BlockPopulator { this.g = generator; populationCache = new GMap<>(); + orderCache = new GMap<>(); ex = Executors.newSingleThreadExecutor(); for(IrisBiome i : generator.getDimension().getBiomes()) { GMap gc = new GMap<>(); + GMap> or = new GMap<>(); int ff = 0; for(String j : i.getSchematicGroups().k()) { @@ -58,6 +60,13 @@ public class GenObjectDecorator extends BlockPopulator GenObjectGroup g = generator.getDimension().getObjectGroup(j); ff += g.size(); gc.put(g, c); + + if(!or.containsKey(g.getPiority())) + { + or.put(g.getPiority(), new GList<>()); + } + + or.get(g.getPiority()).add(g); } catch(Throwable e) @@ -69,6 +78,14 @@ public class GenObjectDecorator extends BlockPopulator if(!gc.isEmpty()) { + GList g = new GList<>(); + for(GList j : or.v()) + { + g.addAll(j); + } + + Collections.sort(g, (a, b) -> a.getPiority() - b.getPiority()); + orderCache.put(i, g); populationCache.put(i, gc); if(Iris.settings.performance.verbose) @@ -88,8 +105,9 @@ public class GenObjectDecorator extends BlockPopulator { return; } - - ex.execute(() -> { + + ex.execute(() -> + { Random random = new Random(((source.getX() - 32) * (source.getZ() + 54)) + world.getSeed()); GSet hits = new GSet<>(); @@ -113,7 +131,7 @@ public class GenObjectDecorator extends BlockPopulator hits.add(biome); - populate(world, random, source, biome, objects); + populate(world, random, source, biome, objects, orderCache.get(biome)); } if(Iris.settings.performance.verbose) @@ -123,9 +141,9 @@ public class GenObjectDecorator extends BlockPopulator }); } - private void populate(World world, Random random, Chunk source, IrisBiome biome, GMap objects) + private void populate(World world, Random random, Chunk source, IrisBiome biome, GMap objects, GList order) { - for(GenObjectGroup i : objects.k()) + for(GenObjectGroup i : order) { for(int j = 0; j < getTries(objects.get(i)); j++) { @@ -138,6 +156,7 @@ public class GenObjectDecorator extends BlockPopulator if(!t.isSolid() || !biome.isSurface(t)) { + L.w(C.WHITE + "Object " + C.YELLOW + i.getName() + "/*" + C.WHITE + " failed to place in " + C.YELLOW + t.toString().toLowerCase() + C.WHITE + " at " + C.YELLOW + F.f(b.getX()) + " " + F.f(b.getY()) + " " + F.f(b.getZ())); continue; } diff --git a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java index 66be7e53a..77995d7ec 100644 --- a/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java +++ b/src/main/java/ninja/bytecode/iris/generator/genobject/GenObjectGroup.java @@ -11,8 +11,6 @@ import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.iris.util.Direction; import ninja.bytecode.shuriken.collections.GList; -import ninja.bytecode.shuriken.execution.TaskExecutor; -import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.format.F; import ninja.bytecode.shuriken.io.IO; import ninja.bytecode.shuriken.logging.L; @@ -22,12 +20,14 @@ public class GenObjectGroup private GList schematics; private GList flags; private String name; + private int priority; public GenObjectGroup(String name) { this.schematics = new GList<>(); this.flags = new GList<>(); this.name = name; + priority = Integer.MIN_VALUE; } public void read(DataInputStream din) throws IOException @@ -148,6 +148,23 @@ public class GenObjectGroup return getSchematics().size(); } + public int getPiority() + { + if(priority == Integer.MIN_VALUE) + { + for(String i : flags) + { + if(i.startsWith("priority ")) + { + priority = Integer.valueOf(i.split("\\Q \\E")[1]); + break; + } + } + } + + return priority; + } + public static GenObjectGroup load(String string) { File folder = Iris.getController(PackController.class).loadFolder(string); @@ -195,19 +212,6 @@ public class GenObjectGroup public void processVariants() { - GList inject = new GList<>(); - for(GenObject i : getSchematics()) - { - for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W}) - { - GenObject cp = i.copy(); - GenObject f = cp; - f.rotate(Direction.N, j); - inject.add(f); - } - } - - getSchematics().add(inject); for(GenObject i : getSchematics()) { i.recalculateMountShift(); @@ -218,6 +222,24 @@ public class GenObjectGroup } } + if(!flags.contains("no rotation")) + { + GList inject = new GList<>(); + for(GenObject i : getSchematics()) + { + for(Direction j : new Direction[] {Direction.S, Direction.E, Direction.W}) + { + GenObject cp = i.copy(); + GenObject f = cp; + f.rotate(Direction.N, j); + f.recalculateMountShift(); + inject.add(f); + } + } + + getSchematics().add(inject); + } + L.i(ChatColor.LIGHT_PURPLE + "Processed " + ChatColor.WHITE + F.f(schematics.size()) + ChatColor.LIGHT_PURPLE + " Schematics in " + ChatColor.WHITE + name); } @@ -227,8 +249,50 @@ public class GenObjectGroup { i.dispose(); } - + schematics.clear(); flags.clear(); } + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((flags == null) ? 0 : flags.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + priority; + return result; + } + + @Override + public boolean equals(Object obj) + { + if(this == obj) + return true; + if(obj == null) + return false; + if(getClass() != obj.getClass()) + return false; + GenObjectGroup other = (GenObjectGroup) obj; + if(flags == null) + { + if(other.flags != null) + return false; + } + else if(!flags.equals(other.flags)) + return false; + if(name == null) + { + if(other.name != null) + return false; + } + else if(!name.equals(other.name)) + return false; + if(priority != other.priority) + return false; + + return true; + } + } diff --git a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java b/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java index 3e870ead9..3578505ee 100644 --- a/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java +++ b/src/main/java/ninja/bytecode/iris/pack/IrisDimension.java @@ -8,8 +8,6 @@ import ninja.bytecode.iris.Iris; import ninja.bytecode.iris.controller.PackController; import ninja.bytecode.shuriken.collections.GList; import ninja.bytecode.shuriken.execution.J; -import ninja.bytecode.shuriken.execution.TaskExecutor; -import ninja.bytecode.shuriken.execution.TaskExecutor.TaskGroup; import ninja.bytecode.shuriken.json.JSONArray; import ninja.bytecode.shuriken.json.JSONException; import ninja.bytecode.shuriken.json.JSONObject; diff --git a/src/main/java/ninja/bytecode/iris/util/Direction.java b/src/main/java/ninja/bytecode/iris/util/Direction.java index 7f9679440..c125585da 100644 --- a/src/main/java/ninja/bytecode/iris/util/Direction.java +++ b/src/main/java/ninja/bytecode/iris/util/Direction.java @@ -1,5 +1,6 @@ package ninja.bytecode.iris.util; +import org.bukkit.block.BlockFace; import org.bukkit.util.Vector; import ninja.bytecode.iris.util.Cuboid.CuboidDirection; @@ -19,7 +20,7 @@ public enum Direction S(0, 0, 1, CuboidDirection.South), E(1, 0, 0, CuboidDirection.East), W(-1, 0, 0, CuboidDirection.West); - + private static GMap, DOP> permute = null; private int x; @@ -27,6 +28,53 @@ public enum Direction private int z; private CuboidDirection f; + public static Direction getDirection(BlockFace f) + { + switch(f) + { + case DOWN: + return D; + case EAST: + return E; + case EAST_NORTH_EAST: + return E; + case EAST_SOUTH_EAST: + return E; + case NORTH: + return N; + case NORTH_EAST: + return N; + case NORTH_NORTH_EAST: + return N; + case NORTH_NORTH_WEST: + return N; + case NORTH_WEST: + return N; + case SELF: + return U; + case SOUTH: + return S; + case SOUTH_EAST: + return S; + case SOUTH_SOUTH_EAST: + return S; + case SOUTH_SOUTH_WEST: + return S; + case SOUTH_WEST: + return S; + case UP: + return U; + case WEST: + return W; + case WEST_NORTH_WEST: + return W; + case WEST_SOUTH_WEST: + return W; + } + + return D; + } + @Override public String toString() { @@ -202,7 +250,7 @@ public enum Direction public static GList news() { - return new GList().add(N,E,W,S); + return new GList().add(N, E, W, S); } public static Direction getDirection(Vector v) @@ -222,7 +270,7 @@ public enum Direction public static GList udnews() { - return new GList().add(U,D,N,E,W,S); + return new GList().add(U, D, N, E, W, S); } /** @@ -441,6 +489,27 @@ public enum Direction } } + public BlockFace getFace() + { + switch(this) + { + case D: + return BlockFace.DOWN; + case E: + return BlockFace.EAST; + case N: + return BlockFace.NORTH; + case S: + return BlockFace.SOUTH; + case U: + return BlockFace.UP; + case W: + return BlockFace.WEST; + } + + return null; + } + public Axis getAxis() { switch(this) diff --git a/src/main/java/ninja/bytecode/iris/util/SBlockVector.java b/src/main/java/ninja/bytecode/iris/util/SBlockVector.java index 2ea22c423..f9cd1e181 100644 --- a/src/main/java/ninja/bytecode/iris/util/SBlockVector.java +++ b/src/main/java/ninja/bytecode/iris/util/SBlockVector.java @@ -1,6 +1,5 @@ package ninja.bytecode.iris.util; -import java.util.Map; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.util.BlockVector; import org.bukkit.util.Vector;