mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-24 17:49:16 +00:00
Compare commits
3 Commits
dev
...
feat/stati
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a74164627 | ||
|
|
894de013dd | ||
|
|
9a81905fdd |
@@ -23,12 +23,11 @@ import com.volmit.iris.engine.data.cache.AtomicCache;
|
|||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
import com.volmit.iris.engine.mantle.MantleComponent;
|
import com.volmit.iris.engine.mantle.MantleComponent;
|
||||||
import com.volmit.iris.engine.mantle.components.MantleCarvingComponent;
|
import com.volmit.iris.engine.mantle.components.*;
|
||||||
import com.volmit.iris.engine.mantle.components.MantleFluidBodyComponent;
|
|
||||||
import com.volmit.iris.engine.mantle.components.MantleJigsawComponent;
|
|
||||||
import com.volmit.iris.engine.mantle.components.MantleObjectComponent;
|
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
import com.volmit.iris.util.collection.KMap;
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.collection.KSet;
|
||||||
|
import com.volmit.iris.util.format.Form;
|
||||||
import com.volmit.iris.util.mantle.Mantle;
|
import com.volmit.iris.util.mantle.Mantle;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
|
|
||||||
@@ -58,6 +57,7 @@ public class IrisEngineMantle implements EngineMantle {
|
|||||||
registerComponent(jigsaw);
|
registerComponent(jigsaw);
|
||||||
object = new MantleObjectComponent(this);
|
object = new MantleObjectComponent(this);
|
||||||
registerComponent(object);
|
registerComponent(object);
|
||||||
|
registerComponent(new MantleStaticComponent(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -826,6 +826,13 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
|||||||
return new PlacedObject(piece.getPlacementOptions(), getData().getObjectLoader().load(object), id, x, z);
|
return new PlacedObject(piece.getPlacementOptions(), getData().getObjectLoader().load(object), id, x, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var staticPlacement : getDimension().getStaticPlacements().getObjects()) {
|
||||||
|
IrisObjectPlacement i = staticPlacement.placement();
|
||||||
|
if (i.getPlace().contains(object)) {
|
||||||
|
return new PlacedObject(i, getData().getObjectLoader().load(object), id, x, z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IrisRegion region = getRegion(x, z);
|
IrisRegion region = getRegion(x, z);
|
||||||
|
|
||||||
for (IrisObjectPlacement i : region.getObjects()) {
|
for (IrisObjectPlacement i : region.getObjects()) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
package com.volmit.iris.engine.mantle.components;
|
package com.volmit.iris.engine.mantle.components;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.engine.mantle.EngineMantle;
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||||
@@ -39,11 +40,13 @@ import com.volmit.iris.util.matter.MatterStructurePOI;
|
|||||||
import com.volmit.iris.util.noise.CNG;
|
import com.volmit.iris.util.noise.CNG;
|
||||||
import com.volmit.iris.util.noise.NoiseType;
|
import com.volmit.iris.util.noise.NoiseType;
|
||||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||||
|
import com.volmit.iris.util.parallel.MultiBurst;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.util.BlockVector;
|
import org.bukkit.util.BlockVector;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@@ -162,99 +165,67 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
|||||||
private int computeRadius() {
|
private int computeRadius() {
|
||||||
var dimension = getDimension();
|
var dimension = getDimension();
|
||||||
|
|
||||||
AtomicInteger xg = new AtomicInteger();
|
|
||||||
AtomicInteger zg = new AtomicInteger();
|
|
||||||
|
|
||||||
KSet<String> objects = new KSet<>();
|
KSet<String> objects = new KSet<>();
|
||||||
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
||||||
for (var region : dimension.getAllRegions(this::getData)) {
|
for (var region : dimension.getAllRegions(this::getData)) {
|
||||||
for (var j : region.getObjects()) {
|
for (var placement : region.getObjects()) {
|
||||||
if (j.getScale().canScaleBeyond()) {
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
scalars.put(j.getScale(), j.getPlace());
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
} else {
|
} else {
|
||||||
objects.addAll(j.getPlace());
|
objects.addAll(placement.getPlace());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (var biome : dimension.getAllBiomes(this::getData)) {
|
for (var biome : region.getAllBiomes(this::getData)) {
|
||||||
for (var j : biome.getObjects()) {
|
for (var placement : biome.getObjects()) {
|
||||||
if (j.getScale().canScaleBeyond()) {
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
scalars.put(j.getScale(), j.getPlace());
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
} else {
|
} else {
|
||||||
objects.addAll(j.getPlace());
|
objects.addAll(placement.getPlace());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BurstExecutor e = getEngineMantle().getTarget().getBurster().burst(objects.size());
|
return computeObjectRadius(objects, scalars, getEngineMantle().getTarget().getBurster(), getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int computeObjectRadius(KSet<String> objects, KMap<IrisObjectScale, KList<String>> scalars, MultiBurst burst, IrisData data) {
|
||||||
|
AtomicInteger x = new AtomicInteger();
|
||||||
|
AtomicInteger z = new AtomicInteger();
|
||||||
|
|
||||||
|
BurstExecutor e = burst.burst(objects.size());
|
||||||
KMap<String, BlockVector> sizeCache = new KMap<>();
|
KMap<String, BlockVector> sizeCache = new KMap<>();
|
||||||
for (String i : objects) {
|
for (String loadKey : objects) {
|
||||||
e.queue(() -> {
|
e.queue(() -> {
|
||||||
try {
|
try {
|
||||||
BlockVector bv = sizeCache.computeIfAbsent(i, (k) -> {
|
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||||
try {
|
|
||||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(i));
|
|
||||||
} catch (IOException ex) {
|
|
||||||
Iris.reportError(ex);
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bv == null) {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||||
Iris.warn("Object " + i + " has a large size (" + bv + ") and may increase memory usage!");
|
Iris.warn("Object " + loadKey + " has a large size (" + bv + ") and may increase memory usage!");
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (xg) {
|
x.getAndUpdate(i -> Math.max(bv.getBlockX(), i));
|
||||||
xg.getAndSet(Math.max(bv.getBlockX(), xg.get()));
|
z.getAndUpdate(i -> Math.max(bv.getBlockZ(), i));
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (zg) {
|
|
||||||
zg.getAndSet(Math.max(bv.getBlockZ(), zg.get()));
|
|
||||||
}
|
|
||||||
} catch (Throwable ed) {
|
} catch (Throwable ed) {
|
||||||
Iris.reportError(ed);
|
Iris.reportError(ed);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<IrisObjectScale, KList<String>> entry : scalars.entrySet()) {
|
for (Map.Entry<IrisObjectScale, KList<String>> entry : scalars.entrySet()) {
|
||||||
double ms = entry.getKey().getMaximumScale();
|
double ms = entry.getKey().getMaximumScale();
|
||||||
for (String j : entry.getValue()) {
|
for (String loadKey : entry.getValue()) {
|
||||||
e.queue(() -> {
|
e.queue(() -> {
|
||||||
try {
|
try {
|
||||||
BlockVector bv = sizeCache.computeIfAbsent(j, (k) -> {
|
BlockVector bv = sampleSize(sizeCache, data, loadKey);
|
||||||
try {
|
|
||||||
return IrisObject.sampleSize(getData().getObjectLoader().findFile(j));
|
|
||||||
} catch (IOException ioException) {
|
|
||||||
Iris.reportError(ioException);
|
|
||||||
ioException.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (bv == null) {
|
|
||||||
throw new RuntimeException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
if (Math.max(bv.getBlockX(), bv.getBlockZ()) > 128) {
|
||||||
Iris.warn("Object " + j + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
|
Iris.warn("Object " + loadKey + " has a large size (" + bv + ") and may increase memory usage! (Object scaled up to " + Form.pc(ms, 2) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (xg) {
|
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockX() * ms), i));
|
||||||
xg.getAndSet((int) Math.max(Math.ceil(bv.getBlockX() * ms), xg.get()));
|
x.getAndUpdate(i -> (int) Math.max(Math.ceil(bv.getBlockZ() * ms), i));
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (zg) {
|
|
||||||
zg.getAndSet((int) Math.max(Math.ceil(bv.getBlockZ() * ms), zg.get()));
|
|
||||||
}
|
|
||||||
} catch (Throwable ee) {
|
} catch (Throwable ee) {
|
||||||
Iris.reportError(ee);
|
Iris.reportError(ee);
|
||||||
|
|
||||||
@@ -264,6 +235,20 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
e.complete();
|
e.complete();
|
||||||
return Math.max(xg.get(), zg.get());
|
return Math.max(x.get(), z.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static BlockVector sampleSize(KMap<String, BlockVector> sizeCache, IrisData data, String loadKey) {
|
||||||
|
BlockVector bv = sizeCache.computeIfAbsent(loadKey, (k) -> {
|
||||||
|
try {
|
||||||
|
return IrisObject.sampleSize(data.getObjectLoader().findFile(loadKey));
|
||||||
|
} catch (IOException ioException) {
|
||||||
|
Iris.reportError(ioException);
|
||||||
|
ioException.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
return Objects.requireNonNull(bv, "sampleSize returned a null block vector");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
package com.volmit.iris.engine.mantle.components;
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.mantle.EngineMantle;
|
||||||
|
import com.volmit.iris.engine.mantle.IrisMantleComponent;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.engine.object.IrisObjectScale;
|
||||||
|
import com.volmit.iris.engine.object.IrisStaticPlacement;
|
||||||
|
import com.volmit.iris.engine.object.NoiseStyle;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
|
import com.volmit.iris.util.collection.KSet;
|
||||||
|
import com.volmit.iris.util.context.ChunkContext;
|
||||||
|
import com.volmit.iris.util.mantle.MantleFlag;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import com.volmit.iris.util.noise.CNG;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
public class MantleStaticComponent extends IrisMantleComponent {
|
||||||
|
private final CNG cng;
|
||||||
|
@Getter
|
||||||
|
private final int radius = computeRadius();
|
||||||
|
|
||||||
|
public MantleStaticComponent(EngineMantle engineMantle) {
|
||||||
|
super(engineMantle, MantleFlag.STATIC, 1);
|
||||||
|
cng = NoiseStyle.STATIC.create(new RNG(seed()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
|
||||||
|
RNG rng = new RNG(cng.fit(Integer.MIN_VALUE, Integer.MAX_VALUE, x, z));
|
||||||
|
for (IrisStaticPlacement placement : getDimension().getStaticPlacements().getAll(x, z)) {
|
||||||
|
placement.place(writer, rng, getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int computeRadius() {
|
||||||
|
var placements = getDimension().getStaticPlacements();
|
||||||
|
|
||||||
|
KSet<String> objects = new KSet<>();
|
||||||
|
KMap<IrisObjectScale, KList<String>> scalars = new KMap<>();
|
||||||
|
for (var staticPlacement : placements.getObjects()) {
|
||||||
|
var placement = staticPlacement.placement();
|
||||||
|
if (placement.getScale().canScaleBeyond()) {
|
||||||
|
scalars.put(placement.getScale(), placement.getPlace());
|
||||||
|
} else {
|
||||||
|
objects.addAll(placement.getPlace());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int jigsaw = placements.getStructures()
|
||||||
|
.stream()
|
||||||
|
.mapToInt(staticPlacement -> staticPlacement.maxDimension(getData()))
|
||||||
|
.max()
|
||||||
|
.orElse(0);
|
||||||
|
int object = MantleObjectComponent.computeObjectRadius(objects, scalars, getEngineMantle().getTarget().getBurster(), getData());
|
||||||
|
|
||||||
|
return Math.max(jigsaw, object);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -310,6 +310,8 @@ public class IrisDimension extends IrisRegistrant {
|
|||||||
@MaxNumber(318)
|
@MaxNumber(318)
|
||||||
@Desc("The Subterrain Fluid Layer Height")
|
@Desc("The Subterrain Fluid Layer Height")
|
||||||
private int caveLavaHeight = 8;
|
private int caveLavaHeight = 8;
|
||||||
|
@Desc("Static Placements for objects and structures")
|
||||||
|
private IrisStaticPlacements staticPlacements = new IrisStaticPlacements();
|
||||||
|
|
||||||
public int getMaxHeight() {
|
public int getMaxHeight() {
|
||||||
return (int) getDimensionHeight().getMax();
|
return (int) getDimensionHeight().getMax();
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Required;
|
||||||
|
import com.volmit.iris.util.data.B;
|
||||||
|
import com.volmit.iris.util.data.IrisBlockData;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import com.volmit.iris.util.matter.MatterStructurePOI;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Desc("Static Object Placement")
|
||||||
|
@Accessors(chain = true, fluent = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class IrisStaticObjectPlacement implements IrisStaticPlacement {
|
||||||
|
@Required
|
||||||
|
@Desc("The X coordinate to spawn the object at")
|
||||||
|
private int x = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Y coordinate to spawn the object at\nuse a value <0 to allow the placement modes to function")
|
||||||
|
private int y = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Z coordinate to spawn the object at")
|
||||||
|
private int z = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The object placement to use")
|
||||||
|
private IrisObjectPlacement placement;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void place(MantleWriter writer, RNG rng, IrisData irisData) {
|
||||||
|
IrisObject v = placement.getScale().get(rng, placement.getObject(() -> irisData, rng));
|
||||||
|
if (v == null) return;
|
||||||
|
|
||||||
|
v.place(x, y, z, writer, placement, rng, irisData);
|
||||||
|
int id = rng.i(0, Integer.MAX_VALUE);
|
||||||
|
v.place(x, y, z, writer, placement, rng, (b, data) -> {
|
||||||
|
writer.setData(b.getX(), b.getY(), b.getZ(), v.getLoadKey() + "@" + id);
|
||||||
|
if (placement.isDolphinTarget() && placement.isUnderwater() && B.isStorageChest(data)) {
|
||||||
|
writer.setData(b.getX(), b.getY(), b.getZ(), MatterStructurePOI.BURIED_TREASURE);
|
||||||
|
}
|
||||||
|
if (data instanceof IrisBlockData d) {
|
||||||
|
writer.setData(b.getX(), b.getY(), b.getZ(), d.getCustom());
|
||||||
|
}
|
||||||
|
}, null, irisData);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
|
||||||
|
public interface IrisStaticPlacement {
|
||||||
|
int x();
|
||||||
|
int y();
|
||||||
|
int z();
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
default boolean shouldPlace(int chunkX, int chunkZ) {
|
||||||
|
return x() >> 4 == chunkX && z() >> 4 == chunkZ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void place(MantleWriter writer, RNG rng, IrisData data);
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
|
||||||
|
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Desc("Static Placements")
|
||||||
|
@Data
|
||||||
|
public class IrisStaticPlacements {
|
||||||
|
@Desc("List of static jigsaw structures")
|
||||||
|
@ArrayType(type = IrisStaticStructurePlacement.class)
|
||||||
|
private KList<IrisStaticStructurePlacement> structures = new KList<>();
|
||||||
|
|
||||||
|
@Desc("List of static objects")
|
||||||
|
@ArrayType(type = IrisStaticObjectPlacement.class)
|
||||||
|
private KList<IrisStaticObjectPlacement> objects = new KList<>();
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
public KList<IrisStaticStructurePlacement> getStructures(int chunkX, int chunkZ) {
|
||||||
|
return filter(structures.stream(), chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
public KList<IrisStaticObjectPlacement> getObjects(int chunkX, int chunkZ) {
|
||||||
|
return filter(objects.stream(), chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ChunkCoordinates
|
||||||
|
public KList<IrisStaticPlacement> getAll(int chunkX, int chunkZ) {
|
||||||
|
return filter(Stream.concat(structures.stream(), objects.stream()), chunkX, chunkZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T extends IrisStaticPlacement> KList<T> filter(Stream<T> stream, int chunkX, int chunkZ) {
|
||||||
|
return stream.filter(p -> p.shouldPlace(chunkX, chunkZ))
|
||||||
|
.collect(Collectors.toCollection(KList::new));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package com.volmit.iris.engine.object;
|
||||||
|
|
||||||
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
|
import com.volmit.iris.engine.jigsaw.PlannedStructure;
|
||||||
|
import com.volmit.iris.engine.mantle.MantleWriter;
|
||||||
|
import com.volmit.iris.engine.object.annotations.ArrayType;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Desc;
|
||||||
|
import com.volmit.iris.engine.object.annotations.RegistryListResource;
|
||||||
|
import com.volmit.iris.engine.object.annotations.Required;
|
||||||
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.math.RNG;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Desc("Static Jigsaw Structure Placement")
|
||||||
|
@Accessors(chain = true, fluent = true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class IrisStaticStructurePlacement implements IrisStaticPlacement {
|
||||||
|
@Required
|
||||||
|
@Desc("The X coordinate to spawn the structure at")
|
||||||
|
private int x = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Y coordinate to spawn the structure at")
|
||||||
|
private int y = 0;
|
||||||
|
@Required
|
||||||
|
@Desc("The Z coordinate to spawn the structure at")
|
||||||
|
private int z = 0;
|
||||||
|
@Required
|
||||||
|
@ArrayType(min = 1, type = String.class)
|
||||||
|
@RegistryListResource(IrisJigsawStructure.class)
|
||||||
|
@Desc("The structures to place")
|
||||||
|
private KList<String> structures;
|
||||||
|
|
||||||
|
public int maxDimension(IrisData data) {
|
||||||
|
return data.getJigsawStructureLoader().loadAll(structures)
|
||||||
|
.stream()
|
||||||
|
.mapToInt(IrisJigsawStructure::getMaxDimension)
|
||||||
|
.max()
|
||||||
|
.orElse(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void place(MantleWriter writer, RNG rng, IrisData data) {
|
||||||
|
IrisJigsawStructure jigsaw = null;
|
||||||
|
while (jigsaw == null && !structures.isEmpty()) {
|
||||||
|
String loadKey = structures.popRandom(rng);
|
||||||
|
jigsaw = data.getJigsawStructureLoader().load(loadKey);
|
||||||
|
|
||||||
|
if (jigsaw == null)
|
||||||
|
Iris.error("Jigsaw structure not found " + loadKey);
|
||||||
|
}
|
||||||
|
if (jigsaw == null) {
|
||||||
|
Iris.error("No jigsaw structure found for " + structures);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new PlannedStructure(jigsaw, new IrisPosition(x, y, z), rng, false)
|
||||||
|
.place(writer, writer.getMantle(), writer.getEngine());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -487,7 +487,7 @@ public class KList<T> extends ArrayList<T> implements List<T> {
|
|||||||
return pop();
|
return pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
return remove(rng.i(0, last()));
|
return remove(rng.i(0, size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public KList<T> sub(int f, int t) {
|
public KList<T> sub(int f, int t) {
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ public enum MantleFlag {
|
|||||||
ETCHED,
|
ETCHED,
|
||||||
TILE,
|
TILE,
|
||||||
CUSTOM,
|
CUSTOM,
|
||||||
DISCOVERED;
|
DISCOVERED,
|
||||||
|
STATIC;
|
||||||
|
|
||||||
static StateList getStateList() {
|
static StateList getStateList() {
|
||||||
return new StateList(MantleFlag.values());
|
return new StateList(MantleFlag.values());
|
||||||
|
|||||||
Reference in New Issue
Block a user