mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-28 03:29:06 +00:00
Chunk regeneration
This commit is contained in:
@@ -407,7 +407,7 @@ public class IrisEngine implements Engine {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getMantle().generateMatter(x >> 4, z >> 4, true);
|
||||
getMantle().generateMatter(x >> 4, z >> 4, multicore);
|
||||
burst().burst(multicore,
|
||||
() -> getTerrainActuator().actuate(x, z, vblocks, multicore),
|
||||
() -> getBiomeActuator().actuate(x, z, vbiomes, multicore)
|
||||
@@ -419,7 +419,7 @@ public class IrisEngine implements Engine {
|
||||
);
|
||||
getPostModifier().modify(x, z, vblocks, multicore);
|
||||
burst().burst(multicore,
|
||||
() -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, true),
|
||||
() -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore),
|
||||
() -> getDepositModifier().modify(x, z, vblocks, multicore)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import com.volmit.iris.engine.object.spawners.IrisSpawner;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
@@ -221,6 +223,11 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
}
|
||||
|
||||
private void spawnIn(Chunk c, boolean initial) {
|
||||
if(initial)
|
||||
{
|
||||
energy += 1.2;
|
||||
}
|
||||
|
||||
IrisBiome biome = getEngine().getSurfaceBiome(c);
|
||||
IrisRegion region = getEngine().getRegion(c);
|
||||
//@builder
|
||||
@@ -362,16 +369,17 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
|
||||
@Override
|
||||
public void onChunkLoad(Chunk e, boolean generated) {
|
||||
if (generated) {
|
||||
energy += 1.2;
|
||||
J.a(() -> spawnIn(e, true), RNG.r.i(5, 50));
|
||||
} else {
|
||||
energy += 0.3;
|
||||
}
|
||||
|
||||
J.a(() -> getMantle().raiseFlag(e.getX(), e.getZ(), MantleFlag.INITIAL_SPAWNED,
|
||||
() -> J.a(() -> spawnIn(e, true), RNG.r.i(5, 200))));
|
||||
energy += 0.3;
|
||||
fixEnergy();
|
||||
}
|
||||
|
||||
public Mantle getMantle()
|
||||
{
|
||||
return getEngine().getMantle().getMantle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chargeEnergy() {
|
||||
charge = M.ms() + 3000;
|
||||
|
||||
@@ -55,8 +55,7 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
Iris.reportError(e);
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.volmit.iris.engine.data.chunk;
|
||||
import com.volmit.iris.core.nms.BiomeBaseInjector;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.data.IrisBiomeStorage;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@@ -35,6 +36,8 @@ public class LinkedTerrainChunk implements TerrainChunk {
|
||||
private final IrisBiomeStorage biome3D;
|
||||
private ChunkData rawChunkData;
|
||||
private final BiomeGrid storage;
|
||||
@Setter
|
||||
private boolean unsafe = false;
|
||||
|
||||
public LinkedTerrainChunk(World world) {
|
||||
this(null, Bukkit.createChunkData(world));
|
||||
@@ -52,6 +55,12 @@ public class LinkedTerrainChunk implements TerrainChunk {
|
||||
|
||||
@Override
|
||||
public BiomeBaseInjector getBiomeBaseInjector() {
|
||||
|
||||
if(unsafe)
|
||||
{
|
||||
return (a,b,c,d) -> {};
|
||||
}
|
||||
|
||||
return (x, y, z, bb) -> INMS.get().forceBiomeInto(x, y, z, bb, storage);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,12 @@ public interface TerrainChunk extends BiomeGrid, ChunkData {
|
||||
return new LinkedTerrainChunk(world, grid);
|
||||
}
|
||||
|
||||
static TerrainChunk createUnsafe(World world, BiomeGrid grid) {
|
||||
LinkedTerrainChunk ltc = new LinkedTerrainChunk(world, grid);
|
||||
ltc.setUnsafe(true);
|
||||
return ltc;
|
||||
}
|
||||
|
||||
static TerrainChunk create(ChunkData raw, BiomeGrid grid) {
|
||||
return new LinkedTerrainChunk(grid, raw);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.mantle.MantleChunk;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import org.bukkit.Chunk;
|
||||
@@ -189,7 +191,12 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
int xx = i + x;
|
||||
int zz = j + z;
|
||||
burst.queue(() -> {
|
||||
getComponents().forEach((f) -> generateMantleComponent(writer, xx, zz, f, c));
|
||||
MantleChunk mc = getMantle().getChunk(xx, zz);
|
||||
|
||||
for(MantleComponent k : getComponents())
|
||||
{
|
||||
generateMantleComponent(writer, xx, zz, k, c, mc);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -203,8 +210,8 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
}
|
||||
}
|
||||
|
||||
default void generateMantleComponent(MantleWriter writer, int x, int z, MantleComponent c, Consumer<Runnable> post) {
|
||||
getMantle().raiseFlag(x, z, c.getFlag(), () -> c.generateLayer(writer, x, z, post));
|
||||
default void generateMantleComponent(MantleWriter writer, int x, int z, MantleComponent c, Consumer<Runnable> post, MantleChunk mc) {
|
||||
mc.raiseFlag(c.getFlag(), () -> c.generateLayer(writer, x, z, post));
|
||||
}
|
||||
|
||||
@ChunkCoordinates
|
||||
@@ -274,4 +281,14 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
default boolean queueRegenerate(int x, int z)
|
||||
{
|
||||
return false; // TODO:
|
||||
}
|
||||
|
||||
default boolean dequeueRegenerate(int x, int z)
|
||||
{
|
||||
return false;// TODO:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class MantleJigsawComponent extends IrisMantleComponent {
|
||||
|
||||
public MantleJigsawComponent(EngineMantle engineMantle) {
|
||||
super(engineMantle, MantleFlag.JIGSAW);
|
||||
cng = NoiseStyle.STATIC.create(new RNG());
|
||||
cng = NoiseStyle.STATIC.create(new RNG(engineMantle.getEngine().getWorld().seed() + 24398848585L));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,26 +29,35 @@ import com.volmit.iris.engine.framework.WrongEngineBroException;
|
||||
import com.volmit.iris.engine.object.common.IrisWorld;
|
||||
import com.volmit.iris.engine.object.dimensional.IrisDimension;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.data.IrisBiomeStorage;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.io.ReactiveFolder;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.generator.WorldInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@@ -130,6 +139,96 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectChunkReplacement(World world, int x, int z, Consumer<Runnable> jobs) {
|
||||
try {
|
||||
if (lastSeed != world.getSeed()) {
|
||||
Iris.warn("Seed for engine " + lastSeed + " does not match world seed if " + world.getSeed());
|
||||
lastSeed = world.getSeed();
|
||||
engine.getTarget().getWorld().seed(lastSeed);
|
||||
engine.hotload();
|
||||
Iris.success("Updated Engine seed to " + lastSeed);
|
||||
}
|
||||
|
||||
loadLock.acquire();
|
||||
IrisBiomeStorage st = new IrisBiomeStorage();
|
||||
TerrainChunk tc = TerrainChunk.createUnsafe(world, st);
|
||||
Hunk<BlockData> blocks = Hunk.view((ChunkData) tc);
|
||||
Hunk<Biome> biomes = Hunk.view((BiomeGrid) tc);
|
||||
this.world.bind(world);
|
||||
getEngine().generate(x * 16, z * 16, blocks, biomes, true);
|
||||
Iris.debug("Regenerated " + x + " " + z);
|
||||
int t = 0;
|
||||
for(int i = getEngine().getHeight() >> 4; i >= 0; i--)
|
||||
{
|
||||
if(!world.isChunkLoaded(x, z))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Chunk c = world.getChunkAt(x, z);
|
||||
for(Entity ee : c.getEntities())
|
||||
{
|
||||
if(ee instanceof Player)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
J.s(ee::remove);
|
||||
}
|
||||
|
||||
J.s(() -> engine.getWorldManager().onChunkLoad(c, false));
|
||||
|
||||
int finalI = i;
|
||||
jobs.accept(() -> {
|
||||
|
||||
for(int xx = 0; xx < 16; xx++)
|
||||
{
|
||||
for(int yy = 0; yy < 16; yy++)
|
||||
{
|
||||
for(int zz = 0; zz < 16; zz++)
|
||||
{
|
||||
if(yy + (finalI << 4) >= engine.getHeight() || yy + (finalI << 4) < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
c.getBlock(xx,yy + (finalI << 4),zz).setBlockData(tc.getBlockData(xx,yy + (finalI << 4),zz), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
loadLock.release();
|
||||
} catch (WrongEngineBroException e) {
|
||||
Iris.warn("Trying to generate with a shut-down engine! Did you reload? Attempting to resolve this...");
|
||||
|
||||
try {
|
||||
setupEngine();
|
||||
Iris.success("Resolved! Should generate now!");
|
||||
} catch (Throwable fe) {
|
||||
Iris.error("FATAL! Iris cannot generate in this world since it was reloaded! This will cause a crash, with missing chunks, so we're crashing right now!");
|
||||
Bukkit.shutdown();
|
||||
throw new RuntimeException();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
loadLock.release();
|
||||
Iris.error("======================================");
|
||||
e.printStackTrace();
|
||||
Iris.reportErrorChunk(x, z, e, "CHUNK");
|
||||
Iris.error("======================================");
|
||||
|
||||
ChunkData d = Bukkit.createChunkData(world);
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (int j = 0; j < 16; j++) {
|
||||
d.setBlock(i, 0, j, Material.RED_GLAZED_TERRACOTTA.createBlockData());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
withExclusiveControl(() -> {
|
||||
@@ -162,8 +261,6 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
|
||||
|
||||
|
||||
try {
|
||||
if (lastSeed != world.getSeed()) {
|
||||
Iris.warn("Seed for engine " + lastSeed + " does not match world seed if " + world.getSeed());
|
||||
@@ -245,4 +342,25 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
|
||||
public boolean shouldGenerateStructures() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateNoise() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateSurface() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldGenerateBedrock() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public BiomeProvider getDefaultBiomeProvider(@NotNull WorldInfo worldInfo) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,13 @@ import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Data
|
||||
public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
@@ -100,6 +102,11 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectChunkReplacement(World world, int x, int z, Consumer<Runnable> jobs) {
|
||||
|
||||
}
|
||||
|
||||
@RegionCoordinates
|
||||
public void generateRegion(int x, int z) {
|
||||
generateRegion(x, z, null);
|
||||
|
||||
@@ -23,6 +23,9 @@ import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineTarget;
|
||||
import com.volmit.iris.engine.framework.Hotloadable;
|
||||
import com.volmit.iris.util.data.DataProvider;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface PlatformChunkGenerator extends Hotloadable, DataProvider {
|
||||
Engine getEngine();
|
||||
@@ -38,6 +41,8 @@ public interface PlatformChunkGenerator extends Hotloadable, DataProvider {
|
||||
return getEngine().getTarget();
|
||||
}
|
||||
|
||||
void injectChunkReplacement(World world, int x, int z, Consumer<Runnable> jobs);
|
||||
|
||||
void close();
|
||||
|
||||
boolean isStudio();
|
||||
|
||||
Reference in New Issue
Block a user