mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Fix villages re-placing on top of each other
This commit is contained in:
parent
beff1d8d42
commit
25bb0912fb
@ -33,6 +33,8 @@ import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.math.RollingSequence;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -136,7 +138,6 @@ public class IrisBoardManager implements BoardProvider, Listener {
|
||||
v.add("&7&m------------------");
|
||||
KList<IrisFeaturePositional> f = new KList<>();
|
||||
engine.getFramework().getEngineParallax().forEachFeature(x, z, f::add);
|
||||
|
||||
v.add(C.AQUA + "Engine" + C.GRAY + ": " + engine.getName() + " " + engine.getMinHeight() + "-" + engine.getMaxHeight());
|
||||
v.add(C.AQUA + "Region" + C.GRAY + ": " + engine.getRegion(x, z).getName());
|
||||
v.add(C.AQUA + "Biome" + C.GRAY + ": " + engine.getBiome(x, y, z).getName());
|
||||
|
@ -18,15 +18,9 @@
|
||||
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||
import com.volmit.iris.engine.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineParallaxManager;
|
||||
import com.volmit.iris.engine.object.IrisFeaturePositional;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.util.Consumer;
|
||||
|
||||
public class IrisEngineParallax implements EngineParallaxManager {
|
||||
@Getter
|
||||
@ -35,48 +29,8 @@ public class IrisEngineParallax implements EngineParallaxManager {
|
||||
@Getter
|
||||
private final int parallaxSize;
|
||||
|
||||
private final ConcurrentLinkedHashMap<Long, KList<IrisFeaturePositional>> featureCache = new ConcurrentLinkedHashMap.Builder<Long, KList<IrisFeaturePositional>>()
|
||||
.initialCapacity(1024)
|
||||
.maximumWeightedCapacity(1024)
|
||||
.concurrencyLevel(32)
|
||||
.build();
|
||||
|
||||
public IrisEngineParallax(Engine engine) {
|
||||
this.engine = engine;
|
||||
parallaxSize = computeParallaxSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
@BlockCoordinates
|
||||
public void forEachFeature(double x, double z, Consumer<IrisFeaturePositional> f) {
|
||||
if (!getEngine().getDimension().hasFeatures(getEngine())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (IrisFeaturePositional ipf : forEachFeature(x, z)) {
|
||||
f.accept(ipf);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@BlockCoordinates
|
||||
public KList<IrisFeaturePositional> forEachFeature(double x, double z) {
|
||||
int cx = ((int) x) >> 4;
|
||||
int cz = ((int) x) >> 4;
|
||||
long key = Cache.key(cx, cz);
|
||||
|
||||
return featureCache.compute(key, (k, v) -> {
|
||||
if (v != null) {
|
||||
return v;
|
||||
}
|
||||
|
||||
KList<IrisFeaturePositional> pos = new KList<>();
|
||||
pos.addAll(EngineParallaxManager.super.forEachFeature(cx << 4, cz << 4));
|
||||
pos.addAll(EngineParallaxManager.super.forEachFeature((cx << 4) + 15, cz << 4));
|
||||
pos.addAll(EngineParallaxManager.super.forEachFeature(cx << 4, (cz << 4) + 15));
|
||||
pos.addAll(EngineParallaxManager.super.forEachFeature((cx << 4) + 15, (cz << 4) + 15));
|
||||
pos.removeDuplicates();
|
||||
return pos;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -398,6 +398,8 @@ public class B {
|
||||
|
||||
f = mm.equals(Material.GRASS)
|
||||
|| mm.equals(Material.TALL_GRASS)
|
||||
|| mm.equals(Material.FERN)
|
||||
|| mm.equals(Material.LARGE_FERN)
|
||||
|| mm.equals(B.getMaterial("CORNFLOWER"))
|
||||
|| mm.equals(Material.SUNFLOWER)
|
||||
|| mm.equals(Material.CHORUS_FLOWER)
|
||||
@ -468,6 +470,7 @@ public class B {
|
||||
|
||||
public static boolean isFoliagePlantable(BlockData d) {
|
||||
return d.getMaterial().equals(Material.GRASS_BLOCK)
|
||||
|| d.getMaterial().equals(Material.ROOTED_DIRT)
|
||||
|| d.getMaterial().equals(Material.DIRT)
|
||||
|| d.getMaterial().equals(Material.COARSE_DIRT)
|
||||
|| d.getMaterial().equals(Material.PODZOL);
|
||||
@ -476,6 +479,7 @@ public class B {
|
||||
public static boolean isFoliagePlantable(Material d) {
|
||||
return d.equals(Material.GRASS_BLOCK)
|
||||
|| d.equals(Material.DIRT)
|
||||
|| d.equals(Material.ROOTED_DIRT)
|
||||
|| d.equals(Material.COARSE_DIRT)
|
||||
|| d.equals(Material.PODZOL);
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
getEngine().getMetrics().getParallaxInsert().put(p.getMilliseconds());
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
Iris.error("Failed to insert parallax at chunk " + (x >> 4) + " " + (z >> 4));
|
||||
Iris.error("Failed to insert parallax at chunk " + x + " " + z);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -211,44 +211,48 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
|
||||
@BlockCoordinates
|
||||
default KList<IrisFeaturePositional> forEachFeature(double x, double z) {
|
||||
KList<IrisFeaturePositional> pos = new KList<>();
|
||||
synchronized (getEngine())
|
||||
{
|
||||
KList<IrisFeaturePositional> pos = new KList<>();
|
||||
|
||||
if (!getEngine().getDimension().hasFeatures(getEngine())) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) {
|
||||
if (i.shouldFilter(x, z, getEngine().getFramework().getComplex().getRng())) {
|
||||
pos.add(i);
|
||||
if (!getEngine().getDimension().hasFeatures(getEngine())) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
int s = (int) Math.ceil(getParallaxSize() / 2D);
|
||||
int i, j;
|
||||
int cx = (int) x >> 4;
|
||||
int cz = (int) z >> 4;
|
||||
|
||||
for (i = -s; i <= s; i++) {
|
||||
for (j = -s; j <= s; j++) {
|
||||
ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
|
||||
|
||||
try {
|
||||
for (IrisFeaturePositional k : m.getFeatures()) {
|
||||
if (k.shouldFilter(x, z, getEngine().getFramework().getComplex().getRng())) {
|
||||
pos.add(k);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz));
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
for (IrisFeaturePositional i : getEngine().getDimension().getSpecificFeatures()) {
|
||||
if (i.shouldFilter(x, z, getEngine().getFramework().getComplex().getRng())) {
|
||||
pos.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
int s = (int) Math.ceil(getParallaxSize() / 2D);
|
||||
int i, j;
|
||||
int cx = (int)Math.round(x) >> 4;
|
||||
int cz = (int)Math.round(z) >> 4;
|
||||
|
||||
for (i = -s; i <= s; i++) {
|
||||
for (j = -s; j <= s; j++) {
|
||||
ParallaxChunkMeta m = getParallaxAccess().getMetaR(i + cx, j + cz);
|
||||
|
||||
try {
|
||||
for (IrisFeaturePositional k : m.getFeatures()) {
|
||||
if (k.shouldFilter(x, z, getEngine().getFramework().getComplex().getRng())) {
|
||||
pos.add(k);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
Iris.error("FILTER ERROR" + " AT " + (cx + i) + " " + (j + cz));
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter")
|
||||
default void generateParallaxArea(int x, int z) {
|
||||
if (!getEngine().getDimension().isPlaceObjects()) {
|
||||
@ -272,7 +276,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
if (!getParallaxAccess().isFeatureGenerated(xx, zz)) {
|
||||
getParallaxAccess().setFeatureGenerated(xx, zz);
|
||||
burst.queue(() -> {
|
||||
RNG rng = new RNG(Cache.key(xx, zz)).nextParallelRNG(getEngine().getTarget().getWorld().seed());
|
||||
RNG rng = new RNG(Cache.key(xx, zz) + getEngine().getTarget().getWorld().seed());
|
||||
IrisRegion region = getComplex().getRegionStream().get(xxx, zzz);
|
||||
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
|
||||
generateParallaxFeatures(rng, xx, zz, region, biome);
|
||||
@ -324,9 +328,10 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
}
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
default KList<Runnable> generateParallaxVacuumLayer(int x, int z) {
|
||||
KList<Runnable> after = new KList<>();
|
||||
if (getParallaxAccess().isParallaxGenerated(x >> 4, z >> 4)) {
|
||||
if (getParallaxAccess().isParallaxGenerated(x, z)) {
|
||||
return after;
|
||||
}
|
||||
|
||||
@ -359,6 +364,7 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
generateParallaxMutations(rng, x, z, false);
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
default void generateParallaxFeatures(RNG rng, int cx, int cz, IrisRegion region, IrisBiome biome) {
|
||||
for (IrisFeaturePotential i : getEngine().getDimension().getFeatures()) {
|
||||
placeZone(rng, cx, cz, i);
|
||||
@ -375,7 +381,11 @@ public interface EngineParallaxManager extends DataProvider, IObjectPlacer {
|
||||
|
||||
default void placeZone(RNG rng, int cx, int cz, IrisFeaturePotential i) {
|
||||
if (i.hasZone(rng, cx, cz)) {
|
||||
getParallaxAccess().getMetaRW(cx, cz).getFeatures().add(new IrisFeaturePositional((cx << 4) + rng.nextInt(16), (cz << 4) + rng.nextInt(16), i.getZone()));
|
||||
getParallaxAccess().getMetaRW(cx, cz).getFeatures()
|
||||
.add(new IrisFeaturePositional(
|
||||
(cx << 4) + rng.nextInt(16),
|
||||
(cz << 4) + rng.nextInt(16),
|
||||
i.getZone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import com.volmit.iris.engine.cache.AtomicCache;
|
||||
import com.volmit.iris.engine.interpolation.IrisInterpolation;
|
||||
import com.volmit.iris.engine.object.annotations.Desc;
|
||||
import com.volmit.iris.engine.object.annotations.Required;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.function.NoiseProvider;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
@ -67,6 +68,7 @@ public class IrisFeaturePositional {
|
||||
s.writeUTF(new Gson().toJson(this));
|
||||
}
|
||||
|
||||
@BlockCoordinates
|
||||
public boolean shouldFilter(double x, double z, RNG rng) {
|
||||
double actualRadius = getFeature().getActualRadius();
|
||||
double dist2 = distance2(x, z, rng);
|
||||
|
Loading…
x
Reference in New Issue
Block a user