This commit is contained in:
Daniel Mills 2020-05-17 22:21:32 -04:00
parent e491401ca0
commit b8f79f6559
9 changed files with 144 additions and 49 deletions

View File

@ -44,7 +44,7 @@
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>

View File

@ -5,13 +5,19 @@ import java.io.File;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import com.google.gson.Gson;
import lombok.Data;
import ninja.bytecode.iris.object.IrisBiome;
import ninja.bytecode.iris.object.IrisBiomeDecorator;
import ninja.bytecode.iris.object.IrisDimension;
import ninja.bytecode.iris.object.IrisNoiseLayer;
import ninja.bytecode.iris.object.IrisObjectPlacement;
import ninja.bytecode.iris.object.IrisRegion;
import ninja.bytecode.iris.util.IO;
import ninja.bytecode.iris.util.ObjectResourceLoader;
import ninja.bytecode.iris.util.ResourceLoader;
import ninja.bytecode.shuriken.json.JSONObject;
@Data
public class IrisDataManager
@ -59,10 +65,35 @@ public class IrisDataManager
try
{
new File(examples, "example-pack/regions").mkdirs();
new File(examples, "example-pack/biomes").mkdirs();
new File(examples, "example-pack/dimensions").mkdirs();
IO.writeAll(new File(examples, "biome-list.txt"), biomes);
IO.writeAll(new File(examples, "environment-list.txt"), envs);
IrisDimension dim = new IrisDimension();
IrisRegion region = new IrisRegion();
region.getLandBiomes().add("plains");
region.getLandBiomes().add("desert");
region.getLandBiomes().add("forest");
region.getLandBiomes().add("mountains");
region.getSeaBiomes().add("ocean");
region.getShoreBiomes().add("beach");
IrisObjectPlacement o = new IrisObjectPlacement();
o.getPlace().add("schematic1");
o.getPlace().add("schematic2");
IrisBiome biome = new IrisBiome();
biome.getAuxiliaryGenerators().add(new IrisNoiseLayer());
biome.getChildren().add("another_biome");
biome.getDecorators().add(new IrisBiomeDecorator());
biome.getObjects().add(o);
IO.writeAll(new File(examples, "example-pack/biomes/example-biome.json"), new JSONObject(new Gson().toJson(biome)).toString(4));
IO.writeAll(new File(examples, "example-pack/regions/example-region.json"), new JSONObject(new Gson().toJson(region)).toString(4));
IO.writeAll(new File(examples, "example-pack/dimensions/example-dimension.json"), new JSONObject(new Gson().toJson(dim)).toString(4));
}
catch(Throwable e)

View File

@ -3,8 +3,5 @@ package ninja.bytecode.iris.object;
public enum Dispersion
{
SCATTER,
SIMPLEX,
CELLS,
WISPY,
ZEBRA
}

View File

@ -1,6 +1,5 @@
package ninja.bytecode.iris.object;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.block.Biome;
@ -12,6 +11,7 @@ import ninja.bytecode.iris.util.CNG;
import ninja.bytecode.iris.util.CellGenerator;
import ninja.bytecode.iris.util.RNG;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.logging.L;
@Data
@EqualsAndHashCode(callSuper = false)
@ -74,7 +74,6 @@ public class IrisBiome extends IrisRegisteredObject
for(int i = 0; i < layers.size(); i++)
{
CNG hgen = getLayerHeightGenerators(random).get(i);
CNG sgen = getLayerSurfaceGenerators(random).get(i);
int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getTerrainZoom(), wz / layers.get(i).getTerrainZoom());
if(d < 0)
@ -82,8 +81,6 @@ public class IrisBiome extends IrisRegisteredObject
continue;
}
List<BlockData> palette = getLayers().get(i).getBlockData();
for(int j = 0; j < d; j++)
{
if(data.size() >= maxDepth)
@ -93,12 +90,12 @@ public class IrisBiome extends IrisRegisteredObject
try
{
data.add(palette.get(sgen.fit(0, palette.size() - 1, (wx + j) / layers.get(i).getTerrainZoom(), (wz - j) / layers.get(i).getTerrainZoom())));
data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getTerrainZoom(), j, (wz - j) / layers.get(i).getTerrainZoom()));
}
catch(Throwable e)
{
L.ex(e);
}
}
@ -111,25 +108,6 @@ public class IrisBiome extends IrisRegisteredObject
return data;
}
public KList<CNG> getLayerSurfaceGenerators(RNG rng)
{
lock.lock();
if(layerSurfaceGenerators == null)
{
layerSurfaceGenerators = new KList<>();
int m = 91235;
for(IrisBiomePaletteLayer i : getLayers())
{
layerSurfaceGenerators.add(i.getGenerator(rng.nextParallelRNG((m += 3) * m * m * m)));
}
}
lock.unlock();
return layerSurfaceGenerators;
}
public KList<CNG> getLayerHeightGenerators(RNG rng)
{
lock.lock();
@ -141,7 +119,7 @@ public class IrisBiome extends IrisRegisteredObject
for(IrisBiomePaletteLayer i : getLayers())
{
layerHeightGenerators.add(i.getGenerator(rng.nextParallelRNG((m++) * m * m * m)));
layerHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m)));
}
}
lock.unlock();

View File

@ -12,7 +12,7 @@ import ninja.bytecode.shuriken.collections.KMap;
@Data
public class IrisBiomeDecorator
{
private Dispersion dispersion = Dispersion.ZEBRA;
private Dispersion dispersion = Dispersion.SCATTER;
private int iterations = 5;
private double zoom = 1;
private KList<String> palette = new KList<String>().qadd("GRASS");

View File

@ -9,36 +9,67 @@ import ninja.bytecode.iris.util.BlockDataTools;
import ninja.bytecode.iris.util.CNG;
import ninja.bytecode.iris.util.RNG;
import ninja.bytecode.shuriken.collections.KList;
import ninja.bytecode.shuriken.collections.KMap;
@Data
public class IrisBiomePaletteLayer
{
private Dispersion dispersion = Dispersion.WISPY;
private Dispersion dispersion = Dispersion.SCATTER;
private int minHeight = 1;
private int maxHeight = 1;
private double terrainZoom = 5;
private KList<String> palette = new KList<String>().qadd("GRASS_BLOCK");
private transient ReentrantLock lock = new ReentrantLock();
private transient KMap<Long, CNG> layerGenerators;
private transient CNG layerGenerator;
private transient CNG heightGenerator;
private transient KList<BlockData> blockData;
public CNG getGenerator(RNG rng)
public CNG getHeightGenerator(RNG rng)
{
long key = rng.nextParallelRNG(1).nextLong();
if(layerGenerators == null)
if(heightGenerator == null)
{
layerGenerators = new KMap<>();
heightGenerator = CNG.signature(rng.nextParallelRNG(minHeight * maxHeight + getBlockData().size()));
}
if(!layerGenerators.containsKey(key))
return heightGenerator;
}
public BlockData get(RNG rng, double x, double y, double z)
{
if(layerGenerator == null)
{
layerGenerators.put(key, CNG.signature(rng.nextParallelRNG(minHeight + maxHeight + getBlockData().size())));
cacheGenerator(rng);
}
return layerGenerators.get(key);
if(layerGenerator != null)
{
if(dispersion.equals(Dispersion.SCATTER))
{
return getBlockData().get(layerGenerator.fit(0, 30000000, x, y, z) % getBlockData().size());
}
else
{
return getBlockData().get(layerGenerator.fit(0, getBlockData().size() - 1, x, y, z));
}
}
return getBlockData().get(0);
}
public void cacheGenerator(RNG rng)
{
RNG rngx = rng.nextParallelRNG(minHeight + maxHeight + getBlockData().size());
switch(dispersion)
{
case SCATTER:
layerGenerator = CNG.signature(rngx).freq(1000000);
break;
case WISPY:
layerGenerator = CNG.signature(rngx);
break;
}
}
public KList<String> add(String b)

View File

@ -7,14 +7,14 @@ import ninja.bytecode.iris.util.RNG;
public class IrisNoiseLayer
{
private double zoom;
private double offsetX;
private double offsetZ;
private long seed;
private double min;
private double max;
private ReentrantLock lock;
private double zoom = 1;
private double offsetX = 0;
private double offsetZ = 0;
private long seed = 0;
private double min = 0;
private double max = 10;
private transient ReentrantLock lock;
private transient CNG generator;
public IrisNoiseLayer()

View File

@ -0,0 +1,42 @@
package ninja.bytecode.iris.objectproperty;
import java.lang.reflect.Field;
import lombok.Data;
@Data
public class ObjectProperty<T>
{
private Class<? extends T> type;
private String fieldName;
private String name;
private String description;
private Object instance;
private Field field;
public ObjectProperty(Class<? extends T> type, String fieldName) throws Throwable
{
this.type = type;
this.fieldName = fieldName;
field = type.getDeclaredField(name);
field.setAccessible(true);
if(field.isAnnotationPresent(Property.class))
{
Property p = field.getAnnotation(Property.class);
name = p.name();
description = p.description();
}
}
public void set(T value) throws Throwable
{
field.set(instance, value);
}
@SuppressWarnings("unchecked")
public T get() throws Throwable
{
return (T) field.get(instance);
}
}

View File

@ -0,0 +1,16 @@
package ninja.bytecode.iris.objectproperty;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@Retention(RUNTIME)
@Target(TYPE)
public @interface PropertyObject
{
String name();
String description();
}