diff --git a/src/main/java/com/volmit/iris/manager/IrisBoardManager.java b/src/main/java/com/volmit/iris/manager/IrisBoardManager.java index fbe53ce06..21927bdac 100644 --- a/src/main/java/com/volmit/iris/manager/IrisBoardManager.java +++ b/src/main/java/com/volmit/iris/manager/IrisBoardManager.java @@ -89,7 +89,7 @@ public class IrisBoardManager implements BoardProvider, Listener int y = player.getLocation().getBlockY(); int z = player.getLocation().getBlockZ(); - Engine engine = g.getCompound().getEngine(y); + Engine engine = g.getCompound().getEngineForHeight(y); int parallaxChunks=0; int parallaxRegions=0; @@ -102,8 +102,8 @@ public class IrisBoardManager implements BoardProvider, Listener parallaxChunks += g.getCompound().getEngine(i).getParallax().getChunkCount(); loadedObjects+= g.getCompound().getData().getObjectLoader().getSize(); memoryGuess += g.getCompound().getData().getObjectLoader().getTotalStorage() * 225; - memoryGuess+= parallaxChunks += 3500; - memoryGuess += parallaxRegions += 1700000; + memoryGuess+= parallaxChunks * 3500; + memoryGuess += parallaxRegions * 1700000; } tp.put(0); // TODO: CHUNK SPEED @@ -117,7 +117,7 @@ public class IrisBoardManager implements BoardProvider, Listener if(engine != null) { v.add("&7&m------------------"); - v.add(C.AQUA + "Engine" + C.GRAY + ": " + engine.getName() + " (" + engine.getMinHeight() + " - " + engine.getMaxHeight() + ")"); + v.add(C.AQUA + "Engine" + C.GRAY + ": " + engine.getName() + " " + engine.getMinHeight() + "-" + engine.getMaxHeight()); v.add(C.AQUA + "Region" + C.GRAY + ": " + engine.getRegion(x, z).getName()); v.add(C.AQUA + "Biome" + C.GRAY + ": " + engine.getBiome(x, y, z).getName()); v.add(C.AQUA + "Height" + C.GRAY + ": " + Math.round(engine.getHeight(x, z))); diff --git a/src/main/java/com/volmit/iris/manager/command/CommandIrisStudioGoto.java b/src/main/java/com/volmit/iris/manager/command/CommandIrisStudioGoto.java index 362810998..9b2f9cdfe 100644 --- a/src/main/java/com/volmit/iris/manager/command/CommandIrisStudioGoto.java +++ b/src/main/java/com/volmit/iris/manager/command/CommandIrisStudioGoto.java @@ -2,12 +2,10 @@ package com.volmit.iris.manager.command; import com.volmit.iris.Iris; import com.volmit.iris.object.IrisBiome; +import com.volmit.iris.object.IrisRegion; import com.volmit.iris.scaffold.IrisWorlds; import com.volmit.iris.scaffold.engine.IrisAccess; -import com.volmit.iris.util.KList; -import com.volmit.iris.util.MortarCommand; -import com.volmit.iris.util.MortarSender; -import com.volmit.iris.util.RNG; +import com.volmit.iris.util.*; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Player; @@ -53,79 +51,49 @@ public class CommandIrisStudioGoto extends MortarCommand } IrisAccess g = IrisWorlds.access(world); - int tries = 10000; - boolean cave = false; - IrisBiome biome2 = null; - if(args.length > 1) + IrisBiome b = Iris.globaldata.getBiomeLoader().load(args[0], false); + IrisRegion r = Iris.globaldata.getRegionLoader().load(args[0], false); + + if(b != null) { - if(args[1].equalsIgnoreCase("-cave")) - { - cave = true; - } + J.a(() -> { + Location l = g.lookForBiome(b, 10000, (v) -> sender.sendMessage("Looking for " + C.BOLD + C.WHITE + b.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places")); - else - { - biome2 = g.getData().getBiomeLoader().load(args[1]); - - if(biome2 == null) + if(l == null) { - sender.sendMessage(args[1] + " is not a biome. Use the file name (without extension)"); - return true; - } - } - } - - for(String i : args) - { - if(i.equalsIgnoreCase("-cave")) - { - cave = true; - } - } - - IrisBiome biome = args[0].equals("this") ? g.getBiome(p.getLocation().getBlockX(), p.getLocation().getBlockZ()) : g.getData().getBiomeLoader().load(args[0]); - - if(biome == null) - { - sender.sendMessage(args[0] + " 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.getCaveBiome(xx, zz) : g.getBiome(xx, zz)).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.getBiome(ax, az) : g.getBiome(ax, az)).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; - } - } + sender.sendMessage("Couldn't find " + b.getName() + "."); } else { - p.teleport(new Location(world, xx, world.getHighestBlockYAt(xx, zz), zz)); - sender.sendMessage("Found in " + (10000 - tries) + " tries!"); - return true; + sender.sendMessage("Found " + b.getName() + "!"); + J.s(() -> sender.player().teleport(l)); } - } + }); } - sender.sendMessage("Tried to find " + biome.getName() + " looked in 10,000 places no dice."); + else if(r != null) + { + J.a(() -> { + Location l = g.lookForRegion(r, 10000, (v) -> sender.sendMessage("Looking for " + C.BOLD + C.WHITE + r.getName() + C.RESET + C.GRAY + ": Checked " + Form.f(v) + " Places")); + + if(l == null) + { + sender.sendMessage("Couldn't find " + r.getName() + "."); + } + + else + { + sender.sendMessage("Found " + r.getName() + "!"); + J.s(() -> sender.player().teleport(l)); + } + }); + } + + else + { + sender.sendMessage(args[0] + " is not a biome or region in this dimension."); + } return true; } @@ -149,6 +117,6 @@ public class CommandIrisStudioGoto extends MortarCommand @Override protected String getArgsUsage() { - return "[biome] [otherbiome] [-cave]"; + return "[biome/region]"; } } diff --git a/src/main/java/com/volmit/iris/scaffold/IrisWorldCreator.java b/src/main/java/com/volmit/iris/scaffold/IrisWorldCreator.java index fb6406dc2..6621c2e13 100644 --- a/src/main/java/com/volmit/iris/scaffold/IrisWorldCreator.java +++ b/src/main/java/com/volmit/iris/scaffold/IrisWorldCreator.java @@ -21,7 +21,7 @@ public class IrisWorldCreator public IrisWorldCreator dimension(String loadKey) { - this.dimensionName = dimensionName; + this.dimensionName = loadKey; return this; } diff --git a/src/main/java/com/volmit/iris/scaffold/engine/EngineCompositeGenerator.java b/src/main/java/com/volmit/iris/scaffold/engine/EngineCompositeGenerator.java index 0ea99bf3d..e93930eba 100644 --- a/src/main/java/com/volmit/iris/scaffold/engine/EngineCompositeGenerator.java +++ b/src/main/java/com/volmit/iris/scaffold/engine/EngineCompositeGenerator.java @@ -10,6 +10,7 @@ import com.volmit.iris.scaffold.hunk.Hunk; import com.volmit.iris.util.Form; import com.volmit.iris.util.KList; import com.volmit.iris.util.M; +import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.World; @@ -69,23 +70,26 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce if (hint == null) { File iris = new File(world.getWorldFolder(), "iris"); - searching: - for (File i : iris.listFiles()) { - // Look for v1 location - if (i.isDirectory() && i.getName().equals("dimensions")) { - for (File j : i.listFiles()) { - if (j.isFile() && j.getName().endsWith(".json")) { - hint = j.getName().replaceAll("\\Q.json\\E", ""); - break searching; + if(iris.exists() && iris.isDirectory()) + { + searching: + for (File i : iris.listFiles()) { + // Look for v1 location + if (i.isDirectory() && i.getName().equals("dimensions")) { + for (File j : i.listFiles()) { + if (j.isFile() && j.getName().endsWith(".json")) { + hint = j.getName().replaceAll("\\Q.json\\E", ""); + break searching; + } } } - } - // Look for v2 location - else if (i.isFile() && i.getName().equals("engine-metadata.json")) { - EngineData metadata = EngineData.load(i); - hint = metadata.getDimension(); - break; + // Look for v2 location + else if (i.isFile() && i.getName().equals("engine-metadata.json")) { + EngineData metadata = EngineData.load(i); + hint = metadata.getDimension(); + break; + } } } } @@ -272,6 +276,7 @@ public class EngineCompositeGenerator extends ChunkGenerator implements IrisAcce @Override public void close() { getComposite().close(); + Bukkit.unloadWorld(getComposite().getWorld(), !isStudio()); } @Override diff --git a/src/main/java/com/volmit/iris/scaffold/engine/IrisAccess.java b/src/main/java/com/volmit/iris/scaffold/engine/IrisAccess.java index 7df2f4b76..0b5f352c9 100644 --- a/src/main/java/com/volmit/iris/scaffold/engine/IrisAccess.java +++ b/src/main/java/com/volmit/iris/scaffold/engine/IrisAccess.java @@ -2,7 +2,15 @@ package com.volmit.iris.scaffold.engine; import com.volmit.iris.manager.IrisDataManager; import com.volmit.iris.object.IrisBiome; +import com.volmit.iris.object.IrisRegion; import com.volmit.iris.scaffold.data.DataProvider; +import com.volmit.iris.util.*; +import org.bukkit.Location; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; public interface IrisAccess extends Hotloadable, DataProvider { @@ -41,4 +49,163 @@ public interface IrisAccess extends Hotloadable, DataProvider { public boolean isFailing(); public boolean isStudio(); + + public default Location lookForBiome(IrisBiome biome, long timeout, Consumer triesc) + { + ChronoLatch cl = new ChronoLatch(250, false); + long s = M.ms(); + int cpus = 2+(Runtime.getRuntime().availableProcessors()/2); + KList engines = new KList<>(); + for(int i = 0; i < getCompound().getSize(); i++) + { + Engine e = getCompound().getEngine(i); + if(e.getDimension().getAllBiomes(e).contains(biome)) + { + engines.add(e); + } + } + + AtomicInteger tries = new AtomicInteger(0); + AtomicBoolean found = new AtomicBoolean(false); + AtomicReference location = new AtomicReference<>(); + + for(int i = 0; i < cpus; i++) + { + J.a(() -> { + try + { + Engine e; + IrisBiome b; + int x,y,z; + + while(!found.get()) + { + try { + synchronized (engines) { + e = engines.getRandom(); + x = RNG.r.i(-29999970, 29999970); + y = RNG.r.i(0, e.getHeight()-1); + z = RNG.r.i(-29999970, 29999970); + + b = e.getBiome(x, y, z); + } + + if(b != null && b.getLoadKey() == null) + { + continue; + } + + if(b != null && b.getLoadKey().equals(biome.getLoadKey())) + { + found.lazySet(true); + location.lazySet(new Location(e.getWorld(), x,y,z)); + } + + tries.getAndIncrement(); + } + + catch(Throwable ex) + { + ex.printStackTrace(); + return; + } + } + } + + catch(Throwable e) + { + e.printStackTrace(); + } + }); + } + + while(!found.get() || location.get() == null) + { + J.sleep(50); + + if(cl.flip()) + { + triesc.accept(tries.get()); + } + + if(M.ms() - s > timeout) + { + return null; + } + } + + return location.get(); + } + + public default Location lookForRegion(IrisRegion reg, long timeout, Consumer triesc) + { + ChronoLatch cl = new ChronoLatch(250, false); + long s = M.ms(); + int cpus = 2+(Runtime.getRuntime().availableProcessors()/2); + KList engines = new KList<>(); + for(int i = 0; i < getCompound().getSize(); i++) + { + Engine e = getCompound().getEngine(i); + if(e.getDimension().getAllRegions(e).contains(reg)) + { + engines.add(e); + } + } + + AtomicInteger tries = new AtomicInteger(0); + AtomicBoolean found = new AtomicBoolean(false); + AtomicReference location = new AtomicReference<>(); + + for(int i = 0; i < cpus; i++) + { + J.a(() -> { + Engine e; + IrisRegion b; + int x,z; + + while(!found.get()) + { + try { + e = engines.getRandom(); + x = RNG.r.i(-29999970, 29999970); + z = RNG.r.i(-29999970, 29999970); + b = e.getRegion(x, z); + + if(b != null && b.getLoadKey().equals(reg.getLoadKey())) + { + found.lazySet(true); + location.lazySet(new Location(e.getWorld(), x, e.getHeight(x, z) + e.getMinHeight() ,z)); + } + + tries.getAndIncrement(); + } + + catch(Throwable xe) + { + xe.printStackTrace(); + return; + } + } + }); + } + + while(!found.get() || location.get() != null) + { + J.sleep(50); + + if(cl.flip()) + { + triesc.accept(tries.get()); + } + + if(M.ms() - s > timeout) + { + triesc.accept(tries.get()); + return null; + } + } + + triesc.accept(tries.get()); + return location.get(); + } } diff --git a/src/main/java/com/volmit/iris/scaffold/parallax/ParallaxWorld.java b/src/main/java/com/volmit/iris/scaffold/parallax/ParallaxWorld.java index 6377d46fd..6326a53d4 100644 --- a/src/main/java/com/volmit/iris/scaffold/parallax/ParallaxWorld.java +++ b/src/main/java/com/volmit/iris/scaffold/parallax/ParallaxWorld.java @@ -1,13 +1,15 @@ package com.volmit.iris.scaffold.parallax; +import com.volmit.iris.scaffold.hunk.Hunk; +import com.volmit.iris.util.ChronoLatch; +import com.volmit.iris.util.J; +import com.volmit.iris.util.KList; +import com.volmit.iris.util.KMap; +import org.bukkit.block.data.BlockData; + import java.io.File; import java.io.IOException; -import com.volmit.iris.util.*; -import org.bukkit.block.data.BlockData; - -import com.volmit.iris.scaffold.hunk.Hunk; - public class ParallaxWorld implements ParallaxAccess { private final KMap loadedRegions; @@ -192,7 +194,7 @@ public class ParallaxWorld implements ParallaxAccess public void cleanup() { - cleanup(10000, 5000); + cleanup(10000, 1000); } @Override diff --git a/src/main/java/com/volmit/iris/scaffold/stream/ProceduralStream.java b/src/main/java/com/volmit/iris/scaffold/stream/ProceduralStream.java index 4a6b549b7..5172a977e 100644 --- a/src/main/java/com/volmit/iris/scaffold/stream/ProceduralStream.java +++ b/src/main/java/com/volmit/iris/scaffold/stream/ProceduralStream.java @@ -1,19 +1,15 @@ package com.volmit.iris.scaffold.stream; -import java.util.List; -import java.util.function.Function; - import com.volmit.iris.scaffold.hunk.Hunk; import com.volmit.iris.scaffold.stream.arithmetic.*; import com.volmit.iris.scaffold.stream.convert.*; import com.volmit.iris.scaffold.stream.interpolation.Interpolated; import com.volmit.iris.scaffold.stream.sources.FunctionStream; import com.volmit.iris.scaffold.stream.utility.*; -import com.volmit.iris.util.Function2; -import com.volmit.iris.util.Function3; -import com.volmit.iris.util.Function4; -import com.volmit.iris.util.IRare; -import com.volmit.iris.util.KList; +import com.volmit.iris.util.*; + +import java.util.List; +import java.util.function.Function; public interface ProceduralStream extends ProceduralLayer, Interpolated { @@ -338,7 +334,17 @@ public interface ProceduralStream extends ProceduralLayer, Interpolated default ProceduralStream selectRarity(List types) { KList rarityTypes = new KList<>(); - types.forEach((i) -> rarityTypes.addMultiple(i, IRare.get(i))); + int totalRarity = 0; + for(V i : types) + { + totalRarity += IRare.get(i); + } + + for(V i : types) + { + rarityTypes.addMultiple(i, Math.max(1, (IRare.get(i) / totalRarity))); + } + return new SelectionStream(this, rarityTypes); }