Marker spawning

This commit is contained in:
cyberpwn 2021-09-12 12:02:36 -04:00
parent 03bc1e722e
commit 6daf0861c9
3 changed files with 31 additions and 23 deletions

View File

@ -171,13 +171,28 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
private void updateChunks() {
for (Player i : getEngine().getWorld().realWorld().getPlayers()) {
int r = 1;
int r = 2;
Chunk c = i.getLocation().getChunk();
for (int x = -r; x <= r; x++) {
for (int z = -r; z <= r; z++) {
if (c.getWorld().isChunkLoaded(c.getX() + x, c.getZ() + z)) {
if (c.getWorld().isChunkLoaded(c.getX() + x, c.getZ() + z) && Chunks.isSafe(getEngine().getWorld().realWorld(), c.getX() + x, c.getZ() + z)) {
getEngine().updateChunk(c.getWorld().getChunkAt(c.getX() + x, c.getZ() + z));
Chunk cx = getEngine().getWorld().realWorld().getChunkAt(c.getX() + x, c.getZ() + z);
int finalX = c.getX() + x;
int finalZ = c.getZ() + z;
J.a(() -> getMantle().raiseFlag(finalX, finalZ, MantleFlag.INITIAL_SPAWNED_MARKER,
() -> {
J.a(() -> spawnIn(cx, true), RNG.r.i(5, 200));
getSpawnersFromMarkers(cx).forEach((block, spawners) -> {
if (spawners.isEmpty()) {
return;
}
IrisSpawner s = new KList<>(spawners).getRandom();
spawn(block, s, true);
});
}));
}
}
}
@ -438,18 +453,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
@Override
public void onChunkLoad(Chunk e, boolean generated) {
J.a(() -> getMantle().raiseFlag(e.getX(), e.getZ(), MantleFlag.INITIAL_SPAWNED,
() -> {
J.a(() -> spawnIn(e, true), RNG.r.i(5, 200));
getSpawnersFromMarkers(e).forEach((block, spawners) -> {
if (spawners.isEmpty()) {
return;
}
IrisSpawner s = new KList<>(spawners).getRandom();
spawn(block, s, true);
});
}));
energy += 0.3;
fixEnergy();
}
@ -464,7 +467,9 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
return;
}
spawn(block, spawnRandomly(s).getRandom());
IrisEntitySpawn ss = spawnRandomly(s).getRandom();
ss.setReferenceSpawner(spawner);
spawn(block, ss);
}
public Mantle getMantle() {

View File

@ -111,19 +111,16 @@ public class IrisEntitySpawn implements IRare {
World world = gen.getWorld().realWorld();
if (spawns > 0) {
for (int id = 0; id < spawns; id++) {
int x = c.getX();
int z = c.getZ();
int h = c.getY();
Location l = c.toLocation(world).add(0, 1, 0);
if (referenceSpawner.getAllowedLightLevels().getMin() > 0 || referenceSpawner.getAllowedLightLevels().getMax() < 15) {
if (referenceSpawner.getAllowedLightLevels().contains(l.getBlock().getLightLevel())) {
if (spawn100(gen, l) != null) {
if (spawn100(gen, l, true) != null) {
s++;
}
}
} else {
if (spawn100(gen, l) != null) {
if (spawn100(gen, l, true) != null) {
s++;
}
}
@ -150,11 +147,16 @@ public class IrisEntitySpawn implements IRare {
}
private Entity spawn100(Engine g, Location at) {
return spawn100(g, at, false);
}
private Entity spawn100(Engine g, Location at, boolean ignoreSurfaces) {
try {
IrisEntity irisEntity = getRealEntity(g);
if (!irisEntity.getSurface().matches(at.clone().subtract(0, 1, 0).getBlock()))
return null; //Make sure it can spawn on the block
if (!ignoreSurfaces && !irisEntity.getSurface().matches(at.clone().subtract(0, 1, 0).getBlock())) {
return null;
}
Entity e = irisEntity.spawn(g, at.add(0.5, 0, 0.5), rng.aquire(() -> new RNG(g.getSeedManager().getEntity())));
if (e != null) {

View File

@ -28,7 +28,8 @@ public enum MantleFlag {
INITIAL_SPAWNED,
REAL,
CARVED,
FLUID_BODIES;
FLUID_BODIES,
INITIAL_SPAWNED_MARKER;
static StateList getStateList() {
return new StateList(MantleFlag.values());