mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-25 10:09:14 +00:00
Merge pull request #1044 from CrazyDev05/object_fix
Object Spawning pattern fix
This commit is contained in:
@@ -23,10 +23,7 @@ import com.volmit.iris.engine.data.cache.Cache;
|
||||
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.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisObject;
|
||||
import com.volmit.iris.engine.object.IrisObjectPlacement;
|
||||
import com.volmit.iris.engine.object.IrisRegion;
|
||||
import com.volmit.iris.engine.object.*;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.context.ChunkContext;
|
||||
import com.volmit.iris.util.data.B;
|
||||
@@ -35,6 +32,8 @@ import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.matter.MatterStructurePOI;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
import com.volmit.iris.util.noise.NoiseType;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -45,7 +44,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|
||||
@Override
|
||||
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
|
||||
RNG rng = new RNG(Cache.key(x, z) + seed());
|
||||
RNG rng = applyNoise(x, z, Cache.key(x, z) + seed());
|
||||
int xxx = 8 + (x << 4);
|
||||
int zzz = 8 + (z << 4);
|
||||
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
|
||||
@@ -53,15 +52,17 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
placeObjects(writer, rng, x, z, biome, region);
|
||||
}
|
||||
|
||||
private RNG applyNoise(int x, int z, long seed) {
|
||||
CNG noise = CNG.signatureFast(new RNG(seed), NoiseType.WHITE, NoiseType.GLOB);
|
||||
return new RNG((long) (seed * noise.noise(x, z)));
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
private void placeObjects(MantleWriter writer, RNG rng, int x, int z, IrisBiome biome, IrisRegion region) {
|
||||
long s = Cache.key(x, z) + seed();
|
||||
RNG rnp = new RNG(s);
|
||||
for (IrisObjectPlacement i : biome.getSurfaceObjects()) {
|
||||
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) {
|
||||
try {
|
||||
placeObject(writer, rnp, x << 4, z << 4, i);
|
||||
rnp.setSeed(s);
|
||||
placeObject(writer, rng, x << 4, z << 4, i);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Iris.error("Failed to place objects in the following biome: " + biome.getName());
|
||||
@@ -75,8 +76,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
for (IrisObjectPlacement i : region.getSurfaceObjects()) {
|
||||
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) {
|
||||
try {
|
||||
placeObject(writer, rnp, x << 4, z << 4, i);
|
||||
rnp.setSeed(s);
|
||||
placeObject(writer, rng, x << 4, z << 4, i);
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Iris.error("Failed to place objects in the following region: " + region.getName());
|
||||
@@ -123,23 +123,19 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
}
|
||||
|
||||
public Set<String> guess(int x, int z) {
|
||||
RNG rng = new RNG(Cache.key(x, z) + seed());
|
||||
long s = Cache.key(x, z) + seed();
|
||||
RNG rngd = new RNG(s);
|
||||
RNG rng = applyNoise(x, z, Cache.key(x, z) + seed());
|
||||
IrisBiome biome = getEngineMantle().getEngine().getSurfaceBiome((x << 4) + 8, (z << 4) + 8);
|
||||
IrisRegion region = getEngineMantle().getEngine().getRegion((x << 4) + 8, (z << 4) + 8);
|
||||
Set<String> v = new KSet<>();
|
||||
for (IrisObjectPlacement i : biome.getSurfaceObjects()) {
|
||||
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) {
|
||||
v.addAll(guessPlacedKeys(rngd, x, z, i));
|
||||
rngd.setSeed(s);
|
||||
v.addAll(guessPlacedKeys(rng, x, z, i));
|
||||
}
|
||||
}
|
||||
|
||||
for (IrisObjectPlacement i : region.getSurfaceObjects()) {
|
||||
if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) {
|
||||
v.addAll(guessPlacedKeys(rngd, x, z, i));
|
||||
rngd.setSeed(s);
|
||||
v.addAll(guessPlacedKeys(rng, x, z, i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.placer.HeightmapObjectPlacer;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
@@ -688,6 +689,25 @@ public class IrisObject extends IrisRegistrant {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!config.getAllowedCollisions().isEmpty() || !config.getForbiddenCollisions().isEmpty()) {
|
||||
Engine engine = rdata.getEngine();
|
||||
String key;
|
||||
BlockVector offset = new BlockVector(config.getTranslate().getX(), config.getTranslate().getY(), config.getTranslate().getZ());
|
||||
for (int i = x - Math.floorDiv(w, 2) + (int) offset.getX(); i <= x + Math.floorDiv(w, 2) - (w % 2 == 0 ? 1 : 0) + (int) offset.getX(); i++) {
|
||||
for (int j = y - Math.floorDiv(h, 2) + (int) offset.getY(); j <= y + Math.floorDiv(h, 2) - (h % 2 == 0 ? 1 : 0) + (int) offset.getY(); j++) {
|
||||
for (int k = z - Math.floorDiv(d, 2) + (int) offset.getZ(); k <= z + Math.floorDiv(d, 2) - (d % 2 == 0 ? 1 : 0) + (int) offset.getX(); k++) {
|
||||
key = engine.getObjectPlacementKey(i, j, k);
|
||||
if (key != null) {
|
||||
if (config.getForbiddenCollisions().contains(key) && !config.getAllowedCollisions().contains(key)) {
|
||||
Iris.warn("%s collides with %s (%s / %s / %s)", getLoadKey(), key, i, j, k);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.isBore()) {
|
||||
BlockVector offset = new BlockVector(config.getTranslate().getX(), config.getTranslate().getY(), config.getTranslate().getZ());
|
||||
for (int i = x - Math.floorDiv(w, 2) + (int) offset.getX(); i <= x + Math.floorDiv(w, 2) - (w % 2 == 0 ? 1 : 0) + (int) offset.getX(); i++) {
|
||||
|
||||
@@ -128,6 +128,14 @@ public class IrisObjectPlacement {
|
||||
@Desc("This object / these objects override the following trees when they grow...")
|
||||
@ArrayType(min = 1, type = IrisTree.class)
|
||||
private KList<IrisTree> trees = new KList<>();
|
||||
@RegistryListResource(IrisObject.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Desc("List of objects to this object is allowed to collied with")
|
||||
private KList<String> allowedCollisions = new KList<>();
|
||||
@RegistryListResource(IrisObject.class)
|
||||
@ArrayType(type = String.class)
|
||||
@Desc("List of objects to this object is forbidden to collied with")
|
||||
private KList<String> forbiddenCollisions = new KList<>();
|
||||
private transient AtomicCache<TableCache> cache = new AtomicCache<>();
|
||||
|
||||
public IrisObjectPlacement toPlacement(String... place) {
|
||||
|
||||
Reference in New Issue
Block a user