diff --git a/pom.xml b/pom.xml index 965b716f9..8c99ae3f2 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ shade - false + true diff --git a/src/main/java/ninja/bytecode/iris/IrisDataManager.java b/src/main/java/ninja/bytecode/iris/IrisDataManager.java index 8d5221436..257097546 100644 --- a/src/main/java/ninja/bytecode/iris/IrisDataManager.java +++ b/src/main/java/ninja/bytecode/iris/IrisDataManager.java @@ -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) diff --git a/src/main/java/ninja/bytecode/iris/object/Dispersion.java b/src/main/java/ninja/bytecode/iris/object/Dispersion.java index 35dc195c6..51e6e98d3 100644 --- a/src/main/java/ninja/bytecode/iris/object/Dispersion.java +++ b/src/main/java/ninja/bytecode/iris/object/Dispersion.java @@ -3,8 +3,5 @@ package ninja.bytecode.iris.object; public enum Dispersion { SCATTER, - SIMPLEX, - CELLS, WISPY, - ZEBRA } diff --git a/src/main/java/ninja/bytecode/iris/object/IrisBiome.java b/src/main/java/ninja/bytecode/iris/object/IrisBiome.java index de50bc65e..f2fe54f77 100644 --- a/src/main/java/ninja/bytecode/iris/object/IrisBiome.java +++ b/src/main/java/ninja/bytecode/iris/object/IrisBiome.java @@ -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 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 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 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(); diff --git a/src/main/java/ninja/bytecode/iris/object/IrisBiomeDecorator.java b/src/main/java/ninja/bytecode/iris/object/IrisBiomeDecorator.java index 31bf3ff31..72c29cbcc 100644 --- a/src/main/java/ninja/bytecode/iris/object/IrisBiomeDecorator.java +++ b/src/main/java/ninja/bytecode/iris/object/IrisBiomeDecorator.java @@ -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 palette = new KList().qadd("GRASS"); diff --git a/src/main/java/ninja/bytecode/iris/object/IrisBiomePaletteLayer.java b/src/main/java/ninja/bytecode/iris/object/IrisBiomePaletteLayer.java index ae1bb6b2b..f3d6a9501 100644 --- a/src/main/java/ninja/bytecode/iris/object/IrisBiomePaletteLayer.java +++ b/src/main/java/ninja/bytecode/iris/object/IrisBiomePaletteLayer.java @@ -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 palette = new KList().qadd("GRASS_BLOCK"); private transient ReentrantLock lock = new ReentrantLock(); - private transient KMap layerGenerators; + private transient CNG layerGenerator; + private transient CNG heightGenerator; private transient KList 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 add(String b) diff --git a/src/main/java/ninja/bytecode/iris/object/IrisNoiseLayer.java b/src/main/java/ninja/bytecode/iris/object/IrisNoiseLayer.java index edfc078f9..441d8a259 100644 --- a/src/main/java/ninja/bytecode/iris/object/IrisNoiseLayer.java +++ b/src/main/java/ninja/bytecode/iris/object/IrisNoiseLayer.java @@ -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() diff --git a/src/main/java/ninja/bytecode/iris/objectproperty/ObjectProperty.java b/src/main/java/ninja/bytecode/iris/objectproperty/ObjectProperty.java new file mode 100644 index 000000000..9aa7702aa --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/objectproperty/ObjectProperty.java @@ -0,0 +1,42 @@ +package ninja.bytecode.iris.objectproperty; + +import java.lang.reflect.Field; + +import lombok.Data; + +@Data +public class ObjectProperty +{ + private Class type; + private String fieldName; + private String name; + private String description; + private Object instance; + private Field field; + + public ObjectProperty(Class 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); + } +} diff --git a/src/main/java/ninja/bytecode/iris/objectproperty/PropertyObject.java b/src/main/java/ninja/bytecode/iris/objectproperty/PropertyObject.java new file mode 100644 index 000000000..fd08cc652 --- /dev/null +++ b/src/main/java/ninja/bytecode/iris/objectproperty/PropertyObject.java @@ -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(); +}