mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Merge branch 'master' into rawCommands
This commit is contained in:
commit
668c7d301b
2
plugins/Iris/cache/instance
vendored
2
plugins/Iris/cache/instance
vendored
@ -1 +1 @@
|
||||
-523376883
|
||||
1036166928
|
||||
|
@ -26,10 +26,7 @@ import com.volmit.iris.core.link.MythicMobsLink;
|
||||
import com.volmit.iris.core.link.OraxenLink;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.service.PreservationSVC;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.engine.object.IrisBiomeCustom;
|
||||
import com.volmit.iris.engine.object.IrisCompat;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.object.IrisWorld;
|
||||
@ -37,10 +34,10 @@ import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
||||
import com.volmit.iris.engine.platform.DummyChunkGenerator;
|
||||
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.exceptions.IrisException;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.format.MemoryMonitor;
|
||||
import com.volmit.iris.util.function.NastyRunnable;
|
||||
import com.volmit.iris.util.io.FileWatcher;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
|
@ -64,8 +64,8 @@ public class IrisSettings {
|
||||
@Data
|
||||
public static class IrisSettingsPerformance {
|
||||
public boolean trimMantleInStudio = false;
|
||||
public int mantleKeepAliveSeconds = 20;
|
||||
public int maxStreamCacheSize = 750_000;
|
||||
public int mantleKeepAliveSeconds = 25;
|
||||
public int maxStreamCacheSize = 256_000;
|
||||
public int maxResourceLoaderCacheSize = 1_000;
|
||||
public int maxObjectLoaderCacheSize = 3_000;
|
||||
public int maxScriptLoaderCacheSize = 500;
|
||||
|
@ -62,6 +62,7 @@ import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.math.Spiraler;
|
||||
import com.volmit.iris.util.noise.CNG;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.plugin.IrisService;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.O;
|
||||
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
|
||||
@ -326,7 +327,7 @@ public class CommandStudio implements DecreeExecutor {
|
||||
engine().getExecution().execute(script.getLoadKey());
|
||||
}
|
||||
|
||||
@Decree(description = "Open the noise explorer (External GUI)", aliases = "nmap")
|
||||
@Decree(description = "Open the noise explorer (External GUI)", aliases = {"nmap", "n"})
|
||||
public void noise() {
|
||||
if (noGUI()) return;
|
||||
sender().sendMessage(C.GREEN + "Opening Noise Explorer!");
|
||||
@ -364,11 +365,13 @@ public class CommandStudio implements DecreeExecutor {
|
||||
NoiseExplorerGUI.launch(l, "Custom Generator");
|
||||
}
|
||||
|
||||
@Decree(description = "Hotload a studio", aliases = "reload", origin = DecreeOrigin.PLAYER)
|
||||
@Decree(description = "Hotload a studio", aliases = "reload")
|
||||
public void hotload() {
|
||||
if (noStudio()) return;
|
||||
|
||||
access().hotload();
|
||||
if (!Iris.service(StudioSVC.class).isProjectOpen()){
|
||||
sender().sendMessage(C.RED + "No studio world open!");
|
||||
return;
|
||||
}
|
||||
Iris.service(StudioSVC.class).getActiveProject().getActiveProvider().getEngine().hotload();
|
||||
sender().sendMessage(C.GREEN + "Hotloaded");
|
||||
}
|
||||
|
||||
@ -663,6 +666,7 @@ public class CommandStudio implements DecreeExecutor {
|
||||
@Param(description = "The dimension to update the workspace of", contextual = true, defaultValue = "overworld")
|
||||
IrisDimension dimension
|
||||
) {
|
||||
sender().sendMessage(C.GOLD + "Updating Code Workspace for " + dimension.getName() + "...");
|
||||
if (new IrisProject(dimension.getLoader().getDataFolder()).updateWorkspace()) {
|
||||
sender().sendMessage(C.GREEN + "Updated Code Workspace for " + dimension.getName());
|
||||
} else {
|
||||
@ -846,7 +850,7 @@ public class CommandStudio implements DecreeExecutor {
|
||||
*/
|
||||
private boolean noStudio() {
|
||||
if (!sender().isPlayer()) {
|
||||
sender().sendMessage(C.RED + "Players only (this is a config error. Ask support to add DecreeOrigin.PLAYER to the command you tried to run)");
|
||||
sender().sendMessage(C.RED + "Players only!");
|
||||
return true;
|
||||
}
|
||||
if (!Iris.service(StudioSVC.class).isProjectOpen()) {
|
||||
|
@ -25,12 +25,15 @@ import com.volmit.iris.core.pregenerator.PregenListener;
|
||||
import com.volmit.iris.core.pregenerator.PregenTask;
|
||||
import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.format.MemoryMonitor;
|
||||
import com.volmit.iris.util.function.Consumer2;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
|
||||
@ -44,6 +47,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@ -51,11 +55,13 @@ public class PregeneratorJob implements PregenListener {
|
||||
private static final Color COLOR_EXISTS = parseColor("#4d7d5b");
|
||||
private static final Color COLOR_BLACK = parseColor("#4d7d5b");
|
||||
private static final Color COLOR_MANTLE = parseColor("#3c2773");
|
||||
private static final Color COLOR_GENERATING = parseColor("#0062ff");
|
||||
private static final Color COLOR_GENERATING = parseColor("#66967f");
|
||||
private static final Color COLOR_NETWORK = parseColor("#a863c2");
|
||||
private static final Color COLOR_NETWORK_GENERATING = parseColor("#836b8c");
|
||||
private static final Color COLOR_GENERATED = parseColor("#34eb93");
|
||||
private static final Color COLOR_GENERATED = parseColor("#65c295");
|
||||
private static final Color COLOR_CLEANED = parseColor("#34eb93");
|
||||
public static PregeneratorJob instance;
|
||||
private final MemoryMonitor monitor;
|
||||
private final PregenTask task;
|
||||
private final boolean saving;
|
||||
private final KList<Consumer<Double>> onProgress = new KList<>();
|
||||
@ -65,10 +71,15 @@ public class PregeneratorJob implements PregenListener {
|
||||
private final Position2 max;
|
||||
private JFrame frame;
|
||||
private PregenRenderer renderer;
|
||||
private int rgc = 0;
|
||||
private ChronoLatch cl = new ChronoLatch(TimeUnit.MINUTES.toMillis(1));
|
||||
private String[] info;
|
||||
private Engine engine;
|
||||
|
||||
public PregeneratorJob(PregenTask task, PregeneratorMethod method) {
|
||||
public PregeneratorJob(PregenTask task, PregeneratorMethod method, Engine engine) {
|
||||
this.engine = engine;
|
||||
instance = this;
|
||||
monitor = new MemoryMonitor(50);
|
||||
saving = false;
|
||||
info = new String[]{"Initializing..."};
|
||||
this.task = task;
|
||||
@ -181,6 +192,7 @@ public class PregeneratorJob implements PregenListener {
|
||||
public void close() {
|
||||
J.a(() -> {
|
||||
try {
|
||||
monitor.close();
|
||||
J.sleep(3000);
|
||||
frame.setVisible(false);
|
||||
} catch (Throwable e) {
|
||||
@ -220,6 +232,8 @@ public class PregeneratorJob implements PregenListener {
|
||||
"Speed: " + Form.f(chunksPerSecond, 0) + " Chunks/s, " + Form.f(regionsPerMinute, 1) + " Regions/m, " + Form.f(chunksPerMinute, 0) + " Chunks/m",
|
||||
Form.duration(eta, 2) + " Remaining " + " (" + Form.duration(elapsed, 2) + " Elapsed)",
|
||||
"Generation Method: " + method,
|
||||
"Memory: " + Form.memSize(monitor.getUsedBytes(), 2) + " (" + Form.pc(monitor.getUsagePercent(), 0) + ") Pressure: " + Form.memSize(monitor.getPressure(), 0) + "/s",
|
||||
|
||||
};
|
||||
|
||||
for (Consumer<Double> i : onProgress) {
|
||||
@ -229,17 +243,36 @@ public class PregeneratorJob implements PregenListener {
|
||||
|
||||
@Override
|
||||
public void onChunkGenerating(int x, int z) {
|
||||
if(engine != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
draw(x, z, COLOR_GENERATING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkGenerated(int x, int z) {
|
||||
if(engine != null)
|
||||
{
|
||||
draw(x, z, engine.draw((x << 4) + 8, (z << 4) + 8));
|
||||
return;
|
||||
}
|
||||
|
||||
draw(x, z, COLOR_GENERATED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegionGenerated(int x, int z) {
|
||||
shouldGc();
|
||||
rgc++;
|
||||
}
|
||||
|
||||
private void shouldGc() {
|
||||
if(cl.flip() && rgc > 16)
|
||||
{
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -247,6 +280,11 @@ public class PregeneratorJob implements PregenListener {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkCleaned(int x, int z) {
|
||||
//draw(x, z, COLOR_CLEANED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegionSkipped(int x, int z) {
|
||||
|
||||
@ -291,6 +329,12 @@ public class PregeneratorJob implements PregenListener {
|
||||
|
||||
@Override
|
||||
public void onChunkExistsInRegionGen(int x, int z) {
|
||||
if(engine != null)
|
||||
{
|
||||
draw(x, z, engine.draw((x << 4) + 8, (z << 4) + 8));
|
||||
return;
|
||||
}
|
||||
|
||||
draw(x, z, COLOR_EXISTS);
|
||||
}
|
||||
|
||||
@ -347,7 +391,7 @@ public class PregeneratorJob implements PregenListener {
|
||||
l.unlock();
|
||||
g.drawImage(image, 0, 0, getParent().getWidth(), getParent().getHeight(), (img, infoflags, x, y, width, height) -> true);
|
||||
g.setColor(Color.WHITE);
|
||||
g.setFont(new Font("Hevetica", Font.BOLD, 28));
|
||||
g.setFont(new Font("Hevetica", Font.BOLD, 13));
|
||||
String[] prog = job.getProgress();
|
||||
int h = g.getFontMetrics().getHeight() + 5;
|
||||
int hh = 20;
|
||||
|
@ -54,7 +54,6 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
|
||||
}
|
||||
|
||||
protected IrisObject loadFile(File j, String name) {
|
||||
lock.lock();
|
||||
try {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
IrisObject t = new IrisObject(0, 0, 0);
|
||||
@ -63,12 +62,10 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
|
||||
t.setLoader(manager);
|
||||
t.setLoadFile(j);
|
||||
logLoad(j, t);
|
||||
lock.unlock();
|
||||
tlt.addAndGet(p.getMilliseconds());
|
||||
return t;
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
lock.unlock();
|
||||
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
@ -108,11 +105,9 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
|
||||
}
|
||||
|
||||
public File findFile(String name) {
|
||||
lock.lock();
|
||||
for (File i : getFolders(name)) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name)) {
|
||||
lock.unlock();
|
||||
return j;
|
||||
}
|
||||
}
|
||||
@ -120,14 +115,12 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
|
||||
File file = new File(i, name + ".iob");
|
||||
|
||||
if (file.exists()) {
|
||||
lock.unlock();
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -136,11 +129,9 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
|
||||
}
|
||||
|
||||
private IrisObject loadRaw(String name){
|
||||
lock.lock();
|
||||
for (File i : getFolders(name)) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".iob") && j.getName().split("\\Q.\\E")[0].equals(name)) {
|
||||
lock.unlock();
|
||||
return loadFile(j, name);
|
||||
}
|
||||
}
|
||||
@ -148,14 +139,12 @@ public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
|
||||
File file = new File(i, name + ".iob");
|
||||
|
||||
if (file.exists()) {
|
||||
lock.unlock();
|
||||
return loadFile(file, name);
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -56,14 +56,12 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
protected KList<File> folderCache;
|
||||
protected Class<? extends T> objectClass;
|
||||
protected String cname;
|
||||
protected IrisLock lock;
|
||||
protected String[] possibleKeys = null;
|
||||
protected IrisData manager;
|
||||
protected AtomicInteger loads;
|
||||
protected ChronoLatch sec;
|
||||
|
||||
public ResourceLoader(File root, IrisData manager, String folderName, String resourceTypeName, Class<? extends T> objectClass) {
|
||||
lock = new IrisLock("Res");
|
||||
this.manager = manager;
|
||||
sec = new ChronoLatch(5000);
|
||||
loads = new AtomicInteger();
|
||||
@ -95,11 +93,9 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
}
|
||||
|
||||
public File findFile(String name) {
|
||||
lock.lock();
|
||||
for (File i : getFolders(name)) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name)) {
|
||||
lock.unlock();
|
||||
return j;
|
||||
}
|
||||
}
|
||||
@ -107,14 +103,12 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
File file = new File(i, name + ".json");
|
||||
|
||||
if (file.exists()) {
|
||||
lock.unlock();
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -195,12 +189,10 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
t.setLoader(manager);
|
||||
getManager().preprocessObject(t);
|
||||
logLoad(j, t);
|
||||
lock.unlock();
|
||||
tlt.addAndGet(p.getMilliseconds());
|
||||
return t;
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
lock.unlock();
|
||||
failLoad(j, e);
|
||||
return null;
|
||||
}
|
||||
@ -248,7 +240,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
|
||||
private T loadRaw(String name)
|
||||
{
|
||||
lock.lock();
|
||||
for (File i : getFolders(name)) {
|
||||
//noinspection ConstantConditions
|
||||
for (File j : i.listFiles()) {
|
||||
@ -264,7 +255,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
}
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -281,7 +271,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
}
|
||||
|
||||
public KList<File> getFolders() {
|
||||
lock.lock();
|
||||
if (folderCache == null) {
|
||||
folderCache = new KList<>();
|
||||
|
||||
@ -295,8 +284,6 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
}
|
||||
}
|
||||
|
||||
lock.unlock();
|
||||
|
||||
if (folderCache == null) {
|
||||
synchronized (this) {
|
||||
return getFolderCache();
|
||||
@ -321,11 +308,9 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
lock.lock();
|
||||
possibleKeys = null;
|
||||
loadCache.invalidate();
|
||||
folderCache = null;
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
public File fileFor(T b) {
|
||||
@ -351,10 +336,8 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
|
||||
}
|
||||
|
||||
public void clearList() {
|
||||
lock.lock();
|
||||
folderCache = null;
|
||||
possibleKeys = null;
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
public KList<String> getPossibleKeys(String arg) {
|
||||
|
@ -44,7 +44,6 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
|
||||
}
|
||||
|
||||
protected IrisScript loadFile(File j, String name) {
|
||||
lock.lock();
|
||||
try {
|
||||
PrecisionStopwatch p = PrecisionStopwatch.start();
|
||||
IrisScript t = new IrisScript(IO.readAll(j));
|
||||
@ -52,12 +51,10 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
|
||||
t.setLoader(manager);
|
||||
t.setLoadFile(j);
|
||||
logLoad(j, t);
|
||||
lock.unlock();
|
||||
tlt.addAndGet(p.getMilliseconds());
|
||||
return t;
|
||||
} catch (Throwable e) {
|
||||
Iris.reportError(e);
|
||||
lock.unlock();
|
||||
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
@ -97,11 +94,9 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
|
||||
}
|
||||
|
||||
public File findFile(String name) {
|
||||
lock.lock();
|
||||
for (File i : getFolders(name)) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".js") && j.getName().split("\\Q.\\E")[0].equals(name)) {
|
||||
lock.unlock();
|
||||
return j;
|
||||
}
|
||||
}
|
||||
@ -109,24 +104,20 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
|
||||
File file = new File(i, name + ".js");
|
||||
|
||||
if (file.exists()) {
|
||||
lock.unlock();
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
private IrisScript loadRaw(String name)
|
||||
{
|
||||
lock.lock();
|
||||
for (File i : getFolders(name)) {
|
||||
for (File j : i.listFiles()) {
|
||||
if (j.isFile() && j.getName().endsWith(".js") && j.getName().split("\\Q.\\E")[0].equals(name)) {
|
||||
lock.unlock();
|
||||
return loadFile(j, name);
|
||||
}
|
||||
}
|
||||
@ -134,14 +125,12 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
|
||||
File file = new File(i, name + ".js");
|
||||
|
||||
if (file.exists()) {
|
||||
lock.unlock();
|
||||
return loadFile(file, name);
|
||||
}
|
||||
}
|
||||
|
||||
Iris.warn("Couldn't find " + resourceTypeName + ": " + name);
|
||||
|
||||
lock.unlock();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
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.Location;
|
||||
import org.bukkit.World;
|
||||
@ -65,9 +65,9 @@ public interface INMSBinding {
|
||||
|
||||
int getBiomeId(Biome biome);
|
||||
|
||||
BiomeContainer newBiomeContainer(int min, int max, int[] data);
|
||||
MCABiomeContainer newBiomeContainer(int min, int max, int[] data);
|
||||
|
||||
BiomeContainer newBiomeContainer(int min, int max);
|
||||
MCABiomeContainer newBiomeContainer(int min, int max);
|
||||
|
||||
default World createWorld(WorldCreator c) {
|
||||
return c.createWorld();
|
||||
@ -81,5 +81,5 @@ public interface INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
PaletteAccess createPalette();
|
||||
MCAPaletteAccess createPalette();
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.ChunkBiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.GlobalPalette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.IdMap;
|
||||
import com.volmit.iris.util.nbt.mca.palette.IdMapper;
|
||||
import com.volmit.iris.util.nbt.mca.palette.Palette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PalettedContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.WrappedPalettedContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAChunkBiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAGlobalPalette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAIdMap;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAIdMapper;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPalette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPalettedContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAWrappedPalettedContainer;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.IRegistry;
|
||||
@ -82,9 +82,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
public class NMSBinding17_1 implements INMSBinding {
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final AtomicCache<IdMapper<IBlockData>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<Palette<IBlockData>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<IdMap<BiomeBase>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<IBlockData>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<IBlockData>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMap<BiomeBase>> biomeMapCache = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
public boolean supportsDataPacks() {
|
||||
@ -92,8 +92,8 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteAccess createPalette() {
|
||||
IdMapper<IBlockData> registry = registryCache.aquireNasty(() -> {
|
||||
public MCAPaletteAccess createPalette() {
|
||||
MCAIdMapper<IBlockData> registry = registryCache.aquireNasty(() -> {
|
||||
Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c");
|
||||
Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d");
|
||||
Field bf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("b");
|
||||
@ -104,14 +104,14 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
int b = bf.getInt(blockData);
|
||||
IdentityHashMap<IBlockData, Integer> c = (IdentityHashMap<IBlockData, Integer>) cf.get(blockData);
|
||||
List<IBlockData> d = (List<IBlockData>) df.get(blockData);
|
||||
return new IdMapper<>(c, d, b);
|
||||
return new MCAIdMapper<>(c, d, b);
|
||||
});
|
||||
Palette<IBlockData> global = globalCache.aquireNasty(() -> new GlobalPalette<>(registry, ((CraftBlockData) AIR).getState()));
|
||||
PalettedContainer<IBlockData> container = new PalettedContainer<>(global, registry,
|
||||
MCAPalette<IBlockData> global = globalCache.aquireNasty(() -> new MCAGlobalPalette<>(registry, ((CraftBlockData) AIR).getState()));
|
||||
MCAPalettedContainer<IBlockData> container = new MCAPalettedContainer<>(global, registry,
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState(),
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
((CraftBlockData) AIR).getState());
|
||||
return new WrappedPalettedContainer<>(container,
|
||||
return new MCAWrappedPalettedContainer<>(container,
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState());
|
||||
}
|
||||
@ -399,8 +399,8 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
return biome.ordinal();
|
||||
}
|
||||
|
||||
private IdMap<BiomeBase> getBiomeMapping() {
|
||||
return biomeMapCache.aquire(() -> new IdMap<>() {
|
||||
private MCAIdMap<BiomeBase> getBiomeMapping() {
|
||||
return biomeMapCache.aquire(() -> new MCAIdMap<>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<BiomeBase> iterator() {
|
||||
@ -420,20 +420,20 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max) {
|
||||
ChunkBiomeContainer<BiomeBase> base = new ChunkBiomeContainer<>(getBiomeMapping(), min, max);
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max) {
|
||||
MCAChunkBiomeContainer<BiomeBase> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max, int[] data) {
|
||||
ChunkBiomeContainer<BiomeBase> base = new ChunkBiomeContainer<>(getBiomeMapping(), min, max, data);
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max, int[] data) {
|
||||
MCAChunkBiomeContainer<BiomeBase> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max, data);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private BiomeContainer getBiomeContainerInterface(IdMap<BiomeBase> biomeMapping, ChunkBiomeContainer<BiomeBase> base) {
|
||||
return new BiomeContainer() {
|
||||
private MCABiomeContainer getBiomeContainerInterface(MCAIdMap<BiomeBase> biomeMapping, MCAChunkBiomeContainer<BiomeBase> base) {
|
||||
return new MCABiomeContainer() {
|
||||
@Override
|
||||
public int[] getData() {
|
||||
return base.writeBiomes();
|
||||
|
@ -20,8 +20,8 @@ package com.volmit.iris.core.nms.v1X;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
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.Location;
|
||||
import org.bukkit.World;
|
||||
@ -137,14 +137,14 @@ public class NMSBinding1X implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max) {
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max) {
|
||||
Iris.error("Cannot use the custom biome data! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max, int[] v) {
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max, int[] v) {
|
||||
Iris.error("Cannot use the custom biome data! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
|
||||
return null;
|
||||
@ -161,7 +161,7 @@ public class NMSBinding1X implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteAccess createPalette() {
|
||||
public MCAPaletteAccess createPalette() {
|
||||
Iris.error("Cannot use the global data palette! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
return null;
|
||||
}
|
||||
|
@ -223,6 +223,11 @@ public class IrisPregenerator {
|
||||
listener.onRegionGenerating(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkCleaned(int x, int z) {
|
||||
listener.onChunkCleaned(x, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegionSkipped(int x, int z) {
|
||||
listener.onRegionSkipped(x, z);
|
||||
|
@ -29,6 +29,8 @@ public interface PregenListener {
|
||||
|
||||
void onRegionGenerating(int x, int z);
|
||||
|
||||
void onChunkCleaned(int x, int z);
|
||||
|
||||
void onRegionSkipped(int x, int z);
|
||||
|
||||
void onNetworkStarted(int x, int z);
|
||||
|
@ -18,20 +18,31 @@
|
||||
|
||||
package com.volmit.iris.core.pregenerator;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.gui.PregeneratorJob;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.mantle.Mantle;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.math.Spiraled;
|
||||
import com.volmit.iris.util.math.Spiraler;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class PregenTask {
|
||||
private static final KList<Position2> order = computeChunkOrder();
|
||||
private static final Position2 ZERO = new Position2(0,0);
|
||||
private static final KList<Position2> ORDER_CENTER = computeChunkOrder();
|
||||
private static final KMap<Position2, KList<Position2>> ORDERS = new KMap<>();
|
||||
|
||||
@Builder.Default
|
||||
private Position2 center = new Position2(0, 0);
|
||||
@Builder.Default
|
||||
@ -39,12 +50,32 @@ public class PregenTask {
|
||||
@Builder.Default
|
||||
private int height = 1;
|
||||
|
||||
public static void iterateRegion(int xr, int zr, Spiraled s) {
|
||||
for (Position2 i : order) {
|
||||
public static void iterateRegion(int xr, int zr, Spiraled s, Position2 pull) {
|
||||
for (Position2 i : ORDERS.computeIfAbsent(pull, PregenTask::computeOrder)) {
|
||||
s.on(i.getX() + (xr << 5), i.getZ() + (zr << 5));
|
||||
}
|
||||
}
|
||||
|
||||
public static void iterateRegion(int xr, int zr, Spiraled s) {
|
||||
iterateRegion(xr, zr, s, new Position2(0,0));
|
||||
}
|
||||
|
||||
private static KList<Position2> computeOrder(Position2 pull) {
|
||||
KList<Position2> p = new KList<>();
|
||||
new Spiraler(33, 33, (x, z) -> {
|
||||
int xx = (x + 15);
|
||||
int zz = (z + 15);
|
||||
if (xx < 0 || xx > 31 || zz < 0 || zz > 31) {
|
||||
return;
|
||||
}
|
||||
|
||||
p.add(new Position2(xx, zz));
|
||||
}).drain();
|
||||
p.sort(Comparator.comparing((i) -> i.distance(pull)));
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
private static KList<Position2> computeChunkOrder() {
|
||||
Position2 center = new Position2(15, 15);
|
||||
KList<Position2> p = new KList<>();
|
||||
|
@ -70,6 +70,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
|
||||
try {
|
||||
PaperLib.getChunkAtAsync(world, x, z, true).get();
|
||||
listener.onChunkGenerated(x, z);
|
||||
listener.onChunkCleaned(x, z);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
J.sleep(5);
|
||||
|
@ -105,6 +105,7 @@ public class MedievalPregenMethod implements PregeneratorMethod {
|
||||
futures.add(J.sfut(() -> {
|
||||
world.getChunkAt(x, z);
|
||||
listener.onChunkGenerated(x, z);
|
||||
listener.onChunkCleaned(x, z);
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -212,6 +212,11 @@ public class SyndicateServer extends Thread implements PregenListener {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkCleaned(int x, int z) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegionSkipped(int x, int z) {
|
||||
|
||||
|
@ -27,6 +27,7 @@ import com.volmit.iris.core.pregenerator.PregeneratorMethod;
|
||||
import com.volmit.iris.core.pregenerator.methods.HeadlessPregenMethod;
|
||||
import com.volmit.iris.core.pregenerator.methods.HybridPregenMethod;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.object.IrisDimension;
|
||||
import com.volmit.iris.engine.platform.HeadlessGenerator;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
@ -120,8 +121,8 @@ public class IrisToolbelt {
|
||||
* @param method the method to execute the task
|
||||
* @return the pregenerator job (already started)
|
||||
*/
|
||||
public static PregeneratorJob pregenerate(PregenTask task, PregeneratorMethod method) {
|
||||
return new PregeneratorJob(task, method);
|
||||
public static PregeneratorJob pregenerate(PregenTask task, PregeneratorMethod method, Engine engine) {
|
||||
return new PregeneratorJob(task, method, engine);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,11 +135,11 @@ public class IrisToolbelt {
|
||||
*/
|
||||
public static PregeneratorJob pregenerate(PregenTask task, PlatformChunkGenerator gen) {
|
||||
if (gen.isHeadless()) {
|
||||
return pregenerate(task, new HeadlessPregenMethod(((HeadlessGenerator) gen).getWorld(), (HeadlessGenerator) gen));
|
||||
return pregenerate(task, new HeadlessPregenMethod(((HeadlessGenerator) gen).getWorld(), (HeadlessGenerator) gen), gen.getEngine());
|
||||
}
|
||||
|
||||
return pregenerate(task, new HybridPregenMethod(gen.getEngine().getWorld().realWorld(),
|
||||
IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())));
|
||||
IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())), gen.getEngine());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,7 +155,7 @@ public class IrisToolbelt {
|
||||
return pregenerate(task, access(world));
|
||||
}
|
||||
|
||||
return pregenerate(task, new HybridPregenMethod(world, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())));
|
||||
return pregenerate(task, new HybridPregenMethod(world, IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())), null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,7 @@ import com.google.gson.Gson;
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.events.IrisEngineHotloadEvent;
|
||||
import com.volmit.iris.core.gui.PregeneratorJob;
|
||||
import com.volmit.iris.core.project.IrisProject;
|
||||
import com.volmit.iris.core.service.PreservationSVC;
|
||||
import com.volmit.iris.engine.actuator.IrisBiomeActuator;
|
||||
@ -55,11 +56,13 @@ import com.volmit.iris.util.atomics.AtomicRollingSequence;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.documentation.BlockCoordinates;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
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.matter.MatterCavern;
|
||||
@ -389,6 +392,7 @@ public class IrisEngine implements Engine {
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
PregeneratorJob.shutdownInstance();
|
||||
closed = true;
|
||||
J.car(art);
|
||||
getWorldManager().close();
|
||||
@ -458,6 +462,18 @@ public class IrisEngine implements Engine {
|
||||
mode.generate(x, z, blocks, vbiomes, multicore);
|
||||
}
|
||||
|
||||
if(!multicore)
|
||||
{
|
||||
for(int i = 0; i < 16; i++)
|
||||
{
|
||||
for(int j = 0; j < 16; j++)
|
||||
{
|
||||
blocks.set(i, 255, j, B.get("GLASS"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getMantle().getMantle().flag(x>>4, z>>4, MantleFlag.REAL, true);
|
||||
getMetrics().getTotal().put(p.getMilliseconds());
|
||||
generated.incrementAndGet();
|
||||
recycle();
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.engine;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineAssignedWorldManager;
|
||||
@ -41,6 +42,8 @@ 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.matter.MatterCavern;
|
||||
import com.volmit.iris.util.matter.MatterFluidBody;
|
||||
import com.volmit.iris.util.matter.MatterMarker;
|
||||
import com.volmit.iris.util.plugin.Chunks;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
@ -49,6 +52,7 @@ import com.volmit.iris.util.scheduling.Looper;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -270,6 +274,11 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
}
|
||||
|
||||
private void spawnIn(Chunk c, boolean initial) {
|
||||
if(getEngine().isClosed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (initial) {
|
||||
energy += 1.2;
|
||||
}
|
||||
@ -458,11 +467,22 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
|
||||
|
||||
@Override
|
||||
public void onChunkLoad(Chunk e, boolean generated) {
|
||||
if(getEngine().isClosed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
energy += 0.3;
|
||||
fixEnergy();
|
||||
getEngine().cleanupMantleChunk(e.getX(), e.getZ());
|
||||
}
|
||||
|
||||
private void spawn(IrisPosition block, IrisSpawner spawner, boolean initial) {
|
||||
if(getEngine().isClosed())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (spawner == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.engine.framework;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.gui.components.RenderType;
|
||||
import com.volmit.iris.core.gui.components.Renderer;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
@ -60,6 +61,7 @@ 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.MatterCavern;
|
||||
import com.volmit.iris.util.matter.MatterFluidBody;
|
||||
import com.volmit.iris.util.matter.MatterUpdate;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
@ -902,4 +904,12 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
|
||||
|
||||
Locator.region(r.getLoadKey()).find(player);
|
||||
}
|
||||
|
||||
default void cleanupMantleChunk(int x, int z)
|
||||
{
|
||||
if(IrisSettings.get().getPerformance().isTrimMantleInStudio() || !isStudio())
|
||||
{
|
||||
J.a(() -> getMantle().cleanupChunk(x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.engine.mantle;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.loader.IrisData;
|
||||
import com.volmit.iris.engine.IrisComplex;
|
||||
@ -40,13 +41,17 @@ import com.volmit.iris.util.mantle.MantleChunk;
|
||||
import com.volmit.iris.util.mantle.MantleFlag;
|
||||
import com.volmit.iris.util.matter.Matter;
|
||||
import com.volmit.iris.util.matter.MatterCavern;
|
||||
import com.volmit.iris.util.matter.MatterFluidBody;
|
||||
import com.volmit.iris.util.matter.MatterMarker;
|
||||
import com.volmit.iris.util.matter.slices.UpdateMatter;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.block.TileState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
// TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING
|
||||
@ -207,17 +212,18 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
int zz = j + z;
|
||||
burst.queue(() -> {
|
||||
IrisContext.touch(getEngine().getContext());
|
||||
MantleChunk mc = getMantle().getChunk(xx, zz);
|
||||
getMantle().raiseFlag(xx, zz, MantleFlag.PLANNED, () -> {
|
||||
MantleChunk mc = getMantle().getChunk(xx, zz);
|
||||
|
||||
for (MantleComponent k : getComponents()) {
|
||||
generateMantleComponent(writer, xx, zz, k, mc);
|
||||
}
|
||||
for (MantleComponent k : getComponents()) {
|
||||
generateMantleComponent(writer, xx, zz, k, mc);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
burst.complete();
|
||||
getMantle().flag(x, z, MantleFlag.REAL, true);
|
||||
}
|
||||
|
||||
default void generateMantleComponent(MantleWriter writer, int x, int z, MantleComponent c, MantleChunk mc) {
|
||||
@ -262,4 +268,35 @@ public interface EngineMantle extends IObjectPlacer {
|
||||
MantleJigsawComponent getJigsawComponent();
|
||||
|
||||
MantleObjectComponent getObjectComponent();
|
||||
|
||||
default boolean isCovered(int x, int z)
|
||||
{
|
||||
int s = getRealRadius();
|
||||
|
||||
for (int i = -s; i <= s; i++) {
|
||||
for (int j = -s; j <= s; j++) {
|
||||
int xx = i + x;
|
||||
int zz = j + z;
|
||||
if(!getMantle().hasFlag(xx, zz, MantleFlag.REAL))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
default void cleanupChunk(int x, int z)
|
||||
{
|
||||
if(!getMantle().hasFlag(x, z, MantleFlag.CLEANED) && isCovered(x, z))
|
||||
{
|
||||
getMantle().raiseFlag(x, z, MantleFlag.CLEANED, () -> {
|
||||
getMantle().deleteChunkSlice(x, z, BlockData.class);
|
||||
getMantle().deleteChunkSlice(x, z, String.class);
|
||||
getMantle().deleteChunkSlice(x, z, MatterCavern.class);
|
||||
getMantle().deleteChunkSlice(x, z, MatterFluidBody.class);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
|
||||
@BlockCoordinates
|
||||
private void placeObject(MantleWriter writer, RNG rng, int x, int z, IrisObjectPlacement objectPlacement) {
|
||||
for (int i = 0; i < objectPlacement.getDensity(); i++) {
|
||||
for (int i = 0; i < objectPlacement.getDensity(rng, x, z, getData()); i++) {
|
||||
IrisObject v = objectPlacement.getScale().get(rng, objectPlacement.getObject(getComplex(), rng));
|
||||
if (v == null) {
|
||||
return;
|
||||
@ -104,7 +104,7 @@ public class MantleObjectComponent extends IrisMantleComponent {
|
||||
@BlockCoordinates
|
||||
private Set<String> guessPlacedKeys(RNG rng, int x, int z, IrisObjectPlacement objectPlacement) {
|
||||
Set<String> f = new KSet<>();
|
||||
for (int i = 0; i < objectPlacement.getDensity(); i++) {
|
||||
for (int i = 0; i < objectPlacement.getDensity(rng, x, z, getData()); i++) {
|
||||
IrisObject v = objectPlacement.getScale().get(rng, objectPlacement.getObject(getComplex(), rng));
|
||||
if (v == null) {
|
||||
continue;
|
||||
|
@ -62,7 +62,6 @@ public class IrisObjectPlacement {
|
||||
private IrisObjectRotation rotation = new IrisObjectRotation();
|
||||
@Desc("Limit the max height or min height of placement.")
|
||||
private IrisObjectLimit clamp = new IrisObjectLimit();
|
||||
|
||||
@MinNumber(0)
|
||||
@MaxNumber(1)
|
||||
@Desc("The maximum layer level of a snow filter overtop of this placement. Set to 0 to disable. Max of 1.")
|
||||
@ -74,6 +73,8 @@ public class IrisObjectPlacement {
|
||||
@MinNumber(1)
|
||||
@Desc("If the chance check passes, place this many in a single chunk")
|
||||
private int density = 1;
|
||||
@Desc("If the chance check passes, and you specify this, it picks a number in the range based on noise, and 'density' is ignored.")
|
||||
private IrisStyledRange densityStyle = null;
|
||||
@MaxNumber(64)
|
||||
@MinNumber(0)
|
||||
@Desc("If the place mode is set to stilt, you can over-stilt it even further into the ground. Especially useful when using fast stilt due to inaccuracies.")
|
||||
@ -164,18 +165,6 @@ public class IrisObjectPlacement {
|
||||
return getSurfaceWarp(rng, data).fitDouble(-(getWarp().getMultiplier() / 2D), (getWarp().getMultiplier() / 2D), x, y, z);
|
||||
}
|
||||
|
||||
public int getTriesForChunk(RNG random) {
|
||||
if (chance <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (chance >= 1 || random.nextDouble() < chance) {
|
||||
return density;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public IrisObject getObject(DataProvider g, RNG random) {
|
||||
if (place.isEmpty()) {
|
||||
return null;
|
||||
@ -194,6 +183,21 @@ public class IrisObjectPlacement {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getDensity() {
|
||||
if (densityStyle == null) {
|
||||
return density;
|
||||
}
|
||||
return densityStyle.getMid();
|
||||
}
|
||||
|
||||
public int getDensity(RNG rng, double x, double z, IrisData data) {
|
||||
if (densityStyle == null) {
|
||||
return density;
|
||||
}
|
||||
|
||||
return (int) Math.round(densityStyle.get(rng, x, z, data));
|
||||
}
|
||||
|
||||
private TableCache getCache(IrisData manager) {
|
||||
return cache.aquire(() -> {
|
||||
TableCache tc = new TableCache();
|
||||
|
@ -29,6 +29,7 @@ import com.volmit.iris.engine.framework.Engine;
|
||||
import com.volmit.iris.engine.framework.EngineTarget;
|
||||
import com.volmit.iris.engine.object.HeadlessWorld;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KSet;
|
||||
import com.volmit.iris.util.documentation.ChunkCoordinates;
|
||||
import com.volmit.iris.util.documentation.RegionCoordinates;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
@ -40,6 +41,7 @@ import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.parallel.BurstExecutor;
|
||||
import com.volmit.iris.util.parallel.MultiBurst;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import lombok.Data;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
@ -48,6 +50,8 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Data
|
||||
@ -59,6 +63,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
private final MultiBurst burst;
|
||||
private final Engine engine;
|
||||
private final long rkey = RNG.r.lmax();
|
||||
private List<Position2> last = new KList<>();
|
||||
|
||||
public HeadlessGenerator(HeadlessWorld world) {
|
||||
this(world, new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), world.isStudio()));
|
||||
@ -83,7 +88,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
.injector((xx, yy, zz, biomeBase) -> chunk.setBiomeAt(ox + xx, yy, oz + zz,
|
||||
INMS.get().getTrueBiomeBaseId(biomeBase)))
|
||||
.build();
|
||||
getEngine().generate(x * 16, z * 16,
|
||||
getEngine().generate(x << 4, z << 4,
|
||||
Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc),
|
||||
false);
|
||||
chunk.cleanupPalettesAndBlockStates();
|
||||
@ -124,11 +129,29 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
|
||||
if (listener != null) {
|
||||
listener.onChunkGenerated(ii, jj);
|
||||
}
|
||||
}));
|
||||
|
||||
}), avgLast(x, z));
|
||||
last.add(new Position2(x, z));
|
||||
e.complete();
|
||||
}
|
||||
|
||||
private Position2 avgLast(int x, int z) {
|
||||
while(last.size() > 3)
|
||||
{
|
||||
last.remove(0);
|
||||
}
|
||||
|
||||
double xx = 0;
|
||||
double zz = 0;
|
||||
|
||||
for(Position2 i : last)
|
||||
{
|
||||
xx += 27 * (i.getX() - x);
|
||||
zz += 27 * (i.getZ() - z);
|
||||
}
|
||||
|
||||
return new Position2((int)xx, (int)zz);
|
||||
}
|
||||
|
||||
@RegionCoordinates
|
||||
public File generateRegionToFile(int x, int z, PregenListener listener) {
|
||||
generateRegion(x, z, listener);
|
||||
|
@ -399,6 +399,17 @@ public class B {
|
||||
public static BlockData getOrNull(String bdxf) {
|
||||
try {
|
||||
String bd = bdxf.trim();
|
||||
|
||||
if(bd.startsWith("minecraft:cauldron[level="))
|
||||
{
|
||||
bd = bd.replaceAll("\\Q:cauldron[\\E", ":water_cauldron[");
|
||||
}
|
||||
|
||||
if(bd.equals("minecraft:grass_path"))
|
||||
{
|
||||
return DIRT_PATH.createBlockData();
|
||||
}
|
||||
|
||||
BlockData bdx = parseBlockData(bd);
|
||||
|
||||
if (bdx == null) {
|
||||
|
@ -27,20 +27,25 @@ import java.util.function.Function;
|
||||
|
||||
public class KCache<K,V> implements MeteredCache {
|
||||
private long max;
|
||||
private CacheLoader<? super K, ? extends V> loader;
|
||||
private CacheLoader<K, V> loader;
|
||||
private LoadingCache<K, V> cache;
|
||||
|
||||
public KCache(CacheLoader<K, V> loader, long max)
|
||||
{
|
||||
this.max = max;
|
||||
this.loader = loader;
|
||||
this.cache = Caffeine
|
||||
this.cache = create(loader);
|
||||
}
|
||||
|
||||
private LoadingCache<K,V> create(CacheLoader<K,V> loader) {
|
||||
return Caffeine
|
||||
.newBuilder()
|
||||
.maximumSize(max)
|
||||
.build((k) -> loader == null ? null : loader.load(k));
|
||||
}
|
||||
|
||||
public void setLoader(CacheLoader<? super K, ? extends V> loader)
|
||||
|
||||
public void setLoader(CacheLoader<K, V> loader)
|
||||
{
|
||||
this.loader = loader;
|
||||
}
|
||||
@ -52,8 +57,9 @@ public class KCache<K,V> implements MeteredCache {
|
||||
|
||||
public void invalidate()
|
||||
{
|
||||
cache.invalidateAll();
|
||||
cache.cleanUp();
|
||||
LoadingCache<?,?> c = cache;
|
||||
cache = create(loader);
|
||||
c.invalidateAll();
|
||||
}
|
||||
|
||||
public V get(K k)
|
||||
|
180
src/main/java/com/volmit/iris/util/data/palette/BitStorage.java
Normal file
180
src/main/java/com/volmit/iris/util/data/palette/BitStorage.java
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.data.palette;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicLongArray;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public class BitStorage {
|
||||
private static final int[] MAGIC = new int[]{
|
||||
-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE,
|
||||
0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756,
|
||||
0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0,
|
||||
390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378,
|
||||
306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 0, 3, 252645135, 252645135,
|
||||
0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0,
|
||||
204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970,
|
||||
178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862,
|
||||
0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0,
|
||||
138547332, 138547332, 0, Integer.MIN_VALUE, 0, 4, 130150524, 130150524, 0, 126322567,
|
||||
126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197,
|
||||
0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0,
|
||||
104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893,
|
||||
97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282,
|
||||
0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0,
|
||||
84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431,
|
||||
79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303,
|
||||
0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0,
|
||||
70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE,
|
||||
0, 5};
|
||||
|
||||
private final AtomicLongArray data;
|
||||
private final int bits;
|
||||
private final long mask;
|
||||
private final int size;
|
||||
private final int valuesPerLong;
|
||||
private final int divideMul;
|
||||
private final int divideAdd;
|
||||
private final int divideShift;
|
||||
|
||||
public BitStorage(int bits, int length) {
|
||||
this(bits, length, (AtomicLongArray) null);
|
||||
}
|
||||
|
||||
private static AtomicLongArray atomic(long[] data)
|
||||
{
|
||||
if(data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
AtomicLongArray d = new AtomicLongArray(data.length);
|
||||
for(int i = 0; i < data.length; i++)
|
||||
{
|
||||
d.set(i, data[i]);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
private static long[] atomic(AtomicLongArray data)
|
||||
{
|
||||
if(data == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
long[] d = new long[data.length()];
|
||||
for(int i = 0; i < data.length(); i++)
|
||||
{
|
||||
d[i] = data.get(i);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
public BitStorage(int bits, int length, long[] data) {
|
||||
this(bits, length, atomic(data));
|
||||
}
|
||||
|
||||
public BitStorage(int bits, int length, AtomicLongArray data) {
|
||||
Validate.inclusiveBetween(1L, 32L, bits);
|
||||
this.size = length;
|
||||
this.bits = bits;
|
||||
this.mask = (1L << bits) - 1L;
|
||||
this.valuesPerLong = (char) (64 / bits);
|
||||
int var3 = 3 * (this.valuesPerLong - 1);
|
||||
this.divideMul = MAGIC[var3 + 0];
|
||||
this.divideAdd = MAGIC[var3 + 1];
|
||||
this.divideShift = MAGIC[var3 + 2];
|
||||
int var4 = (length + this.valuesPerLong - 1) / this.valuesPerLong;
|
||||
if (data != null) {
|
||||
if (data.length() != var4)
|
||||
{
|
||||
throw new RuntimeException("NO!");
|
||||
}
|
||||
this.data = data;
|
||||
} else {
|
||||
this.data = new AtomicLongArray(var4);
|
||||
}
|
||||
}
|
||||
|
||||
private int cellIndex(int var0) {
|
||||
long var1 = Integer.toUnsignedLong(this.divideMul);
|
||||
long var3 = Integer.toUnsignedLong(this.divideAdd);
|
||||
return (int) (var0 * var1 + var3 >> 32L >> this.divideShift);
|
||||
}
|
||||
|
||||
public int getAndSet(int var0, int var1) {
|
||||
Validate.inclusiveBetween(0L, (this.size - 1), var0);
|
||||
Validate.inclusiveBetween(0L, this.mask, var1);
|
||||
int var2 = cellIndex(var0);
|
||||
long var3 = this.data.get(var2);
|
||||
int var5 = (var0 - var2 * this.valuesPerLong) * this.bits;
|
||||
int var6 = (int) (var3 >> var5 & this.mask);
|
||||
this.data.set(var2, var3 & (this.mask << var5 ^ 0xFFFFFFFFFFFFFFFFL) | (var1 & this.mask) << var5);
|
||||
return var6;
|
||||
}
|
||||
|
||||
public void set(int var0, int var1) {
|
||||
Validate.inclusiveBetween(0L, (this.size - 1), var0);
|
||||
Validate.inclusiveBetween(0L, this.mask, var1);
|
||||
int var2 = cellIndex(var0);
|
||||
long var3 = this.data.get(var2);
|
||||
int var5 = (var0 - var2 * this.valuesPerLong) * this.bits;
|
||||
this.data.set(var2, var3 & (this.mask << var5 ^ 0xFFFFFFFFFFFFFFFFL) | (var1 & this.mask) << var5);
|
||||
}
|
||||
|
||||
public int get(int var0) {
|
||||
Validate.inclusiveBetween(0L, (this.size - 1), var0);
|
||||
int var1 = cellIndex(var0);
|
||||
long var2 = this.data.get(var1);
|
||||
int var4 = (var0 - var1 * this.valuesPerLong) * this.bits;
|
||||
return (int) (var2 >> var4 & this.mask);
|
||||
}
|
||||
|
||||
public long[] getRaw() {
|
||||
return atomic(data);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public int getBits() {
|
||||
return this.bits;
|
||||
}
|
||||
|
||||
public void getAll(IntConsumer var0) {
|
||||
int var1 = 0;
|
||||
for(int i = 0; i < data.length(); i++)
|
||||
{
|
||||
long var5 = data.get(i);
|
||||
for (int var7 = 0; var7 < this.valuesPerLong; var7++) {
|
||||
var0.accept((int) (var5 & this.mask));
|
||||
var5 >>= this.bits;
|
||||
if (++var1 >= this.size)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface CountConsumer<T> {
|
@ -0,0 +1,204 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.data.palette;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicIntegerArray;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
|
||||
public static final int NOT_FOUND = -1;
|
||||
|
||||
private static final Object EMPTY_SLOT = null;
|
||||
|
||||
private static final float LOADFACTOR = 0.8F;
|
||||
|
||||
private AtomicReferenceArray<K> keys;
|
||||
|
||||
private AtomicIntegerArray values;
|
||||
|
||||
private AtomicReferenceArray<K> byId;
|
||||
|
||||
private int nextId;
|
||||
|
||||
private int size;
|
||||
|
||||
public CrudeIncrementalIntIdentityHashBiMap(int var0) {
|
||||
var0 = (int) (var0 / 0.8F);
|
||||
this.keys = new AtomicReferenceArray<>(var0);
|
||||
this.values = new AtomicIntegerArray(var0);
|
||||
this.byId = new AtomicReferenceArray<>(var0);
|
||||
}
|
||||
|
||||
public int getId(K var0) {
|
||||
return getValue(indexOf(var0, hash(var0)));
|
||||
}
|
||||
|
||||
|
||||
public K byId(int var0) {
|
||||
if (var0 < 0 || var0 >= this.byId.length())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return this.byId.get(var0);
|
||||
}
|
||||
|
||||
private int getValue(int var0) {
|
||||
if (var0 == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return this.values.get(var0);
|
||||
}
|
||||
|
||||
public boolean contains(K var0) {
|
||||
return (getId(var0) != -1);
|
||||
}
|
||||
|
||||
public boolean contains(int var0) {
|
||||
return (byId(var0) != null);
|
||||
}
|
||||
|
||||
public int add(K var0) {
|
||||
int var1 = nextId();
|
||||
addMapping(var0, var1);
|
||||
return var1;
|
||||
}
|
||||
|
||||
private int nextId() {
|
||||
while (nextId < byId.length() && byId.get(nextId) != null)
|
||||
{
|
||||
nextId++;
|
||||
}
|
||||
return nextId;
|
||||
}
|
||||
|
||||
private void grow(int var0) {
|
||||
AtomicReferenceArray<K> var1 = this.keys;
|
||||
AtomicIntegerArray var2 = this.values;
|
||||
this.keys = new AtomicReferenceArray<>(var0);
|
||||
this.values = new AtomicIntegerArray(var0);
|
||||
this.byId = new AtomicReferenceArray<>(var0);
|
||||
this.nextId = 0;
|
||||
this.size = 0;
|
||||
for (int var3 = 0; var3 < var1.length(); var3++) {
|
||||
if (var1.get(var3) != null)
|
||||
{
|
||||
addMapping(var1.get(var3), var2.get(var3));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addMapping(K var0, int var1) {
|
||||
int var2 = Math.max(var1, this.size + 1);
|
||||
if (var2 >= this.keys.length() * 0.8F) {
|
||||
int i = this.keys.length() << 1;
|
||||
while (i < var1)
|
||||
i <<= 1;
|
||||
grow(i);
|
||||
}
|
||||
int var3 = findEmpty(hash(var0));
|
||||
this.keys.set(var3, var0);
|
||||
this.values.set(var3, var1);
|
||||
this.byId.set(var1, var0);
|
||||
this.size++;
|
||||
if (var1 == this.nextId)
|
||||
this.nextId++;
|
||||
}
|
||||
|
||||
private int hash(K var0) {
|
||||
return (Mth.murmurHash3Mixer(System.identityHashCode(var0)) & Integer.MAX_VALUE) % this.keys.length();
|
||||
}
|
||||
|
||||
private int indexOf(K var0, int var1) {
|
||||
int var2;
|
||||
for (var2 = var1; var2 < this.keys.length(); var2++) {
|
||||
if (this.keys.get(var2) == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (this.keys.get(var2).equals(var0))
|
||||
return var2;
|
||||
if (this.keys.get(var2) == EMPTY_SLOT)
|
||||
return -1;
|
||||
}
|
||||
for (var2 = 0; var2 < var1; var2++) {
|
||||
if (this.keys.get(var2).equals(var0))
|
||||
return var2;
|
||||
if (this.keys.get(var2) == EMPTY_SLOT)
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findEmpty(int var0) {
|
||||
int var1;
|
||||
for (var1 = var0; var1 < this.keys.length(); var1++) {
|
||||
if (this.keys.get(var1) == EMPTY_SLOT)
|
||||
return var1;
|
||||
}
|
||||
for (var1 = 0; var1 < var0; var1++) {
|
||||
if (this.keys.get(var1) == EMPTY_SLOT)
|
||||
return var1;
|
||||
}
|
||||
throw new RuntimeException("Overflowed :(");
|
||||
}
|
||||
|
||||
public Iterator<K> iterator() {
|
||||
return Iterators.filter(new Iterator<K>(){
|
||||
int i = 0;
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return i < byId.length()-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public K next() {
|
||||
return byId.get(i++);
|
||||
}
|
||||
}, Objects::nonNull);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
||||
for(int i = 0; i < Math.max(keys.length(), byId.length()); i++)
|
||||
{
|
||||
if(i < keys.length() - 1)
|
||||
{
|
||||
keys.set(i, null);
|
||||
}
|
||||
|
||||
if(i < byId.length() - 1)
|
||||
{
|
||||
byId.set(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
this.nextId = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.size;
|
||||
}
|
||||
}
|
@ -16,10 +16,11 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class GlobalPalette<T> implements Palette<T> {
|
||||
@ -27,6 +28,17 @@ public class GlobalPalette<T> implements Palette<T> {
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
public GlobalPalette(T... f)
|
||||
{
|
||||
IdMapper<T> mapper = new IdMapper<>();
|
||||
for(T i : f)
|
||||
{
|
||||
mapper.add(i);
|
||||
}
|
||||
registry = mapper;
|
||||
defaultValue = f[0];
|
||||
}
|
||||
|
||||
public GlobalPalette(IdMapper<T> var0, T var1) {
|
||||
this.registry = var0;
|
||||
this.defaultValue = var1;
|
||||
@ -50,6 +62,13 @@ public class GlobalPalette<T> implements Palette<T> {
|
||||
return this.registry.size();
|
||||
}
|
||||
|
||||
public void read(ListTag var0) {
|
||||
@Override
|
||||
public void read(List<T> fromList) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<T> toList) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.data.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class HashMapPalette<T> implements Palette<T> {
|
||||
private final CrudeIncrementalIntIdentityHashBiMap<T> values;
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
private final int bits;
|
||||
|
||||
public HashMapPalette(int var1, PaletteResize<T> var2) {
|
||||
this.bits = var1;
|
||||
this.resizeHandler = var2;
|
||||
this.values = new CrudeIncrementalIntIdentityHashBiMap<>(1 << var1);
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
int var1 = this.values.getId(var0);
|
||||
if (var1 == -1) {
|
||||
var1 = this.values.add(var0);
|
||||
if (var1 >= 1 << this.bits)
|
||||
{
|
||||
var1 = this.resizeHandler.onResize(this.bits + 1, var0);
|
||||
}
|
||||
}
|
||||
return var1;
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < getSize(); var1++) {
|
||||
if (var0.test(this.values.byId(var1)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
return this.values.byId(var0);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.values.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(List<T> data) {
|
||||
data.forEach(values::add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<T> toList) {
|
||||
this.values.iterator().forEachRemaining(i -> {
|
||||
if(i != null)
|
||||
{
|
||||
toList.add(i);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
public interface IdMap<T> extends Iterable<T> {
|
||||
int getId(T paramT);
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterators;
|
||||
@ -50,7 +50,9 @@ public class IdMapper<T> implements IdMap<T> {
|
||||
public void addMapping(T var0, int var1) {
|
||||
this.tToId.put(var0, Integer.valueOf(var1));
|
||||
while (this.idToT.size() <= var1)
|
||||
{
|
||||
this.idToT.add(null);
|
||||
}
|
||||
this.idToT.set(var1, var0);
|
||||
if (this.nextId <= var1)
|
||||
this.nextId = var1 + 1;
|
||||
@ -67,7 +69,9 @@ public class IdMapper<T> implements IdMap<T> {
|
||||
|
||||
public final T byId(int var0) {
|
||||
if (var0 >= 0 && var0 < this.idToT.size())
|
||||
{
|
||||
return this.idToT.get(var0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.data.palette;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class LinearPalette<T> implements Palette<T> {
|
||||
private final AtomicReferenceArray<T> values;
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
private final int bits;
|
||||
private int size;
|
||||
|
||||
public LinearPalette(int var1, PaletteResize<T> var2) {
|
||||
this.values = new AtomicReferenceArray<>(1 << var1);
|
||||
this.bits = var1;
|
||||
this.resizeHandler = var2;
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
int var1;
|
||||
for (var1 = 0; var1 < size; var1++) {
|
||||
if(values.get(var1) == null && var0 == null)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
|
||||
if (values.get(var1) != null && values.get(var1).equals(var0))
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
var1 = size;
|
||||
if (var1 < values.length()) {
|
||||
values.set(var1, var0);
|
||||
size++;
|
||||
return var1;
|
||||
}
|
||||
return resizeHandler.onResize(bits + 1, var0);
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < size; var1++) {
|
||||
if (var0.test(values.get(var1)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
if (var0 >= 0 && var0 < size)
|
||||
return this.values.get(var0);
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(List<T> fromList) {
|
||||
for (int i = 0; i < fromList.size(); i++)
|
||||
{
|
||||
values.set(i, fromList.get(i));
|
||||
}
|
||||
|
||||
size = fromList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<T> toList) {
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
T v = values.get(i);
|
||||
toList.add(v);
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
@ -16,10 +16,12 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface Palette<T> {
|
||||
@ -31,5 +33,7 @@ public interface Palette<T> {
|
||||
|
||||
int getSize();
|
||||
|
||||
void read(ListTag paramListTag);
|
||||
void read(List<T> fromList);
|
||||
|
||||
void write(List<T> toList);
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
interface PaletteResize<T> {
|
||||
int onResize(int paramInt, T paramT);
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.data.palette;
|
||||
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface PaletteType<T> {
|
||||
void writePaletteNode(DataOutputStream dos, T t) throws IOException;
|
||||
|
||||
T readPaletteNode(DataInputStream din) throws IOException;
|
||||
|
||||
default void writeList(DataOutputStream dos, List<T> list) throws IOException {
|
||||
Varint.writeUnsignedVarInt(list.size(), dos);
|
||||
for (T i : list) {
|
||||
writePaletteNode(dos, i);
|
||||
}
|
||||
}
|
||||
|
||||
default List<T> readList(DataInputStream din) throws IOException {
|
||||
int v = Varint.readUnsignedVarInt(din);
|
||||
List<T> t = new ArrayList<>();
|
||||
|
||||
for(int i = 0; i < v; i++)
|
||||
{
|
||||
t.add(readPaletteNode(din));
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.data.palette;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
public static final int GLOBAL_PALETTE_BITS = 9;
|
||||
public static final int MIN_PALETTE_SIZE = 4;
|
||||
private static final int SIZE = 4096;
|
||||
private final PaletteResize<T> dummyPaletteResize = (var0, var1) -> 0;
|
||||
protected BitStorage storage;
|
||||
private Palette<T> palette;
|
||||
private int bits;
|
||||
|
||||
public PalettedContainer() {
|
||||
setBits(4);
|
||||
}
|
||||
|
||||
private static int getIndex(int var0, int var1, int var2) {
|
||||
return var1 << 8 | var2 << 4 | var0;
|
||||
}
|
||||
|
||||
private void setBits(int var0) {
|
||||
if (var0 == this.bits)
|
||||
{
|
||||
return;
|
||||
}
|
||||
this.bits = var0;
|
||||
if (this.bits <= 4) {
|
||||
this.bits = 4;
|
||||
this.palette = new LinearPalette<>(this.bits, this);
|
||||
} else {
|
||||
this.palette = new HashMapPalette<>(this.bits, this);
|
||||
}
|
||||
|
||||
this.palette.idFor(null);
|
||||
this.storage = new BitStorage(this.bits, 4096);
|
||||
}
|
||||
|
||||
public int onResize(int var0, T var1) {
|
||||
BitStorage var2 = this.storage;
|
||||
Palette<T> var3 = this.palette;
|
||||
setBits(var0);
|
||||
for (int var4 = 0; var4 < var2.getSize(); var4++) {
|
||||
T var5 = var3.valueFor(var2.get(var4));
|
||||
if (var5 != null)
|
||||
set(var4, var5);
|
||||
}
|
||||
return this.palette.idFor(var1);
|
||||
}
|
||||
|
||||
public T getAndSet(int var0, int var1, int var2, T var3) {
|
||||
return getAndSet(getIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
public T getAndSetUnchecked(int var0, int var1, int var2, T var3) {
|
||||
return getAndSet(getIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
private T getAndSet(int var0, T var1) {
|
||||
int var2 = this.palette.idFor(var1);
|
||||
int var3 = this.storage.getAndSet(var0, var2);
|
||||
return this.palette.valueFor(var3);
|
||||
}
|
||||
|
||||
public void set(int var0, int var1, int var2, T var3) {
|
||||
set(getIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
private void set(int var0, T var1) {
|
||||
int var2 = this.palette.idFor(var1);
|
||||
this.storage.set(var0, var2);
|
||||
}
|
||||
|
||||
public T get(int var0, int var1, int var2) {
|
||||
return get(getIndex(var0, var1, var2));
|
||||
}
|
||||
|
||||
protected T get(int var0) {
|
||||
return this.palette.valueFor(this.storage.get(var0));
|
||||
}
|
||||
|
||||
public void read(List<T> palette, long[] data) {
|
||||
int var2 = Math.max(4, Mth.ceillog2(palette.size()));
|
||||
if (var2 != this.bits)
|
||||
{
|
||||
setBits(var2);
|
||||
}
|
||||
|
||||
this.palette.read(palette);
|
||||
int var3 = data.length * 64 / 4096;
|
||||
if (var3 == this.bits) {
|
||||
System.arraycopy(data, 0, this.storage.getRaw(), 0, data.length);
|
||||
} else {
|
||||
BitStorage var4 = new BitStorage(var3, 4096, data);
|
||||
for (int var5 = 0; var5 < 4096; var5++)
|
||||
{
|
||||
this.storage.set(var5, var4.get(var5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long[] write(List<T> toList) {
|
||||
HashMapPalette<T> var3 = new HashMapPalette<>(this.bits, this.dummyPaletteResize);
|
||||
T var4 = null;
|
||||
int var5 = 0;
|
||||
int[] var6 = new int[4096];
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
T t = get(i);
|
||||
if (t != var4) {
|
||||
var4 = t;
|
||||
var5 = var3.idFor(t);
|
||||
}
|
||||
var6[i] = var5;
|
||||
}
|
||||
|
||||
var3.write(toList);
|
||||
int var8 = Math.max(4, Mth.ceillog2(toList.size()));
|
||||
BitStorage var9 = new BitStorage(var8, 4096);
|
||||
for (int var10 = 0; var10 < var6.length; var10++) {
|
||||
var9.set(var10, var6[var10]);
|
||||
}
|
||||
return var9.getRaw();
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
return this.palette.maybeHas(var0);
|
||||
}
|
||||
|
||||
public void count(CountConsumer<T> var0) {
|
||||
Int2IntOpenHashMap int2IntOpenHashMap = new Int2IntOpenHashMap();
|
||||
this.storage.getAll(var1 -> int2IntOpenHashMap.put(var1, int2IntOpenHashMap.get(var1) + 1));
|
||||
int2IntOpenHashMap.int2IntEntrySet().forEach(var1 -> var0.accept(this.palette.valueFor(var1.getIntKey()), var1.getIntValue()));
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
package com.volmit.iris.util.data.palette;
|
||||
|
||||
public final class QuartPos {
|
||||
public static final int BITS = 2;
|
147
src/main/java/com/volmit/iris/util/format/MemoryMonitor.java
Normal file
147
src/main/java/com/volmit/iris/util/format/MemoryMonitor.java
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.format;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.math.RollingSequence;
|
||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||
import com.volmit.iris.util.scheduling.Looper;
|
||||
|
||||
public class MemoryMonitor {
|
||||
private Looper looper;
|
||||
private long usedMemory;
|
||||
private long garbageMemory;
|
||||
private long garbageLast;
|
||||
private long garbageBin;
|
||||
private long pressure;
|
||||
private ChronoLatch cl;
|
||||
private RollingSequence pressureAvg;
|
||||
private Runtime runtime;
|
||||
|
||||
public MemoryMonitor(int sampleDelay){
|
||||
this.runtime = Runtime.getRuntime();
|
||||
usedMemory = -1;
|
||||
pressureAvg = new RollingSequence(Math.max(Math.min(100, 1000/sampleDelay), 3));
|
||||
garbageBin = 0;
|
||||
garbageMemory = -1;
|
||||
cl = new ChronoLatch(1000);
|
||||
garbageLast = 0;
|
||||
pressure = 0;
|
||||
|
||||
looper = new Looper() {
|
||||
@Override
|
||||
protected long loop() {
|
||||
sample();
|
||||
return sampleDelay;
|
||||
}
|
||||
};
|
||||
looper.setPriority(Thread.MIN_PRIORITY);
|
||||
looper.setName("Memory Monitor");
|
||||
looper.start();
|
||||
}
|
||||
|
||||
public long getGarbageBytes()
|
||||
{
|
||||
return garbageMemory;
|
||||
}
|
||||
|
||||
public long getUsedBytes()
|
||||
{
|
||||
return usedMemory;
|
||||
}
|
||||
|
||||
public long getMaxBytes()
|
||||
{
|
||||
return runtime.maxMemory();
|
||||
}
|
||||
|
||||
public long getPressure()
|
||||
{
|
||||
return (long) pressureAvg.getAverage();
|
||||
}
|
||||
|
||||
public double getUsagePercent()
|
||||
{
|
||||
return usedMemory / (double)getMaxBytes();
|
||||
}
|
||||
|
||||
private void sample() {
|
||||
long used = getVMUse();
|
||||
if(usedMemory == -1)
|
||||
{
|
||||
usedMemory = used;
|
||||
garbageMemory = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if(used < usedMemory)
|
||||
{
|
||||
usedMemory = used;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
garbageMemory = used - usedMemory;
|
||||
}
|
||||
|
||||
long g = garbageMemory - garbageLast;
|
||||
|
||||
if(g >= 0)
|
||||
{
|
||||
garbageBin+= g;
|
||||
garbageLast = garbageMemory;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
garbageMemory = 0;
|
||||
garbageLast = 0;
|
||||
}
|
||||
|
||||
if(cl.flip())
|
||||
{
|
||||
if(garbageMemory > 0)
|
||||
{
|
||||
pressure = garbageBin;
|
||||
garbageBin = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
pressure = 0;
|
||||
garbageBin = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pressureAvg.put(pressure);
|
||||
}
|
||||
|
||||
private long getVMUse() {
|
||||
return runtime.totalMemory() - runtime.freeMemory();
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
if(looper != null)
|
||||
{
|
||||
looper.interrupt();
|
||||
looper = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.data.palette.PalettedContainer;
|
||||
import com.volmit.iris.util.function.Consumer4;
|
||||
import com.volmit.iris.util.function.Consumer4IO;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private PalettedContainer<T> data;
|
||||
|
||||
public PaletteHunk() {
|
||||
super(16, 16, 16);
|
||||
data = new PalettedContainer<>();
|
||||
}
|
||||
|
||||
public boolean isMapped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
for(int i = 0; i < getWidth(); i++)
|
||||
{
|
||||
for(int j = 0; j < getHeight(); j++)
|
||||
{
|
||||
for(int k = 0; k < getDepth(); k++)
|
||||
{
|
||||
T t = getRaw(i,j,k);
|
||||
if(t != null)
|
||||
{
|
||||
c.accept(i,j,k,t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
|
||||
for(int i = 0; i < getWidth(); i++)
|
||||
{
|
||||
for(int j = 0; j < getHeight(); j++)
|
||||
{
|
||||
for(int k = 0; k < getDepth(); k++)
|
||||
{
|
||||
T t = getRaw(i,j,k);
|
||||
if(t != null)
|
||||
{
|
||||
c.accept(i,j,k,t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
data.set(x,y,z,t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return data.get(x,y,z);
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.hunk.storage;
|
||||
|
||||
import com.volmit.iris.util.data.palette.PalettedContainer;
|
||||
import com.volmit.iris.util.function.Consumer4;
|
||||
import com.volmit.iris.util.function.Consumer4IO;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T> {
|
||||
private final Hunk<T> hunk;
|
||||
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory) {
|
||||
super(width, height, depth);
|
||||
hunk = (width == 16 && height == 16 && depth == 16 && allow) ? new PaletteHunk<>() : factory.get();
|
||||
}
|
||||
|
||||
public PalettedContainer<T> palette()
|
||||
{
|
||||
return isPalette() ? ((PaletteHunk<T>)hunk).getData() : null;
|
||||
}
|
||||
|
||||
public void palette(PalettedContainer<T> t)
|
||||
{
|
||||
if(isPalette()){
|
||||
((PaletteHunk<T>)hunk).setData(t);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPalette()
|
||||
{
|
||||
return getWidth() == 16 && getHeight() == 16 && getDepth() == 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRaw(int x, int y, int z, T t) {
|
||||
hunk.setRaw(x,y,z,t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getRaw(int x, int y, int z) {
|
||||
return hunk.getRaw(x,y,z);
|
||||
}
|
||||
|
||||
public int getEntryCount() {
|
||||
return hunk.getEntryCount();
|
||||
}
|
||||
|
||||
public boolean isMapped() {
|
||||
return hunk.isMapped();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return hunk.isMapped();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSync(Consumer4<Integer, Integer, Integer, T> c) {
|
||||
hunk.iterateSync(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Hunk<T> iterateSyncIO(Consumer4IO<Integer, Integer, Integer, T> c) throws IOException {
|
||||
hunk.iterateSyncIO(c);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void empty(T b) {
|
||||
hunk.empty(b);
|
||||
}
|
||||
}
|
@ -29,7 +29,9 @@ public enum MantleFlag {
|
||||
REAL,
|
||||
CARVED,
|
||||
FLUID_BODIES,
|
||||
INITIAL_SPAWNED_MARKER;
|
||||
INITIAL_SPAWNED_MARKER,
|
||||
CLEANED,
|
||||
PLANNED;
|
||||
|
||||
static StateList getStateList() {
|
||||
return new StateList(MantleFlag.values());
|
||||
|
@ -18,9 +18,15 @@
|
||||
|
||||
package com.volmit.iris.util.matter;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.engine.data.cache.Cache;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.data.palette.PaletteType;
|
||||
import com.volmit.iris.util.data.palette.PalettedContainer;
|
||||
import com.volmit.iris.util.hunk.Hunk;
|
||||
import com.volmit.iris.util.hunk.storage.PaletteOrHunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -30,10 +36,24 @@ import org.bukkit.util.BlockVector;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface MatterSlice<T> extends Hunk<T> {
|
||||
public interface MatterSlice<T> extends Hunk<T>, PaletteType<T> {
|
||||
Class<T> getType();
|
||||
|
||||
Palette<T> getGlobalPalette();
|
||||
|
||||
@Override
|
||||
default void writePaletteNode(DataOutputStream dos, T s) throws IOException {
|
||||
writeNode(s, dos);
|
||||
}
|
||||
|
||||
@Override
|
||||
default T readPaletteNode(DataInputStream din) throws IOException {
|
||||
return readNode(din);
|
||||
}
|
||||
|
||||
default void applyFilter(MatterFilter<T> filter) {
|
||||
updateSync(filter::update);
|
||||
}
|
||||
@ -131,9 +151,30 @@ public interface MatterSlice<T> extends Hunk<T> {
|
||||
}
|
||||
|
||||
default void write(DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(getType().getCanonicalName());
|
||||
if((this instanceof PaletteOrHunk f && f.isPalette()))
|
||||
{
|
||||
PalettedContainer<T> c = f.palette();
|
||||
List<T> palette = new ArrayList<>();
|
||||
long[] data = c.write(palette);
|
||||
|
||||
Varint.writeUnsignedVarInt(palette.size(), dos);
|
||||
for(T i : palette)
|
||||
{
|
||||
writeNode(i, dos);
|
||||
}
|
||||
|
||||
Varint.writeUnsignedVarInt(data.length, dos);
|
||||
for(long i : data)
|
||||
{
|
||||
dos.writeLong(i);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
dos.writeUTF(getType().getCanonicalName());
|
||||
MatterPalette<T> palette = new MatterPalette<T>(this);
|
||||
iterateSync((x, y, z, b) -> palette.assign(b));
|
||||
palette.writePalette(dos);
|
||||
@ -151,6 +192,29 @@ public interface MatterSlice<T> extends Hunk<T> {
|
||||
}
|
||||
|
||||
default void read(DataInputStream din) throws IOException {
|
||||
if((this instanceof PaletteOrHunk f && f.isPalette()))
|
||||
{
|
||||
PalettedContainer<T> c = new PalettedContainer<>();
|
||||
List<T> palette = new ArrayList<>();
|
||||
int ps = Varint.readUnsignedVarInt(din);
|
||||
|
||||
for(int i = 0; i < ps; i++)
|
||||
{
|
||||
palette.add(readNode(din));
|
||||
}
|
||||
|
||||
int ds = Varint.readUnsignedVarInt(din);
|
||||
long[] data = new long[ds];
|
||||
for(int i = 0; i < ds; i++)
|
||||
{
|
||||
data[i] = din.readLong();
|
||||
}
|
||||
|
||||
c.read(palette, data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
MatterPalette<T> palette = new MatterPalette<T>(this, din);
|
||||
|
@ -19,7 +19,9 @@
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.engine.object.IrisBiome;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Sliced
|
||||
public class BiomeMatter extends RegistryMatter<IrisBiome> {
|
||||
@ -27,6 +29,11 @@ public class BiomeMatter extends RegistryMatter<IrisBiome> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<IrisBiome> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BiomeMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, IrisBiome.class);
|
||||
}
|
||||
|
@ -19,9 +19,11 @@
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.B;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -33,6 +35,11 @@ public class BlockMatter extends RawMatter<BlockData> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<BlockData> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BlockMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, BlockData.class);
|
||||
registerWriter(World.class, ((w, d, x, y, z) -> w.getBlockAt(x, y, z).setBlockData(d)));
|
||||
|
@ -18,7 +18,9 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -30,6 +32,11 @@ public class BooleanMatter extends RawMatter<Boolean> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<Boolean> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public BooleanMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, Boolean.class);
|
||||
}
|
||||
|
@ -18,8 +18,10 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterCavern;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -31,6 +33,11 @@ public class CavernMatter extends RawMatter<MatterCavern> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterCavern> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public CavernMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterCavern.class);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import com.volmit.iris.engine.object.IrisPosition;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterEntity;
|
||||
import com.volmit.iris.util.matter.MatterEntityGroup;
|
||||
import com.volmit.iris.util.matter.MatterReader;
|
||||
@ -32,6 +33,7 @@ import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.BoundingBox;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@ -46,6 +48,11 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterEntityGroup> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public EntityMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterEntityGroup.class);
|
||||
registerWriter(World.class, ((w, d, x, y, z) -> {
|
||||
|
@ -18,8 +18,10 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterFluidBody;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -31,6 +33,11 @@ public class FluidBodyMatter extends RawMatter<MatterFluidBody> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterFluidBody> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public FluidBodyMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterFluidBody.class);
|
||||
}
|
||||
|
@ -19,7 +19,9 @@
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -31,6 +33,11 @@ public class IntMatter extends RawMatter<Integer> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<Integer> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public IntMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, Integer.class);
|
||||
}
|
||||
|
@ -19,7 +19,9 @@
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -31,6 +33,11 @@ public class LongMatter extends RawMatter<Long> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<Long> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public LongMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, Long.class);
|
||||
}
|
||||
|
@ -19,8 +19,10 @@
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterMarker;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -36,6 +38,11 @@ public class MarkerMatter extends RawMatter<MatterMarker> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterMarker> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MarkerMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterMarker.class);
|
||||
}
|
||||
|
@ -18,8 +18,10 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -30,6 +32,11 @@ public class NBTMatter<T extends Tag<?>> extends RawMatter<T> {
|
||||
super(width, height, depth, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<T> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNode(T b, DataOutputStream dos) throws IOException {
|
||||
NBTUtil.write(b, dos, false);
|
||||
|
@ -19,6 +19,8 @@
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.Varint;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterTile;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -34,6 +36,11 @@ public class PlayerMatter extends RawMatter<Player> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<Player> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public PlayerMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, Player.class);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.hunk.storage.MappedHunk;
|
||||
import com.volmit.iris.util.hunk.storage.PaletteOrHunk;
|
||||
import com.volmit.iris.util.matter.MatterReader;
|
||||
import com.volmit.iris.util.matter.MatterSlice;
|
||||
import com.volmit.iris.util.matter.MatterWriter;
|
||||
@ -29,14 +30,14 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class RawMatter<T> extends MappedHunk<T> implements MatterSlice<T> {
|
||||
public abstract class RawMatter<T> extends PaletteOrHunk<T> implements MatterSlice<T> {
|
||||
protected final KMap<Class<?>, MatterWriter<?, T>> writers;
|
||||
protected final KMap<Class<?>, MatterReader<?, T>> readers;
|
||||
@Getter
|
||||
private final Class<T> type;
|
||||
|
||||
public RawMatter(int width, int height, int depth, Class<T> type) {
|
||||
super(width, height, depth);
|
||||
super(width, height, depth, true, () -> new MappedHunk<>(width, height, depth));
|
||||
writers = new KMap<>();
|
||||
readers = new KMap<>();
|
||||
this.type = type;
|
||||
|
@ -20,6 +20,8 @@ package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterTile;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
@ -30,6 +32,11 @@ public class RegistryMatter<T extends IrisRegistrant> extends RawMatter<T> {
|
||||
super(width, height, depth, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<T> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNode(T b, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(b.getLoadKey());
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@ -34,6 +35,11 @@ public class StringMatter extends RawMatter<String> {
|
||||
super(width, height, depth, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<String> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeNode(String b, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(b);
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterTile;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
@ -36,6 +37,11 @@ public class TileMatter extends RawMatter<MatterTile> {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterTile> getGlobalPalette() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public TileMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterTile.class);
|
||||
registerWriter(World.class, ((w, d, x, y, z) -> INMS.get().deserializeTile(d.getTileData(), new Location(w, x, y, z))));
|
||||
|
@ -18,6 +18,9 @@
|
||||
|
||||
package com.volmit.iris.util.matter.slices;
|
||||
|
||||
import com.volmit.iris.util.data.palette.GlobalPalette;
|
||||
import com.volmit.iris.util.data.palette.Palette;
|
||||
import com.volmit.iris.util.matter.MatterTile;
|
||||
import com.volmit.iris.util.matter.MatterUpdate;
|
||||
import com.volmit.iris.util.matter.Sliced;
|
||||
|
||||
@ -29,11 +32,17 @@ import java.io.IOException;
|
||||
public class UpdateMatter extends RawMatter<MatterUpdate> {
|
||||
public static final MatterUpdate ON = new MatterUpdate(true);
|
||||
public static final MatterUpdate OFF = new MatterUpdate(false);
|
||||
private static final Palette<MatterUpdate> GLOBAL = new GlobalPalette<>(OFF, ON);
|
||||
|
||||
public UpdateMatter() {
|
||||
this(1, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Palette<MatterUpdate> getGlobalPalette() {
|
||||
return GLOBAL;
|
||||
}
|
||||
|
||||
public UpdateMatter(int width, int height, int depth) {
|
||||
super(width, height, depth, MatterUpdate.class);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.nbt.io.NBTDeserializer;
|
||||
import com.volmit.iris.util.nbt.io.NBTSerializer;
|
||||
import com.volmit.iris.util.nbt.io.NamedTag;
|
||||
import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
@ -46,7 +46,7 @@ public class Chunk {
|
||||
private int dataVersion;
|
||||
private long lastUpdate;
|
||||
private long inhabitedTime;
|
||||
private BiomeContainer biomes;
|
||||
private MCABiomeContainer biomes;
|
||||
private CompoundTag heightMaps;
|
||||
private CompoundTag carvingMasks;
|
||||
private ListTag<CompoundTag> entities;
|
||||
|
@ -18,12 +18,15 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.core.pregenerator.syndicate.SyndicateServer;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.math.Position2;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
@ -37,6 +40,7 @@ public class MCAFile {
|
||||
private final int regionX;
|
||||
private final int regionZ;
|
||||
private AtomicReferenceArray<Chunk> chunks;
|
||||
private ConcurrentLinkedQueue<Runnable> afterSave;
|
||||
|
||||
/**
|
||||
* MCAFile represents a world save file used by Minecraft to store world
|
||||
@ -50,6 +54,7 @@ public class MCAFile {
|
||||
public MCAFile(int regionX, int regionZ) {
|
||||
this.regionX = regionX;
|
||||
this.regionZ = regionZ;
|
||||
afterSave = new ConcurrentLinkedQueue<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +123,7 @@ public class MCAFile {
|
||||
if (raf.readByte() == 0) {
|
||||
continue;
|
||||
}
|
||||
p2.add(new Position2(x & 31, (z / 32) & 31));
|
||||
p2.add(new Position2(x & 31, (z / 31) & 31));
|
||||
}
|
||||
return p2;
|
||||
}
|
||||
@ -198,6 +203,11 @@ public class MCAFile {
|
||||
raf.seek(globalOffset * 4096L - 1);
|
||||
raf.write(0);
|
||||
}
|
||||
|
||||
J.a(() -> {
|
||||
afterSave.forEach(i -> i.run());
|
||||
}, 20);
|
||||
|
||||
return chunksWritten;
|
||||
}
|
||||
|
||||
@ -326,4 +336,8 @@ public class MCAFile {
|
||||
}
|
||||
return chunk.getBlockStateAt(blockX, blockY, blockZ);
|
||||
}
|
||||
|
||||
public void afterSave(Runnable o) {
|
||||
afterSave.add(o);
|
||||
}
|
||||
}
|
||||
|
@ -329,4 +329,8 @@ public class NBTWorld {
|
||||
public int size() {
|
||||
return loadedRegions.size();
|
||||
}
|
||||
|
||||
public boolean isLoaded(int x, int z) {
|
||||
return loadedRegions.containsKey(Cache.key(x, z));
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
@ -27,7 +27,7 @@ import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
public class Section {
|
||||
private CompoundTag data;
|
||||
private PaletteAccess palette;
|
||||
private MCAPaletteAccess palette;
|
||||
private byte[] blockLight;
|
||||
private byte[] skyLight;
|
||||
private int dataVersion;
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
|
||||
public interface BiomeContainer {
|
||||
public interface MCABiomeContainer {
|
||||
int[] getData();
|
||||
|
||||
void setBiome(int x, int y, int z, int id);
|
@ -22,7 +22,7 @@ import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public class BitStorage {
|
||||
public class MCABitStorage {
|
||||
private static final int[] MAGIC = new int[]{
|
||||
-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE,
|
||||
0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756,
|
||||
@ -61,25 +61,25 @@ public class BitStorage {
|
||||
|
||||
private final int divideShift;
|
||||
|
||||
public BitStorage(int var0, int var1) {
|
||||
this(var0, var1, null);
|
||||
public MCABitStorage(int bits, int length) {
|
||||
this(bits, length, null);
|
||||
}
|
||||
|
||||
public BitStorage(int var0, int var1, long[] var2) {
|
||||
Validate.inclusiveBetween(1L, 32L, var0);
|
||||
this.size = var1;
|
||||
this.bits = var0;
|
||||
this.mask = (1L << var0) - 1L;
|
||||
this.valuesPerLong = (char) (64 / var0);
|
||||
public MCABitStorage(int bits, int length, long[] data) {
|
||||
Validate.inclusiveBetween(1L, 32L, bits);
|
||||
this.size = length;
|
||||
this.bits = bits;
|
||||
this.mask = (1L << bits) - 1L;
|
||||
this.valuesPerLong = (char) (64 / bits);
|
||||
int var3 = 3 * (this.valuesPerLong - 1);
|
||||
this.divideMul = MAGIC[var3 + 0];
|
||||
this.divideAdd = MAGIC[var3 + 1];
|
||||
this.divideShift = MAGIC[var3 + 2];
|
||||
int var4 = (var1 + this.valuesPerLong - 1) / this.valuesPerLong;
|
||||
if (var2 != null) {
|
||||
if (var2.length != var4)
|
||||
int var4 = (length + this.valuesPerLong - 1) / this.valuesPerLong;
|
||||
if (data != null) {
|
||||
if (data.length != var4)
|
||||
throw new RuntimeException("NO!");
|
||||
this.data = var2;
|
||||
this.data = data;
|
||||
} else {
|
||||
this.data = new long[var4];
|
||||
}
|
@ -23,16 +23,16 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ChunkBiomeContainer<T> {
|
||||
public class MCAChunkBiomeContainer<T> {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final int WIDTH_BITS = Mth.ceillog2(16) - 2;
|
||||
private static final int WIDTH_BITS = MCAMth.ceillog2(16) - 2;
|
||||
private static final int HORIZONTAL_MASK = (1 << WIDTH_BITS) - 1;
|
||||
private static final int PACKED_X_LENGTH = 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000));
|
||||
private static final int PACKED_X_LENGTH = 1 + MCAMth.log2(MCAMth.smallestEncompassingPowerOfTwo(30000000));
|
||||
private static final int PACKED_Z_LENGTH = PACKED_X_LENGTH;
|
||||
public static final int PACKED_Y_LENGTH = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH;
|
||||
public static final int MAX_SIZE = 1 << WIDTH_BITS + WIDTH_BITS + PACKED_Y_LENGTH - 2;
|
||||
|
||||
public final IdMap<T> biomeRegistry;
|
||||
public final MCAIdMap<T> biomeRegistry;
|
||||
|
||||
private final T[] biomes;
|
||||
|
||||
@ -40,18 +40,18 @@ public class ChunkBiomeContainer<T> {
|
||||
|
||||
private final int quartHeight;
|
||||
|
||||
protected ChunkBiomeContainer(IdMap<T> registry, int minHeight, int maxHeight, T[] abiomebase) {
|
||||
protected MCAChunkBiomeContainer(MCAIdMap<T> registry, int minHeight, int maxHeight, T[] abiomebase) {
|
||||
this.biomeRegistry = registry;
|
||||
this.biomes = abiomebase;
|
||||
this.quartMinY = QuartPos.fromBlock(minHeight);
|
||||
this.quartHeight = QuartPos.fromBlock(maxHeight) - 1;
|
||||
this.quartMinY = MCAQuartPos.fromBlock(minHeight);
|
||||
this.quartHeight = MCAQuartPos.fromBlock(maxHeight) - 1;
|
||||
}
|
||||
|
||||
public ChunkBiomeContainer(IdMap<T> registry, int min, int max) {
|
||||
public MCAChunkBiomeContainer(MCAIdMap<T> registry, int min, int max) {
|
||||
this(registry, min, max, new int[(1 << WIDTH_BITS + WIDTH_BITS) * ceilDiv(max - min, 4)]);
|
||||
}
|
||||
|
||||
public ChunkBiomeContainer(IdMap<T> registry, int minHeight, int maxHeight, int[] aint) {
|
||||
public MCAChunkBiomeContainer(MCAIdMap<T> registry, int minHeight, int maxHeight, int[] aint) {
|
||||
this(registry, minHeight, maxHeight, (T[]) new Object[aint.length]);
|
||||
int i = -1;
|
||||
for (int j = 0; j < this.biomes.length; j++) {
|
||||
@ -82,14 +82,14 @@ public class ChunkBiomeContainer<T> {
|
||||
|
||||
public T getBiome(int i, int j, int k) {
|
||||
int l = i & HORIZONTAL_MASK;
|
||||
int i1 = Mth.clamp(j - this.quartMinY, 0, this.quartHeight);
|
||||
int i1 = MCAMth.clamp(j - this.quartMinY, 0, this.quartHeight);
|
||||
int j1 = k & HORIZONTAL_MASK;
|
||||
return this.biomes[i1 << WIDTH_BITS + WIDTH_BITS | j1 << WIDTH_BITS | l];
|
||||
}
|
||||
|
||||
public void setBiome(int i, int j, int k, T biome) {
|
||||
int l = i & HORIZONTAL_MASK;
|
||||
int i1 = Mth.clamp(j - this.quartMinY, 0, this.quartHeight);
|
||||
int i1 = MCAMth.clamp(j - this.quartMinY, 0, this.quartHeight);
|
||||
int j1 = k & HORIZONTAL_MASK;
|
||||
this.biomes[i1 << WIDTH_BITS + WIDTH_BITS | j1 << WIDTH_BITS | l] = biome;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MCACountConsumer<T> {
|
||||
void accept(T paramT, int paramInt);
|
||||
}
|
@ -24,7 +24,7 @@ import com.google.common.collect.Iterators;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
|
||||
public class MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<K> {
|
||||
public static final int NOT_FOUND = -1;
|
||||
|
||||
private static final Object EMPTY_SLOT = null;
|
||||
@ -41,7 +41,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
|
||||
|
||||
private int size;
|
||||
|
||||
public CrudeIncrementalIntIdentityHashBiMap(int var0) {
|
||||
public MCACrudeIncrementalIntIdentityHashBiMap(int var0) {
|
||||
var0 = (int) (var0 / 0.8F);
|
||||
this.keys = (K[]) new Object[var0];
|
||||
this.values = new int[var0];
|
||||
@ -117,7 +117,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
|
||||
}
|
||||
|
||||
private int hash(K var0) {
|
||||
return (Mth.murmurHash3Mixer(System.identityHashCode(var0)) & Integer.MAX_VALUE) % this.keys.length;
|
||||
return (MCAMth.murmurHash3Mixer(System.identityHashCode(var0)) & Integer.MAX_VALUE) % this.keys.length;
|
||||
}
|
||||
|
||||
private int indexOf(K var0, int var1) {
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class MCAGlobalPalette<T> implements MCAPalette<T> {
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
public MCAGlobalPalette(MCAIdMapper<T> var0, T var1) {
|
||||
this.registry = var0;
|
||||
this.defaultValue = var1;
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
int var1 = this.registry.getId(var0);
|
||||
return (var1 == -1) ? 0 : var1;
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
T var1 = this.registry.byId(var0);
|
||||
return (var1 == null) ? this.defaultValue : var1;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.registry.size();
|
||||
}
|
||||
|
||||
public void read(ListTag var0) {
|
||||
}
|
||||
}
|
@ -24,12 +24,12 @@ import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class HashMapPalette<T> implements Palette<T> {
|
||||
private final IdMapper<T> registry;
|
||||
public class MCAHashMapPalette<T> implements MCAPalette<T> {
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final CrudeIncrementalIntIdentityHashBiMap<T> values;
|
||||
private final MCACrudeIncrementalIntIdentityHashBiMap<T> values;
|
||||
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
private final MCAPaletteResize<T> resizeHandler;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
@ -37,13 +37,13 @@ public class HashMapPalette<T> implements Palette<T> {
|
||||
|
||||
private final int bits;
|
||||
|
||||
public HashMapPalette(IdMapper<T> var0, int var1, PaletteResize<T> var2, Function<CompoundTag, T> var3, Function<T, CompoundTag> var4) {
|
||||
public MCAHashMapPalette(MCAIdMapper<T> var0, int var1, MCAPaletteResize<T> var2, Function<CompoundTag, T> var3, Function<T, CompoundTag> var4) {
|
||||
this.registry = var0;
|
||||
this.bits = var1;
|
||||
this.resizeHandler = var2;
|
||||
this.reader = var3;
|
||||
this.writer = var4;
|
||||
this.values = new CrudeIncrementalIntIdentityHashBiMap(1 << var1);
|
||||
this.values = new MCACrudeIncrementalIntIdentityHashBiMap(1 << var1);
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
public interface MCAIdMap<T> extends Iterable<T> {
|
||||
int getId(T paramT);
|
||||
|
||||
T byId(int paramInt);
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class MCAIdMapper<T> implements MCAIdMap<T> {
|
||||
public static final int DEFAULT = -1;
|
||||
private final IdentityHashMap<T, Integer> tToId;
|
||||
private final List<T> idToT;
|
||||
private int nextId;
|
||||
|
||||
public MCAIdMapper(IdentityHashMap<T, Integer> tToId, List<T> idToT, int nextId) {
|
||||
this.tToId = tToId;
|
||||
this.idToT = idToT;
|
||||
this.nextId = nextId;
|
||||
}
|
||||
|
||||
public MCAIdMapper() {
|
||||
this(512);
|
||||
}
|
||||
|
||||
public MCAIdMapper(int var0) {
|
||||
this.idToT = Lists.newArrayListWithExpectedSize(var0);
|
||||
this.tToId = new IdentityHashMap<>(var0);
|
||||
}
|
||||
|
||||
public void addMapping(T var0, int var1) {
|
||||
this.tToId.put(var0, Integer.valueOf(var1));
|
||||
while (this.idToT.size() <= var1)
|
||||
this.idToT.add(null);
|
||||
this.idToT.set(var1, var0);
|
||||
if (this.nextId <= var1)
|
||||
this.nextId = var1 + 1;
|
||||
}
|
||||
|
||||
public void add(T var0) {
|
||||
addMapping(var0, this.nextId);
|
||||
}
|
||||
|
||||
public int getId(T var0) {
|
||||
Integer var1 = this.tToId.get(var0);
|
||||
return (var1 == null) ? -1 : var1.intValue();
|
||||
}
|
||||
|
||||
public final T byId(int var0) {
|
||||
if (var0 >= 0 && var0 < this.idToT.size())
|
||||
return this.idToT.get(var0);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator<T> iterator() {
|
||||
return Iterators.filter(this.idToT.iterator(), Predicates.notNull());
|
||||
}
|
||||
|
||||
public boolean contains(int var0) {
|
||||
return (byId(var0) != null);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.tToId.size();
|
||||
}
|
||||
}
|
@ -24,12 +24,12 @@ import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class LinearPalette<T> implements Palette<T> {
|
||||
private final IdMapper<T> registry;
|
||||
public class MCALinearPalette<T> implements MCAPalette<T> {
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final T[] values;
|
||||
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
private final MCAPaletteResize<T> resizeHandler;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
@ -37,7 +37,7 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
|
||||
private int size;
|
||||
|
||||
public LinearPalette(IdMapper<T> var0, int var1, PaletteResize<T> var2, Function<CompoundTag, T> var3) {
|
||||
public MCALinearPalette(MCAIdMapper<T> var0, int var1, MCAPaletteResize<T> var2, Function<CompoundTag, T> var3) {
|
||||
this.registry = var0;
|
||||
this.values = (T[]) new Object[1 << var1];
|
||||
this.bits = var1;
|
||||
@ -80,7 +80,9 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
|
||||
public void read(ListTag var0) {
|
||||
for (int var1 = 0; var1 < var0.size(); var1++)
|
||||
{
|
||||
this.values[var1] = this.reader.apply((CompoundTag) var0.get(var1));
|
||||
}
|
||||
this.size = var0.size();
|
||||
}
|
||||
}
|
712
src/main/java/com/volmit/iris/util/nbt/mca/palette/MCAMth.java
Normal file
712
src/main/java/com/volmit/iris/util/nbt/mca/palette/MCAMth.java
Normal file
@ -0,0 +1,712 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class MCAMth {
|
||||
public static final float PI = 3.1415927F;
|
||||
public static final float HALF_PI = 1.5707964F;
|
||||
public static final float TWO_PI = 6.2831855F;
|
||||
public static final float DEG_TO_RAD = 0.017453292F;
|
||||
public static final float RAD_TO_DEG = 57.295776F;
|
||||
public static final float EPSILON = 1.0E-5F;
|
||||
public static final float SQRT_OF_TWO = sqrt(2.0F);
|
||||
private static final int BIG_ENOUGH_INT = 1024;
|
||||
private static final float BIG_ENOUGH_FLOAT = 1024.0F;
|
||||
private static final long UUID_VERSION = 61440L;
|
||||
private static final long UUID_VERSION_TYPE_4 = 16384L;
|
||||
private static final long UUID_VARIANT = -4611686018427387904L;
|
||||
private static final long UUID_VARIANT_2 = -9223372036854775808L;
|
||||
private static final float SIN_SCALE = 10430.378F;
|
||||
|
||||
private static final float[] SIN;
|
||||
private static final Random RANDOM = new Random();
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[]{
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22,
|
||||
20, 15, 25, 17, 4, 8, 31, 27, 13, 23,
|
||||
21, 19, 16, 7, 26, 12, 18, 6, 11, 5,
|
||||
10, 9};
|
||||
private static final double ONE_SIXTH = 0.16666666666666666D;
|
||||
private static final int FRAC_EXP = 8;
|
||||
private static final int LUT_SIZE = 257;
|
||||
private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
|
||||
private static final double[] ASIN_TAB = new double[257];
|
||||
private static final double[] COS_TAB = new double[257];
|
||||
|
||||
static {
|
||||
SIN = make(new float[65536], var0 -> {
|
||||
for (int var1 = 0; var1 < var0.length; var1++)
|
||||
var0[var1] = (float) Math.sin(var1 * Math.PI * 2.0D / 65536.0D);
|
||||
});
|
||||
}
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; var0++) {
|
||||
double var1 = var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
COS_TAB[var0] = Math.cos(var3);
|
||||
ASIN_TAB[var0] = var3;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T make(Supplier<T> var0) {
|
||||
return var0.get();
|
||||
}
|
||||
|
||||
public static <T> T make(T var0, Consumer<T> var1) {
|
||||
var1.accept(var0);
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float sin(float var0) {
|
||||
return SIN[(int) (var0 * 10430.378F) & 0xFFFF];
|
||||
}
|
||||
|
||||
public static float cos(float var0) {
|
||||
return SIN[(int) (var0 * 10430.378F + 16384.0F) & 0xFFFF];
|
||||
}
|
||||
|
||||
public static float sqrt(float var0) {
|
||||
return (float) Math.sqrt(var0);
|
||||
}
|
||||
|
||||
public static int floor(float var0) {
|
||||
int var1 = (int) var0;
|
||||
return (var0 < var1) ? (var1 - 1) : var1;
|
||||
}
|
||||
|
||||
public static int fastFloor(double var0) {
|
||||
return (int) (var0 + 1024.0D) - 1024;
|
||||
}
|
||||
|
||||
public static int floor(double var0) {
|
||||
int var2 = (int) var0;
|
||||
return (var0 < var2) ? (var2 - 1) : var2;
|
||||
}
|
||||
|
||||
public static long lfloor(double var0) {
|
||||
long var2 = (long) var0;
|
||||
return (var0 < var2) ? (var2 - 1L) : var2;
|
||||
}
|
||||
|
||||
public static int absFloor(double var0) {
|
||||
return (int) ((var0 >= 0.0D) ? var0 : (-var0 + 1.0D));
|
||||
}
|
||||
|
||||
public static float abs(float var0) {
|
||||
return Math.abs(var0);
|
||||
}
|
||||
|
||||
public static int abs(int var0) {
|
||||
return Math.abs(var0);
|
||||
}
|
||||
|
||||
public static int ceil(float var0) {
|
||||
int var1 = (int) var0;
|
||||
return (var0 > var1) ? (var1 + 1) : var1;
|
||||
}
|
||||
|
||||
public static int ceil(double var0) {
|
||||
int var2 = (int) var0;
|
||||
return (var0 > var2) ? (var2 + 1) : var2;
|
||||
}
|
||||
|
||||
public static byte clamp(byte var0, byte var1, byte var2) {
|
||||
if (var0 < var1)
|
||||
return var1;
|
||||
if (var0 > var2)
|
||||
return var2;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int clamp(int var0, int var1, int var2) {
|
||||
if (var0 < var1)
|
||||
return var1;
|
||||
if (var0 > var2)
|
||||
return var2;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static long clamp(long var0, long var2, long var4) {
|
||||
if (var0 < var2)
|
||||
return var2;
|
||||
if (var0 > var4)
|
||||
return var4;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float clamp(float var0, float var1, float var2) {
|
||||
if (var0 < var1)
|
||||
return var1;
|
||||
if (var0 > var2)
|
||||
return var2;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double clamp(double var0, double var2, double var4) {
|
||||
if (var0 < var2)
|
||||
return var2;
|
||||
if (var0 > var4)
|
||||
return var4;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double clampedLerp(double var0, double var2, double var4) {
|
||||
if (var4 < 0.0D)
|
||||
return var0;
|
||||
if (var4 > 1.0D)
|
||||
return var2;
|
||||
return lerp(var4, var0, var2);
|
||||
}
|
||||
|
||||
public static float clampedLerp(float var0, float var1, float var2) {
|
||||
if (var2 < 0.0F)
|
||||
return var0;
|
||||
if (var2 > 1.0F)
|
||||
return var1;
|
||||
return lerp(var2, var0, var1);
|
||||
}
|
||||
|
||||
public static double absMax(double var0, double var2) {
|
||||
if (var0 < 0.0D)
|
||||
var0 = -var0;
|
||||
if (var2 < 0.0D)
|
||||
var2 = -var2;
|
||||
return (var0 > var2) ? var0 : var2;
|
||||
}
|
||||
|
||||
public static int intFloorDiv(int var0, int var1) {
|
||||
return Math.floorDiv(var0, var1);
|
||||
}
|
||||
|
||||
public static int nextInt(Random var0, int var1, int var2) {
|
||||
if (var1 >= var2)
|
||||
return var1;
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
|
||||
public static float nextFloat(Random var0, float var1, float var2) {
|
||||
if (var1 >= var2)
|
||||
return var1;
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double nextDouble(Random var0, double var1, double var3) {
|
||||
if (var1 >= var3)
|
||||
return var1;
|
||||
return var0.nextDouble() * (var3 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double average(long[] var0) {
|
||||
long var1 = 0L;
|
||||
for (long var6 : var0)
|
||||
var1 += var6;
|
||||
return var1 / var0.length;
|
||||
}
|
||||
|
||||
public static boolean equal(float var0, float var1) {
|
||||
return (Math.abs(var1 - var0) < 1.0E-5F);
|
||||
}
|
||||
|
||||
public static boolean equal(double var0, double var2) {
|
||||
return (Math.abs(var2 - var0) < 9.999999747378752E-6D);
|
||||
}
|
||||
|
||||
public static int positiveModulo(int var0, int var1) {
|
||||
return Math.floorMod(var0, var1);
|
||||
}
|
||||
|
||||
public static float positiveModulo(float var0, float var1) {
|
||||
return (var0 % var1 + var1) % var1;
|
||||
}
|
||||
|
||||
public static double positiveModulo(double var0, double var2) {
|
||||
return (var0 % var2 + var2) % var2;
|
||||
}
|
||||
|
||||
public static int wrapDegrees(int var0) {
|
||||
int var1 = var0 % 360;
|
||||
if (var1 >= 180)
|
||||
var1 -= 360;
|
||||
if (var1 < -180)
|
||||
var1 += 360;
|
||||
return var1;
|
||||
}
|
||||
|
||||
public static float wrapDegrees(float var0) {
|
||||
float var1 = var0 % 360.0F;
|
||||
if (var1 >= 180.0F)
|
||||
var1 -= 360.0F;
|
||||
if (var1 < -180.0F)
|
||||
var1 += 360.0F;
|
||||
return var1;
|
||||
}
|
||||
|
||||
public static double wrapDegrees(double var0) {
|
||||
double var2 = var0 % 360.0D;
|
||||
if (var2 >= 180.0D)
|
||||
var2 -= 360.0D;
|
||||
if (var2 < -180.0D)
|
||||
var2 += 360.0D;
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static float degreesDifference(float var0, float var1) {
|
||||
return wrapDegrees(var1 - var0);
|
||||
}
|
||||
|
||||
public static float degreesDifferenceAbs(float var0, float var1) {
|
||||
return abs(degreesDifference(var0, var1));
|
||||
}
|
||||
|
||||
public static float rotateIfNecessary(float var0, float var1, float var2) {
|
||||
float var3 = degreesDifference(var0, var1);
|
||||
float var4 = clamp(var3, -var2, var2);
|
||||
return var1 - var4;
|
||||
}
|
||||
|
||||
public static float approach(float var0, float var1, float var2) {
|
||||
var2 = abs(var2);
|
||||
if (var0 < var1)
|
||||
return clamp(var0 + var2, var0, var1);
|
||||
return clamp(var0 - var2, var1, var0);
|
||||
}
|
||||
|
||||
public static float approachDegrees(float var0, float var1, float var2) {
|
||||
float var3 = degreesDifference(var0, var1);
|
||||
return approach(var0, var0 + var3, var2);
|
||||
}
|
||||
|
||||
public static int getInt(String var0, int var1) {
|
||||
return Integer.valueOf(var0, var1);
|
||||
}
|
||||
|
||||
public static int getInt(String var0, int var1, int var2) {
|
||||
return Math.max(var2, getInt(var0, var1));
|
||||
}
|
||||
|
||||
public static double getDouble(String var0, double var1) {
|
||||
try {
|
||||
return Double.parseDouble(var0);
|
||||
} catch (Throwable var3) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDouble(String var0, double var1, double var3) {
|
||||
return Math.max(var3, getDouble(var0, var1));
|
||||
}
|
||||
|
||||
public static int smallestEncompassingPowerOfTwo(int var0) {
|
||||
int var1 = var0 - 1;
|
||||
var1 |= var1 >> 1;
|
||||
var1 |= var1 >> 2;
|
||||
var1 |= var1 >> 4;
|
||||
var1 |= var1 >> 8;
|
||||
var1 |= var1 >> 16;
|
||||
return var1 + 1;
|
||||
}
|
||||
|
||||
public static boolean isPowerOfTwo(int var0) {
|
||||
return (var0 != 0 && (var0 & var0 - 1) == 0);
|
||||
}
|
||||
|
||||
public static int ceillog2(int var0) {
|
||||
var0 = isPowerOfTwo(var0) ? var0 : smallestEncompassingPowerOfTwo(var0);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int) (var0 * 125613361L >> 27L) & 0x1F];
|
||||
}
|
||||
|
||||
public static int log2(int var0) {
|
||||
return ceillog2(var0) - (isPowerOfTwo(var0) ? 0 : 1);
|
||||
}
|
||||
|
||||
public static int color(float var0, float var1, float var2) {
|
||||
return color(floor(var0 * 255.0F), floor(var1 * 255.0F), floor(var2 * 255.0F));
|
||||
}
|
||||
|
||||
public static int color(int var0, int var1, int var2) {
|
||||
int var3 = var0;
|
||||
var3 = (var3 << 8) + var1;
|
||||
var3 = (var3 << 8) + var2;
|
||||
return var3;
|
||||
}
|
||||
|
||||
public static int colorMultiply(int var0, int var1) {
|
||||
int var2 = (var0 & 0xFF0000) >> 16;
|
||||
int var3 = (var1 & 0xFF0000) >> 16;
|
||||
int var4 = (var0 & 0xFF00) >> 8;
|
||||
int var5 = (var1 & 0xFF00) >> 8;
|
||||
int var6 = (var0 & 0xFF) >> 0;
|
||||
int var7 = (var1 & 0xFF) >> 0;
|
||||
int var8 = (int) (var2 * var3 / 255.0F);
|
||||
int var9 = (int) (var4 * var5 / 255.0F);
|
||||
int var10 = (int) (var6 * var7 / 255.0F);
|
||||
return var0 & 0xFF000000 | var8 << 16 | var9 << 8 | var10;
|
||||
}
|
||||
|
||||
public static int colorMultiply(int var0, float var1, float var2, float var3) {
|
||||
int var4 = (var0 & 0xFF0000) >> 16;
|
||||
int var5 = (var0 & 0xFF00) >> 8;
|
||||
int var6 = (var0 & 0xFF) >> 0;
|
||||
int var7 = (int) (var4 * var1);
|
||||
int var8 = (int) (var5 * var2);
|
||||
int var9 = (int) (var6 * var3);
|
||||
return var0 & 0xFF000000 | var7 << 16 | var8 << 8 | var9;
|
||||
}
|
||||
|
||||
public static float frac(float var0) {
|
||||
return var0 - floor(var0);
|
||||
}
|
||||
|
||||
public static double frac(double var0) {
|
||||
return var0 - lfloor(var0);
|
||||
}
|
||||
|
||||
public static long getSeed(int var0, int var1, int var2) {
|
||||
long var3 = (var0 * 3129871) ^ var2 * 116129781L ^ var1;
|
||||
var3 = var3 * var3 * 42317861L + var3 * 11L;
|
||||
return var3 >> 16L;
|
||||
}
|
||||
|
||||
public static UUID createInsecureUUID(Random var0) {
|
||||
long var1 = var0.nextLong() & 0xFFFFFFFFFFFF0FFFL | 0x4000L;
|
||||
long var3 = var0.nextLong() & 0x3FFFFFFFFFFFFFFFL | Long.MIN_VALUE;
|
||||
return new UUID(var1, var3);
|
||||
}
|
||||
|
||||
public static UUID createInsecureUUID() {
|
||||
return createInsecureUUID(RANDOM);
|
||||
}
|
||||
|
||||
public static double inverseLerp(double var0, double var2, double var4) {
|
||||
return (var0 - var2) / (var4 - var2);
|
||||
}
|
||||
|
||||
public static double atan2(double var0, double var2) {
|
||||
double var4 = var2 * var2 + var0 * var0;
|
||||
if (Double.isNaN(var4))
|
||||
return Double.NaN;
|
||||
boolean var6 = (var0 < 0.0D);
|
||||
if (var6)
|
||||
var0 = -var0;
|
||||
boolean var7 = (var2 < 0.0D);
|
||||
if (var7)
|
||||
var2 = -var2;
|
||||
boolean var8 = (var0 > var2);
|
||||
if (var8) {
|
||||
double d = var2;
|
||||
var2 = var0;
|
||||
var0 = d;
|
||||
}
|
||||
double var9 = fastInvSqrt(var4);
|
||||
var2 *= var9;
|
||||
var0 *= var9;
|
||||
double var11 = FRAC_BIAS + var0;
|
||||
int var13 = (int) Double.doubleToRawLongBits(var11);
|
||||
double var14 = ASIN_TAB[var13];
|
||||
double var16 = COS_TAB[var13];
|
||||
double var18 = var11 - FRAC_BIAS;
|
||||
double var20 = var0 * var16 - var2 * var18;
|
||||
double var22 = (6.0D + var20 * var20) * var20 * 0.16666666666666666D;
|
||||
double var24 = var14 + var22;
|
||||
if (var8)
|
||||
var24 = 1.5707963267948966D - var24;
|
||||
if (var7)
|
||||
var24 = Math.PI - var24;
|
||||
if (var6)
|
||||
var24 = -var24;
|
||||
return var24;
|
||||
}
|
||||
|
||||
public static float fastInvSqrt(float var0) {
|
||||
float var1 = 0.5F * var0;
|
||||
int var2 = Float.floatToIntBits(var0);
|
||||
var2 = 1597463007 - (var2 >> 1);
|
||||
var0 = Float.intBitsToFloat(var2);
|
||||
var0 *= 1.5F - var1 * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double fastInvSqrt(double var0) {
|
||||
double var2 = 0.5D * var0;
|
||||
long var4 = Double.doubleToRawLongBits(var0);
|
||||
var4 = 6910469410427058090L - (var4 >> 1L);
|
||||
var0 = Double.longBitsToDouble(var4);
|
||||
var0 *= 1.5D - var2 * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float fastInvCubeRoot(float var0) {
|
||||
int var1 = Float.floatToIntBits(var0);
|
||||
var1 = 1419967116 - var1 / 3;
|
||||
float var2 = Float.intBitsToFloat(var1);
|
||||
var2 = 0.6666667F * var2 + 1.0F / 3.0F * var2 * var2 * var0;
|
||||
var2 = 0.6666667F * var2 + 1.0F / 3.0F * var2 * var2 * var0;
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static int hsvToRgb(float var0, float var1, float var2) {
|
||||
float var8, var9, var10;
|
||||
int var11, var12, var13, var3 = (int) (var0 * 6.0F) % 6;
|
||||
float var4 = var0 * 6.0F - var3;
|
||||
float var5 = var2 * (1.0F - var1);
|
||||
float var6 = var2 * (1.0F - var4 * var1);
|
||||
float var7 = var2 * (1.0F - (1.0F - var4) * var1);
|
||||
switch (var3) {
|
||||
case 0:
|
||||
var8 = var2;
|
||||
var9 = var7;
|
||||
var10 = var5;
|
||||
var11 = clamp((int) (var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int) (var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int) (var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 1:
|
||||
var8 = var6;
|
||||
var9 = var2;
|
||||
var10 = var5;
|
||||
var11 = clamp((int) (var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int) (var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int) (var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 2:
|
||||
var8 = var5;
|
||||
var9 = var2;
|
||||
var10 = var7;
|
||||
var11 = clamp((int) (var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int) (var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int) (var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 3:
|
||||
var8 = var5;
|
||||
var9 = var6;
|
||||
var10 = var2;
|
||||
var11 = clamp((int) (var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int) (var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int) (var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 4:
|
||||
var8 = var7;
|
||||
var9 = var5;
|
||||
var10 = var2;
|
||||
var11 = clamp((int) (var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int) (var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int) (var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 5:
|
||||
var8 = var2;
|
||||
var9 = var5;
|
||||
var10 = var6;
|
||||
var11 = clamp((int) (var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int) (var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int) (var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
}
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
|
||||
}
|
||||
|
||||
public static int murmurHash3Mixer(int var0) {
|
||||
var0 ^= var0 >>> 16;
|
||||
var0 *= -2048144789;
|
||||
var0 ^= var0 >>> 13;
|
||||
var0 *= -1028477387;
|
||||
var0 ^= var0 >>> 16;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static long murmurHash3Mixer(long var0) {
|
||||
var0 ^= var0 >>> 33L;
|
||||
var0 *= -49064778989728563L;
|
||||
var0 ^= var0 >>> 33L;
|
||||
var0 *= -4265267296055464877L;
|
||||
var0 ^= var0 >>> 33L;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double[] cumulativeSum(double... var0) {
|
||||
float var1 = 0.0F;
|
||||
for (double var5 : var0)
|
||||
var1 = (float) (var1 + var5);
|
||||
int var2;
|
||||
for (var2 = 0; var2 < var0.length; var2++)
|
||||
var0[var2] = var0[var2] / var1;
|
||||
for (var2 = 0; var2 < var0.length; var2++)
|
||||
var0[var2] = ((var2 == 0) ? 0.0D : var0[var2 - 1]) + var0[var2];
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int getRandomForDistributionIntegral(Random var0, double[] var1) {
|
||||
double var2 = var0.nextDouble();
|
||||
for (int var4 = 0; var4 < var1.length; var4++) {
|
||||
if (var2 < var1[var4])
|
||||
return var4;
|
||||
}
|
||||
return var1.length;
|
||||
}
|
||||
|
||||
public static double[] binNormalDistribution(double var0, double var2, double var4, int var6, int var7) {
|
||||
double[] var8 = new double[var7 - var6 + 1];
|
||||
int var9 = 0;
|
||||
for (int var10 = var6; var10 <= var7; var10++) {
|
||||
var8[var9] = Math.max(0.0D, var0 *
|
||||
|
||||
StrictMath.exp(-(var10 - var4) * (var10 - var4) / 2.0D * var2 * var2));
|
||||
var9++;
|
||||
}
|
||||
return var8;
|
||||
}
|
||||
|
||||
public static double[] binBiModalNormalDistribution(double var0, double var2, double var4, double var6, double var8, double var10, int var12, int var13) {
|
||||
double[] var14 = new double[var13 - var12 + 1];
|
||||
int var15 = 0;
|
||||
for (int var16 = var12; var16 <= var13; var16++) {
|
||||
var14[var15] = Math.max(0.0D, var0 *
|
||||
|
||||
StrictMath.exp(-(var16 - var4) * (var16 - var4) / 2.0D * var2 * var2) + var6 *
|
||||
StrictMath.exp(-(var16 - var10) * (var16 - var10) / 2.0D * var8 * var8));
|
||||
var15++;
|
||||
}
|
||||
return var14;
|
||||
}
|
||||
|
||||
public static double[] binLogDistribution(double var0, double var2, int var4, int var5) {
|
||||
double[] var6 = new double[var5 - var4 + 1];
|
||||
int var7 = 0;
|
||||
for (int var8 = var4; var8 <= var5; var8++) {
|
||||
var6[var7] = Math.max(var0 * StrictMath.log(var8) + var2, 0.0D);
|
||||
var7++;
|
||||
}
|
||||
return var6;
|
||||
}
|
||||
|
||||
public static float lerp(float var0, float var1, float var2) {
|
||||
return var1 + var0 * (var2 - var1);
|
||||
}
|
||||
|
||||
public static double lerp(double var0, double var2, double var4) {
|
||||
return var2 + var0 * (var4 - var2);
|
||||
}
|
||||
|
||||
public static double lerp2(double var0, double var2, double var4, double var6, double var8, double var10) {
|
||||
return lerp(var2,
|
||||
|
||||
lerp(var0, var4, var6),
|
||||
lerp(var0, var8, var10));
|
||||
}
|
||||
|
||||
public static double lerp3(double var0, double var2, double var4, double var6, double var8, double var10, double var12, double var14, double var16, double var18, double var20) {
|
||||
return lerp(var4,
|
||||
|
||||
lerp2(var0, var2, var6, var8, var10, var12),
|
||||
lerp2(var0, var2, var14, var16, var18, var20));
|
||||
}
|
||||
|
||||
public static double smoothstep(double var0) {
|
||||
return var0 * var0 * var0 * (var0 * (var0 * 6.0D - 15.0D) + 10.0D);
|
||||
}
|
||||
|
||||
public static double smoothstepDerivative(double var0) {
|
||||
return 30.0D * var0 * var0 * (var0 - 1.0D) * (var0 - 1.0D);
|
||||
}
|
||||
|
||||
public static int sign(double var0) {
|
||||
if (var0 == 0.0D)
|
||||
return 0;
|
||||
return (var0 > 0.0D) ? 1 : -1;
|
||||
}
|
||||
|
||||
public static float rotLerp(float var0, float var1, float var2) {
|
||||
return var1 + var0 * wrapDegrees(var2 - var1);
|
||||
}
|
||||
|
||||
public static float diffuseLight(float var0, float var1, float var2) {
|
||||
return Math.min(var0 * var0 * 0.6F + var1 * var1 * (3.0F + var1) / 4.0F + var2 * var2 * 0.8F, 1.0F);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float rotlerp(float var0, float var1, float var2) {
|
||||
float var3 = var1 - var0;
|
||||
while (var3 < -180.0F)
|
||||
var3 += 360.0F;
|
||||
while (var3 >= 180.0F)
|
||||
var3 -= 360.0F;
|
||||
return var0 + var2 * var3;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float rotWrap(double var0) {
|
||||
while (var0 >= 180.0D)
|
||||
var0 -= 360.0D;
|
||||
while (var0 < -180.0D)
|
||||
var0 += 360.0D;
|
||||
return (float) var0;
|
||||
}
|
||||
|
||||
public static float triangleWave(float var0, float var1) {
|
||||
return (Math.abs(var0 % var1 - var1 * 0.5F) - var1 * 0.25F) / var1 * 0.25F;
|
||||
}
|
||||
|
||||
public static float square(float var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static double square(double var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static int square(int var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static double clampedMap(double var0, double var2, double var4, double var6, double var8) {
|
||||
return clampedLerp(var6, var8, inverseLerp(var0, var2, var4));
|
||||
}
|
||||
|
||||
public static double map(double var0, double var2, double var4, double var6, double var8) {
|
||||
return lerp(inverseLerp(var0, var2, var4), var6, var8);
|
||||
}
|
||||
|
||||
public static double wobble(double var0) {
|
||||
return var0 + (2.0D * (new Random(floor(var0 * 3000.0D))).nextDouble() - 1.0D) * 1.0E-7D / 2.0D;
|
||||
}
|
||||
|
||||
public static int roundToward(int var0, int var1) {
|
||||
return (var0 + var1 - 1) / var1 * var1;
|
||||
}
|
||||
|
||||
public static int randomBetweenInclusive(Random var0, int var1, int var2) {
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
|
||||
public static float randomBetween(Random var0, float var1, float var2) {
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
|
||||
public static float normal(Random var0, float var1, float var2) {
|
||||
return var1 + (float) var0.nextGaussian() * var2;
|
||||
}
|
||||
|
||||
public static double length(int var0, double var1, int var3) {
|
||||
return Math.sqrt((var0 * var0) + var1 * var1 + (var3 * var3));
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface MCAPalette<T> {
|
||||
int idFor(T paramT);
|
||||
|
||||
boolean maybeHas(Predicate<T> paramPredicate);
|
||||
|
||||
T valueFor(int paramInt);
|
||||
|
||||
int getSize();
|
||||
|
||||
void read(ListTag paramListTag);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
public interface MCAPaletteAccess {
|
||||
void setBlock(int x, int y, int z, CompoundTag data);
|
||||
|
||||
CompoundTag getBlock(int x, int y, int z);
|
||||
|
||||
void writeToSection(CompoundTag tag);
|
||||
|
||||
void readFromSection(CompoundTag tag);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
interface MCAPaletteResize<T> {
|
||||
int onResize(int paramInt, T paramT);
|
||||
}
|
@ -25,15 +25,15 @@ import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
public class MCAPalettedContainer<T> implements MCAPaletteResize<T> {
|
||||
public static final int GLOBAL_PALETTE_BITS = 9;
|
||||
public static final int MIN_PALETTE_SIZE = 4;
|
||||
private static final int SIZE = 4096;
|
||||
private final Palette<T> globalPalette;
|
||||
private final MCAPalette<T> globalPalette;
|
||||
|
||||
private final PaletteResize<T> dummyPaletteResize = (var0, var1) -> 0;
|
||||
private final MCAPaletteResize<T> dummyPaletteResize = (var0, var1) -> 0;
|
||||
|
||||
private final IdMapper<T> registry;
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
@ -41,13 +41,13 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
protected BitStorage storage;
|
||||
protected MCABitStorage storage;
|
||||
|
||||
private Palette<T> palette;
|
||||
private MCAPalette<T> palette;
|
||||
|
||||
private int bits;
|
||||
|
||||
public PalettedContainer(Palette<T> var0, IdMapper<T> var1, Function<CompoundTag, T> var2, Function<T, CompoundTag> var3, T var4) {
|
||||
public MCAPalettedContainer(MCAPalette<T> var0, MCAIdMapper<T> var1, Function<CompoundTag, T> var2, Function<T, CompoundTag> var3, T var4) {
|
||||
this.globalPalette = var0;
|
||||
this.registry = var1;
|
||||
this.reader = var2;
|
||||
@ -66,20 +66,20 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
this.bits = var0;
|
||||
if (this.bits <= 4) {
|
||||
this.bits = 4;
|
||||
this.palette = new LinearPalette<>(this.registry, this.bits, this, this.reader);
|
||||
this.palette = new MCALinearPalette<>(this.registry, this.bits, this, this.reader);
|
||||
} else if (this.bits < 9) {
|
||||
this.palette = new HashMapPalette<>(this.registry, this.bits, this, this.reader, this.writer);
|
||||
this.palette = new MCAHashMapPalette<>(this.registry, this.bits, this, this.reader, this.writer);
|
||||
} else {
|
||||
this.palette = this.globalPalette;
|
||||
this.bits = Mth.ceillog2(this.registry.size());
|
||||
this.bits = MCAMth.ceillog2(this.registry.size());
|
||||
}
|
||||
this.palette.idFor(this.defaultValue);
|
||||
this.storage = new BitStorage(this.bits, 4096);
|
||||
this.storage = new MCABitStorage(this.bits, 4096);
|
||||
}
|
||||
|
||||
public int onResize(int var0, T var1) {
|
||||
BitStorage var2 = this.storage;
|
||||
Palette<T> var3 = this.palette;
|
||||
MCABitStorage var2 = this.storage;
|
||||
MCAPalette<T> var3 = this.palette;
|
||||
setBits(var0);
|
||||
for (int var4 = 0; var4 < var2.getSize(); var4++) {
|
||||
T var5 = var3.valueFor(var2.get(var4));
|
||||
@ -123,28 +123,28 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
}
|
||||
|
||||
public void read(ListTag var0, long[] var1) {
|
||||
int var2 = Math.max(4, Mth.ceillog2(var0.size()));
|
||||
int var2 = Math.max(4, MCAMth.ceillog2(var0.size()));
|
||||
if (var2 != this.bits)
|
||||
setBits(var2);
|
||||
this.palette.read(var0);
|
||||
int var3 = var1.length * 64 / 4096;
|
||||
if (this.palette == this.globalPalette) {
|
||||
Palette<T> var4 = new HashMapPalette<>(this.registry, var2, this.dummyPaletteResize, this.reader, this.writer);
|
||||
MCAPalette<T> var4 = new MCAHashMapPalette<>(this.registry, var2, this.dummyPaletteResize, this.reader, this.writer);
|
||||
var4.read(var0);
|
||||
BitStorage var5 = new BitStorage(var2, 4096, var1);
|
||||
MCABitStorage var5 = new MCABitStorage(var2, 4096, var1);
|
||||
for (int var6 = 0; var6 < 4096; var6++)
|
||||
this.storage.set(var6, this.globalPalette.idFor(var4.valueFor(var5.get(var6))));
|
||||
} else if (var3 == this.bits) {
|
||||
System.arraycopy(var1, 0, this.storage.getRaw(), 0, var1.length);
|
||||
} else {
|
||||
BitStorage var4 = new BitStorage(var3, 4096, var1);
|
||||
MCABitStorage var4 = new MCABitStorage(var3, 4096, var1);
|
||||
for (int var5 = 0; var5 < 4096; var5++)
|
||||
this.storage.set(var5, var4.get(var5));
|
||||
}
|
||||
}
|
||||
|
||||
public void write(CompoundTag var0, String var1, String var2) {
|
||||
HashMapPalette<T> var3 = new HashMapPalette<>(this.registry, this.bits, this.dummyPaletteResize, this.reader, this.writer);
|
||||
MCAHashMapPalette<T> var3 = new MCAHashMapPalette<>(this.registry, this.bits, this.dummyPaletteResize, this.reader, this.writer);
|
||||
T var4 = this.defaultValue;
|
||||
int var5 = var3.idFor(this.defaultValue);
|
||||
int[] var6 = new int[4096];
|
||||
@ -159,8 +159,8 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
ListTag<CompoundTag> paletteList = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
var3.write(paletteList);
|
||||
var0.put(var1, paletteList);
|
||||
int var8 = Math.max(4, Mth.ceillog2(paletteList.size()));
|
||||
BitStorage var9 = new BitStorage(var8, 4096);
|
||||
int var8 = Math.max(4, MCAMth.ceillog2(paletteList.size()));
|
||||
MCABitStorage var9 = new MCABitStorage(var8, 4096);
|
||||
for (int var10 = 0; var10 < var6.length; var10++) {
|
||||
var9.set(var10, var6[var10]);
|
||||
}
|
||||
@ -171,7 +171,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
return this.palette.maybeHas(var0);
|
||||
}
|
||||
|
||||
public void count(CountConsumer<T> var0) {
|
||||
public void count(MCACountConsumer<T> var0) {
|
||||
Int2IntOpenHashMap int2IntOpenHashMap = new Int2IntOpenHashMap();
|
||||
this.storage.getAll(var1 -> int2IntOpenHashMap.put(var1, int2IntOpenHashMap.get(var1) + 1));
|
||||
int2IntOpenHashMap.int2IntEntrySet().forEach(var1 -> var0.accept(this.palette.valueFor(var1.getIntKey()), var1.getIntValue()));
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||
* Copyright (c) 2021 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.nbt.mca.palette;
|
||||
|
||||
public final class MCAQuartPos {
|
||||
public static final int BITS = 2;
|
||||
|
||||
public static final int SIZE = 4;
|
||||
|
||||
private static final int SECTION_TO_QUARTS_BITS = 2;
|
||||
|
||||
public static int fromBlock(int var0) {
|
||||
return var0 >> 2;
|
||||
}
|
||||
|
||||
public static int toBlock(int var0) {
|
||||
return var0 << 2;
|
||||
}
|
||||
|
||||
public static int fromSection(int var0) {
|
||||
return var0 << 2;
|
||||
}
|
||||
|
||||
public static int toSection(int var0) {
|
||||
return var0 >> 2;
|
||||
}
|
||||
}
|
@ -24,8 +24,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import java.util.function.Function;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class WrappedPalettedContainer<T> implements PaletteAccess {
|
||||
private final PalettedContainer<T> container;
|
||||
public class MCAWrappedPalettedContainer<T> implements MCAPaletteAccess {
|
||||
private final MCAPalettedContainer<T> container;
|
||||
private final Function<T, CompoundTag> reader;
|
||||
private final Function<CompoundTag, T> writer;
|
||||
|
Loading…
x
Reference in New Issue
Block a user