Merge branch 'master' into onlyWarnWhenPlayer

This commit is contained in:
CocoTheOwner 2021-09-27 15:24:23 +02:00
commit 88469f6141
100 changed files with 1193 additions and 860 deletions

View File

@ -1,3 +1,21 @@
/*
* 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/>.
*/
plugins {
id 'java'
}

View File

@ -22,7 +22,7 @@ plugins {
}
group 'com.volmit.iris'
version '1.8.13'
version '1.9'
def apiVersion = '1.17'
def name = getRootProject().getName() // Defined in settings.gradle
def main = 'com.volmit.iris.Iris'

View File

@ -1 +0,0 @@
1036166928

View File

@ -18,6 +18,9 @@
package com.volmit.iris;
import com.google.gson.ExclusionStrategy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.ServerConfigurator;
import com.volmit.iris.core.link.IrisPapiExpansion;
@ -27,6 +30,7 @@ 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.StudioSVC;
import com.volmit.iris.engine.EnginePanic;
import com.volmit.iris.engine.object.IrisCompat;
import com.volmit.iris.engine.object.IrisDimension;
import com.volmit.iris.engine.object.IrisWorld;
@ -37,15 +41,14 @@ import com.volmit.iris.util.collection.KMap;
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.hunk.bits.TecTest;
import com.volmit.iris.util.io.FileWatcher;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.io.InstanceState;
import com.volmit.iris.util.io.JarScanner;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterTest;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.IrisService;
import com.volmit.iris.util.plugin.Metrics;
@ -68,6 +71,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.plugin.IllegalPluginAccessException;
import org.bukkit.plugin.Plugin;
import java.io.BufferedInputStream;
@ -299,6 +303,8 @@ public class Iris extends VolmitPlugin implements Listener {
@SuppressWarnings("deprecation")
public static void later(NastyRunnable object) {
try
{
Bukkit.getScheduler().scheduleAsyncDelayedTask(instance, () ->
{
try {
@ -310,6 +316,12 @@ public class Iris extends VolmitPlugin implements Listener {
}, RNG.r.i(100, 1200));
}
catch(IllegalPluginAccessException ignored)
{
}
}
public static int jobCount() {
return syncJobs.size();
}
@ -446,9 +458,9 @@ public class Iris extends VolmitPlugin implements Listener {
J.ar(this::checkConfigHotload, 60);
J.sr(this::tickQueue, 0);
J.s(this::setupPapi);
J.s(TecTest::go);
J.a(ServerConfigurator::configure, 20);
splash();
J.a(MatterTest::test, 20);
if (IrisSettings.get().getStudio().isAutoStartDefaultStudio()) {
Iris.info("Starting up auto Studio!");
@ -468,6 +480,16 @@ public class Iris extends VolmitPlugin implements Listener {
}
}
public static void panic()
{
EnginePanic.panic();
}
public static void addPanic(String s, String v)
{
EnginePanic.add(s, v);
}
@SuppressWarnings("unchecked")
public void onEnable() {
enable();

View File

@ -34,6 +34,7 @@ import java.io.IOException;
public class IrisSettings {
public static transient IrisSettings settings;
private IrisSettingsGeneral general = new IrisSettingsGeneral();
private IrisSettingsWorld world = new IrisSettingsWorld();
private IrisSettingsGUI gui = new IrisSettingsGUI();
private IrisSettingsAutoconfiguration autoConfiguration = new IrisSettingsAutoconfiguration();
private IrisSettingsGenerator generator = new IrisSettingsGenerator();
@ -56,6 +57,24 @@ public class IrisSettings {
public boolean autoRestartOnCustomBiomeInstall = true;
}
@Data
public static class IrisAsyncTeleport {
public boolean enabled = false;
public int loadViewDistance = 2;
public boolean urgent = false;
}
@Data
public static class IrisSettingsWorld {
public IrisAsyncTeleport asyncTeleport = new IrisAsyncTeleport();
public boolean postLoadBlockUpdates = true;
public boolean anbientEntitySpawningSystem = true;
public long asyncTickIntervalMS = 700;
public double targetSpawnEntitiesPerChunk = 0.95;
public boolean markerEntitySpawningSystem = true;
public boolean effectSystem = true;
}
@Data
public static class IrisSettingsConcurrency {
public int parallelism = -1;
@ -64,11 +83,11 @@ public class IrisSettings {
@Data
public static class IrisSettingsPerformance {
public boolean trimMantleInStudio = false;
public int mantleKeepAliveSeconds = 25;
public int maxStreamCacheSize = 256_000;
public int maxResourceLoaderCacheSize = 1_000;
public int maxObjectLoaderCacheSize = 3_000;
public int maxScriptLoaderCacheSize = 500;
public int mantleKeepAlive = 60;
public int cacheSize = 4_096;
public int resourceLoaderCacheSize = 1_024;
public int objectLoaderCacheSize = 4_096;
public int scriptLoaderCacheSize = 512;
}
@Data
@ -100,7 +119,7 @@ public class IrisSettings {
@Data
public static class IrisSettingsGenerator {
public String defaultWorldType = "overworld";
public boolean headlessPregeneration = false;
public boolean headlessPregeneration = true;
public int maxBiomeChildDepth = 4;
public boolean preventLeafDecay = true;
}

View File

@ -41,16 +41,13 @@ import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class ServerConfigurator {
public static void configure()
{
public static void configure() {
IrisSettings.IrisSettingsAutoconfiguration s = IrisSettings.get().getAutoConfiguration();
if(s.isConfigureSpigotTimeoutTime())
{
if (s.isConfigureSpigotTimeoutTime()) {
J.attempt(ServerConfigurator::increaseKeepAliveSpigot);
}
if(s.isConfigurePaperWatchdogDelay())
{
if (s.isConfigurePaperWatchdogDelay()) {
J.attempt(ServerConfigurator::increasePaperWatchdog);
}
@ -63,9 +60,9 @@ public class ServerConfigurator {
f.load(spigotConfig);
long tt = f.getLong("settings.timeout-time");
if(tt < TimeUnit.MINUTES.toSeconds(5))
{
Iris.warn("Updating spigot.yml timeout-time: " + tt + " -> " + TimeUnit.MINUTES.toSeconds(5) + " (5 minutes). You can disable this change (autoconfigureServer) in Iris settings, then change back the value.");
if (tt < TimeUnit.MINUTES.toSeconds(5)) {
Iris.warn("Updating spigot.yml timeout-time: " + tt + " -> " + TimeUnit.MINUTES.toSeconds(5) + " (5 minutes)");
Iris.warn("You can disable this change (autoconfigureServer) in Iris settings, then change back the value.");
f.set("settings.timeout-time", TimeUnit.MINUTES.toSeconds(5));
f.save(spigotConfig);
}
@ -77,9 +74,9 @@ public class ServerConfigurator {
f.load(spigotConfig);
long tt = f.getLong("settings.watchdog.early-warning-delay");
if(tt < TimeUnit.MINUTES.toMillis(3))
{
Iris.warn("Updating paper.yml watchdog early-warning-delay: " + tt + " -> " + TimeUnit.MINUTES.toMillis(3) + " (3 minutes). You can disable this change (autoconfigureServer) in Iris settings, then change back the value.");
if (tt < TimeUnit.MINUTES.toMillis(3)) {
Iris.warn("Updating paper.yml watchdog early-warning-delay: " + tt + " -> " + TimeUnit.MINUTES.toMillis(3) + " (3 minutes)");
Iris.warn("You can disable this change (autoconfigureServer) in Iris settings, then change back the value.");
f.set("settings.watchdog.early-warning-delay", TimeUnit.MINUTES.toMillis(3));
f.save(spigotConfig);
}
@ -110,8 +107,7 @@ public class ServerConfigurator {
return null;
}
public static void installDataPacks(boolean fullInstall)
{
public static void installDataPacks(boolean fullInstall) {
Iris.info("Checking Data Packs...");
boolean reboot = false;
File packs = new File("plugins/Iris/packs");
@ -151,8 +147,7 @@ public class ServerConfigurator {
Iris.info("Data Packs Setup!");
if(fullInstall)
{
if (fullInstall) {
verifyDataPacksPost(IrisSettings.get().getAutoConfiguration().isAutoRestartOnCustomBiomeInstall());
}
}
@ -194,14 +189,10 @@ public class ServerConfigurator {
}
}
if(bad)
{
if(allowRestarting)
{
if (bad) {
if (allowRestarting) {
restart();
}
else if (INMS.get().supportsDataPacks()) {
} else if (INMS.get().supportsDataPacks()) {
Iris.error("============================================================================");
Iris.error(C.ITALIC + "You need to restart your server to properly generate custom biomes.");
Iris.error(C.ITALIC + "By continuing, Iris will use backup biomes in place of the custom biomes.");
@ -224,7 +215,9 @@ public class ServerConfigurator {
public static void restart() {
J.s(() -> {
Iris.warn("New data pack entries have been installed in Iris! Restarting server! (You can disable this auto restart in iris settings). This will only happen when your pack changes (updates/first time setup)");
Iris.warn("New data pack entries have been installed in Iris! Restarting server!");
Iris.warn("This will only happen when your pack changes (updates/first time setup)");
Iris.warn("(You can disable this auto restart in iris settings)");
J.s(() -> {
Iris.warn("Looks like the restart command diddn't work. Stopping the server instead!");
Bukkit.shutdown();
@ -268,7 +261,8 @@ public class ServerConfigurator {
}
if (warn) {
Iris.error("The Pack " + dimension.getLoadKey() + " is INCAPABLE of generating custom biomes, restart your server before generating with this pack!");
Iris.error("The Pack " + dimension.getLoadKey() + " is INCAPABLE of generating custom biomes");
Iris.error("If not done automatically, restart your server before generating with this pack!");
}
return !warn;

View File

@ -62,7 +62,6 @@ 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;

View File

@ -24,7 +24,6 @@ import com.volmit.iris.core.pregenerator.IrisPregenerator;
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;
@ -35,7 +34,6 @@ 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;
import javax.swing.JFrame;
import javax.swing.JPanel;
@ -46,7 +44,6 @@ import java.awt.Graphics2D;
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;
@ -72,9 +69,9 @@ public class PregeneratorJob implements PregenListener {
private JFrame frame;
private PregenRenderer renderer;
private int rgc = 0;
private ChronoLatch cl = new ChronoLatch(TimeUnit.MINUTES.toMillis(1));
private final ChronoLatch cl = new ChronoLatch(TimeUnit.MINUTES.toMillis(1));
private String[] info;
private Engine engine;
private final Engine engine;
public PregeneratorJob(PregenTask task, PregeneratorMethod method, Engine engine) {
this.engine = engine;
@ -101,8 +98,7 @@ public class PregeneratorJob implements PregenListener {
J.a(this.pregenerator::start, 20);
}
public Mantle getMantle()
{
public Mantle getMantle() {
return pregenerator.getMantle();
}
@ -243,8 +239,7 @@ public class PregeneratorJob implements PregenListener {
@Override
public void onChunkGenerating(int x, int z) {
if(engine != null)
{
if (engine != null) {
return;
}
@ -253,8 +248,7 @@ public class PregeneratorJob implements PregenListener {
@Override
public void onChunkGenerated(int x, int z) {
if(engine != null)
{
if (engine != null) {
draw(x, z, engine.draw((x << 4) + 8, (z << 4) + 8));
return;
}
@ -269,8 +263,7 @@ public class PregeneratorJob implements PregenListener {
}
private void shouldGc() {
if(cl.flip() && rgc > 16)
{
if (cl.flip() && rgc > 16) {
System.gc();
}
}
@ -329,8 +322,7 @@ public class PregeneratorJob implements PregenListener {
@Override
public void onChunkExistsInRegionGen(int x, int z) {
if(engine != null)
{
if (engine != null) {
draw(x, z, engine.draw((x << 4) + 8, (z << 4) + 8));
return;
}

View File

@ -55,7 +55,6 @@ import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.IrisMatter;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import lombok.Data;

View File

@ -22,23 +22,16 @@ import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.engine.object.IrisObject;
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.data.KCache;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
public class ObjectResourceLoader extends ResourceLoader<IrisObject> {
public ObjectResourceLoader(File root, IrisData idm, String folderName, String resourceTypeName) {
super(root, idm, folderName, resourceTypeName, IrisObject.class);
loadCache = new KCache<>(this::loadRaw, IrisSettings.get().getPerformance().getMaxObjectLoaderCacheSize());
loadCache = new KCache<>(this::loadRaw, IrisSettings.get().getPerformance().getObjectLoaderCacheSize());
}
public boolean supportsSchemas() {

View File

@ -25,7 +25,6 @@ import com.volmit.iris.core.project.SchemaBuilder;
import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.engine.framework.MeteredCache;
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.data.KCache;
import com.volmit.iris.util.format.C;
@ -34,7 +33,6 @@ import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.json.JSONArray;
import com.volmit.iris.util.json.JSONObject;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.IrisLock;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Data;
@ -42,6 +40,8 @@ import lombok.Data;
import java.io.File;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Predicate;
import java.util.stream.Stream;
@ -53,7 +53,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
protected String folderName;
protected String resourceTypeName;
protected KCache<String, T> loadCache;
protected KList<File> folderCache;
protected final AtomicReference<KList<File>> folderCache;
protected Class<? extends T> objectClass;
protected String cname;
protected String[] possibleKeys = null;
@ -63,6 +63,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
public ResourceLoader(File root, IrisData manager, String folderName, String resourceTypeName, Class<? extends T> objectClass) {
this.manager = manager;
folderCache = new AtomicReference<>();
sec = new ChronoLatch(5000);
loads = new AtomicInteger();
this.objectClass = objectClass;
@ -70,7 +71,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
this.resourceTypeName = resourceTypeName;
this.root = root;
this.folderName = folderName;
loadCache = new KCache<>(this::loadRaw, IrisSettings.get().getPerformance().getMaxResourceLoaderCacheSize());
loadCache = new KCache<>(this::loadRaw, IrisSettings.get().getPerformance().getResourceLoaderCacheSize());
Iris.debug("Loader<" + C.GREEN + resourceTypeName + C.LIGHT_PURPLE + "> created in " + C.RED + "IDM/" + manager.getId() + C.LIGHT_PURPLE + " on " + C.GRAY + manager.getDataFolder().getPath());
Iris.service(PreservationSVC.class).registerCache(this);
}
@ -238,8 +239,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
return load(name, true);
}
private T loadRaw(String name)
{
private T loadRaw(String name) {
for (File i : getFolders(name)) {
//noinspection ConstantConditions
for (File j : i.listFiles()) {
@ -271,26 +271,20 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
}
public KList<File> getFolders() {
if (folderCache == null) {
folderCache = new KList<>();
if (folderCache.get() == null) {
folderCache.set(new KList<>());
for (File i : root.listFiles()) {
if (i.isDirectory()) {
if (i.getName().equals(folderName)) {
folderCache.add(i);
folderCache.get().add(i);
break;
}
}
}
}
if (folderCache == null) {
synchronized (this) {
return getFolderCache();
}
}
return folderCache;
return folderCache.get();
}
public KList<File> getFolders(String rc) {
@ -310,7 +304,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
public void clearCache() {
possibleKeys = null;
loadCache.invalidate();
folderCache = null;
folderCache.set(null);
}
public File fileFor(T b) {
@ -336,7 +330,7 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
}
public void clearList() {
folderCache = null;
folderCache.set(null);
possibleKeys = null;
}
@ -364,6 +358,11 @@ public class ResourceLoader<T extends IrisRegistrant> implements MeteredCache {
return loadCache.getSize();
}
@Override
public KCache<?, ?> getRawCache() {
return loadCache;
}
@Override
public long getMaxSize() {
return loadCache.getMaxSize();

View File

@ -32,7 +32,7 @@ import java.io.File;
public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
public ScriptResourceLoader(File root, IrisData idm, String folderName, String resourceTypeName) {
super(root, idm, folderName, resourceTypeName, IrisScript.class);
loadCache = new KCache<>(this::loadRaw, IrisSettings.get().getPerformance().getMaxScriptLoaderCacheSize());
loadCache = new KCache<>(this::loadRaw, IrisSettings.get().getPerformance().getScriptLoaderCacheSize());
}
public boolean supportsSchemas() {
@ -113,8 +113,7 @@ public class ScriptResourceLoader extends ResourceLoader<IrisScript> {
return null;
}
private IrisScript loadRaw(String name)
{
private IrisScript loadRaw(String name) {
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)) {

View File

@ -18,23 +18,15 @@
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.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

View File

@ -133,8 +133,7 @@ public class AsyncPregenMethod implements PregeneratorMethod {
@Override
public Mantle getMantle() {
if(IrisToolbelt.isIrisWorld(world))
{
if (IrisToolbelt.isIrisWorld(world)) {
return IrisToolbelt.access(world).getEngine().getMantle().getMantle();
}

View File

@ -102,8 +102,7 @@ public class HybridPregenMethod implements PregeneratorMethod {
@Override
public Mantle getMantle() {
if (headless == null)
{
if (headless == null) {
return inWorld.getMantle();
}

View File

@ -111,8 +111,7 @@ public class MedievalPregenMethod implements PregeneratorMethod {
@Override
public Mantle getMantle() {
if(IrisToolbelt.isIrisWorld(world))
{
if (IrisToolbelt.isIrisWorld(world)) {
return IrisToolbelt.access(world).getEngine().getMantle().getMantle();
}

View File

@ -31,11 +31,14 @@ import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.J;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.server.ServerCommandEvent;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
public class CommandSVC implements IrisService, DecreeSystem {
private final KMap<String, CompletableFuture<String>> futures = new KMap<>();
private CompletableFuture<String> consoleFuture = null;
private final transient AtomicCache<VirtualDecreeCommand> commandCache = new AtomicCache<>();
@Override
@ -70,6 +73,17 @@ public class CommandSVC implements IrisService, DecreeSystem {
}
}
@EventHandler
public void on(ServerCommandEvent e) {
if (consoleFuture != null && !consoleFuture.isCancelled() && !consoleFuture.isDone()) {
if (!e.getCommand().contains(" ")) {
String pick = e.getCommand().trim().toLowerCase(Locale.ROOT);
consoleFuture.complete(pick);
e.setCancelled(true);
}
}
}
@Override
public VirtualDecreeCommand getRoot() {
return commandCache.aquireNastyPrint(() -> VirtualDecreeCommand.createRoot(new CommandIris()));
@ -78,4 +92,8 @@ public class CommandSVC implements IrisService, DecreeSystem {
public void post(String password, CompletableFuture<String> future) {
futures.put(password, future);
}
public void postConsole(CompletableFuture<String> future) {
consoleFuture = future;
}
}

View File

@ -19,27 +19,25 @@
package com.volmit.iris.core.service;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.MeteredCache;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.context.IrisContext;
import com.volmit.iris.util.data.KCache;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.IrisService;
import com.volmit.iris.util.scheduling.Looper;
import com.volmit.iris.util.stream.utility.CachedStream2D;
import java.util.Comparator;
import java.util.Objects;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
public class PreservationSVC implements IrisService {
private final KList<Thread> threads = new KList<>();
private final KList<ExecutorService> services = new KList<>();
private final List<Thread> threads = new CopyOnWriteArrayList<>();
private final List<ExecutorService> services = new CopyOnWriteArrayList<>();
private Looper dereferencer;
private final KList<MeteredCache> caches = new KList<>();
private final List<MeteredCache> caches = new CopyOnWriteArrayList<>();
public void register(Thread t) {
threads.add(t);
@ -53,17 +51,14 @@ public class PreservationSVC implements IrisService {
services.add(service);
}
public void printCaches()
{
public void printCaches() {
long s = caches.stream().filter(i -> !i.isClosed()).mapToLong(MeteredCache::getSize).sum();
long m = caches.stream().filter(i -> !i.isClosed()).mapToLong(MeteredCache::getMaxSize).sum();
double p = 0;
double mf = 0;
for(MeteredCache i : caches)
{
if(i.isClosed())
{
for (MeteredCache i : caches) {
if (i.isClosed()) {
continue;
}
@ -79,8 +74,8 @@ public class PreservationSVC implements IrisService {
public void dereference() {
IrisContext.dereference();
IrisData.dereference();
threads.removeWhere((i) -> !i.isAlive());
services.removeWhere(ExecutorService::isShutdown);
threads.removeIf((i) -> !i.isAlive());
services.removeIf(ExecutorService::isShutdown);
updateCaches();
}
@ -127,12 +122,15 @@ public class PreservationSVC implements IrisService {
});
}
public void updateCaches()
{
caches.removeWhere(MeteredCache::isClosed);
public void updateCaches() {
caches.removeIf(MeteredCache::isClosed);
}
public void registerCache(MeteredCache cache) {
caches.add(cache);
}
public List<KCache<?, ?>> caches() {
return caches.stream().map(MeteredCache::getRawCache).collect(Collectors.toList());
}
}

View File

@ -0,0 +1,54 @@
/*
* 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.engine;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KMap;
public class EnginePanic {
private static final KMap<String, String> stuff = new KMap<>();
private static KMap<String, String> last = new KMap<>();
public static void add(String key, String value)
{
stuff.put(key, value);
}
public static void saveLast()
{
last = stuff.copy();
}
public static void lastPanic()
{
for(String i : last.keySet())
{
Iris.error("Last Panic " + i + ": " + stuff.get(i));
}
}
public static void panic()
{
lastPanic();
for(String i : stuff.keySet())
{
Iris.error("Engine Panic " + i + ": " + stuff.get(i));
}
}
}

View File

@ -89,7 +89,7 @@ public class IrisComplex implements DataProvider {
}
public IrisComplex(Engine engine, boolean simple) {
int cacheSize = IrisSettings.get().getPerformance().getMaxStreamCacheSize();
int cacheSize = IrisSettings.get().getPerformance().getCacheSize();
IrisBiome emptyBiome = new IrisBiome();
UUID focusUUID = UUID.nameUUIDFromBytes("focus".getBytes());
this.rng = new RNG(engine.getSeedManager().getComplex());
@ -124,7 +124,7 @@ public class IrisComplex implements DataProvider {
Interpolated.of(a -> 0D, a -> focusRegion))
: regionStyleStream
.selectRarity(engine.getDimension().getRegions(), (i) -> data.getRegionLoader().load(i))
.convertCached((s) -> data.getRegionLoader().load(s)).cache2D(engine, cacheSize);
.convertCached((s) -> data.getRegionLoader().load(s)).cache2D("regionStream", engine, cacheSize);
regionIDStream = regionIdentityStream.convertCached((i) -> new UUID(Double.doubleToLongBits(i), String.valueOf(i * 38445).hashCode() * 3245556666L));
caveBiomeStream = regionStream.convert((r)
-> engine.getDimension().getCaveBiomeStyle().create(rng.nextParallelRNG(InferredType.CAVE.ordinal()), getData()).stream()
@ -139,7 +139,7 @@ public class IrisComplex implements DataProvider {
return data.getBiomeLoader().load(s)
.setInferredType(InferredType.CAVE);
})
).convertAware2D(ProceduralStream::get).cache2D(engine, cacheSize);
).convertAware2D(ProceduralStream::get).cache2D("caveBiomeStream", engine, cacheSize);
inferredStreams.put(InferredType.CAVE, caveBiomeStream);
landBiomeStream = regionStream.convert((r)
-> engine.getDimension().getLandBiomeStyle().create(rng.nextParallelRNG(InferredType.LAND.ordinal()), getData()).stream()
@ -148,7 +148,7 @@ public class IrisComplex implements DataProvider {
.convertCached((s) -> data.getBiomeLoader().load(s)
.setInferredType(InferredType.LAND))
).convertAware2D(ProceduralStream::get)
.cache2D(engine, cacheSize);
.cache2D("landBiomeStream", engine, cacheSize);
inferredStreams.put(InferredType.LAND, landBiomeStream);
seaBiomeStream = regionStream.convert((r)
-> engine.getDimension().getSeaBiomeStyle().create(rng.nextParallelRNG(InferredType.SEA.ordinal()), getData()).stream()
@ -157,7 +157,7 @@ public class IrisComplex implements DataProvider {
.convertCached((s) -> data.getBiomeLoader().load(s)
.setInferredType(InferredType.SEA))
).convertAware2D(ProceduralStream::get)
.cache2D(engine, cacheSize);
.cache2D("seaBiomeStream", engine, cacheSize);
inferredStreams.put(InferredType.SEA, seaBiomeStream);
shoreBiomeStream = regionStream.convert((r)
-> engine.getDimension().getShoreBiomeStyle().create(rng.nextParallelRNG(InferredType.SHORE.ordinal()), getData()).stream()
@ -165,60 +165,54 @@ public class IrisComplex implements DataProvider {
.selectRarity(r.getShoreBiomes(), (i) -> data.getBiomeLoader().load(i))
.convertCached((s) -> data.getBiomeLoader().load(s)
.setInferredType(InferredType.SHORE))
).convertAware2D(ProceduralStream::get).cache2D(engine, cacheSize);
).convertAware2D(ProceduralStream::get).cache2D("shoreBiomeStream", engine, cacheSize);
inferredStreams.put(InferredType.SHORE, shoreBiomeStream);
bridgeStream = focus != null ? ProceduralStream.of((x, z) -> focus.getInferredType(),
Interpolated.of(a -> 0D, a -> focus.getInferredType())) :
engine.getDimension().getContinentalStyle().create(rng.nextParallelRNG(234234565), getData())
.bake().scale(1D / engine.getDimension().getContinentZoom()).bake().stream()
.convert((v) -> v >= engine.getDimension().getLandChance() ? InferredType.SEA : InferredType.LAND).cache2D(engine, cacheSize);
.convert((v) -> v >= engine.getDimension().getLandChance() ? InferredType.SEA : InferredType.LAND)
.cache2D("bridgeStream", engine, cacheSize);
baseBiomeStream = focus != null ? ProceduralStream.of((x, z) -> focus,
Interpolated.of(a -> 0D, a -> focus)) :
bridgeStream.convertAware2D((t, x, z) -> inferredStreams.get(t).get(x, z))
.convertAware2D(this::implode).cache2D(engine, cacheSize);
.convertAware2D(this::implode).cache2D("baseBiomeStream", engine, cacheSize);
heightStream = ProceduralStream.of((x, z) -> {
IrisBiome b = focus != null ? focus : baseBiomeStream.get(x, z);
return getHeight(engine, b, x, z, engine.getSeedManager().getHeight());
}, Interpolated.DOUBLE).clamp(0, engine.getHeight()).cache2D(engine, cacheSize, true);
}, Interpolated.DOUBLE).clamp(0, engine.getHeight()).cache2D("heightStream", engine, cacheSize);
roundedHeighteightStream = heightStream.round();
slopeStream = heightStream.slope(3).cache2D(engine, cacheSize);
slopeStream = heightStream.slope(3).cache2D("slopeStream", engine, cacheSize);
trueBiomeStream = focus != null ? ProceduralStream.of((x, y) -> focus, Interpolated.of(a -> 0D,
b -> focus))
.cache2D(engine, cacheSize) : heightStream
.cache2D("trueBiomeStream-focus", engine, cacheSize) : heightStream
.convertAware2D((h, x, z) ->
fixBiomeType(h, baseBiomeStream.get(x, z),
regionStream.get(x, z), x, z, fluidHeight))
.cache2D(engine, cacheSize);
trueBiomeStream = focus != null ? ProceduralStream.of((x, y) -> focus, Interpolated.of(a -> 0D,
b -> focus))
.cache2D(engine, cacheSize) : heightStream
.convertAware2D((h, x, z) ->
fixBiomeType(h, baseBiomeStream.get(x, z),
regionStream.get(x, z), x, z, fluidHeight))
.cache2D(engine, cacheSize);
trueBiomeDerivativeStream = trueBiomeStream.convert(IrisBiome::getDerivative).cache2D(engine, cacheSize);
heightFluidStream = heightStream.max(fluidHeight).cache2D(engine, cacheSize, true);
.cache2D("trueBiomeStream", engine, cacheSize);
trueBiomeDerivativeStream = trueBiomeStream.convert(IrisBiome::getDerivative).cache2D("trueBiomeDerivativeStream", engine, cacheSize);
heightFluidStream = heightStream.max(fluidHeight).cache2D("heightFluidStream", engine, cacheSize);
maxHeightStream = ProceduralStream.ofDouble((x, z) -> height);
terrainSurfaceDecoration = trueBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.NONE)).cache2D(engine, cacheSize);
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.NONE)).cache2D("terrainSurfaceDecoration", engine, cacheSize);
terrainCeilingDecoration = trueBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.CEILING)).cache2D(engine, cacheSize);
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.CEILING)).cache2D("terrainCeilingDecoration", engine, cacheSize);
terrainCaveSurfaceDecoration = caveBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.NONE)).cache2D(engine, cacheSize);
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.NONE)).cache2D("terrainCaveSurfaceDecoration", engine, cacheSize);
terrainCaveCeilingDecoration = caveBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.CEILING)).cache2D(engine, cacheSize);
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.CEILING)).cache2D("terrainCaveCeilingDecoration", engine, cacheSize);
shoreSurfaceDecoration = trueBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SHORE_LINE)).cache2D(engine, cacheSize);
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SHORE_LINE)).cache2D("shoreSurfaceDecoration", engine, cacheSize);
seaSurfaceDecoration = trueBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SEA_SURFACE)).cache2D(engine, cacheSize);
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SEA_SURFACE)).cache2D("seaSurfaceDecoration", engine, cacheSize);
seaFloorDecoration = trueBiomeStream
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SEA_FLOOR)).cache2D(engine, cacheSize);
.convertAware2D((b, xx, zz) -> decorateFor(b, xx, zz, IrisDecorationPart.SEA_FLOOR)).cache2D("seaFloorDecoration", engine, cacheSize);
baseBiomeIDStream = trueBiomeStream.convertAware2D((b, x, z) -> {
UUID d = regionIDStream.get(x, z);
return new UUID(b.getLoadKey().hashCode() * 818223L,
d.hashCode());
})
.cache2D(engine, cacheSize);
.cache2D("", engine, cacheSize);
//@done
}

View File

@ -21,30 +21,20 @@ package com.volmit.iris.engine;
import com.google.common.util.concurrent.AtomicDouble;
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;
import com.volmit.iris.engine.actuator.IrisDecorantActuator;
import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineEffects;
import com.volmit.iris.engine.framework.EngineMetrics;
import com.volmit.iris.engine.framework.EngineMode;
import com.volmit.iris.engine.framework.EngineStage;
import com.volmit.iris.engine.framework.EngineTarget;
import com.volmit.iris.engine.framework.EngineWorldManager;
import com.volmit.iris.engine.framework.SeedManager;
import com.volmit.iris.engine.framework.WrongEngineBroException;
import com.volmit.iris.engine.mantle.EngineMantle;
import com.volmit.iris.engine.mode.ModeOverworld;
import com.volmit.iris.engine.modifier.IrisCarveModifier;
import com.volmit.iris.engine.modifier.IrisDepositModifier;
import com.volmit.iris.engine.modifier.IrisPerfectionModifier;
import com.volmit.iris.engine.modifier.IrisPostModifier;
import com.volmit.iris.engine.object.IrisBiome;
import com.volmit.iris.engine.object.IrisBiomePaletteLayer;
import com.volmit.iris.engine.object.IrisDecorator;
@ -53,10 +43,8 @@ import com.volmit.iris.engine.object.IrisJigsawStructure;
import com.volmit.iris.engine.object.IrisObjectPlacement;
import com.volmit.iris.engine.scripting.EngineExecutionEnvironment;
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;
@ -65,8 +53,6 @@ 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;
import com.volmit.iris.util.matter.MatterFluidBody;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
@ -196,8 +182,7 @@ public class IrisEngine implements Engine {
}
private void setupMode() {
if(mode != null)
{
if (mode != null) {
mode.close();
}
@ -462,17 +447,6 @@ 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();

View File

@ -21,7 +21,6 @@ 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.data.cache.Multicache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.framework.EngineAssignedWorldManager;
import com.volmit.iris.engine.object.IRare;
@ -43,8 +42,6 @@ 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.parallel.MultiBurst;
import com.volmit.iris.util.plugin.Chunks;
@ -56,10 +53,8 @@ import com.volmit.iris.util.scheduling.jobs.QueueJob;
import io.papermc.lib.PaperLib;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -68,7 +63,6 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import java.net.MalformedURLException;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -76,7 +70,6 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -133,6 +126,10 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
getEngine().getWorld().tryGetRealWorld();
}
if (!IrisSettings.get().getWorld().isMarkerEntitySpawningSystem() && !IrisSettings.get().getWorld().isAnbientEntitySpawningSystem()) {
return 3000;
}
if (getEngine().getWorld().hasRealWorld()) {
if (getEngine().getWorld().getPlayers().isEmpty()) {
return 5000;
@ -179,7 +176,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
onAsyncTick();
}
return 700;
return IrisSettings.get().getWorld().getAsyncTickIntervalMS();
}
};
looper.setPriority(Thread.MIN_PRIORITY);
@ -195,7 +192,12 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
for (int x = -r; x <= r; x++) {
for (int z = -r; z <= r; z++) {
if (c.getWorld().isChunkLoaded(c.getX() + x, c.getZ() + z) && Chunks.isSafe(getEngine().getWorld().realWorld(), c.getX() + x, c.getZ() + z)) {
if (IrisSettings.get().getWorld().isPostLoadBlockUpdates()) {
getEngine().updateChunk(c.getWorld().getChunkAt(c.getX() + x, c.getZ() + z));
}
if (IrisSettings.get().getWorld().isMarkerEntitySpawningSystem()) {
Chunk cx = getEngine().getWorld().realWorld().getChunkAt(c.getX() + x, c.getZ() + z);
int finalX = c.getX() + x;
int finalZ = c.getZ() + z;
@ -216,6 +218,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
}
}
}
}
private boolean onAsyncTick() {
if (getEngine().isClosed()) {
@ -231,12 +234,12 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
if (!getEngine().getWorld().hasRealWorld()) {
Iris.debug("Can't spawn. No real world");
J.sleep(10000);
J.sleep(5000);
return false;
}
double epx = getEntitySaturation();
if (epx > 1) {
if (epx > IrisSettings.get().getWorld().getTargetSpawnEntitiesPerChunk()) {
Iris.debug("Can't spawn. The entity per chunk ratio is at " + Form.pc(epx, 2) + " > 100% (total entities " + entityCount + ")");
J.sleep(5000);
return false;
@ -286,8 +289,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
}
private void spawnIn(Chunk c, boolean initial) {
if(getEngine().isClosed())
{
if (getEngine().isClosed()) {
return;
}
@ -295,10 +297,11 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
energy += 1.2;
}
IrisBiome biome = getEngine().getSurfaceBiome(c);
IrisRegion region = getEngine().getRegion(c);
//@builder
IrisEntitySpawn v = spawnRandomly(Stream.concat(getData().getSpawnerLoader()
IrisBiome biome = IrisSettings.get().getWorld().isAnbientEntitySpawningSystem()
? getEngine().getSurfaceBiome(c) : null;
IrisEntitySpawn v = IrisSettings.get().getWorld().isAnbientEntitySpawningSystem()
? spawnRandomly(Stream.concat(getData().getSpawnerLoader()
.loadAll(getDimension().getEntitySpawners())
.shuffleCopy(RNG.r).stream()
.filter(this::canSpawn)
@ -313,8 +316,10 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
.shuffleCopy(RNG.r).stream().filter(this::canSpawn)
.flatMap((i) -> stream(i, initial))))
.collect(Collectors.toList()))
.popRandom(RNG.r);
.popRandom(RNG.r) : null;
//@done
if (IrisSettings.get().getWorld().isMarkerEntitySpawningSystem()) {
getSpawnersFromMarkers(c).forEach((block, spawners) -> {
if (spawners.isEmpty()) {
return;
@ -325,6 +330,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
J.a(() -> getMantle().raiseFlag(c.getX(), c.getZ(), MantleFlag.INITIAL_SPAWNED_MARKER,
() -> spawn(block, s, true)));
});
}
if (v != null && v.getReferenceSpawner() != null) {
int maxEntCount = v.getReferenceSpawner().getMaxEntitiesPerChunk();
@ -343,7 +349,6 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
J.s(() -> spawn(c, v));
}
}
//@done
}
private void spawn(Chunk c, IrisEntitySpawn i) {
@ -479,8 +484,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
@Override
public void onChunkLoad(Chunk e, boolean generated) {
if(getEngine().isClosed())
{
if (getEngine().isClosed()) {
return;
}
@ -490,8 +494,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
}
private void spawn(IrisPosition block, IrisSpawner spawner, boolean initial) {
if(getEngine().isClosed())
{
if (getEngine().isClosed()) {
return;
}
@ -521,33 +524,35 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
@Override
public void teleportAsync(PlayerTeleportEvent e) {
if (IrisSettings.get().getWorld().getAsyncTeleport().isEnabled()) {
e.setCancelled(true);
warmupAreaAsync(e.getPlayer(), e.getTo(), ()
-> J.s(() -> {
warmupAreaAsync(e.getPlayer(), e.getTo(), () -> J.s(() -> {
ignoreTP.set(true);
e.getPlayer().teleport(e.getTo(), e.getCause());
ignoreTP.set(false);
}));
}
}
private void warmupAreaAsync(Player player, Location to, Runnable r) {
J.a(() -> {
int viewDistance = 3;
int viewDistance = IrisSettings.get().getWorld().getAsyncTeleport().getLoadViewDistance();
KList<Future<Chunk>> futures = new KList<>();
for(int i = -viewDistance; i <= viewDistance; i++)
{
for(int j = -viewDistance; j <= viewDistance; j++)
{
for (int i = -viewDistance; i <= viewDistance; i++) {
for (int j = -viewDistance; j <= viewDistance; j++) {
int finalJ = j;
int finalI = i;
if(to.getWorld().isChunkLoaded((to.getBlockX() >> 4) + i, (to.getBlockZ() >> 4) + j))
{
if (to.getWorld().isChunkLoaded((to.getBlockX() >> 4) + i, (to.getBlockZ() >> 4) + j)) {
futures.add(CompletableFuture.completedFuture(null));
continue;
}
futures.add(MultiBurst.burst.completeValue(() -> PaperLib.getChunkAtAsync(to.getWorld(), (to.getBlockX() >> 4) + finalI, (to.getBlockZ() >> 4) + finalJ, true).get()));
futures.add(MultiBurst.burst.completeValue(()
-> PaperLib.getChunkAtAsync(to.getWorld(),
(to.getBlockX() >> 4) + finalI,
(to.getBlockZ() >> 4) + finalJ,
true, IrisSettings.get().getWorld().getAsyncTeleport().isUrgent()).get()));
}
}

View File

@ -25,7 +25,6 @@ import com.volmit.iris.core.gui.components.Renderer;
import com.volmit.iris.core.loader.IrisData;
import com.volmit.iris.core.loader.IrisRegistrant;
import com.volmit.iris.engine.IrisComplex;
import com.volmit.iris.engine.IrisWorldManager;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.data.chunk.TerrainChunk;
import com.volmit.iris.engine.mantle.EngineMantle;
@ -61,7 +60,6 @@ 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;
@ -74,13 +72,11 @@ import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EnderSignal;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
import org.bukkit.inventory.Inventory;
@ -794,12 +790,10 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
}
default void gotoJigsaw(IrisJigsawStructure s, Player player) {
if(s.getLoadKey().equals(getDimension().getStronghold()))
{
if (s.getLoadKey().equals(getDimension().getStronghold())) {
KList<Position2> p = getDimension().getStrongholds(getSeedManager().getSpawn());
if(p.isEmpty())
{
if (p.isEmpty()) {
player.sendMessage(C.GOLD + "No strongholds in world.");
}
@ -905,10 +899,8 @@ 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())
{
default void cleanupMantleChunk(int x, int z) {
if (IrisSettings.get().getPerformance().isTrimMantleInStudio() || !isStudio()) {
J.a(() -> getMantle().cleanupChunk(x, z));
}
}

View File

@ -71,26 +71,19 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on(PlayerTeleportEvent e) {
if(ignoreTP.get())
{
if (ignoreTP.get()) {
return;
}
if(!PaperLib.isPaper() || e.getTo() == null)
{
if (!PaperLib.isPaper() || e.getTo() == null) {
return;
}
try
{
if(e.getTo().getWorld().equals(getTarget().getWorld().realWorld()))
{
try {
if (e.getTo().getWorld().equals(getTarget().getWorld().realWorld())) {
getEngine().getWorldManager().teleportAsync(e);
}
}
catch(Throwable ex)
{
} catch (Throwable ex) {
}
}

View File

@ -32,19 +32,16 @@ public interface EngineMode extends Staged {
Engine getEngine();
default MultiBurst burst()
{
default MultiBurst burst() {
return getEngine().burst();
}
default EngineStage burst(EngineStage... stages)
{
default EngineStage burst(EngineStage... stages) {
return (x, z, blocks, biomes, multicore) -> {
BurstExecutor e = burst().burst(stages.length);
e.setMulticore(multicore);
for(EngineStage i : stages)
{
for (EngineStage i : stages) {
e.queue(() -> i.generate(x, z, blocks, biomes, multicore));
}
@ -52,13 +49,11 @@ public interface EngineMode extends Staged {
};
}
default IrisComplex getComplex()
{
default IrisComplex getComplex() {
return getEngine().getComplex();
}
default EngineMantle getMantle()
{
default EngineMantle getMantle() {
return getEngine().getMantle();
}
@ -67,8 +62,7 @@ public interface EngineMode extends Staged {
}
@BlockCoordinates
default void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes, boolean multicore)
{
default void generate(int x, int z, Hunk<BlockData> blocks, Hunk<Biome> biomes, boolean multicore) {
for (EngineStage i : getStages()) {
i.generate(x, z, blocks, biomes, multicore);
}

View File

@ -25,18 +25,15 @@ public abstract class IrisEngineMode implements EngineMode {
private final KList<EngineStage> stages;
private boolean closed;
public IrisEngineMode(Engine engine)
{
public IrisEngineMode(Engine engine) {
this.engine = engine;
this.stages = new KList<>();
this.closed = false;
}
@Override
public synchronized void close()
{
if(closed)
{
public synchronized void close() {
if (closed) {
return;
}

View File

@ -18,14 +18,16 @@
package com.volmit.iris.engine.framework;
public interface MeteredCache
{
import com.volmit.iris.util.data.KCache;
public interface MeteredCache {
long getSize();
KCache<?, ?> getRawCache();
long getMaxSize();
default double getUsage()
{
default double getUsage() {
return (double) getSize() / (double) getMaxSize();
}

View File

@ -25,8 +25,7 @@ public interface Staged {
void registerStage(EngineStage stage);
default void dump()
{
default void dump() {
getStages().forEach(EngineStage::close);
getStages().clear();
}

View File

@ -18,7 +18,6 @@
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;
@ -46,12 +45,9 @@ 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
@ -185,7 +181,7 @@ public interface EngineMantle extends IObjectPlacer {
}
default void trim() {
getMantle().trim(TimeUnit.SECONDS.toMillis(IrisSettings.get().getPerformance().getMantleKeepAliveSeconds()));
getMantle().trim(TimeUnit.SECONDS.toMillis(IrisSettings.get().getPerformance().getMantleKeepAlive()));
}
default MultiBurst burst() {
@ -269,16 +265,14 @@ public interface EngineMantle extends IObjectPlacer {
MantleObjectComponent getObjectComponent();
default boolean isCovered(int x, int z)
{
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))
{
if (!getMantle().hasFlag(xx, zz, MantleFlag.REAL)) {
return false;
}
}
@ -287,10 +281,8 @@ public interface EngineMantle extends IObjectPlacer {
return true;
}
default void cleanupChunk(int x, int z)
{
if(!getMantle().hasFlag(x, z, MantleFlag.CLEANED) && isCovered(x, z))
{
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);

View File

@ -524,9 +524,17 @@ public class MantleWriter implements IObjectPlacer {
}
public <T> void set(IrisPosition pos, T data) {
try
{
setData(pos.getX(), pos.getY(), pos.getZ(), data);
}
catch(Throwable e)
{
Iris.error("No set? " + data.toString() + " for " + pos.toString());
}
}
public <T> void set(List<IrisPosition> positions, T data) {
for (IrisPosition i : positions) {
set(i, data);

View File

@ -25,8 +25,7 @@ import com.volmit.iris.engine.framework.EngineMode;
import com.volmit.iris.engine.framework.IrisEngineMode;
public class ModeEnclosure extends IrisEngineMode implements EngineMode {
public ModeEnclosure(Engine engine)
{
public ModeEnclosure(Engine engine) {
super(engine);
var terrain = new IrisTerrainNormalActuator(getEngine());
var biome = new IrisBiomeActuator(getEngine());

View File

@ -25,8 +25,7 @@ import com.volmit.iris.engine.framework.EngineMode;
import com.volmit.iris.engine.framework.IrisEngineMode;
public class ModeIslands extends IrisEngineMode implements EngineMode {
public ModeIslands(Engine engine)
{
public ModeIslands(Engine engine) {
super(engine);
var terrain = new IrisTerrainNormalActuator(getEngine());
var biome = new IrisBiomeActuator(getEngine());

View File

@ -31,8 +31,7 @@ import com.volmit.iris.engine.modifier.IrisPostModifier;
import org.bukkit.block.data.BlockData;
public class ModeOverworld extends IrisEngineMode implements EngineMode {
public ModeOverworld(Engine engine)
{
public ModeOverworld(Engine engine) {
super(engine);
var terrain = new IrisTerrainNormalActuator(getEngine());
var biome = new IrisBiomeActuator(getEngine());
@ -49,11 +48,9 @@ public class ModeOverworld extends IrisEngineMode implements EngineMode {
));
registerStage((x, z, k, p, m) -> cave.modify(x >> 4, z >> 4, k, m));
registerStage((x, z, k, p, m) -> deposit.modify(x, z, k, m));
registerStage(burst(
(x, z, k, p, m) -> decorant.actuate(x, z, k, m),
(x, z, k, p, m) -> post.modify(x, z, k, m),
(x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m)
));
registerStage((x, z, k, p, m) -> decorant.actuate(x, z, k, m));
registerStage((x, z, k, p, m) -> post.modify(x, z, k, m));
registerStage((x, z, K, p, m) -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, K, m));
registerStage((x, z, k, p, m) -> perfection.modify(x, z, k, m));
}
}

View File

@ -25,8 +25,7 @@ import com.volmit.iris.engine.framework.EngineMode;
import com.volmit.iris.engine.framework.IrisEngineMode;
public class ModeSuperFlat extends IrisEngineMode implements EngineMode {
public ModeSuperFlat(Engine engine)
{
public ModeSuperFlat(Engine engine) {
super(engine);
var terrain = new IrisTerrainNormalActuator(getEngine());
var biome = new IrisBiomeActuator(getEngine());

View File

@ -39,7 +39,6 @@ import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterCavern;
import com.volmit.iris.util.matter.slices.MarkerMatter;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import com.volmit.iris.util.stream.utility.CachedStream2D;
import lombok.Data;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
@ -237,6 +236,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
blocks = biome.generateCeilingLayers(getDimension(), xx, zz, rng, 3, zone.ceiling, getData(), getComplex());
if (zone.ceiling + 1 < mantle.getWorldHeight()) {
for (int i = 0; i < zone.ceiling + 1; i++) {
if (!blocks.hasIndex(i)) {
break;
@ -257,6 +257,7 @@ public class IrisCarveModifier extends EngineAssignedModifier<BlockData> {
output.set(rx, zone.ceiling + i + 1, rz, b);
}
}
}
@Data
public static class CaveZone {

View File

@ -1,9 +1,26 @@
/*
* 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.engine.object;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.annotations.ArrayType;
import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.engine.object.annotations.RegistryListResource;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KList;
import lombok.Data;

View File

@ -1,6 +1,29 @@
/*
* 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.engine.object;
import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.engine.object.annotations.ArrayType;
import com.volmit.iris.engine.object.annotations.DependsOn;
import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.engine.object.annotations.MaxNumber;
import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.RNG;
import lombok.Data;

View File

@ -44,13 +44,11 @@ public enum IrisDimensionModeType {
;
private final Function<Engine, EngineMode> factory;
IrisDimensionModeType(Function<Engine, EngineMode> factory)
{
IrisDimensionModeType(Function<Engine, EngineMode> factory) {
this.factory = factory;
}
public EngineMode create(Engine e)
{
public EngineMode create(Engine e) {
return factory.apply(e);
}
}

View File

@ -21,8 +21,13 @@ package com.volmit.iris.engine.object;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.annotations.*;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.engine.object.annotations.ArrayType;
import com.volmit.iris.engine.object.annotations.DependsOn;
import com.volmit.iris.engine.object.annotations.Desc;
import com.volmit.iris.engine.object.annotations.MaxNumber;
import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.scheduling.ChronoLatch;
import com.volmit.iris.util.scheduling.J;

View File

@ -26,10 +26,7 @@ import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.RegistryListResource;
import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterFluidBody;
import com.volmit.iris.util.noise.CNG;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

View File

@ -26,10 +26,7 @@ import com.volmit.iris.engine.object.annotations.MinNumber;
import com.volmit.iris.engine.object.annotations.RegistryListResource;
import com.volmit.iris.engine.object.annotations.Required;
import com.volmit.iris.engine.object.annotations.Snippet;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.MatterFluidBody;
import com.volmit.iris.util.noise.CNG;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

View File

@ -29,7 +29,6 @@ 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;
@ -41,7 +40,6 @@ 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;
@ -51,7 +49,6 @@ 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
@ -135,16 +132,14 @@ public class HeadlessGenerator implements PlatformChunkGenerator {
}
private Position2 avgLast(int x, int z) {
while(last.size() > 3)
{
while (last.size() > 3) {
last.remove(0);
}
double xx = 0;
double zz = 0;
for(Position2 i : last)
{
for (Position2 i : last) {
xx += 27 * (i.getX() - x);
zz += 27 * (i.getZ() - z);
}

View File

@ -42,12 +42,9 @@ public class KMap<K, V> extends ConcurrentHashMap<K, V> {
put(gMap);
}
public K getKey(V value)
{
for(KeyPair<K,V> i : keypair())
{
if(i.getV().equals(value))
{
public K getKey(V value) {
for (KeyPair<K, V> i : keypair()) {
if (i.getV().equals(value)) {
return i.getK();
}
}

View File

@ -400,13 +400,11 @@ public class B {
try {
String bd = bdxf.trim();
if(bd.startsWith("minecraft:cauldron[level="))
{
if (bd.startsWith("minecraft:cauldron[level=")) {
bd = bd.replaceAll("\\Q:cauldron[\\E", ":water_cauldron[");
}
if(bd.equals("minecraft:grass_path"))
{
if (bd.equals("minecraft:grass_path")) {
return DIRT_PATH.createBlockData();
}

View File

@ -0,0 +1,50 @@
/*
* 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;
import com.volmit.iris.util.function.Function2;
import java.util.concurrent.atomic.AtomicReferenceArray;
public class ChunkCache<T> {
private final AtomicReferenceArray<T> cache;
public ChunkCache() {
cache = new AtomicReferenceArray<>(256);
}
public T compute(int x, int z, Function2<Integer, Integer, T> function) {
T t = get(x & 15, z & 15);
if (t == null) {
t = function.apply(x, z);
set(x & 15, z & 15, t);
}
return t;
}
private void set(int x, int z, T t) {
cache.set(x * 16 + z, t);
}
private T get(int x, int z) {
return cache.get(x * 16 + z);
}
}

View File

@ -0,0 +1,42 @@
/*
* 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;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.collection.KMap;
public class ComplexCache<T> {
private final KMap<Long, ChunkCache<T>> chunks;
public ComplexCache() {
chunks = new KMap<>();
}
public boolean has(int x, int z) {
return chunks.containsKey(Cache.key(x, z));
}
public void invalidate(int x, int z) {
chunks.remove(Cache.key(x, z));
}
public ChunkCache<T> chunk(int x, int z) {
return chunks.computeIfAbsent(Cache.key(x, z), (f) -> new ChunkCache<>());
}
}

View File

@ -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.data;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
/**
* <p>Encodes signed and unsigned values using a common variable-length
* scheme, found for example in
* <a href="http://code.google.com/apis/protocolbuffers/docs/encoding.html">
* Google's Protocol Buffers</a>. It uses fewer bytes to encode smaller values,
* but will use slightly more bytes to encode large values.</p>
* <p/>
* <p>Signed values are further encoded using so-called zig-zag encoding
* in order to make them "compatible" with variable-length encoding.</p>
*/
public final class DUTF {
private DUTF() {
}
public static void write(String s, DataOutputStream dos) throws IOException {
byte[] b = s.getBytes(StandardCharsets.UTF_8);
dos.writeShort(b.length);
dos.write(b);
}
public static String read(DataInputStream din) throws IOException {
byte[] d = new byte[din.readShort()];
din.read(d);
return new String(d, StandardCharsets.UTF_8);
}
}

View File

@ -16,23 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.util.hunk.bits.DataContainer;
import com.volmit.iris.util.hunk.bits.Writable;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.RNG;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
public class MatterTest {
public static void test()
{
package com.volmit.iris.util.data;
}
@FunctionalInterface
public interface Heafty {
int getHeaft();
}

View File

@ -22,17 +22,22 @@ import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.volmit.iris.engine.framework.MeteredCache;
import java.util.function.Function;
import com.volmit.iris.util.math.RollingSequence;
public class KCache<K, V> implements MeteredCache {
private long max;
private final long max;
private CacheLoader<K, V> loader;
private LoadingCache<K, V> cache;
private final LoadingCache<K, V> cache;
private final boolean fastDump;
private final RollingSequence msu = new RollingSequence(100);
public KCache(CacheLoader<K, V> loader, long max)
{
public KCache(CacheLoader<K, V> loader, long max) {
this(loader, max, false);
}
public KCache(CacheLoader<K, V> loader, long max, boolean fastDump) {
this.max = max;
this.fastDump = fastDump;
this.loader = loader;
this.cache = create(loader);
}
@ -41,29 +46,25 @@ public class KCache<K,V> implements MeteredCache {
return Caffeine
.newBuilder()
.maximumSize(max)
.softValues()
.initialCapacity((int) (max))
.build((k) -> loader == null ? null : loader.load(k));
}
public void setLoader(CacheLoader<K, V> loader)
{
public void setLoader(CacheLoader<K, V> loader) {
this.loader = loader;
}
public void invalidate(K k)
{
public void invalidate(K k) {
cache.invalidate(k);
}
public void invalidate()
{
LoadingCache<?,?> c = cache;
cache = create(loader);
c.invalidateAll();
public void invalidate() {
cache.invalidateAll();
}
public V get(K k)
{
public V get(K k) {
return cache.get(k);
}
@ -72,6 +73,11 @@ public class KCache<K,V> implements MeteredCache {
return cache.estimatedSize();
}
@Override
public KCache<?, ?> getRawCache() {
return this;
}
@Override
public long getMaxSize() {
return max;

View File

@ -59,32 +59,26 @@ public class BitStorage {
this(bits, length, (AtomicLongArray) null);
}
private static AtomicLongArray atomic(long[] data)
{
if(data == 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++)
{
for (int i = 0; i < data.length; i++) {
d.set(i, data[i]);
}
return d;
}
private static long[] atomic(AtomicLongArray data)
{
if(data == null)
{
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++)
{
for (int i = 0; i < data.length(); i++) {
d[i] = data.get(i);
}
@ -107,8 +101,7 @@ public class BitStorage {
this.divideShift = MAGIC[var3 + 2];
int var4 = (length + this.valuesPerLong - 1) / this.valuesPerLong;
if (data != null) {
if (data.length() != var4)
{
if (data.length() != var4) {
throw new RuntimeException("NO!");
}
this.data = data;
@ -166,8 +159,7 @@ public class BitStorage {
public void getAll(IntConsumer var0) {
int var1 = 0;
for(int i = 0; i < data.length(); i++)
{
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));

View File

@ -20,7 +20,6 @@ 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;
@ -49,16 +48,14 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
public K byId(int var0) {
if (var0 < 0 || var0 >= this.byId.length())
{
if (var0 < 0 || var0 >= this.byId.length()) {
return null;
}
return this.byId.get(var0);
}
private int getValue(int var0) {
if (var0 == -1)
{
if (var0 == -1) {
return -1;
}
return this.values.get(var0);
@ -79,8 +76,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
}
private int nextId() {
while (nextId < byId.length() && byId.get(nextId) != null)
{
while (nextId < byId.length() && byId.get(nextId) != null) {
nextId++;
}
return nextId;
@ -95,8 +91,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
this.nextId = 0;
this.size = 0;
for (int var3 = 0; var3 < var1.length(); var3++) {
if (var1.get(var3) != null)
{
if (var1.get(var3) != null) {
addMapping(var1.get(var3), var2.get(var3));
}
}
@ -126,8 +121,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
private int indexOf(K var0, int var1) {
int var2;
for (var2 = var1; var2 < this.keys.length(); var2++) {
if (this.keys.get(var2) == null)
{
if (this.keys.get(var2) == null) {
return 0;
}
if (this.keys.get(var2).equals(var0))
@ -160,6 +154,7 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
public Iterator<K> iterator() {
return Iterators.filter(new Iterator<K>() {
int i = 0;
@Override
public boolean hasNext() {
return i < byId.length() - 1;
@ -174,15 +169,12 @@ public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
public void clear() {
for(int i = 0; i < Math.max(keys.length(), byId.length()); i++)
{
if(i < keys.length() - 1)
{
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)
{
if (i < byId.length() - 1) {
byId.set(i, null);
}
}

View File

@ -18,8 +18,6 @@
package com.volmit.iris.util.data.palette;
import com.volmit.iris.util.nbt.tag.ListTag;
import java.util.List;
import java.util.function.Predicate;
@ -28,11 +26,9 @@ public class GlobalPalette<T> implements Palette<T> {
private final T defaultValue;
public GlobalPalette(T... f)
{
public GlobalPalette(T... f) {
IdMapper<T> mapper = new IdMapper<>();
for(T i : f)
{
for (T i : f) {
mapper.add(i);
}
registry = mapper;

View File

@ -20,12 +20,8 @@ package com.volmit.iris.util.data.palette;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KMap;
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 KMap<T, Integer> values;
@ -41,16 +37,14 @@ public class HashMapPalette<T> implements Palette<T> {
}
public int idFor(T var0) {
if(var0 == null)
{
if (var0 == null) {
return 0;
}
return this.values.computeIfAbsent(var0, (k) -> {
int newId = id++;
if (newId >= 1 << this.bits)
{
if (newId >= 1 << this.bits) {
Iris.info(newId + " to...");
newId = this.resizeHandler.onResize(this.bits + 1, var0);
Iris.info(newId + "..");

View File

@ -49,8 +49,7 @@ 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)
{
while (this.idToT.size() <= var1) {
this.idToT.add(null);
}
this.idToT.set(var1, var0);
@ -68,8 +67,7 @@ public class IdMapper<T> implements IdMap<T> {
}
public final T byId(int var0) {
if (var0 >= 0 && var0 < this.idToT.size())
{
if (var0 >= 0 && var0 < this.idToT.size()) {
return this.idToT.get(var0);
}
return null;

View File

@ -20,7 +20,6 @@ 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;
@ -37,13 +36,11 @@ public class LinearPalette<T> implements Palette<T> {
public int idFor(T var0) {
int var1;
for (var1 = 0; var1 < size; var1++) {
if(values.get(var1) == null && var0 == null)
{
if (values.get(var1) == null && var0 == null) {
return var1;
}
if (values.get(var1) != null && values.get(var1).equals(var0))
{
if (values.get(var1) != null && values.get(var1).equals(var0)) {
return var1;
}
}
@ -57,8 +54,7 @@ public class LinearPalette<T> implements Palette<T> {
}
public T valueFor(int var0) {
if (var0 >= 0 && var0 < size)
{
if (var0 >= 0 && var0 < size) {
return this.values.get(var0);
}
return null;
@ -70,8 +66,7 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public void read(List<T> fromList) {
for (int i = 0; i < fromList.size(); i++)
{
for (int i = 0; i < fromList.size(); i++) {
values.set(i, fromList.get(i));
}
@ -80,8 +75,7 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public void write(List<T> toList) {
for (int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
T v = values.get(i);
toList.add(v);
}

View File

@ -18,11 +18,7 @@
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> {
int idFor(T paramT);

View File

@ -42,8 +42,7 @@ public interface PaletteType<T> {
int v = Varint.readUnsignedVarInt(din);
List<T> t = new ArrayList<>();
for(int i = 0; i < v; i++)
{
for (int i = 0; i < v; i++) {
t.add(readPaletteNode(din));
}

View File

@ -21,8 +21,8 @@ package com.volmit.iris.util.data.palette;
import com.volmit.iris.Iris;
import com.volmit.iris.util.math.M;
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> {
@ -43,8 +43,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
}
private void setBits(int var0) {
if (var0 == this.bits)
{
if (var0 == this.bits) {
return;
}
this.bits = var0;
@ -65,8 +64,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
setBits(var0);
for (int var4 = 0; var4 < var2.getSize(); var4++) {
T var5 = var3.valueFor(var2.get(var4));
if (var5 != null)
{
if (var5 != null) {
set(var4, var5);
}
}
@ -95,8 +93,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
private void set(int var0, T var1) {
int var2 = this.palette.idFor(var1);
if(M.r(0.003))
{
if (M.r(0.003)) {
Iris.info("ID for " + var1 + " is " + var2 + " Palette: " + palette.getSize());
}
@ -113,8 +110,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
public void read(List<T> palette, long[] data) {
int var2 = Math.max(4, Mth.ceillog2(palette.size()));
if (var2 != this.bits)
{
if (var2 != this.bits) {
setBits(var2);
}
@ -124,8 +120,7 @@ public class PalettedContainer<T> implements PaletteResize<T> {
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++)
{
for (int var5 = 0; var5 < 4096; var5++) {
this.storage.set(var5, var4.get(var5));
}
}

View File

@ -528,19 +528,29 @@ public class VirtualDecreeCommand {
m++;
}
if (sender.isPlayer()) {
CompletableFuture<String> future = new CompletableFuture<>();
Iris.service(CommandSVC.class).post(password, future);
if (IrisSettings.get().getGeneral().isCommandSounds() && sender.isPlayer()) {
if (IrisSettings.get().getGeneral().isCommandSounds()) {
(sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.65f);
(sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.125f, 1.99f);
}
try {
return future.get(15, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
}
} else {
CompletableFuture<String> future = new CompletableFuture<>();
Iris.service(CommandSVC.class).postConsole(future);
try {
return future.get(15, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException ignored) {
}
}
return null;
}

View File

@ -24,9 +24,11 @@ import com.volmit.iris.util.math.RollingSequence;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
@ -158,6 +160,40 @@ public class Form {
return wrap(s, len, newLineSep, soft, " ");
}
public static String hardWrap(String s, int len) {
StringBuilder ss = new StringBuilder();
for(int i = 0; i < s.length(); i+= len)
{
if(i + len > s.length())
{
ss.append(s, i, s.length());
break;
}
ss.append(s, i, i + len).append("\n");
}
return ss.toString();
}
public static List<String> hardWrapList(String s, int len) {
List<String> l = new ArrayList<>();
for(int i = 0; i < s.length(); i+= len)
{
if(i + len > s.length())
{
l.add(s.substring(i));
break;
}
l.add(s.substring(i, i + len));
}
return l;
}
/**
* Wrap words
*

View File

@ -18,7 +18,6 @@
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;
@ -30,9 +29,9 @@ public class MemoryMonitor {
private long garbageLast;
private long garbageBin;
private long pressure;
private ChronoLatch cl;
private RollingSequence pressureAvg;
private Runtime runtime;
private final ChronoLatch cl;
private final RollingSequence pressureAvg;
private final Runtime runtime;
public MemoryMonitor(int sampleDelay) {
this.runtime = Runtime.getRuntime();
@ -56,74 +55,55 @@ public class MemoryMonitor {
looper.start();
}
public long getGarbageBytes()
{
public long getGarbageBytes() {
return garbageMemory;
}
public long getUsedBytes()
{
public long getUsedBytes() {
return usedMemory;
}
public long getMaxBytes()
{
public long getMaxBytes() {
return runtime.maxMemory();
}
public long getPressure()
{
public long getPressure() {
return (long) pressureAvg.getAverage();
}
public double getUsagePercent()
{
public double getUsagePercent() {
return usedMemory / (double) getMaxBytes();
}
private void sample() {
long used = getVMUse();
if(usedMemory == -1)
{
if (usedMemory == -1) {
usedMemory = used;
garbageMemory = 0;
return;
}
if(used < usedMemory)
{
if (used < usedMemory) {
usedMemory = used;
}
else
{
} else {
garbageMemory = used - usedMemory;
}
long g = garbageMemory - garbageLast;
if(g >= 0)
{
if (g >= 0) {
garbageBin += g;
garbageLast = garbageMemory;
}
else
{
} else {
garbageMemory = 0;
garbageLast = 0;
}
if(cl.flip())
{
if(garbageMemory > 0)
{
if (cl.flip()) {
if (garbageMemory > 0) {
pressure = garbageBin;
garbageBin = 0;
}
else
{
} else {
pressure = 0;
garbageBin = 0;
}
@ -136,10 +116,8 @@ public class MemoryMonitor {
return runtime.totalMemory() - runtime.freeMemory();
}
public void close()
{
if(looper != null)
{
public void close() {
if (looper != null) {
looper.interrupt();
looper = null;
}

View File

@ -65,9 +65,8 @@ public class DataBits {
this(bits, length, (AtomicLongArray) null);
}
public DataBits(int bits, int length, DataInputStream din) throws IOException
{
this(bits, length, longs(din));
public DataBits(int bits, int length, DataInputStream din) throws IOException {
this(bits, length, longs(din, dataLength(bits, length)));
}
public DataBits(int bits, int length, AtomicLongArray data) {
@ -83,8 +82,7 @@ public class DataBits {
int var4 = (length + valuesPerLong - 1) / valuesPerLong;
if (data != null) {
if (data.length() != var4)
{
if (data.length() != var4) {
throw new RuntimeException("NO! Trying to load " + data.length() + " into actual size of " + var4 + " because length: " + length + " (bits: " + bits + ")");
}
this.data = data;
@ -93,36 +91,30 @@ public class DataBits {
}
}
public String toString()
{
public String toString() {
return "DBits: " + size + "/" + bits + "[" + data.length() + "]";
}
private static int dataLength(int bits, int length)
{
private static int dataLength(int bits, int length) {
return (length + ((char) (64 / bits)) - 1) / ((char) (64 / bits));
}
private static AtomicLongArray longs(DataInputStream din) throws IOException{
AtomicLongArray a = new AtomicLongArray(din.readInt());
private static AtomicLongArray longs(DataInputStream din, int longSize) throws IOException {
AtomicLongArray a = new AtomicLongArray(longSize);
for(int i = 0; i < a.length(); i++)
{
a.set(i, din.readLong());
for (int i = 0; i < a.length(); i++) {
a.set(i, Varint.readUnsignedVarLong(din));
}
return a;
}
public DataBits setBits(int newBits)
{
if(bits != newBits)
{
public DataBits setBits(int newBits) {
if (bits != newBits) {
DataBits newData = new DataBits(newBits, size);
AtomicInteger c = new AtomicInteger(0);
for(int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
newData.set(i, get(i));
}
@ -183,14 +175,12 @@ public class DataBits {
public void getAll(IntConsumer var0) {
int var1 = 0;
for(int i = 0; i < data.length(); i++)
{
for (int i = 0; i < data.length(); i++) {
long var5 = data.get(i);
for (int var7 = 0; var7 < valuesPerLong; var7++) {
var0.accept((int) (var5 & mask));
var5 >>= bits;
if (++var1 >= size)
{
if (++var1 >= size) {
return;
}
}
@ -198,11 +188,8 @@ public class DataBits {
}
public void write(DataOutputStream dos) throws IOException {
dos.writeInt(data.length());
for(int i = 0; i < data.length(); i++)
{
dos.writeLong(data.get(i));
for (int i = 0; i < data.length(); i++) {
Varint.writeUnsignedVarLong(data.get(i), dos);
}
}
}

View File

@ -31,7 +31,7 @@ import java.util.concurrent.atomic.AtomicReference;
public class DataContainer<T> {
protected static final int INITIAL_BITS = 3;
protected static final int LINEAR_BITS_LIMIT = 5;
protected static final int LINEAR_BITS_LIMIT = 4;
protected static final int LINEAR_INITIAL_LENGTH = (int) Math.pow(2, LINEAR_BITS_LIMIT) + 1;
protected static final int[] BIT = computeBitLimits();
private final AtomicReference<Palette<T>> palette;
@ -40,114 +40,157 @@ public class DataContainer<T> {
private final int length;
private final Writable<T> writer;
public DataContainer(Writable<T> writer, int length, T empty)
{
public DataContainer(Writable<T> writer, int length) {
this.writer = writer;
this.length = length;
this.bits = new AtomicInteger(INITIAL_BITS);
this.data = new AtomicReference<>(new DataBits(INITIAL_BITS, length));
this.palette = new AtomicReference<>(newPalette(INITIAL_BITS));
this.ensurePaletted(empty);
}
public DataContainer(DataInputStream din, Writable<T> writer) throws IOException {
this.writer = writer;
this.length = din.readInt();
this.length = Varint.readUnsignedVarInt(din);
this.palette = new AtomicReference<>(newPalette(din));
this.data = new AtomicReference<>(new DataBits(palette.get().bits(), length, din));
this.bits = new AtomicInteger(palette.get().bits());
}
public static String readBitString(DataInputStream din) throws IOException
{
DataContainer<Character> c = new DataContainer<>(din, new Writable<Character>() {
@Override
public Character readNodeData(DataInputStream din) throws IOException {
return din.readChar();
}
@Override
public void writeNodeData(DataOutputStream dos, Character character) throws IOException {
dos.writeChar(character);
}
});
StringBuilder sb = new StringBuilder();
for(int i = c.size()-1; i >= 0; i--)
{
sb.setCharAt(i, c.get(i));
}
return sb.toString();
}
public static void writeBitString(String s, DataOutputStream dos) throws IOException {
DataContainer<Character> c = new DataContainer<>(new Writable<Character>() {
@Override
public Character readNodeData(DataInputStream din) throws IOException {
return din.readChar();
}
@Override
public void writeNodeData(DataOutputStream dos, Character character) throws IOException {
dos.writeChar(character);
}
}, s.length());
for(int i = 0; i < s.length(); i++)
{
c.set(i, s.charAt(i));
}
c.writeDos(dos);
}
public DataBits getData()
{
return data.get();
}
public Palette<T> getPalette()
{
return palette.get();
}
public String toString() {
return "DataContainer <" + length + " x " + bits + " bits> -> Palette<" + palette.get().getClass().getSimpleName().replaceAll("\\QPalette\\E", "") + ">: " + palette.get().size() +
" " + data.get().toString() + " PalBit: " + palette.get().bits();
}
public byte[] write() throws IOException
{
public byte[] write() throws IOException {
ByteArrayOutputStream boas = new ByteArrayOutputStream();
write(boas);
return boas.toByteArray();
}
public void write(OutputStream out) throws IOException
{
public void write(OutputStream out) throws IOException {
writeDos(new DataOutputStream(out));
}
public void writeDos(DataOutputStream dos) throws IOException
{
dos.writeInt(length);
dos.writeInt(palette.get().size());
public void writeDos(DataOutputStream dos) throws IOException {
Varint.writeUnsignedVarInt(length, dos);
Varint.writeUnsignedVarInt(palette.get().size(), dos);
palette.get().iterateIO((data, __) -> writer.writeNodeData(dos, data));
data.get().write(dos);
dos.flush();
}
private Palette<T> newPalette(DataInputStream din) throws IOException {
int paletteSize = din.readInt();
Palette<T> d = newPalette(bits(paletteSize));
int paletteSize = Varint.readUnsignedVarInt(din);
Palette<T> d = newPalette(bits(paletteSize+1));
d.from(paletteSize, writer, din);
return d;
}
private Palette<T> newPalette(int bits)
{
if(bits <= LINEAR_BITS_LIMIT)
{
private Palette<T> newPalette(int bits) {
if (bits <= LINEAR_BITS_LIMIT) {
return new LinearPalette<>(LINEAR_INITIAL_LENGTH);
}
return new HashPalette<>();
}
private void checkBits()
{
if(palette.get().size() >= BIT[bits.get()])
{
setBits(bits.get() + 1);
public void ensurePaletted(T t) {
if (palette.get().id(t) == -1) {
expandOne();
}
}
public void ensurePaletted(T t)
{
if(palette.get().id(t) == -1)
{
checkBits();
}
}
public void set(int position, T t)
public void set(int position, T t) {
synchronized (this)
{
int id = palette.get().id(t);
if(id == -1)
{
checkBits();
if (id == -1) {
expandOne();
id = palette.get().add(t);
}
data.get().set(position, id);
}
}
public T get(int position)
private void expandOne() {
if (palette.get().size() + 1 >= BIT[bits.get()]) {
setBits(bits.get() + 1);
}
}
public T get(int position) {
synchronized (this)
{
int id = data.get().get(position) + 1;
if(id <= 0)
{
if (id <= 0) {
return null;
}
return palette.get().get(id - 1);
}
}
public void setBits(int bits)
{
if(this.bits.get() != bits)
{
if(this.bits.get() <= LINEAR_BITS_LIMIT != bits <= LINEAR_BITS_LIMIT)
{
public void setBits(int bits) {
if (this.bits.get() != bits) {
if (this.bits.get() <= LINEAR_BITS_LIMIT != bits <= LINEAR_BITS_LIMIT) {
palette.set(newPalette(bits).from(palette.get()));
}
@ -159,29 +202,28 @@ public class DataContainer<T> {
private static int[] computeBitLimits() {
int[] m = new int[16];
for(int i = 0; i < m.length; i++)
{
for (int i = 0; i < m.length; i++) {
m[i] = (int) Math.pow(2, i);
}
return m;
}
protected static int bits(int size)
{
if(DataContainer.BIT[INITIAL_BITS] >= size)
{
protected static int bits(int size) {
if (DataContainer.BIT[INITIAL_BITS] >= size) {
return INITIAL_BITS;
}
for(int i = 0; i < DataContainer.BIT.length; i++)
{
if(DataContainer.BIT[i] >= size)
{
for (int i = 0; i < DataContainer.BIT.length; i++) {
if (DataContainer.BIT[i] >= size) {
return i;
}
}
return DataContainer.BIT.length - 1;
}
public int size() {
return getData().getSize();
}
}

View File

@ -18,7 +18,6 @@
package com.volmit.iris.util.hunk.bits;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.function.Consumer2;
@ -30,17 +29,16 @@ public class HashPalette<T> implements Palette<T> {
private final KMap<Integer, T> lookup;
private final AtomicInteger size;
public HashPalette()
{
public HashPalette() {
this.size = new AtomicInteger(0);
this.palette = new LinkedHashMap<>();
this.lookup = new KMap<>();
add(null);
}
@Override
public T get(int id) {
if(id < 0 || id >= size.get())
{
if (id < 0 || id >= size.get()) {
return null;
}
@ -52,8 +50,7 @@ public class HashPalette<T> implements Palette<T> {
int index = size.getAndIncrement();
palette.put(t, index);
if(t != null)
{
if (t != null) {
lookup.put(index, t);
}
@ -62,19 +59,28 @@ public class HashPalette<T> implements Palette<T> {
@Override
public int id(T t) {
if(t == null)
{
return 0;
}
Integer v = palette.get(t);
return v != null ? v : -1;
}
@Override
public int size() {
return size.get();
return size.get() - 1;
}
@Override
public void iterate(Consumer2<T, Integer> c) {
for(T i : palette.keySet())
for (T i : palette.keySet()) {
if(i == null)
{
continue;
}
c.accept(i, id(i));
}
}

View File

@ -18,7 +18,9 @@
package com.volmit.iris.util.hunk.bits;
import com.volmit.iris.Iris;
import com.volmit.iris.util.function.Consumer2;
import org.bukkit.block.data.BlockData;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@ -28,16 +30,15 @@ public class LinearPalette<T> implements Palette<T> {
private final AtomicReference<AtomicReferenceArray<T>> palette;
private final AtomicInteger size;
public LinearPalette(int initialSize)
{
public LinearPalette(int initialSize) {
this.size = new AtomicInteger(0);
this.palette = new AtomicReference<>(new AtomicReferenceArray<>(initialSize));
palette.get().set(size.getAndIncrement(), null);
}
@Override
public T get(int id) {
if(id < 0 || id >= size.get())
{
if (id < 0 || id >= size.get()) {
return null;
}
@ -53,12 +54,10 @@ public class LinearPalette<T> implements Palette<T> {
}
private void grow(int newLength) {
if(newLength > palette.get().length())
{
if (newLength > palette.get().length()) {
AtomicReferenceArray<T> a = new AtomicReferenceArray<>(newLength + size.get());
for(int i = 0; i < palette.get().length(); i++)
{
for (int i = 0; i < palette.get().length(); i++) {
a.set(i, palette.get().get(i));
}
@ -68,15 +67,13 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public int id(T t) {
for(int i = 0; i < size(); i++)
if(t == null)
{
if(t == null && palette.get().get(i) == null)
{
return i;
return 0;
}
if(t != null && t.equals(palette.get().get(i)))
{
for (int i = 1; i < size() + 1; i++) {
if (t.equals(palette.get().get(i))) {
return i;
}
}
@ -86,13 +83,12 @@ public class LinearPalette<T> implements Palette<T> {
@Override
public int size() {
return size.get();
return size.get()-1;
}
@Override
public void iterate(Consumer2<T, Integer> c) {
for(int i = 0; i < size(); i++)
{
for (int i = 1; i < size()+1; i++) {
c.accept(palette.get().get(i), i);
}
}

View File

@ -34,15 +34,13 @@ public interface Palette<T> {
int size();
default int bits()
{
return DataContainer.bits(size());
default int bits() {
return DataContainer.bits(size()+1);
}
void iterate(Consumer2<T, Integer> c);
default void iterateIO(Consumer2IO<T, Integer> c)
{
default void iterateIO(Consumer2IO<T, Integer> c) {
iterate((a, b) -> {
try {
c.accept(a, b);
@ -53,22 +51,19 @@ public interface Palette<T> {
}
default Palette<T> from(int size, Writable<T> writable, DataInputStream in) throws IOException {
for(int i = 0; i < size; i++)
{
for (int i = 0; i < size; i++) {
add(writable.readNodeData(in));
}
return this;
}
default Palette<T> from(Palette<T> oldPalette)
{
default Palette<T> from(Palette<T> oldPalette) {
oldPalette.iterate((k, v) -> add(k));
return this;
}
default KList<T> list()
{
default KList<T> list() {
KList<T> t = new KList<>();
iterate((tx, __) -> t.add(tx));
return t;

View File

@ -0,0 +1,110 @@
/*
* 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.bits;
import com.volmit.iris.Iris;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KSet;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.io.IO;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.slices.BlockMatter;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Set;
public class TecTest {
public static Set<BlockData> randomBlocks(int max)
{
KSet<BlockData> d = new KSet<>();
while(d.size() < max)
{
Material m = Material.values()[RNG.r.i(Material.values().length - 1)];
if(m.isBlock())
{
d.add(m.createBlockData());
}
}
return d;
}
public static void go()
{
}
public static boolean test(int size, int pal)
{
try
{
Iris.info("Test? " + size + " " + pal);
KList<BlockData> blocks = new KList<>(randomBlocks(pal));
Iris.info("Fill " + pal + " -> " + size + " Entries");
Writable<BlockData> writer = new BlockMatter();
DataContainer<BlockData> dc = new DataContainer<>(writer, size);
for(int i = 0; i < dc.size(); i++)
{
dc.set(i, blocks.getRandom());
}
Iris.info(dc.toString());
byte[] dat = dc.write();
DataContainer<BlockData> dx = new DataContainer<>(new DataInputStream(new ByteArrayInputStream(dat)), writer);
Iris.info(dx.toString());
byte[] dat2 = dx.write();
Iris.info("Size: " + Form.memSize(dat.length, 2) + " -> " + Form.memSize(dat2.length, 2));
if(Arrays.equals(dat, dat2)) {
Iris.info("MATCH");
return true;
}
else
{
for(int i = 0; i < dc.size(); i++)
{
if(!dx.get(i).equals(dc.get(i)))
{
Iris.info("FAIL Expected " + dc.get(i).getAsString(true) + " but got " + dx.get(i).getAsString(true));
return false;
}
}
Iris.info("MATCH but different output?");
return true;
}
}
catch(Throwable e)
{
e.printStackTrace();
return false;
}
}
}

View File

@ -27,7 +27,6 @@ import lombok.EqualsAndHashCode;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
@Data

View File

@ -18,8 +18,6 @@
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;
@ -29,7 +27,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;
@SuppressWarnings({"DefaultAnnotationParam", "Lombok"})
@Data
@ -37,16 +35,15 @@ import java.util.Map;
public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
private DataContainer<T> data;
public PaletteHunk(int w, int h, int d, Writable<T> writer, T e) {
public PaletteHunk(int w, int h, int d, Writable<T> writer) {
super(w, h, d);
data = new DataContainer<>(writer, w * h * d, e);
data = new DataContainer<>(writer, w * h * d);
}
public void setPalette(DataContainer<T> c) {
data = c;
}
public boolean isMapped() {
return false;
}
@ -57,15 +54,11 @@ public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
@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++)
{
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)
{
if (t != null) {
c.accept(i, j, k, t);
}
}
@ -76,15 +69,11 @@ public class PaletteHunk<T> extends StorageHunk<T> implements Hunk<T> {
@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++)
{
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)
{
if (t != null) {
c.accept(i, j, k, t);
}
}

View File

@ -18,7 +18,6 @@
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;
@ -26,30 +25,27 @@ import com.volmit.iris.util.hunk.bits.DataContainer;
import com.volmit.iris.util.hunk.bits.Writable;
import java.io.IOException;
import java.util.Map;
import java.util.function.Supplier;
public abstract class PaletteOrHunk<T> extends StorageHunk<T> implements Hunk<T>, Writable<T> {
private final Hunk<T> hunk;
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory, T e) {
public PaletteOrHunk(int width, int height, int depth, boolean allow, Supplier<Hunk<T>> factory) {
super(width, height, depth);
hunk = (allow) ? new PaletteHunk<>(width, height, depth, this, e) : factory.get();
hunk = (allow && (width * height * depth <= 4096)) ? new PaletteHunk<>(width, height, depth, this) : factory.get();
}
public DataContainer<T> palette()
{
public DataContainer<T> palette() {
return isPalette() ? ((PaletteHunk<T>) hunk).getData() : null;
}
public void setPalette(DataContainer<T> c) {
if(isPalette())
{
if (isPalette()) {
((PaletteHunk<T>) hunk).setPalette(c);
}
}
public boolean isPalette()
{
public boolean isPalette() {
return hunk instanceof PaletteHunk;
}

View File

@ -19,13 +19,13 @@
package com.volmit.iris.util.io;
import com.volmit.iris.Iris;
import com.volmit.iris.util.format.Form;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.CharArrayWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -163,11 +163,14 @@ public class IO {
return new String(hexChars).toUpperCase();
}
public static String print(byte[] bytes) {
return Form.memSize(bytes.length, 2) + "[" + bytesToHex(bytes) + "]";
}
public static String longsToHex(long[] bytes) {
byte[] v = new byte[bytes.length * 8];
for(int i = 0; i < bytes.length; i++)
{
for (int i = 0; i < bytes.length; i++) {
v[i * 8] = (byte) (bytes[i] >>> 56);
v[(i * 8) + 1] = (byte) (bytes[i] >>> 48);
v[(i * 8) + 2] = (byte) (bytes[i] >>> 40);

View File

@ -38,7 +38,6 @@ import com.volmit.iris.util.matter.MatterSlice;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.HyperLock;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.J;
import lombok.Getter;
import org.bukkit.Chunk;
@ -477,6 +476,7 @@ public class Mantle {
if (file.exists()) {
try {
Iris.addPanic("reading.tectonic-plate", file.getAbsolutePath());
region = TectonicPlate.read(worldHeight, file);
if (region.getX() != x || region.getZ() != z) {
@ -488,6 +488,8 @@ public class Mantle {
} catch (Throwable e) {
Iris.error("Failed to read Tectonic Plate " + file.getAbsolutePath() + " creating a new chunk instead.");
Iris.reportError(e);
e.printStackTrace();
Iris.panic();
region = new TectonicPlate(worldHeight, x, z);
loadedRegions.put(k, region);
Iris.debug("Created new Tectonic Plate (Due to Load Failure) " + C.DARK_GREEN + x + " " + z);

View File

@ -18,6 +18,8 @@
package com.volmit.iris.util.mantle;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.EnginePanic;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.function.Consumer4;
import com.volmit.iris.util.matter.IrisMatter;
@ -77,8 +79,9 @@ public class MantleChunk {
}
for (int i = 0; i < s; i++) {
Iris.addPanic("read.section", "Section[" + i + "]");
if (din.readBoolean()) {
sections.set(i, Matter.read(din));
sections.set(i, Matter.readDin(din));
}
}
}

View File

@ -19,13 +19,11 @@
package com.volmit.iris.util.mantle;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.EnginePanic;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.documentation.ChunkCoordinates;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.nbt.mca.Section;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Getter;
@ -77,7 +75,9 @@ public class TectonicPlate {
this(worldHeight, din.readInt(), din.readInt());
for (int i = 0; i < chunks.length(); i++) {
if (din.readBoolean()) {
Iris.addPanic("read-chunk", "Chunk[" + i + "]");
chunks.set(i, new MantleChunk(sectionHeight, din));
EnginePanic.saveLast();
}
}
}

View File

@ -44,6 +44,11 @@ public class IrisMatter extends IrisRegistrant implements Matter {
private final KMap<Class<?>, MatterSlice<?>> sliceMap;
public IrisMatter(int width, int height, int depth) {
if(width < 1 || height < 1 || depth < 1)
{
throw new RuntimeException("Invalid Matter Size " + width + "x" + height + "x" + depth);
}
this.width = width;
this.height = height;
this.depth = depth;

View File

@ -18,6 +18,7 @@
package com.volmit.iris.util.matter;
import com.volmit.iris.Iris;
import com.volmit.iris.engine.object.IrisObject;
import com.volmit.iris.engine.object.IrisPosition;
import com.volmit.iris.util.collection.KSet;
@ -95,6 +96,10 @@ public interface Matter {
return read(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
}
static Matter readDin(DataInputStream in) throws IOException, ClassNotFoundException {
return readDin(in, (b) -> new IrisMatter(b.getX(), b.getY(), b.getZ()));
}
/**
* Reads the input stream into a matter object using a matter factory.
* Does not close the input stream. Be a man, close it yourself.
@ -105,16 +110,26 @@ public interface Matter {
* @throws IOException shit happens yo
*/
static Matter read(InputStream in, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
DataInputStream din = new DataInputStream(in);
Matter matter = matterFactory.apply(new BlockPosition(
Varint.readUnsignedVarInt(din),
Varint.readUnsignedVarInt(din),
Varint.readUnsignedVarInt(din)));
int sliceCount = din.readByte();
matter.getHeader().read(din);
return readDin(new DataInputStream(in), matterFactory);
}
while (sliceCount-- > 0) {
static Matter readDin(DataInputStream din, Function<BlockPosition, Matter> matterFactory) throws IOException, ClassNotFoundException {
Matter matter = matterFactory.apply(new BlockPosition(
din.readInt(),
din.readInt(),
din.readInt()));
Iris.addPanic("read.matter.size", matter.getWidth() + "x" + matter.getHeight() + "x" + matter.getDepth());
int sliceCount = din.readByte();
Iris.addPanic("read.matter.slicecount", sliceCount + "");
matter.getHeader().read(din);
Iris.addPanic("read.matter.header", matter.getHeader().toString());
for(int i = 0; i < sliceCount; i++)
{
Iris.addPanic("read.matter.slice", i + "");
String cn = din.readUTF();
Iris.addPanic("read.matter.slice.class", cn);
try {
Class<?> type = Class.forName(cn);
MatterSlice<?> slice = matter.createSlice(type, matter);
@ -336,10 +351,6 @@ public interface Matter {
Map<Class<?>, MatterSlice<?>> getSliceMap();
default void write(File f) throws IOException {
write(f, true);
}
default void write(File f, boolean compression) throws IOException {
OutputStream out = new FileOutputStream(f);
write(out);
out.close();
@ -381,9 +392,9 @@ public interface Matter {
default void writeDos(DataOutputStream dos) throws IOException {
trimSlices();
Varint.writeUnsignedVarInt(getWidth(), dos);
Varint.writeUnsignedVarInt(getHeight(), dos);
Varint.writeUnsignedVarInt(getDepth(), dos);
dos.writeInt(getWidth());
dos.writeInt(getHeight());
dos.writeInt(getDepth());
dos.writeByte(getSliceTypes().size());
getHeader().write(dos);

View File

@ -34,13 +34,13 @@ public class MatterHeader {
public void write(DataOutputStream out) throws IOException {
out.writeUTF(author);
Varint.writeUnsignedVarLong(createdAt, out);
Varint.writeUnsignedVarInt(version, out);
out.writeLong(createdAt);
out.writeShort(version);
}
public void read(DataInputStream din) throws IOException {
setAuthor(din.readUTF());
setCreatedAt(Varint.readUnsignedVarLong(din));
setVersion(Varint.readUnsignedVarInt(din));
setCreatedAt(din.readLong());
setVersion(din.readShort());
}
}

View File

@ -19,12 +19,10 @@
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.bits.DataContainer;
import com.volmit.iris.util.hunk.bits.Writable;
@ -38,8 +36,6 @@ 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>, PaletteType<T>, Writable<T> {
Class<T> getType();
@ -164,8 +160,8 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
default void write(DataOutputStream dos) throws IOException {
dos.writeUTF(getType().getCanonicalName());
if((this instanceof PaletteOrHunk f && f.isPalette()))
{
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
f.palette().writeDos(dos);
return;
}
@ -189,8 +185,7 @@ public interface MatterSlice<T> extends Hunk<T>, PaletteType<T>, Writable<T> {
}
default void read(DataInputStream din) throws IOException {
if((this instanceof PaletteOrHunk f && f.isPalette()))
{
if ((this instanceof PaletteOrHunk f && f.isPalette())) {
f.setPalette(new DataContainer<>(din, this));
return;
}

View File

@ -21,10 +21,10 @@ 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.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -44,7 +44,7 @@ public class BlockMatter extends RawMatter<BlockData> {
}
public BlockMatter(int width, int height, int depth) {
super(width, height, depth, BlockData.class, AIR);
super(width, height, depth, BlockData.class);
registerWriter(World.class, ((w, d, x, y, z) -> w.getBlockAt(x, y, z).setBlockData(d)));
registerReader(World.class, (w, x, y, z) -> {
BlockData d = w.getBlockAt(x, y, z).getBlockData();
@ -59,6 +59,6 @@ public class BlockMatter extends RawMatter<BlockData> {
@Override
public BlockData readNode(DataInputStream din) throws IOException {
return B.get(din.readUTF());
return Bukkit.createBlockData(din.readUTF());
}
}

View File

@ -20,7 +20,6 @@ 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;
@ -38,7 +37,7 @@ public class BooleanMatter extends RawMatter<Boolean> {
}
public BooleanMatter(int width, int height, int depth) {
super(width, height, depth, Boolean.class, false);
super(width, height, depth, Boolean.class);
}
@Override

View File

@ -21,7 +21,6 @@ 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;
@ -41,7 +40,7 @@ public class CavernMatter extends RawMatter<MatterCavern> {
}
public CavernMatter(int width, int height, int depth) {
super(width, height, depth, MatterCavern.class, EMPTY);
super(width, height, depth, MatterCavern.class);
}
public static MatterCavern get(String customBiome, int liquid) {

View File

@ -33,7 +33,6 @@ 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;
@ -55,7 +54,7 @@ public class EntityMatter extends RawMatter<MatterEntityGroup> {
}
public EntityMatter(int width, int height, int depth) {
super(width, height, depth, MatterEntityGroup.class, EMPTY);
super(width, height, depth, MatterEntityGroup.class);
registerWriter(World.class, ((w, d, x, y, z) -> {
for (MatterEntity i : d.getEntities()) {
Location realPosition = new Location(w, x + i.getXOff(), y + i.getYOff(), z + i.getZOff());

View File

@ -21,7 +21,6 @@ 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;
@ -39,7 +38,7 @@ public class IntMatter extends RawMatter<Integer> {
}
public IntMatter(int width, int height, int depth) {
super(width, height, depth, Integer.class, 0);
super(width, height, depth, Integer.class);
}
@Override

View File

@ -21,7 +21,6 @@ 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;
@ -39,7 +38,7 @@ public class LongMatter extends RawMatter<Long> {
}
public LongMatter(int width, int height, int depth) {
super(width, height, depth, Long.class, 0L);
super(width, height, depth, Long.class);
}
@Override

View File

@ -22,7 +22,6 @@ 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;
@ -45,7 +44,7 @@ public class MarkerMatter extends RawMatter<MatterMarker> {
}
public MarkerMatter(int width, int height, int depth) {
super(width, height, depth, MatterMarker.class, NONE);
super(width, height, depth, MatterMarker.class);
}
@Override

View File

@ -20,10 +20,7 @@ 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.CompoundTag;
import com.volmit.iris.util.nbt.tag.IntTag;
import com.volmit.iris.util.nbt.tag.Tag;
import org.bukkit.entity.Player;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@ -31,7 +28,7 @@ import java.io.IOException;
public class NBTMatter<T extends Tag<?>> extends RawMatter<T> {
public NBTMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c, e);
super(width, height, depth, c);
}
@Override

View File

@ -19,7 +19,6 @@
package com.volmit.iris.util.matter.slices;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.hunk.bits.Writable;
import com.volmit.iris.util.hunk.storage.MappedHunk;
import com.volmit.iris.util.hunk.storage.PaletteOrHunk;
import com.volmit.iris.util.matter.MatterReader;
@ -37,8 +36,8 @@ public abstract class RawMatter<T> extends PaletteOrHunk<T> implements MatterSli
@Getter
private final Class<T> type;
public RawMatter(int width, int height, int depth, Class<T> type, T e) {
super(width, height, depth, false, () -> new MappedHunk<>(width, height, depth), e);
public RawMatter(int width, int height, int depth, Class<T> type) {
super(width, height, depth, true, () -> new MappedHunk<>(width, height, depth));
writers = new KMap<>();
readers = new KMap<>();
this.type = type;

View File

@ -21,7 +21,6 @@ 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;
@ -29,7 +28,7 @@ import java.io.IOException;
public class RegistryMatter<T extends IrisRegistrant> extends RawMatter<T> {
public RegistryMatter(int width, int height, int depth, Class<T> c, T e) {
super(width, height, depth, c, e);
super(width, height, depth, c);
}
@Override

View File

@ -32,7 +32,7 @@ public class StringMatter extends RawMatter<String> {
}
public StringMatter(int width, int height, int depth) {
super(width, height, depth, String.class, "");
super(width, height, depth, String.class);
}
@Override

View File

@ -45,7 +45,7 @@ public class TileMatter extends RawMatter<MatterTile> {
}
public TileMatter(int width, int height, int depth) {
super(width, height, depth, MatterTile.class, EMPTY);
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))));
registerReader(World.class, (w, x, y, z) -> {
Location l = new Location(w, x, y, z);

View File

@ -20,7 +20,6 @@ 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;
@ -44,7 +43,7 @@ public class UpdateMatter extends RawMatter<MatterUpdate> {
}
public UpdateMatter(int width, int height, int depth) {
super(width, height, depth, MatterUpdate.class, OFF);
super(width, height, depth, MatterUpdate.class);
}
@Override

View File

@ -253,7 +253,13 @@ public class Chunk {
}
public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) {
Section section = sections.get(MCAUtil.blockToChunk(blockY));
int s = MCAUtil.blockToChunk(blockY);
if (sections.length() <= s) {
return null;
}
Section section = sections.get(s);
if (section == null) {
return null;
}
@ -274,6 +280,11 @@ public class Chunk {
*/
public void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) {
int sectionIndex = MCAUtil.blockToChunk(blockY);
if (sections.length() <= sectionIndex) {
return;
}
Section section = sections.get(sectionIndex);
if (section == null) {
section = Section.newSection();

View File

@ -18,7 +18,6 @@
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;

View File

@ -79,8 +79,7 @@ public class MCALinearPalette<T> implements MCAPalette<T> {
}
public void read(ListTag var0) {
for (int var1 = 0; var1 < var0.size(); var1++)
{
for (int var1 = 0; var1 < var0.size(); var1++) {
this.values[var1] = this.reader.apply((CompoundTag) var0.get(var1));
}
this.size = var0.size();

View File

@ -23,6 +23,7 @@ import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import java.util.List;
import java.util.concurrent.Callable;
@ -151,9 +152,21 @@ public class MultiBurst {
public void close() {
if (service != null) {
service.shutdown();
PrecisionStopwatch p = PrecisionStopwatch.start();
try {
while (!service.awaitTermination(10, TimeUnit.SECONDS)) {
while (!service.awaitTermination(1, TimeUnit.SECONDS)) {
Iris.info("Still waiting to shutdown burster...");
if (p.getMilliseconds() > 7000) {
Iris.warn("Forcing Shutdown...");
try {
service.shutdownNow();
} catch (Throwable e) {
}
break;
}
}
} catch (Throwable e) {
e.printStackTrace();

View File

@ -72,8 +72,7 @@ public interface Job {
}, sender.isPlayer() ? 0 : 20);
f.whenComplete((fs, ff) -> {
J.car(c);
if(!silentMsg)
{
if (!silentMsg) {
sender.sendMessage(C.AQUA + "Completed " + getName() + " in " + Form.duration(p.getMilliseconds(), 1));
}
whenComplete.run();

View File

@ -288,16 +288,12 @@ public interface ProceduralStream<T> extends ProceduralLayer, Interpolated<T> {
return new To3DStream<T>(this);
}
default ProceduralStream<T> cache2D(Engine engine, int maxSize) {
return cache2D(engine, maxSize, false);
default ProceduralStream<T> cache2D(String name, Engine engine, int size) {
return new CachedStream2D<T>(name, engine, this, size);
}
default ProceduralStream<T> cache2D(Engine engine, int maxSize, boolean weak) {
return new CachedStream2D<T>(engine, this, maxSize, weak);
}
default ProceduralStream<T> cache3D(Engine engine, int maxSize) {
return new CachedStream3D<T>(engine, this, maxSize);
default ProceduralStream<T> cache3D(String name, Engine engine, int maxSize) {
return new CachedStream3D<T>(name, engine, this, maxSize);
}
default <V> ProceduralStream<V> convert(Function<T, V> converter) {

View File

@ -18,11 +18,7 @@
package com.volmit.iris.util.stream.utility;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
import com.volmit.iris.Iris;
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.service.PreservationSVC;
import com.volmit.iris.engine.data.cache.Cache;
import com.volmit.iris.engine.framework.Engine;
@ -36,7 +32,7 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
private final KCache<Long, T> cache;
private final Engine engine;
public CachedStream2D(Engine engine, ProceduralStream<T> stream, int size, boolean weak) {
public CachedStream2D(String name, Engine engine, ProceduralStream<T> stream, int size) {
super();
this.stream = stream;
this.engine = engine;
@ -69,6 +65,11 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
return cache.getSize();
}
@Override
public KCache<?, ?> getRawCache() {
return cache;
}
@Override
public long getMaxSize() {
return cache.getMaxSize();

View File

@ -32,7 +32,7 @@ public class CachedStream3D<T> extends BasicStream<T> implements ProceduralStrea
private final KCache<BlockPosition, T> cache;
private final Engine engine;
public CachedStream3D(Engine engine, ProceduralStream<T> stream, int size) {
public CachedStream3D(String name, Engine engine, ProceduralStream<T> stream, int size) {
super();
this.stream = stream;
this.engine = engine;
@ -65,6 +65,11 @@ public class CachedStream3D<T> extends BasicStream<T> implements ProceduralStrea
return cache.getSize();
}
@Override
public KCache<?, ?> getRawCache() {
return cache;
}
@Override
public long getMaxSize() {
return cache.getMaxSize();