mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-01-04 15:41:30 +00:00
Tweaks
This commit is contained in:
@@ -21,7 +21,7 @@ public class IrisWorldCreator
|
||||
|
||||
public IrisWorldCreator dimension(String loadKey)
|
||||
{
|
||||
this.dimensionName = dimensionName;
|
||||
this.dimensionName = loadKey;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Integer> triesc)
|
||||
{
|
||||
ChronoLatch cl = new ChronoLatch(250, false);
|
||||
long s = M.ms();
|
||||
int cpus = 2+(Runtime.getRuntime().availableProcessors()/2);
|
||||
KList<Engine> 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> 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<Integer> triesc)
|
||||
{
|
||||
ChronoLatch cl = new ChronoLatch(250, false);
|
||||
long s = M.ms();
|
||||
int cpus = 2+(Runtime.getRuntime().availableProcessors()/2);
|
||||
KList<Engine> 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> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Long, ParallaxRegion> loadedRegions;
|
||||
@@ -192,7 +194,7 @@ public class ParallaxWorld implements ParallaxAccess
|
||||
|
||||
public void cleanup()
|
||||
{
|
||||
cleanup(10000, 5000);
|
||||
cleanup(10000, 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<T> extends ProceduralLayer, Interpolated<T>
|
||||
{
|
||||
@@ -338,7 +334,17 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T>
|
||||
default <V> ProceduralStream<V> selectRarity(List<V> types)
|
||||
{
|
||||
KList<V> 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<V>(this, rarityTypes);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user