9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-26 02:29:14 +00:00

Merge remote-tracking branch 'origin/Development' into Development

This commit is contained in:
Vatuu
2022-09-21 01:49:58 +02:00
43 changed files with 10971 additions and 293 deletions

View File

@@ -23,7 +23,9 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.ServerConfigurator;
import com.volmit.iris.core.link.*;
import com.volmit.iris.core.link.IrisPapiExpansion;
import com.volmit.iris.core.link.MultiverseCoreLink;
import com.volmit.iris.core.link.MythicMobsLink;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.core.pregenerator.LazyPregenerator;
@@ -41,7 +43,10 @@ import com.volmit.iris.util.exceptions.IrisException;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.function.NastyRunnable;
import com.volmit.iris.util.io.*;
import com.volmit.iris.util.io.FileWatcher;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.io.InstanceState;
import com.volmit.iris.util.io.JarScanner;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.parallel.MultiBurst;
@@ -56,11 +61,7 @@ import com.volmit.iris.util.scheduling.ShurikenQueue;
import io.papermc.lib.PaperLib;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.serializer.ComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -82,12 +83,11 @@ import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
@SuppressWarnings("CanBeFinal")
public class Iris extends VolmitPlugin implements Listener {
public static final String OVERWORLD_TAG = "2086";
public static final String OVERWORLD_TAG = "2087";
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();

View File

@@ -39,6 +39,8 @@ import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import lombok.Data;
@@ -467,4 +469,38 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
public boolean isClosed() {
return closed;
}
public void savePrefetch(Engine engine) {
BurstExecutor b = MultiBurst.burst.burst(loaders.size());
for(ResourceLoader<?> i : loaders.values()) {
b.queue(() -> {
try {
i.saveFirstAccess(engine);
} catch(IOException e) {
throw new RuntimeException(e);
}
});
}
b.complete();
Iris.info("Saved Prefetch Cache to speed up future world startups");
}
public void loadPrefetch(Engine engine) {
BurstExecutor b = MultiBurst.burst.burst(loaders.size());
for(ResourceLoader<?> i : loaders.values()) {
b.queue(() -> {
try {
i.loadFirstAccess(engine);
} catch(IOException e) {
throw new RuntimeException(e);
}
});
}
b.complete();
Iris.info("Loaded Prefetch Cache to reduce generation disk use.");
}
}

View File

@@ -23,32 +23,51 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.project.SchemaBuilder;
import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.io.CustomOutputStream;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.json.JSONArray;
import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Data;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@Data
public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
public static final AtomicDouble tlt = new AtomicDouble(0);
private static final int CACHE_SIZE = 100000;
protected KSet<String> firstAccess;
protected File root;
protected String folderName;
protected String resourceTypeName;
@@ -63,6 +82,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
public ResourceLoader(File root, IrisData manager, String folderName, String resourceTypeName, Class<? extends T> objectClass) {
this.manager = manager;
firstAccess = new KSet<>();
folderCache = new AtomicReference<>();
sec = new ChronoLatch(5000);
loads = new AtomicInteger();
@@ -221,6 +241,24 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
return m;
}
public KList<T> loadAllParallel(KList<String> s) {
KList<T> m = new KList<>();
BurstExecutor burst = MultiBurst.burst.burst(s.size());
for(String i : s) {
burst.queue(() -> {
T t = load(i);
if(t != null) {
m.add(t);
}
});
}
burst.complete();
return m;
}
public KList<T> loadAll(KList<String> s, Consumer<T> postLoad) {
KList<T> m = new KList<>();
@@ -282,12 +320,52 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
return null;
}
firstAccess.add(name);
return loadCache.get(name);
}
public void loadFirstAccess(Engine engine) throws IOException
{
String id = "DIM" + Math.abs(engine.getSeedManager().getSeed() + engine.getDimension().getVersion() + engine.getDimension().getLoadKey().hashCode());
File file = Iris.instance.getDataFile("prefetch/" + id + "/" + Math.abs(getFolderName().hashCode()) + ".ipfch");
if(!file.exists()) {
return;
}
FileInputStream fin = new FileInputStream(file);
GZIPInputStream gzi = new GZIPInputStream(fin);
DataInputStream din = new DataInputStream(gzi);
int m = din.readInt();
KList<String> s = new KList<>();
for(int i = 0; i < m; i++) {
s.add(din.readUTF());
}
din.close();
file.deleteOnExit();
Iris.info("Loading " + s.size() + " prefetch " + getFolderName());
loadAllParallel(s);
}
public void saveFirstAccess(Engine engine) throws IOException {
String id = "DIM" + Math.abs(engine.getSeedManager().getSeed() + engine.getDimension().getVersion() + engine.getDimension().getLoadKey().hashCode());
File file = Iris.instance.getDataFile("prefetch/" + id + "/" + Math.abs(getFolderName().hashCode()) + ".ipfch");
file.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(file);
GZIPOutputStream gzo = new CustomOutputStream(fos, 9);
DataOutputStream dos = new DataOutputStream(gzo);
dos.writeInt(firstAccess.size());
for(String i : firstAccess) {
dos.writeUTF(i);
}
dos.flush();
dos.close();
}
public KList<File> getFolders() {
synchronized(folderCache) {
if(folderCache.get() == null) {
KList<File> fc = new KList<>();

View File

@@ -18,9 +18,11 @@
package com.volmit.iris.core.nms;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.WorldCreator;
@@ -56,6 +58,8 @@ public interface INMSBinding {
Object getCustomBiomeBaseFor(String mckey);
Object getCustomBiomeBaseHolderFor(String mckey);
int getBiomeBaseIdForKey(String key);
String getKeyForBiomeBase(Object biomeBase);
Object getBiomeBase(World world, Biome biome);
@@ -83,4 +87,6 @@ public interface INMSBinding {
}
MCAPaletteAccess createPalette();
void injectBiomesFromMantle(Chunk e, Mantle mantle);
}

View File

@@ -0,0 +1,155 @@
package com.volmit.iris.core.nms.v19_2;
import com.mojang.serialization.Codec;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisBiomeCustom;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.math.RNG;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Climate;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock;
import org.bukkit.craftbukkit.v1_19_R1.generator.CustomChunkGenerator;
import org.bukkit.craftbukkit.v1_19_R1.generator.InternalChunkGenerator;
import org.bukkit.generator.BiomeProvider;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class CustomBiomeSource extends BiomeSource {
private final long seed;
private final Engine engine;
private final Registry<Biome> biomeCustomRegistry;
private final Registry<Biome> biomeRegistry;
private final AtomicCache<RegistryAccess> registryAccess = new AtomicCache<>();
private final RNG rng;
private final KMap<String, Holder<Biome>> customBiomes;
public CustomBiomeSource(long seed, Engine engine, World world) {
super(getAllBiomes(
((RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()))
.registry(Registry.BIOME_REGISTRY).orElse(null),
((CraftWorld) world).getHandle().registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null),
engine));
this.engine = engine;
this.seed = seed;
this.biomeCustomRegistry = registry().registry(Registry.BIOME_REGISTRY).orElse(null);
this.biomeRegistry = ((CraftWorld) world).getHandle().registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null);
this.rng = new RNG(engine.getSeedManager().getBiome());
this.customBiomes = fillCustomBiomes(biomeCustomRegistry, engine);
}
private KMap<String, Holder<Biome>> fillCustomBiomes(Registry<Biome> customRegistry, Engine engine) {
KMap<String, Holder<Biome>> m = new KMap<>();
for(IrisBiome i : engine.getAllBiomes()) {
if(i.isCustom()) {
for(IrisBiomeCustom j : i.getCustomDerivitives()) {
m.put(j.getId(), customRegistry.getHolder(customRegistry.getResourceKey(customRegistry
.get(new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId()))).get()).get());
}
}
}
return m;
}
private static List<Holder<Biome>> getAllBiomes(Registry<Biome> customRegistry, Registry<Biome> registry, Engine engine) {
List<Holder<Biome>> b = new ArrayList<>();
for(IrisBiome i : engine.getAllBiomes()) {
if(i.isCustom()) {
for(IrisBiomeCustom j : i.getCustomDerivitives()) {
b.add(customRegistry.getHolder(customRegistry.getResourceKey(customRegistry
.get(new ResourceLocation(engine.getDimension().getLoadKey() + ":" + j.getId()))).get()).get());
}
} else {
b.add(CraftBlock.biomeToBiomeBase(registry, i.getVanillaDerivative()));
}
}
return b;
}
private RegistryAccess registry() {
return registryAccess.aquire(() -> (RegistryAccess) getFor(RegistryAccess.Frozen.class, ((CraftServer) Bukkit.getServer()).getHandle().getServer()));
}
private static Object getFor(Class<?> type, Object source) {
Object o = fieldFor(type, source);
if(o != null) {
return o;
}
return invokeFor(type, source);
}
private static Object fieldFor(Class<?> returns, Object in) {
return fieldForClass(returns, in.getClass(), in);
}
private static Object invokeFor(Class<?> returns, Object in) {
for(Method i : in.getClass().getMethods()) {
if(i.getReturnType().equals(returns)) {
i.setAccessible(true);
try {
Iris.debug("[NMS] Found " + returns.getSimpleName() + " in " + in.getClass().getSimpleName() + "." + i.getName() + "()");
return i.invoke(in);
} catch(Throwable e) {
e.printStackTrace();
}
}
}
return null;
}
@SuppressWarnings("unchecked")
private static <T> T fieldForClass(Class<T> returnType, Class<?> sourceType, Object in) {
for(Field i : sourceType.getDeclaredFields()) {
if(i.getType().equals(returnType)) {
i.setAccessible(true);
try {
Iris.debug("[NMS] Found " + returnType.getSimpleName() + " in " + sourceType.getSimpleName() + "." + i.getName());
return (T) i.get(in);
} catch(IllegalAccessException e) {
e.printStackTrace();
}
}
}
return null;
}
@Override
protected Codec<? extends BiomeSource> codec() {
throw new UnsupportedOperationException("Not supported");
}
@Override
public Holder<Biome> getNoiseBiome(int x, int y, int z, Climate.Sampler sampler) {
int m = (y - engine.getMinHeight()) << 2;
IrisBiome ib = engine.getComplex().getTrueBiomeStream().get(x << 2, z << 2);
if(ib.isCustom()) {
return customBiomes.get(ib.getCustomBiome(rng, x << 2, m, z << 2).getId());
} else {
org.bukkit.block.Biome v = ib.getSkyBiome(rng, x << 2, m, z << 2);
return CraftBlock.biomeToBiomeBase(biomeRegistry, v);
}
}
}

View File

@@ -23,6 +23,9 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.INMSBinding;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.nbt.io.NBTUtil;
import com.volmit.iris.util.nbt.mca.NBTWorld;
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
@@ -37,20 +40,20 @@ import com.volmit.iris.util.nbt.mca.palette.MCAWrappedPalettedContainer;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import net.minecraft.core.*;
import net.minecraft.core.Registry;
import net.minecraft.nbt.NbtIo;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.ChunkAccess;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.*;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_19_R1.CraftChunk;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.block.data.CraftBlockData;
@@ -161,23 +164,7 @@ public class NMSBinding19_2 implements INMSBinding {
@Override
public Object getBiomeBaseFromId(int id) {
try {
return byIdRef.aquire(() -> {
for(Method i : IdMap.class.getDeclaredMethods()) {
if(i.getParameterCount() == 1 && i.getParameterTypes()[0].equals(int.class)) {
Iris.info("[NMS] Found byId method in " + IdMap.class.getSimpleName() + "." + i.getName() + "(int) => " + Biome.class.getSimpleName());
return i;
}
}
Iris.error("Cannot find byId method!");
return null;
}).invoke(getCustomBiomeRegistry(), id);
} catch(IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return null;
return getCustomBiomeRegistry().getHolder(id);
}
@Override
@@ -192,7 +179,7 @@ public class NMSBinding19_2 implements INMSBinding {
@Override
public int getTrueBiomeBaseId(Object biomeBase) {
return getCustomBiomeRegistry().getId((net.minecraft.world.level.biome.Biome) biomeBase);
return getCustomBiomeRegistry().getId(((Holder<net.minecraft.world.level.biome.Biome>) biomeBase).value());
}
@Override
@@ -214,6 +201,10 @@ public class NMSBinding19_2 implements INMSBinding {
return getCustomBiomeRegistry().getHolder(getTrueBiomeBaseId(getCustomBiomeRegistry().get(new ResourceLocation(mckey)))).get();
}
public int getBiomeBaseIdForKey(String key) {
return getCustomBiomeRegistry().getId(getCustomBiomeRegistry().get(new ResourceLocation(key)));
}
@Override
public String getKeyForBiomeBase(Object biomeBase) {
return getCustomBiomeRegistry().getKey((net.minecraft.world.level.biome.Biome) biomeBase).getPath(); // something, not something:something
@@ -221,7 +212,8 @@ public class NMSBinding19_2 implements INMSBinding {
@Override
public Object getBiomeBase(World world, Biome biome) {
return getBiomeBase(((CraftWorld) world).getHandle().registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null), biome);
return org.bukkit.craftbukkit.v1_19_R1.block.CraftBlock.biomeToBiomeBase(((CraftWorld) world).getHandle()
.registryAccess().registry(Registry.BIOME_REGISTRY).orElse(null), biome);
}
@Override
@@ -333,6 +325,12 @@ public class NMSBinding19_2 implements INMSBinding {
return true;
}
public void setBiomes(int cx, int cz, World world, Hunk<Object> biomes) {
LevelChunk c = ((CraftWorld)world).getHandle().getChunk(cx, cz);
biomes.iterateSync((x,y,z,b) -> c.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>)b));
c.setUnsaved(true);
}
@Override
public void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk) {
try {
@@ -391,6 +389,26 @@ public class NMSBinding19_2 implements INMSBinding {
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState());
}
@Override
public void injectBiomesFromMantle(Chunk e, Mantle mantle) {
LevelChunk chunk = ((CraftChunk)e).getHandle();
AtomicInteger c = new AtomicInteger();
AtomicInteger r = new AtomicInteger();
mantle.iterateChunk(e.getX(), e.getZ(), MatterBiomeInject.class, (x,y,z,b) -> {
if(b != null) {
if(b.isCustom()) {
chunk.setBiome(x, y, z, getCustomBiomeRegistry().getHolder(b.getBiomeId()).get());
c.getAndIncrement();
}
else {
chunk.setBiome(x, y, z, (Holder<net.minecraft.world.level.biome.Biome>) getBiomeBase(e.getWorld(), b.getBiome()));
r.getAndIncrement();
}
}
});
}
private static Object getFor(Class<?> type, Object source) {
Object o = fieldFor(type, source);

View File

@@ -20,9 +20,11 @@ package com.volmit.iris.core.nms.v1X;
import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.INMSBinding;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
import com.volmit.iris.util.nbt.tag.CompoundTag;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Biome;
@@ -57,6 +59,11 @@ public class NMSBinding1X implements INMSBinding {
return null;
}
@Override
public void injectBiomesFromMantle(Chunk e, Mantle mantle) {
}
@Override
public void deserializeTile(CompoundTag s, Location newPosition) {
@@ -117,6 +124,11 @@ public class NMSBinding1X implements INMSBinding {
return null;
}
@Override
public int getBiomeBaseIdForKey(String key) {
return 0;
}
@Override
public String getKeyForBiomeBase(Object biomeBase) {
return null;

View File

@@ -61,7 +61,7 @@ public class IrisPregenerator {
public IrisPregenerator(PregenTask task, PregeneratorMethod generator, PregenListener listener) {
this.listener = listenify(listener);
cl = new ChronoLatch(5000);
limiter = new Semaphore(Runtime.getRuntime().availableProcessors());
limiter = new Semaphore(1024);
generatedRegions = new KSet<>();
this.shutdown = new AtomicBoolean(false);
this.paused = new AtomicBoolean(false);

View File

@@ -57,7 +57,7 @@ public class StudioSVC implements IrisService {
@Override
public void onEnable() {
J.a(() -> {
J.s(() -> {
String pack = IrisSettings.get().getGenerator().getDefaultWorldType();
File f = IrisPack.packsPack(pack);

View File

@@ -33,6 +33,7 @@ import com.volmit.iris.engine.object.IrisRegion;
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.IrisContext;
import com.volmit.iris.util.data.DataProvider;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG;
@@ -132,28 +133,32 @@ public class IrisComplex implements DataProvider {
.cache2D("regionStream", engine, cacheSize).waste("Region Stream");
regionIDStream = regionIdentityStream.convertCached((i) -> new UUID(Double.doubleToLongBits(i),
String.valueOf(i * 38445).hashCode() * 3245556666L)).waste("Region ID Stream");
caveBiomeStream = regionStream.convert((r)
caveBiomeStream = regionStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getRegion().get(x, z))
.convert((r)
-> engine.getDimension().getCaveBiomeStyle().create(rng.nextParallelRNG(InferredType.CAVE.ordinal()), getData()).stream()
.zoom(r.getCaveBiomeZoom())
.selectRarity(data.getBiomeLoader().loadAll(r.getCaveBiomes()))
.onNull(emptyBiome)
).convertAware2D(ProceduralStream::get).cache2D("caveBiomeStream", engine, cacheSize).waste("Cave Biome Stream");
inferredStreams.put(InferredType.CAVE, caveBiomeStream);
landBiomeStream = regionStream.convert((r)
landBiomeStream = regionStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getRegion().get(x, z))
.convert((r)
-> engine.getDimension().getLandBiomeStyle().create(rng.nextParallelRNG(InferredType.LAND.ordinal()), getData()).stream()
.zoom(r.getLandBiomeZoom())
.selectRarity(data.getBiomeLoader().loadAll(r.getLandBiomes(), (t) -> t.setInferredType(InferredType.LAND)))
).convertAware2D(ProceduralStream::get)
.cache2D("landBiomeStream", engine, cacheSize).waste("Land Biome Stream");
inferredStreams.put(InferredType.LAND, landBiomeStream);
seaBiomeStream = regionStream.convert((r)
seaBiomeStream = regionStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getRegion().get(x, z))
.convert((r)
-> engine.getDimension().getSeaBiomeStyle().create(rng.nextParallelRNG(InferredType.SEA.ordinal()), getData()).stream()
.zoom(r.getSeaBiomeZoom())
.selectRarity(data.getBiomeLoader().loadAll(r.getSeaBiomes(), (t) -> t.setInferredType(InferredType.SEA)))
).convertAware2D(ProceduralStream::get)
.cache2D("seaBiomeStream", engine, cacheSize).waste("Sea Biome Stream");
inferredStreams.put(InferredType.SEA, seaBiomeStream);
shoreBiomeStream = regionStream.convert((r)
shoreBiomeStream = regionStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getRegion().get(x, z))
.convert((r)
-> engine.getDimension().getShoreBiomeStyle().create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), getData()).stream()
.zoom(r.getShoreBiomeZoom())
.selectRarity(data.getBiomeLoader().loadAll(r.getShoreBiomes(), (t) -> t.setInferredType(InferredType.SHORE)))
@@ -173,34 +178,39 @@ public class IrisComplex implements DataProvider {
heightStream = ProceduralStream.of((x, z) -> {
IrisBiome b = focusBiome != null ? focusBiome : baseBiomeStream.get(x, z);
return getHeight(engine, b, x, z, engine.getSeedManager().getHeight());
}, Interpolated.DOUBLE).clamp(0, engine.getHeight()).cache2D("heightStream", engine, cacheSize).waste("Height Stream");
roundedHeighteightStream = heightStream.round().waste("Rounded Height Stream");
slopeStream = heightStream.slope(3).cache2D("slopeStream", engine, cacheSize).waste("Slope Stream");
}, Interpolated.DOUBLE).cache2D("heightStream", engine, cacheSize).waste("Height Stream");
roundedHeighteightStream = heightStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getHeight().get(x, z))
.round().waste("Rounded Height Stream");
slopeStream = heightStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getHeight().get(x, z))
.slope(3).cache2D("slopeStream", engine, cacheSize).waste("Slope Stream");
trueBiomeStream = focusBiome != null ? ProceduralStream.of((x, y) -> focusBiome, Interpolated.of(a -> 0D,
b -> focusBiome))
.cache2D("trueBiomeStream-focus", engine, cacheSize) : heightStream
.convertAware2D((h, x, z) ->
fixBiomeType(h, baseBiomeStream.get(x, z),
regionStream.get(x, z), x, z, fluidHeight))
regionStream.contextInjecting((c,xx,zz)-> IrisContext.getOr(engine).getChunkContext().getRegion().get(xx, zz)).get(x, z), x, z, fluidHeight))
.cache2D("trueBiomeStream", engine, cacheSize).waste("True Biome Stream");
trueBiomeDerivativeStream = trueBiomeStream.convert(IrisBiome::getDerivative).cache2D("trueBiomeDerivativeStream", engine, cacheSize).waste("True Biome Derivative Stream");
heightFluidStream = heightStream.max(fluidHeight).cache2D("heightFluidStream", engine, cacheSize).waste("Height Fluid Stream");
trueBiomeDerivativeStream = trueBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getBiome().get(x, z))
.convert(IrisBiome::getDerivative).cache2D("trueBiomeDerivativeStream", engine, cacheSize).waste("True Biome Derivative Stream");
heightFluidStream = heightStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getHeight().get(x, z))
.max(fluidHeight).cache2D("heightFluidStream", engine, cacheSize).waste("Height Fluid Stream");
maxHeightStream = ProceduralStream.ofDouble((x, z) -> height).waste("Max Height Stream");
terrainSurfaceDecoration = trueBiomeStream
terrainSurfaceDecoration = trueBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getBiome().get(x, z))
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.NONE)).cache2D("terrainSurfaceDecoration", engine, cacheSize).waste("Surface Decoration Stream");
terrainCeilingDecoration = trueBiomeStream
terrainCeilingDecoration = trueBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getBiome().get(x, z))
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.CEILING)).cache2D("terrainCeilingDecoration", engine, cacheSize).waste("Ceiling Decoration Stream");
terrainCaveSurfaceDecoration = caveBiomeStream
terrainCaveSurfaceDecoration = caveBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getCave().get(x, z))
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.NONE)).cache2D("terrainCaveSurfaceDecoration", engine, cacheSize).waste("Cave Surface Stream");
terrainCaveCeilingDecoration = caveBiomeStream
terrainCaveCeilingDecoration = caveBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getCave().get(x, z))
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.CEILING)).cache2D("terrainCaveCeilingDecoration", engine, cacheSize).waste("Cave Ceiling Stream");
shoreSurfaceDecoration = trueBiomeStream
shoreSurfaceDecoration = trueBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getBiome().get(x, z))
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SHORE_LINE)).cache2D("shoreSurfaceDecoration", engine, cacheSize).waste("Shore Surface Stream");
seaSurfaceDecoration = trueBiomeStream
seaSurfaceDecoration = trueBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getBiome().get(x, z))
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SEA_SURFACE)).cache2D("seaSurfaceDecoration", engine, cacheSize).waste("Sea Surface Stream");
seaFloorDecoration = trueBiomeStream
seaFloorDecoration = trueBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getBiome().get(x, z))
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SEA_FLOOR)).cache2D("seaFloorDecoration", engine, cacheSize).waste("Sea Floor Stream");
baseBiomeIDStream = trueBiomeStream.convertAware2D((b, x, z) -> {
baseBiomeIDStream = trueBiomeStream.contextInjecting((c,x,z)-> IrisContext.getOr(engine).getChunkContext().getBiome().get(x, z))
.convertAware2D((b, x, z) -> {
UUID d = regionIDStream.get(x, z);
return new UUID(b.getLoadKey().hashCode() * 818223L,
d.hashCode());
@@ -318,7 +328,7 @@ public class IrisComplex implements DataProvider {
}
return 0;
});
});;
double d = 0;

View File

@@ -129,8 +129,9 @@ public class IrisEngine implements Engine {
context = new IrisContext(this);
cleaning = new AtomicBoolean(false);
context.touch();
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + target.getDimension().getDimensionHeight() + " height) Seed: " + getSeedManager().getSeed());
getData().setEngine(this);
getData().loadPrefetch(this);
Iris.info("Initializing Engine: " + target.getWorld().name() + "/" + target.getDimension().getLoadKey() + " (" + target.getDimension().getDimensionHeight() + " height) Seed: " + getSeedManager().getSeed());
minHeight = 0;
failing = false;
closed = false;
@@ -146,6 +147,7 @@ public class IrisEngine implements Engine {
}
private void tickRandomPlayer() {
recycle();
if(perSecondBudLatch.flip()) {
buds.set(bud.get());
bud.set(0);
@@ -454,7 +456,10 @@ public class IrisEngine implements Engine {
getMantle().getMantle().flag(x >> 4, z >> 4, MantleFlag.REAL, true);
getMetrics().getTotal().put(p.getMilliseconds());
generated.incrementAndGet();
recycle();
if(generated.get() == 661) {
J.a(() -> getData().savePrefetch(this));
}
} catch(Throwable e) {
Iris.reportError(e);
fail("Failed to generate " + x + ", " + z, e);

View File

@@ -21,6 +21,7 @@ package com.volmit.iris.engine;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineAssignedWorldManager;
import com.volmit.iris.engine.object.*;
@@ -31,14 +32,14 @@ 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.Position2;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.matter.MatterMarker;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.Chunks;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.Looper;
import com.volmit.iris.util.scheduling.*;
import com.volmit.iris.util.scheduling.jobs.QueueJob;
import io.papermc.lib.PaperLib;
import lombok.Data;
@@ -81,6 +82,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
private int actuallySpawned = 0;
private int cooldown = 0;
private List<Entity> precount = new KList<>();
private KSet<Position2> injectBiomes = new KSet<>();
public IrisWorldManager() {
super(null);
@@ -463,6 +465,10 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
getEngine().getMantle().save();
}
public void requestBiomeInject(Position2 p) {
injectBiomes.add(p);
}
@Override
public void onChunkLoad(Chunk e, boolean generated) {
if(getEngine().isClosed()) {
@@ -472,6 +478,10 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
energy += 0.3;
fixEnergy();
getEngine().cleanupMantleChunk(e.getX(), e.getZ());
if(generated) {
//INMS.get().injectBiomesFromMantle(e, getMantle());
}
}
private void spawn(IrisPosition block, IrisSpawner spawner, boolean initial) {

View File

@@ -18,9 +18,7 @@
package com.volmit.iris.engine.actuator;
import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.engine.data.chunk.TerrainChunk;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineAssignedActuator;
import com.volmit.iris.engine.object.IrisBiome;
@@ -28,15 +26,12 @@ import com.volmit.iris.engine.object.IrisBiomeCustom;
import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.view.BiomeGridHunkHolder;
import com.volmit.iris.util.hunk.view.BiomeGridHunkView;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.matter.slices.BiomeInjectMatter;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import io.papermc.lib.PaperLib;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator;
public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
private final RNG rng;
@@ -48,80 +43,34 @@ public class IrisBiomeActuator extends EngineAssignedActuator<Biome> {
}
@BlockCoordinates
private boolean injectBiome(Hunk<Biome> h, int x, int y, int z, Object bb) {
@Override
public void onActuate(int x, int z, Hunk<Biome> h, boolean multicore, ChunkContext context) {
try {
if(h instanceof BiomeGridHunkView hh) {
ChunkGenerator.BiomeGrid g = hh.getChunk();
if(g instanceof TerrainChunk) {
((TerrainChunk) g).getBiomeBaseInjector().setBiome(x, y, z, bb);
} else {
hh.forceBiomeBaseInto(x, y, z, bb);
PrecisionStopwatch p = PrecisionStopwatch.start();
int m = 0;
for(int xf = 0; xf < h.getWidth(); xf++) {
IrisBiome ib;
for(int zf = 0; zf < h.getDepth(); zf++) {
ib = context.getBiome().get(xf, zf);
MatterBiomeInject matter = null;
if(ib.isCustom()) {
IrisBiomeCustom custom = ib.getCustomBiome(rng, x, 0, z);
matter = BiomeInjectMatter.get(INMS.get().getBiomeBaseIdForKey(getDimension().getLoadKey() + ":" + custom.getId()));
} else {
Biome v = ib.getSkyBiome(rng, x, 0, z);
matter = BiomeInjectMatter.get(v);
}
getEngine().getMantle().getMantle().set(x + xf, 0, z + zf, matter);
m++;
}
return true;
} else if(h instanceof BiomeGridHunkHolder hh) {
ChunkGenerator.BiomeGrid g = hh.getChunk();
if(g instanceof TerrainChunk) {
((TerrainChunk) g).getBiomeBaseInjector().setBiome(x, y, z, bb);
} else {
hh.forceBiomeBaseInto(x, y, z, bb);
}
return true;
}
getEngine().getMetrics().getBiome().put(p.getMilliseconds());
} catch(Throwable e) {
e.printStackTrace();
}
return false;
}
@BlockCoordinates
@Override
public void onActuate(int x, int z, Hunk<Biome> h, boolean multicore, ChunkContext context) {
PrecisionStopwatch p = PrecisionStopwatch.start();
BurstExecutor burst = burst().burst(PaperLib.isPaper() && multicore);
for(int xf = 0; xf < h.getWidth(); xf++) {
int finalXf = xf;
burst.queue(() -> {
IrisBiome ib;
for(int zf = 0; zf < h.getDepth(); zf++) {
ib = context.getBiome().get(finalXf, zf);
int maxHeight = (int) (getComplex().getFluidHeight() + ib.getMaxWithObjectHeight(getData()));
if(ib.isCustom()) {
try {
IrisBiomeCustom custom = ib.getCustomBiome(rng, x, 0, z);
Object biomeBase = INMS.get().getCustomBiomeBaseHolderFor(getDimension().getLoadKey() + ":" + custom.getId());
if(biomeBase == null || !injectBiome(h, x, 0, z, biomeBase)) {
throw new RuntimeException("Cant inject biome!");
}
for(int i = 0; i < maxHeight; i++) {
injectBiome(h, finalXf, i, zf, biomeBase);
}
} catch(Throwable e) {
Iris.reportError(e);
Biome v = ib.getSkyBiome(rng, x, 0, z);
for(int i = 0; i < maxHeight; i++) {
h.set(finalXf, i, zf, v);
}
}
} else {
Biome v = ib.getSkyBiome(rng, x, 0, z);
if(v != null) {
for(int i = 0; i < maxHeight; i++) {
h.set(finalXf, i, zf, v);
}
} else if(cl.flip()) {
Iris.error("No biome provided for " + ib.getLoadKey());
}
}
}
});
}
burst.complete();
getEngine().getMetrics().getBiome().put(p.getMilliseconds());
}
}

View File

@@ -73,69 +73,64 @@ public class IrisDecorantActuator extends EngineAssignedActuator<BlockData> {
}
PrecisionStopwatch p = PrecisionStopwatch.start();
BurstExecutor burst = burst().burst(multicore);
for(int i = 0; i < output.getWidth(); i++) {
int finalI = i;
burst.queue(() -> {
int height;
int realX = Math.round(x + finalI);
int realZ;
IrisBiome biome, cave;
for(int j = 0; j < output.getDepth(); j++) {
boolean solid;
int emptyFor = 0;
int lastSolid = 0;
realZ = Math.round(z + j);
height = (int) Math.round(context.getHeight().get(finalI, j));
biome = context.getBiome().get(finalI, j);
cave = shouldRay ? context.getCave().get(finalI, j) : null;
int height;
int realX = Math.round(x + i);
int realZ;
IrisBiome biome, cave;
for(int j = 0; j < output.getDepth(); j++) {
boolean solid;
int emptyFor = 0;
int lastSolid = 0;
realZ = Math.round(z + j);
height = (int) Math.round(context.getHeight().get(i, j));
biome = context.getBiome().get(i, j);
cave = shouldRay ? context.getCave().get(i, j) : null;
if(biome.getDecorators().isEmpty() && (cave == null || cave.getDecorators().isEmpty())) {
continue;
}
if(biome.getDecorators().isEmpty() && (cave == null || cave.getDecorators().isEmpty())) {
continue;
}
if(height < getDimension().getFluidHeight()) {
getSeaSurfaceDecorator().decorate(finalI, j,
realX, Math.round(finalI + 1), Math.round(x + finalI - 1),
realZ, Math.round(z + j + 1), Math.round(z + j - 1),
output, biome, getDimension().getFluidHeight(), getEngine().getHeight());
getSeaFloorDecorator().decorate(finalI, j,
realX, realZ, output, biome, height + 1,
getDimension().getFluidHeight() + 1);
}
if(height < getDimension().getFluidHeight()) {
getSeaSurfaceDecorator().decorate(i, j,
realX, Math.round(i + 1), Math.round(x + i - 1),
realZ, Math.round(z + j + 1), Math.round(z + j - 1),
output, biome, getDimension().getFluidHeight(), getEngine().getHeight());
getSeaFloorDecorator().decorate(i, j,
realX, realZ, output, biome, height + 1,
getDimension().getFluidHeight() + 1);
}
if(height == getDimension().getFluidHeight()) {
getShoreLineDecorator().decorate(finalI, j,
realX, Math.round(x + finalI + 1), Math.round(x + finalI - 1),
realZ, Math.round(z + j + 1), Math.round(z + j - 1),
output, biome, height, getEngine().getHeight());
}
if(height == getDimension().getFluidHeight()) {
getShoreLineDecorator().decorate(i, j,
realX, Math.round(x + i + 1), Math.round(x + i - 1),
realZ, Math.round(z + j + 1), Math.round(z + j - 1),
output, biome, height, getEngine().getHeight());
}
getSurfaceDecorator().decorate(finalI, j, realX, realZ, output, biome, height, getEngine().getHeight() - height);
getSurfaceDecorator().decorate(i, j, realX, realZ, output, biome, height, getEngine().getHeight() - height);
if(cave != null && cave.getDecorators().isNotEmpty()) {
for(int k = height; k > 0; k--) {
solid = PREDICATE_SOLID.test(output.get(finalI, k, j));
if(cave != null && cave.getDecorators().isNotEmpty()) {
for(int k = height; k > 0; k--) {
solid = PREDICATE_SOLID.test(output.get(i, k, j));
if(solid) {
if(emptyFor > 0) {
getSurfaceDecorator().decorate(finalI, j, realX, realZ, output, cave, k, lastSolid);
getCeilingDecorator().decorate(finalI, j, realX, realZ, output, cave, lastSolid - 1, emptyFor);
emptyFor = 0;
}
lastSolid = k;
} else {
emptyFor++;
if(solid) {
if(emptyFor > 0) {
getSurfaceDecorator().decorate(i, j, realX, realZ, output, cave, k, lastSolid);
getCeilingDecorator().decorate(i, j, realX, realZ, output, cave, lastSolid - 1, emptyFor);
emptyFor = 0;
}
lastSolid = k;
} else {
emptyFor++;
}
}
}
});
}
}
burst.complete();
getEngine().getMetrics().getDecoration().put(p.getMilliseconds());
}

View File

@@ -27,7 +27,6 @@ import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Getter;
import org.bukkit.Material;
@@ -54,14 +53,10 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator<BlockData>
public void onActuate(int x, int z, Hunk<BlockData> h, boolean multicore, ChunkContext context) {
PrecisionStopwatch p = PrecisionStopwatch.start();
BurstExecutor e = burst().burst(multicore);
for(int xf = 0; xf < h.getWidth(); xf++) {
int finalXf = xf;
e.queue(() -> terrainSliver(x, z, finalXf, h, context));
terrainSliver(x, z, xf, h, context);
}
e.complete();
getEngine().getMetrics().getTerrain().put(p.getMilliseconds());
}

View File

@@ -38,7 +38,7 @@ public class LinkedTerrainChunk implements TerrainChunk {
private final BiomeGrid storage;
private ChunkData rawChunkData;
@Setter
private boolean unsafe = false;
private boolean unsafe = true;
public LinkedTerrainChunk(World world) {
this(null, Bukkit.createChunkData(world));

View File

@@ -146,9 +146,6 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent
@EventHandler
public void on(BlockBreakEvent e) {
if(e.getPlayer().getWorld().equals(getTarget().getWorld().realWorld())) {
WasteDetector.printAll();
onBlockBreak(e);
}
}

View File

@@ -73,16 +73,11 @@ public interface EngineMode extends Staged {
@BlockCoordinates
default void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes, boolean multicore) {
PrecisionStopwatch p = PrecisionStopwatch.start();
PrecisionStopwatch p2 = PrecisionStopwatch.start();
ChunkContext ctx = new ChunkContext(x, z, getComplex());
IrisContext.getOr(getEngine()).setChunkContext(ctx);
r.put(p.getMilliseconds());
for(EngineStage i : getStages()) {
i.generate(x, z, blocks, biomes, multicore, ctx);
}
r2.put(p2.getMilliseconds());
// Iris.warn(Form.duration(r.getAverage(), 2) + " Prep: TOTAL: " + C.RED + Form.duration(r2.getAverage(), 2));
}
}

View File

@@ -38,8 +38,10 @@ public class MantleCarvingComponent extends IrisMantleComponent {
@Override
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
RNG rng = new RNG(Cache.key(x, z) + seed());
IrisRegion region = context.getRegion().get(8, 8);
IrisBiome biome = context.getBiome().get(8, 8);
int xxx = 8 + (x << 4);
int zzz = 8 + (z << 4);
IrisRegion region =getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
carve(writer, rng, x, z, region, biome);
}

View File

@@ -38,8 +38,10 @@ public class MantleFluidBodyComponent extends IrisMantleComponent {
@Override
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
RNG rng = new RNG(Cache.key(x, z) + seed() + 405666);
IrisRegion region = context.getRegion().get(8, 8);
IrisBiome biome = context.getBiome().get(8, 8);
int xxx = 8 + (x << 4);
int zzz = 8 + (z << 4);
IrisRegion region =getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
generate(writer, rng, x, z, region, biome);
}

View File

@@ -49,8 +49,10 @@ public class MantleJigsawComponent extends IrisMantleComponent {
@Override
public void generateLayer(MantleWriter writer, int x, int z, ChunkContext context) {
RNG rng = new RNG(cng.fit(-Integer.MAX_VALUE, Integer.MAX_VALUE, x, z));
IrisRegion region = context.getRegion().get(8, 8);
IrisBiome biome = context.getBiome().get(8, 8);
int xxx = 8 + (x << 4);
int zzz = 8 + (z << 4);
IrisRegion region =getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
generateJigsaw(writer, rng, x, z, biome, region);
}

View File

@@ -44,8 +44,10 @@ 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());
IrisRegion region = context.getRegion().get(8, 8);
IrisBiome biome = context.getBiome().get(8, 8);
int xxx = 8 + (x << 4);
int zzz = 8 + (z << 4);
IrisRegion region =getComplex().getRegionStream().get(xxx, zzz);
IrisBiome biome = getComplex().getTrueBiomeStream().get(xxx, zzz);
placeObjects(writer, rng, x, z, biome, region);
}

View File

@@ -23,6 +23,7 @@ import com.volmit.iris.engine.actuator.IrisDecorantActuator;
import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineMode;
import com.volmit.iris.engine.framework.EngineStage;
import com.volmit.iris.engine.framework.IrisEngineMode;
import com.volmit.iris.engine.modifier.IrisCarveModifier;
import com.volmit.iris.engine.modifier.IrisDepositModifier;
@@ -40,17 +41,30 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
var post = new IrisPostModifier(getEngine());
var deposit = new IrisDepositModifier(getEngine());
var perfection = new IrisPerfectionModifier(getEngine());
EngineStage sBiome = (x, z, k, p, m, c) -> biome.actuate(x, z, p, m, c);
EngineStage sGenMatter = (x, z, k, p, m, c) -> generateMatter(x >> 4, z >> 4, m, c);
EngineStage sTerrain = (x, z, k, p, m, c) -> terrain.actuate(x, z, k, m, c);
EngineStage sDecorant = (x, z, k, p, m, c) -> decorant.actuate(x, z, k, m, c);
EngineStage sCave = (x, z, k, p, m, c) -> cave.modify(x >> 4, z >> 4, k, m, c);
EngineStage sDeposit = (x, z, k, p, m, c) -> deposit.modify(x, z, k, m,c);
EngineStage sPost = (x, z, k, p, m, c) -> post.modify(x, z, k, m, c);
EngineStage sInsertMatter = (x, z, K, p, m, c) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m);
EngineStage sPerfection = (x, z, k, p, m, c) -> perfection.modify(x, z, k, m, c);
registerStage((x, z, k, p, m, c) -> biome.actuate(x, z, p, m, c));
registerStage(burst(
(x, z, k, p, m, c) -> generateMatter(x >> 4, z >> 4, m, c),
(x, z, k, p, m, c) -> terrain.actuate(x, z, k, m, c)
sGenMatter,
sTerrain
));
registerStage((x, z, k, p, m, c) -> cave.modify(x >> 4, z >> 4, k, m, c));
registerStage((x, z, k, p, m, c) -> deposit.modify(x, z, k, m,c));
registerStage((x, z, k, p, m, c) -> decorant.actuate(x, z, k, m, c));
registerStage((x, z, k, p, m, c) -> post.modify(x, z, k, m, c));
registerStage((x, z, K, p, m, c) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m));
registerStage((x, z, k, p, m, c) -> perfection.modify(x, z, k, m, c));
registerStage(burst(
sCave,
sPost
));
registerStage(burst(
sDeposit,
sInsertMatter,
sDecorant
));
registerStage(sPerfection);
}
}

View File

@@ -157,7 +157,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
if(i == buf + 1) {
buf = i;
zone.ceiling = buf;
} else if(zone.isValid()) {
} else if(zone.isValid(getEngine())) {
processZone(output, mc, mantle, zone, rx, rz, rx + (x << 4), rz + (z << 4));
zone = new CaveZone();
zone.setFloor(i);
@@ -165,7 +165,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
}
}
if(zone.isValid()) {
if(zone.isValid(getEngine())) {
processZone(output, mc, mantle, zone, rx, rz, rx + (x << 4), rz + (z << 4));
}
});
@@ -276,8 +276,8 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
return (ceiling - floor) - 1;
}
public boolean isValid() {
return floor < ceiling && ceiling - floor >= 1 && floor >= 0 && ceiling <= IrisContext.get().getEngine().getHeight() && airThickness() > 0;
public boolean isValid(Engine engine) {
return floor < ceiling && ceiling - floor >= 1 && floor >= 0 && ceiling <= engine.getHeight() && airThickness() > 0;
}
public String toString() {

View File

@@ -32,6 +32,7 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.generator.WorldInfo;
import java.io.File;
import java.util.Collection;
@@ -109,6 +110,14 @@ public class IrisWorld {
}
}
public void bind(WorldInfo worldInfo) {
name(worldInfo.getName())
.worldFolder(new File(worldInfo.getName()))
.minHeight(worldInfo.getMinHeight())
.maxHeight(worldInfo.getMaxHeight())
.environment(worldInfo.getEnvironment());
}
public void bind(World world) {
if(hasRealWorld()) {
return;

View File

@@ -20,6 +20,7 @@ package com.volmit.iris.engine.platform;
import com.volmit.iris.Iris;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.nms.v19_2.CustomBiomeSource;
import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.engine.IrisEngine;
import com.volmit.iris.engine.data.chunk.TerrainChunk;
@@ -44,37 +45,55 @@ import com.volmit.iris.util.stream.utility.ProfiledStream;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Setter;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.WorldGenLevel;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.HeightMap;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_R1.generator.CustomChunkGenerator;
import org.bukkit.craftbukkit.v1_19_R1.generator.InternalChunkGenerator;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldInitEvent;
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 sun.misc.Unsafe;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Random;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
@EqualsAndHashCode(callSuper = true)
@Data
public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator {
public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChunkGenerator, Listener {
private static final int LOAD_LOCKS = Runtime.getRuntime().availableProcessors() * 4;
private final Semaphore loadLock;
private final IrisWorld world;
private final File dataLocation;
private final String dimensionKey;
private final ReactiveFolder folder;
private final ReentrantLock lock = new ReentrantLock();
private final KList<BlockPopulator> populators;
private final ChronoLatch hotloadChecker;
private final AtomicBoolean setup;
@@ -98,6 +117,49 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
this.dataLocation = dataLocation;
this.dimensionKey = dimensionKey;
this.folder = new ReactiveFolder(dataLocation, (_a, _b, _c) -> hotload());
Bukkit.getServer().getPluginManager().registerEvents(this, Iris.instance);
}
@EventHandler
public void onWorldInit(WorldInitEvent event) {
try {
if(world.name().equals(event.getWorld().getName()) && world.getRawWorldSeed() == event.getWorld().getSeed()) {
ServerLevel serverLevel = ((CraftWorld)event.getWorld()).getHandle();
Engine engine = getEngine(event.getWorld());
Class<?> clazz = serverLevel.getChunkSource().chunkMap.generator.getClass();
Field biomeSource = getField(clazz, "c");
biomeSource.setAccessible(true);
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
CustomBiomeSource customBiomeSource = new CustomBiomeSource(event.getWorld().getSeed(), engine, event.getWorld());
unsafe.putObject(biomeSource.get(serverLevel.getChunkSource().chunkMap.generator), unsafe.objectFieldOffset(biomeSource), customBiomeSource);
biomeSource.set(serverLevel.getChunkSource().chunkMap.generator, customBiomeSource);
Iris.info("Injected Iris Biome Source into " + event.getWorld().getName());
}
else {
Iris.info("World " + event.getWorld().getName() + " is not an Iris world in this context");
}
}
catch(Throwable e) {
e.printStackTrace();
}
}
private static Field getField(Class clazz, String fieldName)
throws NoSuchFieldException {
try {
return clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
Class superClass = clazz.getSuperclass();
if (superClass == null) {
throw e;
} else {
return getField(superClass, fieldName);
}
}
}
private void setupEngine() {
@@ -143,7 +205,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
Hunk<BlockData> blocks = Hunk.view(tc);
Hunk<Biome> biomes = Hunk.view(tc, tc.getMinHeight(), tc.getMaxHeight());
this.world.bind(world);
getEngine().generate(x << 4, z << 4, blocks, biomes, true);
getEngine().generate(x << 4, z << 4, blocks, biomes, false);
Iris.debug("Regenerated " + x + " " + z);
int t = 0;
for(int i = getEngine().getHeight() >> 4; i >= 0; i--) {
@@ -197,34 +259,41 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
}
}
private Engine getEngine(World world) {
private Engine getEngine(WorldInfo world) {
if(setup.get()) {
return getEngine();
}
synchronized(this) {
getWorld().setRawWorldSeed(world.getSeed());
setupEngine();
this.hotloader = studio ? new Looper() {
@Override
protected long loop() {
if(hotloadChecker.flip()) {
folder.check();
}
lock.lock();
return 250;
}
} : null;
if(studio) {
hotloader.setPriority(Thread.MIN_PRIORITY);
hotloader.start();
hotloader.setName(getTarget().getWorld().name() + " Hotloader");
}
setup.set(true);
if(setup.get())
{
return getEngine();
}
setup.set(true);
getWorld().setRawWorldSeed(world.getSeed());
setupEngine();
this.hotloader = studio ? new Looper() {
@Override
protected long loop() {
if(hotloadChecker.flip()) {
folder.check();
}
return 250;
}
} : null;
if(studio) {
hotloader.setPriority(Thread.MIN_PRIORITY);
hotloader.start();
hotloader.setName(getTarget().getWorld().name() + " Hotloader");
}
lock.unlock();
return engine;
}
@@ -273,14 +342,15 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
getEngine(world);
}
private final AtomicInteger a = new AtomicInteger(0);
@Override
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) {
public void generateNoise(@NotNull WorldInfo world, @NotNull Random random, int x, int z, @NotNull ChunkGenerator.ChunkData d) {
try {
getEngine(world);
computeStudioGenerator();
TerrainChunk tc = TerrainChunk.create(world, biome);
TerrainChunk tc = TerrainChunk.create(d, new IrisBiomeStorage());
this.world.bind(world);
if(studioGenerator != null) {
studioGenerator.generateChunk(getEngine(), tc, x, z);
} else {
@@ -291,28 +361,26 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
biomes.apply();
}
ChunkData c = tc.getRaw();
Iris.debug("Generated " + x + " " + z);
return c;
} catch(Throwable e) {
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());
}
}
return d;
}
}
@Override
public int getBaseHeight(@NotNull WorldInfo worldInfo, @NotNull Random random, int x, int z, @NotNull HeightMap heightMap) {
return 4;
}
private void computeStudioGenerator() {
if(!getEngine().getDimension().getStudioMode().equals(lastMode)) {
lastMode = getEngine().getDimension().getStudioMode();

View File

@@ -0,0 +1,29 @@
package com.volmit.iris.engine.platform;
import org.bukkit.block.Biome;
import org.bukkit.generator.ChunkGenerator;
import org.jetbrains.annotations.NotNull;
public class DummyBiomeGrid implements ChunkGenerator.BiomeGrid {
@NotNull
@Override
public Biome getBiome(int x, int z) {
return null;
}
@NotNull
@Override
public Biome getBiome(int x, int y, int z) {
return null;
}
@Override
public void setBiome(int x, int z, @NotNull Biome bio) {
}
@Override
public void setBiome(int x, int y, int z, @NotNull Biome bio) {
}
}

View File

@@ -1,5 +1,6 @@
package com.volmit.iris.engine.platform;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KList;
import org.bukkit.block.Biome;
import org.bukkit.generator.BiomeProvider;

View File

@@ -0,0 +1,27 @@
package com.volmit.iris.util.cache;
import com.volmit.iris.util.data.ChunkCache;
import com.volmit.iris.util.function.Function2;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Function;
public class ChunkCache2D<T> {
private final AtomicReferenceArray<T> cache;
public ChunkCache2D() {
this.cache = new AtomicReferenceArray<>(256);
}
public T get(int x, int z, Function2<Integer, Integer, T> resolver) {
int key = ((z & 15) * 16) + (x & 15);
T t = cache.get(key);
if(t == null) {
t = resolver.apply(x, z);
cache.set(key, t);
}
return t;
}
}

View File

@@ -0,0 +1,34 @@
package com.volmit.iris.util.cache;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.context.ChunkedDataCache;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.mantle.Mantle;
import com.volmit.iris.util.scheduling.ChronoLatch;
import it.unimi.dsi.fastutil.longs.Long2LongMaps;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
public class WorldCache2D<T> {
private final KCache<Long, ChunkCache2D<T>> chunks;
private final Function2<Integer, Integer, T> resolver;
public WorldCache2D(Function2<Integer, Integer, T> resolver) {
this.resolver = resolver;
chunks = new KCache<>((x) -> new ChunkCache2D<>(), 1024);
}
public T get(int x, int z) {
ChunkCache2D<T> chunk = chunks.get(Cache.key(x >> 4, z >> 4));
return chunk.get(x, z, resolver);
}
public long getSize() {
return chunks.getSize() * 256L;
}
}

View File

@@ -3,6 +3,7 @@ package com.volmit.iris.util.context;
import com.volmit.iris.engine.IrisComplex;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisRegion;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
@@ -28,6 +29,7 @@ public class ChunkContext {
public ChunkContext(int x, int z, IrisComplex c, boolean cache) {
this.x = x;
this.z = z;
if(cache) {
BurstExecutor b = MultiBurst.burst.burst();
height = new ChunkedDataCache<>(b, c.getHeightStream(), x, z);

View File

@@ -1,12 +1,18 @@
package com.volmit.iris.util.context;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.documentation.BlockCoordinates;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.stream.ProceduralStream;
import lombok.Data;
import java.util.HashSet;
@Data
public class ChunkedDataCache<T> {
private final int x;
private final int z;
private final KSet<T> uniques;
private final Object[] data;
private final boolean cache;
private final ProceduralStream<T> stream;
@@ -21,6 +27,7 @@ public class ChunkedDataCache<T> {
this.cache = cache;
this.x = x;
this.z = z;
this.uniques = cache ? new KSet<>() : null;
if(cache) {
data = new Object[256];
int i,j;
@@ -29,7 +36,11 @@ public class ChunkedDataCache<T> {
int finalI = i;
for(j = 0; j < 16; j++) {
int finalJ = j;
burst.queue(() -> data[(finalJ * 16) + finalI] = stream.get(x+ finalI, z+ finalJ));
burst.queue(() -> {
T t = stream.get(x+ finalI, z+ finalJ);
data[(finalJ * 16) + finalI] = t;
uniques.add(t);
});
}
}
}

View File

@@ -24,6 +24,10 @@ import com.github.benmanes.caffeine.cache.LoadingCache;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.math.RollingSequence;
import java.time.Duration;
import java.time.temporal.TemporalUnit;
import java.util.concurrent.TimeUnit;
public class KCache<K, V> implements MeteredCache {
private final long max;
private CacheLoader<K, V> loader;
@@ -46,7 +50,6 @@ public class KCache<K, V> implements MeteredCache {
return Caffeine
.newBuilder()
.maximumSize(max)
.softValues()
.initialCapacity((int) (max))
.build((k) -> loader == null ? null : loader.load(k));
}

View File

@@ -65,8 +65,7 @@ public class ChunkDataHunkHolder extends AtomicHunk<BlockData> {
for(int k = 0; k < getDepth(); k++) {
BlockData b = super.getRaw(j, i, k);
if(b != null)
{
if(b != null) {
chunk.setBlock(j, i + chunk.getMinHeight(), k, b);
}
}

View File

@@ -18,12 +18,14 @@
package com.volmit.iris.util.hunk.view;
import com.volmit.iris.util.data.B;
import com.volmit.iris.util.hunk.Hunk;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
@SuppressWarnings("ClassCanBeRecord")
public class ChunkDataHunkView implements Hunk<BlockData> {
private static final BlockData AIR = B.getAir();
private final ChunkData chunk;
public ChunkDataHunkView(ChunkData chunk) {
@@ -54,17 +56,44 @@ public class ChunkDataHunkView implements Hunk<BlockData> {
chunk.setRegion(x1, y1 + chunk.getMinHeight(), z1, x2, y2 + chunk.getMinHeight(), z2, t);
}
public BlockData get(int x, int y, int z) {
return getRaw(x, y, z);
}
public void set(int x, int y, int z, BlockData t) {
setRaw(x, y, z, t);
}
@Override
public void setRaw(int x, int y, int z, BlockData t) {
if(t == null) {
return;
}
chunk.setBlock(x, y + chunk.getMinHeight(), z, t);
try {
chunk.setBlock(x, y + chunk.getMinHeight(), z, t);
}
catch(Throwable ignored)
{
}
}
@Override
public BlockData getRaw(int x, int y, int z) {
return chunk.getBlockData(x, y + chunk.getMinHeight(), z);
try {
return chunk.getBlockData(x, y + chunk.getMinHeight(), z);
}
catch(Throwable e)
{
}
return AIR;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -22,31 +22,7 @@ import com.volmit.iris.util.function.NoiseProvider;
public class Starcast {
public static double starcast(int x, int z, double r, double checks, boolean optimized, NoiseProvider n) {
if(optimized) {
if(checks == 3) return sc3(x, z, r, n);
else if(checks == 5) return sc5(x, z, r, n);
else if(checks == 6) return sc6(x, z, r, n);
else if(checks == 7) return sc7(x, z, r, n);
else if(checks == 9) return sc9(x, z, r, n);
else if(checks == 12) return sc12(x, z, r, n);
else if(checks == 24) return sc24(x, z, r, n);
else if(checks == 32) return sc32(x, z, r, n);
else if(checks == 48) return sc48(x, z, r, n);
else if(checks == 64) return sc64(x, z, r, n);
}
double m = 360D / checks;
double v = 0;
for(int i = 0; i < 360; i += m) {
double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i));
double cx = x + ((r * cos) - (r * sin));
double cz = z + ((r * sin) + (r * cos));
v += n.noise(cx, cz);
}
return v / checks;
return CompiledStarcast.getStarcast((float)x, (float)z, (float)r, (float)checks, n);
}
public static double starcast(int x, int z, double r, double checks, NoiseProvider n) {

View File

@@ -0,0 +1,31 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.bukkit.block.Biome;
@Data
@AllArgsConstructor
public class MatterBiomeInject {
private final boolean custom;
private final Integer biomeId;
private final Biome biome;
}

View File

@@ -0,0 +1,80 @@
/*
* Iris is a World Generator for Minecraft Bukkit Servers
* Copyright (c) 2022 Arcane Arts (Volmit Software)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.data.palette.Palette;
import com.volmit.iris.util.matter.MatterBiomeInject;
import com.volmit.iris.util.matter.MatterCavern;
import com.volmit.iris.util.matter.Sliced;
import org.bukkit.block.Biome;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
@Sliced
public class BiomeInjectMatter extends RawMatter<MatterBiomeInject> {
public BiomeInjectMatter() {
this(1, 1, 1);
}
@Override
public Palette<MatterBiomeInject> getGlobalPalette() {
return null;
}
public BiomeInjectMatter(int width, int height, int depth) {
super(width, height, depth, MatterBiomeInject.class);
}
public static MatterBiomeInject get(Biome biome)
{
return get(false, 0, biome);
}
public static MatterBiomeInject get(int customBiome) {
return get(true, customBiome, null);
}
public static MatterBiomeInject get(boolean custom, int customBiome, Biome biome) {
return new MatterBiomeInject(custom, customBiome, biome);
}
@Override
public void writeNode(MatterBiomeInject b, DataOutputStream dos) throws IOException {
dos.writeBoolean(b.isCustom());
if(b.isCustom()) {
dos.writeShort(b.getBiomeId());
}
else {
dos.writeByte(b.getBiome().ordinal());
}
}
@Override
public MatterBiomeInject readNode(DataInputStream din) throws IOException {
boolean b = din.readBoolean();
int id = b ? din.readShort() : 0;
Biome biome = !b ? Biome.values()[din.readByte()] : Biome.PLAINS;
return new MatterBiomeInject(b, id, biome);
}
}

View File

@@ -25,6 +25,7 @@ import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IRare;
import com.volmit.iris.engine.object.IrisStyledRange;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.function.Function2;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.function.Function4;
@@ -62,6 +63,7 @@ import com.volmit.iris.util.stream.interpolation.Interpolated;
import com.volmit.iris.util.stream.sources.FunctionStream;
import com.volmit.iris.util.stream.utility.CachedStream2D;
import com.volmit.iris.util.stream.utility.CachedStream3D;
import com.volmit.iris.util.stream.utility.ContextInjectingStream;
import com.volmit.iris.util.stream.utility.NullSafeStream;
import com.volmit.iris.util.stream.utility.ProfiledStream;
import com.volmit.iris.util.stream.utility.SemaphoreStream;
@@ -135,12 +137,18 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
return new AddingStream<>(this, a);
}
default ProceduralStream<T> contextInjecting(Function3<ChunkContext, Integer, Integer, T> contextAccessor) {
//return this;
return new ContextInjectingStream<>(this, contextAccessor);
}
default ProceduralStream<T> add(ProceduralStream<Double> a) {
return add2D((x, z) -> a.get(x, z));
}
default ProceduralStream<T> waste(String name) {
return new WasteDetector<T>(this, name);
return this;
//return new WasteDetector<T>(this, name);
}
default ProceduralStream<T> subtract(ProceduralStream<Double> a) {

View File

@@ -23,6 +23,7 @@ import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.cache.WorldCache2D;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.hunk.Hunk;
import com.volmit.iris.util.hunk.storage.ArrayHunk;
@@ -31,7 +32,7 @@ import com.volmit.iris.util.stream.ProceduralStream;
public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStream<T>, MeteredCache {
private final ProceduralStream<T> stream;
private final KCache<Long, T> cache;
private final WorldCache2D<T> cache;
private final Engine engine;
private boolean chunked = true;
@@ -39,7 +40,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
super();
this.stream = stream;
this.engine = engine;
cache = new KCache<>(k -> stream.get(Cache.keyX(k), Cache.keyZ(k)), size);
cache = new WorldCache2D<>(stream::get);
Iris.service(PreservationSVC.class).registerCache(this);
}
@@ -56,7 +57,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
@Override
public T get(double x, double z) {
//return stream.get(x, z);
return cache.get(Cache.key((int) x, (int) z));
return cache.get((int) x, (int) z);
}
@Override
@@ -71,12 +72,12 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
@Override
public KCache<?, ?> getRawCache() {
return cache;
return null;
}
@Override
public long getMaxSize() {
return cache.getMaxSize();
return 256 * 32;
}
@Override

View File

@@ -0,0 +1,53 @@
package com.volmit.iris.util.stream.utility;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.context.ChunkContext;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.function.Function3;
import com.volmit.iris.util.stream.BasicStream;
import com.volmit.iris.util.stream.ProceduralStream;
import java.util.concurrent.atomic.AtomicInteger;
public class ContextInjectingStream<T> extends BasicStream<T> {
private final Function3<ChunkContext, Integer, Integer, T> contextAccessor;
public ContextInjectingStream(ProceduralStream<T> stream, Function3<ChunkContext, Integer, Integer, T> contextAccessor) {
super(stream);
this.contextAccessor = contextAccessor;
}
@Override
public T get(double x, double z) {
IrisContext context = IrisContext.get();
if(context != null) {
ChunkContext chunkContext = context.getChunkContext();
if(chunkContext != null && (int)x >> 4 == chunkContext.getX() >> 4 && (int)z >> 4 == chunkContext.getZ() >> 4) {
T t = contextAccessor.apply(chunkContext, (int)x&15, (int)z&15);
if(t != null) {
return t;
}
}
}
return getTypedSource().get(x, z);
}
@Override
public T get(double x, double y, double z) {
return getTypedSource().get(x, y, z);
}
@Override
public double toDouble(T t) {
return getTypedSource().toDouble(t);
}
@Override
public T fromDouble(double d) {
return getTypedSource().fromDouble(d);
}
}