diff --git a/.github/workflows/gradlebuild.yml b/.github/workflows/gradlebuild.yml index c2e7040dc..8b4b81aaf 100644 --- a/.github/workflows/gradlebuild.yml +++ b/.github/workflows/gradlebuild.yml @@ -12,14 +12,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: set up JDK 16 - uses: actions/setup-java@v2 - with: - java-version: '16' - distribution: 'adopt' + - uses: actions/checkout@v2 + - name: set up JDK 16 + uses: actions/setup-java@v2 + with: + java-version: '16' + distribution: 'adopt' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Build with Gradle - run: ./gradlew build + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build diff --git a/build.gradle b/build.gradle index 9560a1d0c..f0314caac 100644 --- a/build.gradle +++ b/build.gradle @@ -91,10 +91,10 @@ file(jar.archiveFile.get().getAsFile().getParentFile().getParentFile().getParent processResources { filesMatching('**/plugin.yml') { expand( - 'name': name.toString(), - 'version': version.toString(), - 'main': main.toString(), - 'apiversion': apiVersion.toString() + 'name': name.toString(), + 'version': version.toString(), + 'main': main.toString(), + 'apiversion': apiVersion.toString() ) } } @@ -158,17 +158,17 @@ compileJava { } shadowJar -{ - minimize() - append("plugin.yml") - relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic' - relocate 'io.papermc.lib', 'com.volmit.iris.util.paper' - dependencies { - include(dependency('io.papermc:paperlib')) - include(dependency('com.dfsek:Paralithic')) - include(dependency('net.kyori:')) - } -} + { + minimize() + append("plugin.yml") + relocate 'com.dfsek.paralithic', 'com.volmit.iris.util.paralithic' + relocate 'io.papermc.lib', 'com.volmit.iris.util.paper' + dependencies { + include(dependency('io.papermc:paperlib')) + include(dependency('com.dfsek:Paralithic')) + include(dependency('net.kyori:')) + } + } dependencies { // Provided or Classpath @@ -197,4 +197,5 @@ dependencies { implementation 'bsf:bsf:2.4.0' implementation 'rhino:js:1.7R2' implementation 'com.github.ben-manes.caffeine:caffeine:3.0.3' + implementation 'org.apache.commons:commons-lang3:3.12.0' } diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index da8360e3f..a9b0a0a7e 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -31,7 +31,6 @@ import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.biome.IrisBiomeCustom; -import com.volmit.iris.engine.object.block.IrisBlockData; import com.volmit.iris.engine.object.common.IrisWorld; import com.volmit.iris.engine.object.compat.IrisCompat; import com.volmit.iris.engine.object.dimensional.IrisDimension; @@ -49,28 +48,38 @@ 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.nbt.mca.*; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.plugin.*; import com.volmit.iris.util.reflect.ShadeFix; -import com.volmit.iris.util.scheduling.*; +import com.volmit.iris.util.scheduling.J; +import com.volmit.iris.util.scheduling.Looper; +import com.volmit.iris.util.scheduling.Queue; +import com.volmit.iris.util.scheduling.ShurikenQueue; import io.papermc.lib.PaperLib; import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.text.serializer.ComponentSerializer; +import net.minecraft.world.level.chunk.storage.RegionFile; import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.block.data.BlockData; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.generator.ChunkGenerator; import org.bukkit.plugin.Plugin; +import org.checkerframework.checker.units.qual.K; import java.io.*; import java.lang.annotation.Annotation; import java.net.URL; import java.util.Date; import java.util.Map; +import java.util.Set; @SuppressWarnings("CanBeFinal") public class Iris extends VolmitPlugin implements Listener { @@ -117,6 +126,128 @@ public class Iris extends VolmitPlugin implements Listener { }).start(); } + private void testmca() { + try + { + int forceBits = 6; + int possibilities = (int) (Math.pow(2, forceBits) - 1); + KList bp = new KList<>(); + Set bf = new KSet<>(); + + while(bp.size() < possibilities) + { + BlockData b = null; + + while(b == null) + { + try + { + b = Material.values()[RNG.r.i(Material.values().length-1)].createBlockData(); + } + + catch(Throwable e) + { + + } + } + + bp.addIfMissing(b); + } + + MCAFile file = new MCAFile(0, 0); + for(int cx = 0; cx < 32; cx++) + { + for(int cz = 0; cz < 32; cz++) + { + Chunk c = Chunk.newChunk(); + + for(int i = 0; i < 16; i++) + { + for(int j = 0; j < 16; j++) + { + for(int k = 0; k < 16; k++) + { + BlockData b = bp.getRandom(); + c.setBlockStateAt(i,j,k, NBTWorld.getCompound(b), false); + } + } + } + + file.setChunk(cx, cz, c); + } + } + + try { + File f = new File("r.0.0.mca"); + Iris.info("Write " + MCAUtil.write(file, f) + " chunks"); + file = MCAUtil.read(f); + + for(int i = 0; i < 1024; i++) { + Chunk c = file.getChunks().get(i); + + if (c == null) { + Iris.error("Missing Chunk: " + i); + continue; + } + + Section s = c.getSection(0); + + if (s == null) + { + Iris.error("Missing section 0 in chunk: " + i); + continue; + } + + for(int a = 0; a < 16; a++) + { + for(int b = 0; b < 16; b++) + { + for(int ca = 0; ca < 16; ca++) + { + BlockData data = NBTWorld.getBlockData(s.getBlockStateAt(a, b, ca)); + bf.add(data); + } + } + } + } + + Iris.info("Read .. OK?"); + + Iris.info("Possibilities: " + bp.size()); + Iris.info("Read Possibss: " + bf.size()); + int match = 0; + for(BlockData i : bp) + { + if(bf.contains(i)) + { + match++; + } + + else + { + Iris.warn("Couldn't find preset " + i.getAsString(true) + " in any section"); + } + } + + for(BlockData i : bf) + { + if(!bp.contains(i)) + { + Iris.warn("Forign block data " + i.getAsString(true) + "! (ignore leaves, they are modded by us)"); + } + } + Iris.info("Matched: " + match); + } catch (IOException e) { + e.printStackTrace(); + } + } + + catch(Throwable ee) + { + ee.printStackTrace(); + } + } + @SuppressWarnings("unchecked") private void enable() { audiences = BukkitAudiences.create(this); @@ -130,10 +261,10 @@ public class Iris extends VolmitPlugin implements Listener { configWatcher = new FileWatcher(getDataFile("settings.json")); services.values().forEach(IrisService::onEnable); services.values().forEach(this::registerListener); + J.s(this::testmca, 20); } - public void postShutdown(Runnable r) - { + public void postShutdown(Runnable r) { postShutdown.add(r); } @@ -437,18 +568,12 @@ public class Iris extends VolmitPlugin implements Listener { @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { - if(worldName.equals("test")) - { - try - { + if (worldName.equals("test")) { + try { throw new RuntimeException(); - } - - catch(Throwable e) - { + } catch (Throwable e) { Iris.info(e.getStackTrace()[1].getClassName()); - if(e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) - { + if (e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) { Iris.debug("MVC Test detected, Quick! Send them the dummy!"); return new DummyChunkGenerator(); } @@ -490,8 +615,7 @@ public class Iris extends VolmitPlugin implements Listener { Iris.debug("Generator Config: " + w.toString()); File ff = new File(w.worldFolder(), "iris/pack"); - if(!ff.exists() || ff.listFiles().length == 0) - { + if (!ff.exists() || ff.listFiles().length == 0) { ff.mkdirs(); service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile()); } @@ -736,21 +860,17 @@ public class Iris extends VolmitPlugin implements Listener { } } - public static void dump() - { - try - { + public static void dump() { + try { File fi = Iris.instance.getDataFile("dump", "td-" + new java.sql.Date(M.ms()) + ".txt"); - FileOutputStream fos = new FileOutputStream(fi ); + FileOutputStream fos = new FileOutputStream(fi); Map f = Thread.getAllStackTraces(); PrintWriter pw = new PrintWriter(fos); - for(Thread i : f.keySet()) - { + for (Thread i : f.keySet()) { pw.println("========================================"); pw.println("Thread: '" + i.getName() + "' ID: " + i.getId() + " STATUS: " + i.getState().name()); - for(StackTraceElement j : f.get(i)) - { + for (StackTraceElement j : f.get(i)) { pw.println(" @ " + j.toString()); } @@ -761,10 +881,7 @@ public class Iris extends VolmitPlugin implements Listener { pw.close(); System.out.println("DUMPED! See " + fi.getAbsolutePath()); - } - - catch(Throwable e) - { + } catch (Throwable e) { e.printStackTrace(); } } diff --git a/src/main/java/com/volmit/iris/core/IrisSettings.java b/src/main/java/com/volmit/iris/core/IrisSettings.java index 7025af4e3..804e91dae 100644 --- a/src/main/java/com/volmit/iris/core/IrisSettings.java +++ b/src/main/java/com/volmit/iris/core/IrisSettings.java @@ -20,12 +20,9 @@ package com.volmit.iris.core; import com.google.gson.Gson; import com.volmit.iris.Iris; -import com.volmit.iris.engine.object.basic.IrisRange; -import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.json.JSONException; import com.volmit.iris.util.json.JSONObject; -import com.volmit.iris.util.scheduling.J; import lombok.Data; import java.io.File; @@ -57,8 +54,7 @@ public class IrisSettings { return getParallax().getParallaxRegionEvictionMS(); } - public static int getPriority(int c) - { + public static int getPriority(int c) { return Math.max(Math.min(c, Thread.MAX_PRIORITY), Thread.MIN_PRIORITY); } diff --git a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java index fa8e99db0..ab9f42b73 100644 --- a/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java +++ b/src/main/java/com/volmit/iris/core/command/object/CommandIrisObjectAnalyze.java @@ -21,23 +21,13 @@ package com.volmit.iris.core.command.object; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.J; -import com.volmit.iris.util.scheduling.Queue; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; -import java.text.NumberFormat; -import java.util.*; -import java.util.stream.Collectors; - public class CommandIrisObjectAnalyze extends MortarCommand { public CommandIrisObjectAnalyze() { diff --git a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCompile.java b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCompile.java index 6aacda65a..ce8d4fbdf 100644 --- a/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCompile.java +++ b/src/main/java/com/volmit/iris/core/command/studio/CommandIrisStudioCompile.java @@ -21,13 +21,10 @@ package com.volmit.iris.core.command.studio; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.IrisProject; -import com.volmit.iris.core.service.ConversionSVC; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.plugin.MortarCommand; import com.volmit.iris.util.plugin.VolmitSender; -import com.volmit.iris.util.scheduling.jobs.Job; -import com.volmit.iris.util.scheduling.jobs.JobCollection; public class CommandIrisStudioCompile extends MortarCommand { public CommandIrisStudioCompile() { @@ -49,8 +46,7 @@ public class CommandIrisStudioCompile extends MortarCommand { return true; } - if(args.length == 0) - { + if (args.length == 0) { sender.sendMessage(getArgsUsage()); return true; } diff --git a/src/main/java/com/volmit/iris/core/decrees/DecIris.java b/src/main/java/com/volmit/iris/core/decrees/DecIris.java index b4282cc37..1bb668ba2 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -31,14 +31,8 @@ import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.C; -import com.volmit.iris.util.math.M; -import lombok.val; import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintWriter; -import java.sql.Date; -import java.util.Map; @Decree(name = "irisd", aliases = {"ird"}, description = "Basic Command") public class DecIris implements DecreeExecutor { @@ -126,7 +120,8 @@ public class DecIris implements DecreeExecutor { case "%" -> v = value1 % value2; case ">>" -> v = value1 >> value2; case "<<" -> v = value1 << value2; - }; + } + ; if (v == null) { sender().sendMessage(C.RED + "The operator you entered: (" + operator + ") is invalid!"); return; diff --git a/src/main/java/com/volmit/iris/core/decrees/DecObject.java b/src/main/java/com/volmit/iris/core/decrees/DecObject.java index f4deb7b97..89c27cd78 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -115,8 +115,8 @@ public class DecObject implements DecreeExecutor { @Decree(description = "Contract a selection based on your looking direction", aliases = "-") public void contract( @Param(description = "The amount to inset by", defaultValue = "1") - int amount - ){ + int amount + ) { if (!WandSVC.isHoldingWand(player())) { sender().sendMessage("Hold your wand."); return; @@ -140,8 +140,8 @@ public class DecObject implements DecreeExecutor { @Decree(description = "Set point 1 to look", aliases = "p1") public void position1( @Param(description = "Whether to use your current position, or where you look", defaultValue = "true") - boolean here - ){ + boolean here + ) { if (!WandSVC.isHoldingWand(player())) { sender().sendMessage("Ready your Wand."); return; @@ -166,7 +166,7 @@ public class DecObject implements DecreeExecutor { public void position2( @Param(description = "Whether to use your current position, or where you look", defaultValue = "true") boolean here - ){ + ) { if (!WandSVC.isHoldingWand(player())) { sender().sendMessage("Ready your Wand."); return; @@ -186,16 +186,18 @@ public class DecObject implements DecreeExecutor { player().setItemInHand(WandSVC.createWand(g[0], g[1])); } } + private static final Set skipBlocks = Set.of(Material.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH, Material.POPPY, Material.DANDELION); + @Decree(description = "Paste an object") public void paste( @Param(description = "The object to paste", customHandler = ObjectHandler.class) String object, @Param(description = "Whether or not to edit the object (need to hold wand)", defaultValue = "false") - boolean edit, + boolean edit, @Param(description = "The amount of degrees to rotate by", defaultValue = "0") - int rotate, + int rotate, @Param(description = "The factor by which to scale the object placement", defaultValue = "1") double scale // , diff --git a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java index 90abc32d3..ab33c2f32 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecStudio.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecStudio.java @@ -76,7 +76,6 @@ import org.bukkit.util.Vector; import java.awt.*; import java.io.File; import java.io.IOException; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.function.Supplier; diff --git a/src/main/java/com/volmit/iris/core/nms/INMSBinding.java b/src/main/java/com/volmit/iris/core/nms/INMSBinding.java index 78c242df1..f6c218166 100644 --- a/src/main/java/com/volmit/iris/core/nms/INMSBinding.java +++ b/src/main/java/com/volmit/iris/core/nms/INMSBinding.java @@ -18,6 +18,7 @@ package com.volmit.iris.core.nms; +import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID; import com.volmit.iris.util.nbt.tag.CompoundTag; import org.bukkit.Location; import org.bukkit.World; @@ -74,4 +75,6 @@ public interface INMSBinding { default boolean supportsDataPacks() { return false; } + + RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException; } diff --git a/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java b/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java index 542297741..9c83a05ac 100644 --- a/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java +++ b/src/main/java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java @@ -22,6 +22,8 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.nms.INMSBinding; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.nbt.io.NBTUtil; +import com.volmit.iris.util.nbt.mca.NBTWorld; +import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID; import com.volmit.iris.util.nbt.tag.CompoundTag; import net.minecraft.core.BlockPosition; import net.minecraft.core.IRegistry; @@ -35,6 +37,8 @@ import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.WorldServer; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.TileEntity; import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.chunk.BiomeStorage; @@ -44,8 +48,10 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.block.Biome; +import org.bukkit.block.data.BlockData; import org.bukkit.craftbukkit.v1_17_R1.CraftServer; import org.bukkit.craftbukkit.v1_17_R1.CraftWorld; +import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity; import org.bukkit.entity.EntityType; import org.bukkit.generator.ChunkGenerator; @@ -53,6 +59,10 @@ import org.bukkit.generator.ChunkGenerator; import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class NMSBinding17_1 implements INMSBinding { @@ -63,6 +73,24 @@ public class NMSBinding17_1 implements INMSBinding { return true; } + @Override + public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { + Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c"); + Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d"); + cf.setAccessible(true); + df.setAccessible(true); + net.minecraft.core.RegistryBlockID blockData = Block.p; + IdentityHashMap c = (IdentityHashMap) cf.get(blockData); + List d = (List) df.get(blockData); + List realTags = new ArrayList<>(); + HashMap realMap = new HashMap<>(512); + d.forEach((i) -> realTags.add(NBTWorld.getCompound(CraftBlockData.fromData(i)))); + c.forEach((k,v) -> realMap.put(NBTWorld.getCompound(CraftBlockData.fromData(k)), v)); + RegistryBlockID registry = new RegistryBlockID(realMap, realTags); + Iris.info("INMS: Stole Global Palette: " + realTags.size() + " Tags, " + realMap.size() + " Mapped"); + return registry; + } + private Object getBiomeStorage(ChunkGenerator.BiomeGrid g) { try { return getFieldForBiomeStorage(g).get(g); diff --git a/src/main/java/com/volmit/iris/core/nms/v1X/NMSBinding1X.java b/src/main/java/com/volmit/iris/core/nms/v1X/NMSBinding1X.java index e0f8b0f99..ba07fadcb 100644 --- a/src/main/java/com/volmit/iris/core/nms/v1X/NMSBinding1X.java +++ b/src/main/java/com/volmit/iris/core/nms/v1X/NMSBinding1X.java @@ -18,7 +18,9 @@ package com.volmit.iris.core.nms.v1X; +import com.volmit.iris.Iris; import com.volmit.iris.core.nms.INMSBinding; +import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID; import com.volmit.iris.util.nbt.tag.CompoundTag; import org.bukkit.Location; import org.bukkit.World; @@ -142,4 +144,10 @@ public class NMSBinding1X implements INMSBinding { public void forceBiomeInto(int x, int y, int z, Object somethingVeryDirty, ChunkGenerator.BiomeGrid chunk) { } + + @Override + public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { + Iris.error("Cannot use the global data palette! Iris is incapable of using MCA generation on this version of minecraft!"); + return null; + } } diff --git a/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java b/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java index c3f8c7169..3c329c9c1 100644 --- a/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java +++ b/src/main/java/com/volmit/iris/core/pregenerator/methods/AsyncPregenMethod.java @@ -28,7 +28,6 @@ import io.papermc.lib.PaperLib; import org.bukkit.Chunk; import org.bukkit.World; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; public class AsyncPregenMethod implements PregeneratorMethod { diff --git a/src/main/java/com/volmit/iris/core/project/IrisPack.java b/src/main/java/com/volmit/iris/core/project/IrisPack.java index 98822810d..613b654a4 100644 --- a/src/main/java/com/volmit/iris/core/project/IrisPack.java +++ b/src/main/java/com/volmit/iris/core/project/IrisPack.java @@ -32,13 +32,11 @@ import java.net.MalformedURLException; public class IrisPack { private final File folder; - public IrisPack(File folder) - { + public IrisPack(File folder) { this.folder = folder; } - public void delete() - { + public void delete() { IO.delete(folder); folder.delete(); } diff --git a/src/main/java/com/volmit/iris/core/project/IrisProject.java b/src/main/java/com/volmit/iris/core/project/IrisProject.java index 1a949fdc7..35b50adf6 100644 --- a/src/main/java/com/volmit/iris/core/project/IrisProject.java +++ b/src/main/java/com/volmit/iris/core/project/IrisProject.java @@ -39,9 +39,7 @@ import com.volmit.iris.engine.platform.PlatformChunkGenerator; 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.B; 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.io.IO; import com.volmit.iris.util.json.JSONArray; @@ -55,7 +53,6 @@ import com.volmit.iris.util.scheduling.PrecisionStopwatch; import com.volmit.iris.util.scheduling.jobs.Job; import com.volmit.iris.util.scheduling.jobs.JobCollection; import com.volmit.iris.util.scheduling.jobs.ParallelQueueJob; -import com.volmit.iris.util.scheduling.jobs.QueueJob; import lombok.Data; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -519,18 +516,16 @@ public class IrisProject { @Override public void execute(File f) { try { - IrisObject o = new IrisObject(0,0,0); + IrisObject o = new IrisObject(0, 0, 0); o.read(f); - if(o.getBlocks().isEmpty()) - { + if (o.getBlocks().isEmpty()) { sender.sendMessageRaw("" + f.getPath() + "'>- IOB " + f.getName() + " has 0 blocks!"); } - if(o.getW() == 0 || o.getH() == 0 || o.getD() == 0) - { + if (o.getW() == 0 || o.getH() == 0 || o.getD() == 0) { sender.sendMessageRaw("" + f.getPath() + "\nThe width height or depth has a zero in it (bad format)" + "'>- IOB " + f.getName() + " is not 3D!"); @@ -558,7 +553,7 @@ public class IrisProject { } catch (Throwable e) { sender.sendMessageRaw("" + f.getPath() + - "\n" +e.getMessage() + + "\n" + e.getMessage() + "'>- JSON Error " + f.getName()); } } @@ -576,8 +571,7 @@ public class IrisProject { String key = data.toLoadKey(f); ResourceLoader loader = data.getTypedLoaderFor(f); - if(loader == null) - { + if (loader == null) { sender.sendMessageBasic("Can't find loader for " + f.getPath()); return; } @@ -587,15 +581,10 @@ public class IrisProject { load.scanForErrors(p, sender); } - public void compare(Class c, JSONObject j, VolmitSender sender, KList path) - { - try - { + public void compare(Class c, JSONObject j, VolmitSender sender, KList path) { + try { Object o = c.getClass().getConstructor().newInstance(); - } - - catch(Throwable e) - { + } catch (Throwable e) { } } diff --git a/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java b/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java index 989f3126e..609ca038e 100644 --- a/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java +++ b/src/main/java/com/volmit/iris/core/project/SchemaBuilder.java @@ -32,7 +32,6 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.potion.PotionEffectType; import java.awt.*; -import java.lang.reflect.AccessibleObject; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.List; diff --git a/src/main/java/com/volmit/iris/core/project/loader/IrisData.java b/src/main/java/com/volmit/iris/core/project/loader/IrisData.java index 518a151ab..18d857096 100644 --- a/src/main/java/com/volmit/iris/core/project/loader/IrisData.java +++ b/src/main/java/com/volmit/iris/core/project/loader/IrisData.java @@ -19,7 +19,6 @@ package com.volmit.iris.core.project.loader; import com.volmit.iris.Iris; -import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.block.IrisBlockData; @@ -44,9 +43,8 @@ import com.volmit.iris.util.math.RNG; import lombok.Data; import java.io.File; -import java.util.*; +import java.util.Objects; import java.util.function.Function; -import java.util.stream.Collectors; @Data public class IrisData { @@ -73,9 +71,8 @@ public class IrisData { private Engine engine; private final int id; - public static IrisData get(File dataFolder) - { - return dataLoaders.compute(dataFolder, (k,v) -> v == null ? new IrisData(dataFolder) : v); + public static IrisData get(File dataFolder) { + return dataLoaders.compute(dataFolder, (k, v) -> v == null ? new IrisData(dataFolder) : v); } private IrisData(File dataFolder) { @@ -86,20 +83,16 @@ public class IrisData { hotloaded(); } - public static void dereference() - { + public static void dereference() { dataLoaders.v().forEach(IrisData::cleanupEngine); } public ResourceLoader getTypedLoaderFor(File f) { - String[] k = f.getPath().split("\\Q"+File.separator+"\\E"); + String[] k = f.getPath().split("\\Q" + File.separator + "\\E"); - for(String i : k) - { - for(ResourceLoader j : loaders.values()) - { - if(j.getFolderName().equals(i)) - { + for (String i : k) { + for (ResourceLoader j : loaders.values()) { + if (j.getFolderName().equals(i)) { return j; } } @@ -108,10 +101,8 @@ public class IrisData { return null; } - public void cleanupEngine() - { - if(engine != null && engine.isClosed()) - { + public void cleanupEngine() { + if (engine != null && engine.isClosed()) { engine = null; Iris.debug("Dereferenced Data " + getId() + " " + getDataFolder()); } @@ -119,11 +110,9 @@ public class IrisData { public static int cacheSize() { int m = 0; - for(IrisData i : dataLoaders.values()) - { - for(ResourceLoader j : i.getLoaders().values()) - { - m+=j.getLoadCache().size(); + for (IrisData i : dataLoaders.values()) { + for (ResourceLoader j : i.getLoaders().values()) { + m += j.getLoadCache().size(); } } @@ -332,18 +321,14 @@ public class IrisData { } public String toLoadKey(File f) { - if(f.getPath().startsWith(getDataFolder().getPath())) - { + if (f.getPath().startsWith(getDataFolder().getPath())) { String[] full = f.getPath().split("\\Q" + File.separator + "\\E"); String[] df = getDataFolder().getPath().split("\\Q" + File.separator + "\\E"); String g = ""; boolean m = true; - for(int i = 0; i < full.length; i++) - { - if(i >= df.length) - { - if(m) - { + for (int i = 0; i < full.length; i++) { + if (i >= df.length) { + if (m) { m = false; continue; } @@ -354,10 +339,7 @@ public class IrisData { String ff = g.toString().substring(1).split("\\Q.\\E")[0]; return ff; - } - - else - { + } else { Iris.error("Forign file from loader " + f.getPath() + " (loader realm: " + getDataFolder().getPath() + ")"); } diff --git a/src/main/java/com/volmit/iris/core/service/CommandSVC.java b/src/main/java/com/volmit/iris/core/service/CommandSVC.java index 6adaeb2b7..793100629 100644 --- a/src/main/java/com/volmit/iris/core/service/CommandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/CommandSVC.java @@ -18,7 +18,6 @@ package com.volmit.iris.core.service; -import com.volmit.iris.Iris; import com.volmit.iris.core.decrees.DecIris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.util.collection.KList; diff --git a/src/main/java/com/volmit/iris/core/service/PreservationSVC.java b/src/main/java/com/volmit/iris/core/service/PreservationSVC.java index a6ea2ac7f..9628c8b48 100644 --- a/src/main/java/com/volmit/iris/core/service/PreservationSVC.java +++ b/src/main/java/com/volmit/iris/core/service/PreservationSVC.java @@ -28,29 +28,24 @@ import com.volmit.iris.util.scheduling.Looper; import java.util.concurrent.ExecutorService; -public class PreservationSVC implements IrisService -{ +public class PreservationSVC implements IrisService { private KList threads = new KList<>(); private KList services = new KList<>(); private Looper dereferencer; - public void register(Thread t) - { + public void register(Thread t) { threads.add(t); } - public void register(MultiBurst burst) - { + public void register(MultiBurst burst) { } - public void register(ExecutorService service) - { + public void register(ExecutorService service) { services.add(service); } - public void dereference() - { + public void dereference() { IrisContext.dereference(); IrisData.dereference(); } @@ -76,33 +71,22 @@ public class PreservationSVC implements IrisService dereference(); postShutdown(() -> { - for(Thread i : threads) - { - if(i.isAlive()) - { - try - { + for (Thread i : threads) { + if (i.isAlive()) { + try { i.interrupt(); Iris.info("Shutdown Thread " + i.getName()); - } - - catch(Throwable e) - { + } catch (Throwable e) { Iris.reportError(e); } } } - for(ExecutorService i : services) - { - try - { + for (ExecutorService i : services) { + try { i.shutdownNow(); Iris.info("Shutdown Executor Service " + i); - } - - catch(Throwable e) - { + } catch (Throwable e) { Iris.reportError(e); } } diff --git a/src/main/java/com/volmit/iris/core/service/StudioSVC.java b/src/main/java/com/volmit/iris/core/service/StudioSVC.java index 214c581a6..8b28a45c1 100644 --- a/src/main/java/com/volmit/iris/core/service/StudioSVC.java +++ b/src/main/java/com/volmit/iris/core/service/StudioSVC.java @@ -21,7 +21,6 @@ package com.volmit.iris.core.service; import com.google.gson.Gson; import com.google.gson.JsonSyntaxException; import com.volmit.iris.Iris; -import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.IrisProject; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.tools.IrisToolbelt; @@ -77,8 +76,7 @@ public class StudioSVC implements IrisService { for (World i : Bukkit.getWorlds()) { if (IrisToolbelt.isIrisWorld(i)) { - if(IrisToolbelt.isStudio(i)) - { + if (IrisToolbelt.isStudio(i)) { IrisToolbelt.evacuate(i); IrisToolbelt.access(i).close(); } @@ -165,8 +163,7 @@ public class StudioSVC implements IrisService { try { url = getListing(false).get(key); - if(url == null) - { + if (url == null) { Iris.warn("ITS ULL for " + key); } diff --git a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java index dfb0ca4b0..d185e4427 100644 --- a/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java +++ b/src/main/java/com/volmit/iris/core/tools/IrisToolbelt.java @@ -128,7 +128,8 @@ public class IrisToolbelt { return pregenerate(task, new HeadlessPregenMethod(((HeadlessGenerator) gen).getWorld(), (HeadlessGenerator) gen)); } - return pregenerate(task, new HybridPregenMethod(gen.getEngine().getWorld().realWorld(), IrisSettings.getThreadCount((int) IrisSettings.get().getConcurrency().getParallelism()))); + return pregenerate(task, new HybridPregenMethod(gen.getEngine().getWorld().realWorld(), + IrisSettings.getThreadCount((int) IrisSettings.get().getConcurrency().getParallelism()))); } /** diff --git a/src/main/java/com/volmit/iris/engine/IrisComplex.java b/src/main/java/com/volmit/iris/engine/IrisComplex.java index cfff636a1..6b1a9394b 100644 --- a/src/main/java/com/volmit/iris/engine/IrisComplex.java +++ b/src/main/java/com/volmit/iris/engine/IrisComplex.java @@ -19,7 +19,6 @@ 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.project.loader.IrisData; import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; @@ -32,13 +31,10 @@ import com.volmit.iris.engine.object.decoration.IrisDecorationPart; import com.volmit.iris.engine.object.decoration.IrisDecorator; import com.volmit.iris.engine.object.feature.IrisFeaturePositional; import com.volmit.iris.engine.object.noise.IrisGenerator; -import com.volmit.iris.engine.object.noise.IrisInterpolator; -import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle; import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.DataProvider; -import com.volmit.iris.util.function.NoiseProvider; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.CNG; @@ -49,7 +45,6 @@ import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; -import java.lang.reflect.Field; import java.util.List; import java.util.UUID; diff --git a/src/main/java/com/volmit/iris/engine/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 3e6e735f6..590648584 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -30,7 +30,10 @@ import com.volmit.iris.engine.actuator.IrisTerrainNormalActuator; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.*; import com.volmit.iris.engine.mantle.EngineMantle; -import com.volmit.iris.engine.modifier.*; +import com.volmit.iris.engine.modifier.IrisCaveModifier; +import com.volmit.iris.engine.modifier.IrisDepositModifier; +import com.volmit.iris.engine.modifier.IrisPostModifier; +import com.volmit.iris.engine.modifier.IrisRavineModifier; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.biome.IrisBiomePaletteLayer; import com.volmit.iris.engine.object.decoration.IrisDecorator; @@ -41,20 +44,17 @@ import com.volmit.iris.util.atomics.AtomicRollingSequence; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.context.IrisContext; import com.volmit.iris.util.documentation.BlockCoordinates; -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.hunk.Hunk; import com.volmit.iris.util.io.IO; import com.volmit.iris.util.math.M; import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.math.RollingSequence; import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import lombok.Data; -import lombok.EqualsAndHashCode; -import org.bukkit.Chunk; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -62,7 +62,6 @@ import org.bukkit.command.CommandSender; import java.io.File; import java.io.IOException; -import java.util.Random; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -133,13 +132,12 @@ public class IrisEngine implements Engine { } private void tickRandomPlayer() { - if(effects != null) { + if (effects != null) { effects.tickRandomPlayer(); } } - private void prehotload() - { + private void prehotload() { worldManager.close(); complex.close(); execution.close(); @@ -153,10 +151,8 @@ public class IrisEngine implements Engine { effects.close(); } - private void setupEngine() - { - try - { + private void setupEngine() { + try { Iris.debug("Setup Engine " + getCacheID()); cacheId = RNG.r.nextInt(); worldManager = new IrisWorldManager(this); @@ -171,10 +167,7 @@ public class IrisEngine implements Engine { postModifier = new IrisPostModifier(this); effects = new IrisEngineEffects(this); J.a(this::computeBiomeMaxes); - } - - catch(Throwable e) - { + } catch (Throwable e) { Iris.error("FAILED TO SETUP ENGINE!"); e.printStackTrace(); } @@ -397,34 +390,44 @@ public class IrisEngine implements Engine { @BlockCoordinates @Override public void generate(int x, int z, Hunk vblocks, Hunk vbiomes, boolean multicore) throws WrongEngineBroException { - if(closed) - { + if (closed) { throw new WrongEngineBroException(); } context.touch(); getEngineData().getStatistics().generatedChunk(); try { + PrecisionStopwatch p = PrecisionStopwatch.start(); Hunk blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y + getMinHeight(), z + zz, t)); - getMantle().generateMatter(x >> 4, z >> 4, multicore); - burst().burst(multicore, - () -> getTerrainActuator().actuate(x, z, vblocks, multicore), - () -> getBiomeActuator().actuate(x, z, vbiomes, multicore) - ); - burst().burst(multicore, - () -> getCaveModifier().modify(x, z, vblocks, multicore), - () -> getDecorantActuator().actuate(x, z, blocks, multicore), - () -> getRavineModifier().modify(x, z, vblocks, multicore) - ); + if (multicore) { + for (int i = 0; i < 16; i++) { + for (int j = 0; j < 16; j++) { + blocks.set(i, 0, j, Material.RED_GLAZED_TERRACOTTA.createBlockData()); + } + } + } else { + getMantle().generateMatter(x >> 4, z >> 4, multicore); - getPostModifier().modify(x, z, vblocks, multicore); + burst().burst(multicore, + () -> getTerrainActuator().actuate(x, z, vblocks, multicore), + () -> getBiomeActuator().actuate(x, z, vbiomes, multicore) + ); + burst().burst(multicore, + () -> getCaveModifier().modify(x, z, vblocks, multicore), + () -> getDecorantActuator().actuate(x, z, blocks, multicore), + () -> getRavineModifier().modify(x, z, vblocks, multicore) + ); + + getPostModifier().modify(x, z, vblocks, multicore); + + burst().burst(multicore, + () -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore), + () -> getDepositModifier().modify(x, z, vblocks, multicore) + ); + } - burst().burst(multicore, - () -> getMantle().insertMatter(x >> 4, z >> 4, BlockData.class, blocks, multicore), - () -> getDepositModifier().modify(x, z, vblocks, multicore) - ); getMetrics().getTotal().put(p.getMilliseconds()); generated.incrementAndGet(); diff --git a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java index 819b0f227..4ae977893 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngineMantle.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine; -import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; @@ -29,7 +28,6 @@ import com.volmit.iris.engine.mantle.components.MantleJigsawComponent; import com.volmit.iris.engine.mantle.components.MantleObjectComponent; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.deposits.IrisDepositGenerator; -import com.volmit.iris.engine.object.feature.IrisFeaturePositional; import com.volmit.iris.engine.object.feature.IrisFeaturePotential; import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; import com.volmit.iris.engine.object.objects.IrisObject; @@ -39,21 +37,14 @@ import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; -import com.volmit.iris.util.documentation.BlockCoordinates; -import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.mantle.Mantle; -import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.parallel.BurstExecutor; -import com.volmit.iris.util.stream.ProceduralStream; -import com.volmit.iris.util.stream.interpolation.Interpolated; -import com.volmit.iris.util.stream.utility.CachedStream2D; import lombok.Data; import org.bukkit.util.BlockVector; import java.io.File; import java.io.IOException; -import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java index bd794b1ba..f9d261d46 100644 --- a/src/main/java/com/volmit/iris/engine/IrisWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/IrisWorldManager.java @@ -39,7 +39,6 @@ import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.Looper; -import io.papermc.lib.PaperLib; import lombok.Data; import lombok.EqualsAndHashCode; import org.bukkit.Chunk; @@ -99,10 +98,8 @@ public class IrisWorldManager extends EngineAssignedWorldManager { interrupt(); } - if(getEngine().getWorld().hasRealWorld()) - { - if(chunkUpdater.flip()) - { + if (getEngine().getWorld().hasRealWorld()) { + if (chunkUpdater.flip()) { updateChunks(); } @@ -152,8 +149,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager { } private void updateChunks() { - for(Player i : getEngine().getWorld().realWorld().getPlayers()) - { + for (Player i : getEngine().getWorld().realWorld().getPlayers()) { J.s(() -> { Chunk c = i.getLocation().getChunk(); J.a(() -> getEngine().updateChunk(c)); diff --git a/src/main/java/com/volmit/iris/engine/actuator/IrisBiomeActuator.java b/src/main/java/com/volmit/iris/engine/actuator/IrisBiomeActuator.java index 347aad64c..5871fd383 100644 --- a/src/main/java/com/volmit/iris/engine/actuator/IrisBiomeActuator.java +++ b/src/main/java/com/volmit/iris/engine/actuator/IrisBiomeActuator.java @@ -26,12 +26,10 @@ import com.volmit.iris.engine.framework.EngineAssignedActuator; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.biome.IrisBiomeCustom; import com.volmit.iris.util.documentation.BlockCoordinates; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.hunk.view.BiomeGridHunkView; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; -import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator; diff --git a/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java b/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java index 60cab2592..b4ce3231b 100644 --- a/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java +++ b/src/main/java/com/volmit/iris/engine/actuator/IrisDecorantActuator.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine.actuator; -import com.volmit.iris.Iris; import com.volmit.iris.engine.decorator.*; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedActuator; @@ -26,7 +25,6 @@ import com.volmit.iris.engine.framework.EngineDecorator; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.carve.IrisCaveLayer; import com.volmit.iris.util.documentation.BlockCoordinates; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; @@ -35,7 +33,6 @@ import lombok.Getter; import org.bukkit.Material; import org.bukkit.block.data.BlockData; -import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiPredicate; import java.util.function.Predicate; @@ -99,7 +96,7 @@ public class IrisDecorantActuator extends EngineAssignedActuator { int realX = (int) Math.round(modX(x + finalI)); int realZ; IrisBiome biome, cave; - for (int j=0; j < output.getDepth(); j++) { + for (int j = 0; j < output.getDepth(); j++) { boolean solid, liquid; int emptyFor = 0; int liquidFor = 0; @@ -113,8 +110,7 @@ public class IrisDecorantActuator extends EngineAssignedActuator { continue; } - if(height < getDimension().getFluidHeight()) - { + if (height < getDimension().getFluidHeight()) { getSeaSurfaceDecorator().decorate(finalI, j, realX, (int) Math.round(modX(x + finalI + 1)), (int) Math.round(modX(x + finalI - 1)), realZ, (int) Math.round(modZ(z + j + 1)), (int) Math.round(modZ(z + j - 1)), diff --git a/src/main/java/com/volmit/iris/engine/actuator/IrisTerrainNormalActuator.java b/src/main/java/com/volmit/iris/engine/actuator/IrisTerrainNormalActuator.java index 56fce5f95..64341d239 100644 --- a/src/main/java/com/volmit/iris/engine/actuator/IrisTerrainNormalActuator.java +++ b/src/main/java/com/volmit/iris/engine/actuator/IrisTerrainNormalActuator.java @@ -18,11 +18,9 @@ package com.volmit.iris.engine.actuator; -import com.volmit.iris.Iris; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedActuator; import com.volmit.iris.engine.object.biome.IrisBiome; -import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.hunk.Hunk; @@ -66,8 +64,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator getEngine().getMetrics().getTerrain().put(p.getMilliseconds()); } - private int fluidOrHeight(int height) - { + private int fluidOrHeight(int height) { return Math.max(getDimension().getFluidHeight(), height); } @@ -97,7 +94,7 @@ public class IrisTerrainNormalActuator extends EngineAssignedActuator KList blocks = null; KList fblocks = null; - int depth,fdepth; + int depth, fdepth; for (int i = hf; i >= 0; i--) { if (i >= h.getHeight()) { diff --git a/src/main/java/com/volmit/iris/engine/data/cache/AtomicCache.java b/src/main/java/com/volmit/iris/engine/data/cache/AtomicCache.java index 89f5322ac..27341de5d 100644 --- a/src/main/java/com/volmit/iris/engine/data/cache/AtomicCache.java +++ b/src/main/java/com/volmit/iris/engine/data/cache/AtomicCache.java @@ -18,107 +18,68 @@ package com.volmit.iris.engine.data.cache; -import com.volmit.iris.util.math.M; -import com.volmit.iris.util.scheduling.IrisLock; +import com.volmit.iris.Iris; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.ReentrantLock; import java.util.function.Supplier; public class AtomicCache { - private transient volatile T t; - private transient volatile long a; - private transient volatile int validations; - private final IrisLock check; - private final IrisLock time; - private final IrisLock write; - private final boolean nullSupport; + private transient final AtomicReference t; + private transient final AtomicBoolean set; + private transient final ReentrantLock lock; + private transient final boolean nullSupport; public AtomicCache() { this(false); } public AtomicCache(boolean nullSupport) { + set = nullSupport ? new AtomicBoolean() : null; + t = new AtomicReference<>(); + lock = new ReentrantLock(); this.nullSupport = nullSupport; - check = new IrisLock("Check"); - write = new IrisLock("Write"); - time = new IrisLock("Time"); - validations = 0; - a = -1; - t = null; } public void reset() { - check.lock(); - write.lock(); - time.lock(); - a = -1; - t = null; - time.unlock(); - write.unlock(); - check.unlock(); + t.set(null); + + if (nullSupport) { + set.set(false); + } } public T aquire(Supplier t) { - if (nullSupport) { - return aquireNull(t); + if (this.t.get() != null) { + return this.t.get(); + } else if (nullSupport && set.get()) { + return null; } - if (this.t != null && validations > 1000) { - return this.t; + lock.lock(); + + if (this.t.get() != null) { + lock.unlock(); + return this.t.get(); + } else if (nullSupport && set.get()) { + lock.unlock(); + return null; } - if (this.t != null && M.ms() - a > 1000) { - if (this.t != null) { - //noinspection NonAtomicOperationOnVolatileField - validations++; + try { + this.t.set(t.get()); + + if (nullSupport) { + set.set(true); } - - return this.t; + } catch (Throwable e) { + Iris.error("Atomic cache failure!"); + e.printStackTrace(); } - check.lock(); + lock.unlock(); - if (this.t == null) { - write.lock(); - this.t = t.get(); - - time.lock(); - - if (a == -1) { - a = M.ms(); - } - - time.unlock(); - write.unlock(); - } - - check.unlock(); - return this.t; - } - - public T aquireNull(Supplier t) { - if (validations > 1000) { - return this.t; - } - - if (M.ms() - a > 1000) { - //noinspection NonAtomicOperationOnVolatileField - validations++; - return this.t; - } - - check.lock(); - write.lock(); - this.t = t.get(); - - time.lock(); - - if (a == -1) { - a = M.ms(); - } - - time.unlock(); - write.unlock(); - check.unlock(); - return this.t; + return this.t.get(); } } diff --git a/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java b/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java index c09941c07..a461dbb48 100644 --- a/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java +++ b/src/main/java/com/volmit/iris/engine/data/chunk/MCATerrainChunk.java @@ -92,8 +92,7 @@ public class MCATerrainChunk implements TerrainChunk { return; } - if(blockData == null) - { + if (blockData == null) { Iris.error("NULL BD"); } diff --git a/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java b/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java index 24bb11171..0a4298c2c 100644 --- a/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java +++ b/src/main/java/com/volmit/iris/engine/decorator/IrisSeaSurfaceDecorator.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine.decorator; -import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.biome.IrisBiome; diff --git a/src/main/java/com/volmit/iris/engine/framework/BlockUpdater.java b/src/main/java/com/volmit/iris/engine/framework/BlockUpdater.java index b1050f15e..5acfb5c51 100644 --- a/src/main/java/com/volmit/iris/engine/framework/BlockUpdater.java +++ b/src/main/java/com/volmit/iris/engine/framework/BlockUpdater.java @@ -21,8 +21,6 @@ package com.volmit.iris.engine.framework; import com.volmit.iris.util.math.RNG; import org.bukkit.Chunk; import org.bukkit.block.data.BlockData; -import org.bukkit.generator.LimitedRegion; -import org.bukkit.generator.WorldInfo; public interface BlockUpdater { diff --git a/src/main/java/com/volmit/iris/engine/framework/Engine.java b/src/main/java/com/volmit/iris/engine/framework/Engine.java index da5799c4e..a10ae8e6d 100644 --- a/src/main/java/com/volmit/iris/engine/framework/Engine.java +++ b/src/main/java/com/volmit/iris/engine/framework/Engine.java @@ -45,10 +45,8 @@ import com.volmit.iris.util.data.B; import com.volmit.iris.util.data.DataProvider; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.function.Function2; import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.math.BlockPosition; import com.volmit.iris.util.math.M; @@ -60,7 +58,10 @@ import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import com.volmit.iris.util.stream.ProceduralStream; import io.papermc.lib.PaperLib; -import org.bukkit.*; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.block.Biome; import org.bukkit.block.Block; import org.bukkit.block.data.BlockData; @@ -70,7 +71,6 @@ import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import java.awt.*; -import java.awt.Color; import java.util.Arrays; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; @@ -393,8 +393,7 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat items.addAll(i.getLoot(debug, items.isEmpty(), rng, slot, x, y, z, b + b, mgf + b)); } - if(PaperLib.isPaper() && getWorld().hasRealWorld()) - { + if (PaperLib.isPaper() && getWorld().hasRealWorld()) { PaperLib.getChunkAtAsync(getWorld().realWorld(), x >> 4, z >> 4).thenAccept((c) -> { Runnable r = () -> { for (ItemStack i : items) { @@ -404,20 +403,13 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat scramble(inv, rng); }; - if(Bukkit.isPrimaryThread()) - { + if (Bukkit.isPrimaryThread()) { r.run(); - } - - else - { + } else { J.s(r); } }); - } - - else - { + } else { for (ItemStack i : items) { inv.addItem(i); } diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedActuator.java b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedActuator.java index 8460d8e3f..77eae4f29 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedActuator.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedActuator.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine.framework; -import com.volmit.iris.Iris; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.hunk.Hunk; diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedModifier.java b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedModifier.java index e69648b80..6bcbd2267 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedModifier.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedModifier.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine.framework; -import com.volmit.iris.Iris; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.hunk.Hunk; diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java index 593fc55f5..a3349e633 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineAssignedWorldManager.java @@ -80,8 +80,7 @@ public abstract class EngineAssignedWorldManager extends EngineAssignedComponent Iris.debug("Ps: " + p.size()); - for(Position2 i : p) - { + for (Position2 i : p) { Iris.debug("- " + i.getX() + " " + i.getZ()); } diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java b/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java index fb4b0a1af..47b73b49d 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineComponent.java @@ -33,8 +33,7 @@ public interface EngineComponent { String getName(); - default MultiBurst burst() - { + default MultiBurst burst() { return getEngine().burst(); } diff --git a/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java b/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java index 7a7c18b4a..c644c9e3c 100644 --- a/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java +++ b/src/main/java/com/volmit/iris/engine/framework/EngineTarget.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine.framework; -import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.object.common.IrisWorld; import com.volmit.iris.engine.object.dimensional.IrisDimension; diff --git a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java index 9cdaf127b..febb334ba 100644 --- a/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java +++ b/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java @@ -21,11 +21,8 @@ package com.volmit.iris.engine.jigsaw; import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.core.tools.IrisToolbelt; -import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.engine.object.common.IObjectPlacer; -import com.volmit.iris.engine.object.entity.IrisEntity; import com.volmit.iris.engine.object.feature.IrisFeature; import com.volmit.iris.engine.object.feature.IrisFeaturePositional; import com.volmit.iris.engine.object.jigsaw.IrisJigsawPiece; @@ -38,9 +35,7 @@ import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.math.RNG; import lombok.Data; import org.bukkit.Axis; -import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.entity.Entity; import java.util.function.Consumer; @@ -116,20 +111,13 @@ public class PlannedStructure { int offset = i.getPosition().getY() - startHeight; int height = 0; - if(i.getStructure().getStructure().getLockY() == -1) - { - if(i.getStructure().getStructure().getOverrideYRange() != null) - { - height = (int)i.getStructure().getStructure().getOverrideYRange().get(rng, xx, zz, getData()); - } - - else - { + if (i.getStructure().getStructure().getLockY() == -1) { + if (i.getStructure().getStructure().getOverrideYRange() != null) { + height = (int) i.getStructure().getStructure().getOverrideYRange().get(rng, xx, zz, getData()); + } else { height = placer.getHighest(xx, zz, getData()); } - } - - else{ + } else { height = i.getStructure().getStructure().getLockY(); } @@ -244,8 +232,7 @@ public class PlannedStructure { } private boolean generateRotatedPiece(PlannedPiece piece, IrisJigsawPieceConnector pieceConnector, IrisJigsawPiece idea, IrisObjectRotation rotation) { - if (!idea.getPlacementOptions().getRotation().isEnabled()) - { + if (!idea.getPlacementOptions().getRotation().isEnabled()) { rotation = piece.getRotation(); } diff --git a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index 597012502..b644f1c70 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -33,17 +33,13 @@ import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.mantle.Mantle; -import com.volmit.iris.util.mantle.MantleFlag; -import com.volmit.iris.util.noise.CNG; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; -import com.volmit.iris.util.scheduling.PrecisionStopwatch; import org.bukkit.Chunk; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; import java.util.List; -import java.util.concurrent.*; import java.util.function.Consumer; // TODO: MOVE PLACER OUT OF MATTER INTO ITS OWN THING @@ -181,8 +177,7 @@ public interface EngineMantle extends IObjectPlacer { KList post = new KList<>(); Consumer c = (i) -> { - synchronized (post) - { + synchronized (post) { post.add(i); } }; @@ -201,8 +196,7 @@ public interface EngineMantle extends IObjectPlacer { burst.complete(); - while(!post.isEmpty()) - { + while (!post.isEmpty()) { KList px = post.copy(); post.clear(); burst().burst(multicore, px); diff --git a/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java b/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java index c304c7e5d..39353eb7a 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java +++ b/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java @@ -20,7 +20,6 @@ package com.volmit.iris.engine.mantle; import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.engine.IrisEngineMantle; import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.object.common.IObjectPlacer; import com.volmit.iris.engine.object.feature.IrisFeaturePositional; @@ -34,8 +33,7 @@ import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; @Data -public class MantleWriter implements IObjectPlacer -{ +public class MantleWriter implements IObjectPlacer { private final EngineMantle engineMantle; private final Mantle mantle; private final KMap cachedChunks; @@ -43,8 +41,7 @@ public class MantleWriter implements IObjectPlacer private final int x; private final int z; - public MantleWriter(EngineMantle engineMantle, Mantle mantle, int x, int z, int radius) - { + public MantleWriter(EngineMantle engineMantle, Mantle mantle, int x, int z, int radius) { this.engineMantle = engineMantle; this.mantle = mantle; this.cachedChunks = new KMap<>(); @@ -59,8 +56,7 @@ public class MantleWriter implements IObjectPlacer } } - public void setData(int x, int y, int z, T t) - { + public void setData(int x, int y, int z, T t) { int cx = x >> 4; int cz = z >> 4; @@ -68,31 +64,22 @@ public class MantleWriter implements IObjectPlacer return; } - if(cx >= this.x - radius && cx <= this.x + radius - && cz >= this.z - radius && cz <= this.z + radius) - { + if (cx >= this.x - radius && cx <= this.x + radius + && cz >= this.z - radius && cz <= this.z + radius) { MantleChunk chunk = cachedChunks.get(Cache.key(cx, cz)); - if(chunk == null) - { + if (chunk == null) { Iris.error("Mantle Writer Accessed " + cx + "," + cz + " and came up null (and yet within bounds!)"); return; } - if(t instanceof IrisFeaturePositional) - { + if (t instanceof IrisFeaturePositional) { chunk.addFeature((IrisFeaturePositional) t); - } - - else - { + } else { Matter matter = chunk.getOrCreate(y >> 4); matter.slice(matter.getClass(t)).set(x & 15, y & 15, z & 15, t); } - } - - else - { + } else { Iris.error("Mantle Writer[" + this.x + "," + this.z + ",R" + this.radius + "] Tried to access " + x + "," + y + "," + z + " (Chunk " + cx + "," + cz + ") which is OUT OF BOUNDS!"); } } @@ -144,6 +131,6 @@ public class MantleWriter implements IObjectPlacer @Override public void setTile(int xx, int yy, int zz, TileData tile) { - getEngineMantle().setTile(xx,yy,zz,tile); + getEngineMantle().setTile(xx, yy, zz, tile); } } diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisDepositModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisDepositModifier.java index 3e2e7bb63..634a86c02 100644 --- a/src/main/java/com/volmit/iris/engine/modifier/IrisDepositModifier.java +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisDepositModifier.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine.modifier; -import com.volmit.iris.Iris; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedModifier; import com.volmit.iris.engine.object.biome.IrisBiome; @@ -26,11 +25,9 @@ import com.volmit.iris.engine.object.deposits.IrisDepositGenerator; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.engine.object.regional.IrisRegion; import com.volmit.iris.util.data.HeightMap; -import com.volmit.iris.util.format.Form; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.parallel.BurstExecutor; -import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import org.bukkit.block.data.BlockData; import org.bukkit.util.BlockVector; diff --git a/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java b/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java index 5b772153a..52a68a678 100644 --- a/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java +++ b/src/main/java/com/volmit/iris/engine/modifier/IrisPostModifier.java @@ -19,26 +19,14 @@ package com.volmit.iris.engine.modifier; import com.volmit.iris.Iris; -import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineAssignedModifier; import com.volmit.iris.engine.object.biome.IrisBiome; import com.volmit.iris.engine.object.common.CaveResult; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.data.B; -import com.volmit.iris.util.format.Form; -import com.volmit.iris.util.function.*; import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.hunk.storage.ArrayHunk; -import com.volmit.iris.util.math.Average; import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.math.RollingSequence; -import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.scheduling.PrecisionStopwatch; -import com.volmit.iris.util.stream.ProceduralStream; -import com.volmit.iris.util.stream.interpolation.Interpolated; import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Levelled; @@ -46,8 +34,6 @@ import org.bukkit.block.data.Waterlogged; import org.bukkit.block.data.type.Slab; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; -import java.util.function.Supplier; public class IrisPostModifier extends EngineAssignedModifier { private static final BlockData AIR = B.get("AIR"); diff --git a/src/main/java/com/volmit/iris/engine/object/basic/IrisPosition.java b/src/main/java/com/volmit/iris/engine/object/basic/IrisPosition.java index e85f499b1..6e2d9deea 100644 --- a/src/main/java/com/volmit/iris/engine/object/basic/IrisPosition.java +++ b/src/main/java/com/volmit/iris/engine/object/basic/IrisPosition.java @@ -54,8 +54,9 @@ public class IrisPosition { public IrisPosition(Vector v) { this(v.getBlockX(), v.getBlockY(), v.getBlockZ()); } + public IrisPosition(double x, double y, double z) { - this((int)x,(int)y,(int)z); + this((int) x, (int) y, (int) z); } diff --git a/src/main/java/com/volmit/iris/engine/object/biome/IrisBiome.java b/src/main/java/com/volmit/iris/engine/object/biome/IrisBiome.java index e086f36cd..2696a5571 100644 --- a/src/main/java/com/volmit/iris/engine/object/biome/IrisBiome.java +++ b/src/main/java/com/volmit/iris/engine/object/biome/IrisBiome.java @@ -35,7 +35,6 @@ import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; import com.volmit.iris.engine.object.loot.IrisLootReference; import com.volmit.iris.engine.object.meta.IrisEffect; import com.volmit.iris.engine.object.noise.IrisGeneratorStyle; -import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle; import com.volmit.iris.engine.object.noise.IrisSlopeClip; import com.volmit.iris.engine.object.noise.NoiseStyle; import com.volmit.iris.engine.object.objects.IrisObject; @@ -198,8 +197,8 @@ public class IrisBiome extends IrisRegistrant implements IRare { private final transient AtomicCache> genCache = new AtomicCache<>(); private final transient AtomicCache> genCacheMax = new AtomicCache<>(); private final transient AtomicCache> genCacheMin = new AtomicCache<>(); - private final transient AtomicCache> surfaceObjectsCache = new AtomicCache<>(false); - private final transient AtomicCache> carveObjectsCache = new AtomicCache<>(false); + private final transient AtomicCache> surfaceObjectsCache = new AtomicCache<>(); + private final transient AtomicCache> carveObjectsCache = new AtomicCache<>(); private final transient AtomicCache cacheColor = new AtomicCache<>(); private final transient AtomicCache cacheColorObjectDensity = new AtomicCache<>(); private final transient AtomicCache cacheColorDecoratorLoad = new AtomicCache<>(); diff --git a/src/main/java/com/volmit/iris/engine/object/cave/IrisCave.java b/src/main/java/com/volmit/iris/engine/object/cave/IrisCave.java index 13483cd7d..4abb7bca7 100644 --- a/src/main/java/com/volmit/iris/engine/object/cave/IrisCave.java +++ b/src/main/java/com/volmit/iris/engine/object/cave/IrisCave.java @@ -18,26 +18,16 @@ package com.volmit.iris.engine.object.cave; -import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.project.loader.IrisRegistrant; import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.engine.object.noise.IrisWorm; -import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.data.B; import com.volmit.iris.util.json.JSONObject; -import com.volmit.iris.util.mantle.Mantle; -import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.noise.Worm; -import com.volmit.iris.util.noise.Worm3; -import com.volmit.iris.util.noise.WormIterator3; import com.volmit.iris.util.plugin.VolmitSender; import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; -import org.bukkit.block.data.BlockData; -import org.bukkit.util.Vector; @EqualsAndHashCode(callSuper = true) @Accessors(chain = true) diff --git a/src/main/java/com/volmit/iris/engine/object/cave/IrisCavePlacer.java b/src/main/java/com/volmit/iris/engine/object/cave/IrisCavePlacer.java index 3f1ac227d..b31aa2389 100644 --- a/src/main/java/com/volmit/iris/engine/object/cave/IrisCavePlacer.java +++ b/src/main/java/com/volmit/iris/engine/object/cave/IrisCavePlacer.java @@ -33,13 +33,11 @@ import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.noise.Worm3; import com.volmit.iris.util.noise.WormIterator3; -import com.volmit.iris.util.plugin.VolmitSender; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; import org.bukkit.block.data.BlockData; -import org.bukkit.util.BlockVector; import org.bukkit.util.Vector; import java.util.concurrent.atomic.AtomicBoolean; @@ -66,22 +64,18 @@ public class IrisCavePlacer implements IRare { private transient final AtomicCache caveCache = new AtomicCache<>(); private transient final AtomicBoolean fail = new AtomicBoolean(false); - public IrisCave getRealCave(IrisData data) - { + public IrisCave getRealCave(IrisData data) { return caveCache.aquire(() -> data.getCaveLoader().load(getCave())); } - public void generateCave(Mantle mantle, RNG rng, IrisData data, int x, int y, int z) - { - if(fail.get()) - { + public void generateCave(Mantle mantle, RNG rng, IrisData data, int x, int y, int z) { + if (fail.get()) { return; } IrisCave cave = getRealCave(data); - if(cave == null) - { + if (cave == null) { Iris.warn("Unable to locate cave for generation!"); fail.set(true); return; @@ -90,8 +84,7 @@ public class IrisCavePlacer implements IRare { WormIterator3 w = cave.getWorm().iterate3D(rng, data, x, y, z); KList points = new KList<>(); int itr = 0; - while(w.hasNext()) - { + while (w.hasNext()) { itr++; Worm3 wx = w.next(); points.add(new Vector(wx.getX().getPosition(), wx.getY().getPosition(), wx.getZ().getPosition())); diff --git a/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java b/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java index d5629b3c0..f5e4a52a5 100644 --- a/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java +++ b/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java @@ -22,6 +22,7 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.tools.IrisToolbelt; +import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.engine.platform.BukkitChunkGenerator; import com.volmit.iris.engine.platform.HeadlessGenerator; @@ -65,8 +66,21 @@ public class HeadlessWorld { } } + @SuppressWarnings("ConstantConditions") public HeadlessGenerator generate() { - return new HeadlessGenerator(this); + Engine e = null; + + if (getWorld().tryGetRealWorld()) { + if (IrisToolbelt.isIrisWorld(getWorld().realWorld())) { + e = IrisToolbelt.access(getWorld().realWorld()).getEngine(); + } + } + + if (e != null) { + Iris.info("Using Existing Engine " + getWorld().name() + " for Headless Pregeneration."); + } + + return e != null ? new HeadlessGenerator(this, e) : new HeadlessGenerator(this); } public World load() { @@ -81,7 +95,8 @@ public class HeadlessWorld { } public static HeadlessWorld from(World world) { - return new HeadlessWorld(world.getName(), IrisToolbelt.access(world).getEngine().getTarget().getDimension(), world.getSeed()); + return new HeadlessWorld(world.getName(), IrisToolbelt.access(world) + .getEngine().getTarget().getDimension(), world.getSeed()); } public static HeadlessWorld from(String name, String dimension, long seed) { diff --git a/src/main/java/com/volmit/iris/engine/object/common/IrisWorld.java b/src/main/java/com/volmit/iris/engine/object/common/IrisWorld.java index 2066ca736..ba22dce05 100644 --- a/src/main/java/com/volmit/iris/engine/object/common/IrisWorld.java +++ b/src/main/java/com/volmit/iris/engine/object/common/IrisWorld.java @@ -24,6 +24,7 @@ import com.volmit.iris.util.collection.KList; import lombok.Builder; import lombok.Data; import lombok.experimental.Accessors; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Entity; @@ -61,6 +62,21 @@ public class IrisWorld { .environment(world.getEnvironment()); } + public boolean tryGetRealWorld() { + if (hasRealWorld()) { + return true; + } + + World w = Bukkit.getWorld(name); + + if (w != null) { + realWorld = w; + return true; + } + + return false; + } + public boolean hasRealWorld() { return realWorld != null; } diff --git a/src/main/java/com/volmit/iris/engine/object/deposits/IrisDepositGenerator.java b/src/main/java/com/volmit/iris/engine/object/deposits/IrisDepositGenerator.java index 9cb1607fe..2fb8e4ba8 100644 --- a/src/main/java/com/volmit/iris/engine/object/deposits/IrisDepositGenerator.java +++ b/src/main/java/com/volmit/iris/engine/object/deposits/IrisDepositGenerator.java @@ -22,7 +22,6 @@ import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.object.annotations.*; import com.volmit.iris.engine.object.block.IrisBlockData; -import com.volmit.iris.engine.object.noise.IrisGenerator; import com.volmit.iris.engine.object.objects.IrisObject; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; diff --git a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java index 0c9aa95eb..2413e3bd7 100644 --- a/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java +++ b/src/main/java/com/volmit/iris/engine/object/dimensional/IrisDimension.java @@ -39,7 +39,6 @@ import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructure; import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; import com.volmit.iris.engine.object.loot.IrisLootReference; import com.volmit.iris.engine.object.noise.IrisGeneratorStyle; -import com.volmit.iris.engine.object.noise.IrisInterpolator; import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle; import com.volmit.iris.engine.object.noise.NoiseStyle; import com.volmit.iris.engine.object.objects.IrisObjectPlacement; diff --git a/src/main/java/com/volmit/iris/engine/object/entity/IrisEntitySpawn.java b/src/main/java/com/volmit/iris/engine/object/entity/IrisEntitySpawn.java index 3ae2d9d39..2f1a829d3 100644 --- a/src/main/java/com/volmit/iris/engine/object/entity/IrisEntitySpawn.java +++ b/src/main/java/com/volmit/iris/engine/object/entity/IrisEntitySpawn.java @@ -105,21 +105,14 @@ public class IrisEntitySpawn implements IRare { }; if (l != null) { - if(referenceSpawner.getAllowedLightLevels().getMin() > 0 || referenceSpawner.getAllowedLightLevels().getMax() < 15) - { - if(referenceSpawner.getAllowedLightLevels().contains(l.getBlock().getLightLevel())) - { - if (spawn100(gen, l) != null) - { + if (referenceSpawner.getAllowedLightLevels().getMin() > 0 || referenceSpawner.getAllowedLightLevels().getMax() < 15) { + if (referenceSpawner.getAllowedLightLevels().contains(l.getBlock().getLightLevel())) { + if (spawn100(gen, l) != null) { s++; } } - } - - else - { - if (spawn100(gen, l) != null) - { + } else { + if (spawn100(gen, l) != null) { s++; } } diff --git a/src/main/java/com/volmit/iris/engine/object/feature/IrisFeaturePositional.java b/src/main/java/com/volmit/iris/engine/object/feature/IrisFeaturePositional.java index 0edd0b49b..a7191cf11 100644 --- a/src/main/java/com/volmit/iris/engine/object/feature/IrisFeaturePositional.java +++ b/src/main/java/com/volmit/iris/engine/object/feature/IrisFeaturePositional.java @@ -65,13 +65,9 @@ public class IrisFeaturePositional { public static IrisFeaturePositional read(DataInputStream s) throws IOException { String sx = s.readUTF(); - try - { + try { return new Gson().fromJson(sx, IrisFeaturePositional.class); - } - - catch(Throwable e) - { + } catch (Throwable e) { Iris.error(sx); e.printStackTrace(); throw new IOException(e); diff --git a/src/main/java/com/volmit/iris/engine/object/noise/IrisGenerator.java b/src/main/java/com/volmit/iris/engine/object/noise/IrisGenerator.java index f61c171db..5df9df69b 100644 --- a/src/main/java/com/volmit/iris/engine/object/noise/IrisGenerator.java +++ b/src/main/java/com/volmit/iris/engine/object/noise/IrisGenerator.java @@ -24,7 +24,6 @@ import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.object.annotations.*; import com.volmit.iris.engine.object.common.IRare; import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.context.IrisContext; import com.volmit.iris.util.interpolation.IrisInterpolation; import com.volmit.iris.util.json.JSONObject; import com.volmit.iris.util.math.RNG; diff --git a/src/main/java/com/volmit/iris/engine/object/noise/IrisGeneratorStyle.java b/src/main/java/com/volmit/iris/engine/object/noise/IrisGeneratorStyle.java index ea3e872e3..2bcf60bcc 100644 --- a/src/main/java/com/volmit/iris/engine/object/noise/IrisGeneratorStyle.java +++ b/src/main/java/com/volmit/iris/engine/object/noise/IrisGeneratorStyle.java @@ -18,7 +18,6 @@ package com.volmit.iris.engine.object.noise; -import com.volmit.iris.Iris; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.object.annotations.Desc; diff --git a/src/main/java/com/volmit/iris/engine/object/noise/IrisWorm.java b/src/main/java/com/volmit/iris/engine/object/noise/IrisWorm.java index 97b862308..02e85329e 100644 --- a/src/main/java/com/volmit/iris/engine/object/noise/IrisWorm.java +++ b/src/main/java/com/volmit/iris/engine/object/noise/IrisWorm.java @@ -21,17 +21,8 @@ package com.volmit.iris.engine.object.noise; import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.object.annotations.Desc; -import com.volmit.iris.engine.object.annotations.MinNumber; -import com.volmit.iris.engine.object.annotations.Required; -import com.volmit.iris.engine.object.basic.IrisRange; -import com.volmit.iris.engine.object.common.IRare; -import com.volmit.iris.engine.object.noise.IrisGeneratorStyle; -import com.volmit.iris.engine.object.noise.IrisNoiseGenerator; -import com.volmit.iris.engine.object.noise.IrisStyledRange; -import com.volmit.iris.engine.object.noise.NoiseStyle; import com.volmit.iris.util.function.NoiseProvider; import com.volmit.iris.util.math.RNG; -import com.volmit.iris.util.noise.Worm; import com.volmit.iris.util.noise.WormIterator2; import com.volmit.iris.util.noise.WormIterator3; import lombok.AllArgsConstructor; @@ -64,13 +55,11 @@ public class IrisWorm { private transient final AtomicCache angleProviderCache = new AtomicCache<>(); - public NoiseProvider getAngleProvider(RNG rng, IrisData data) - { + public NoiseProvider getAngleProvider(RNG rng, IrisData data) { return angleProviderCache.aquire(() -> (xx, zz) -> angleStyle.create(rng, data).fitDouble(-0.5, 0.5, xx, zz) * segmentDistance.get(rng, xx, zz, data)); } - public WormIterator2 iterate2D(RNG rng, IrisData data, int x, int z) - { + public WormIterator2 iterate2D(RNG rng, IrisData data, int x, int z) { return WormIterator2.builder() .maxDistance(maxDistance) .maxIterations(maxSegments == -1 ? maxDistance : maxSegments) @@ -78,8 +67,7 @@ public class IrisWorm { .build(); } - public WormIterator3 iterate3D(RNG rng, IrisData data, int x, int y, int z) - { + public WormIterator3 iterate3D(RNG rng, IrisData data, int x, int y, int z) { return WormIterator3.builder() .maxDistance(maxDistance) .maxIterations(maxSegments == -1 ? maxDistance : maxSegments) diff --git a/src/main/java/com/volmit/iris/engine/object/regional/IrisRegion.java b/src/main/java/com/volmit/iris/engine/object/regional/IrisRegion.java index 728d99c80..e263bd2bd 100644 --- a/src/main/java/com/volmit/iris/engine/object/regional/IrisRegion.java +++ b/src/main/java/com/volmit/iris/engine/object/regional/IrisRegion.java @@ -34,7 +34,6 @@ import com.volmit.iris.engine.object.jigsaw.IrisJigsawStructurePlacement; import com.volmit.iris.engine.object.loot.IrisLootReference; import com.volmit.iris.engine.object.meta.IrisEffect; import com.volmit.iris.engine.object.noise.IrisGeneratorStyle; -import com.volmit.iris.engine.object.noise.IrisShapedGeneratorStyle; import com.volmit.iris.engine.object.noise.NoiseStyle; import com.volmit.iris.engine.object.objects.IrisObjectPlacement; import com.volmit.iris.engine.object.spawners.IrisSpawner; diff --git a/src/main/java/com/volmit/iris/engine/object/spawners/IrisSpawner.java b/src/main/java/com/volmit/iris/engine/object/spawners/IrisSpawner.java index 2a0e98687..5a0b08279 100644 --- a/src/main/java/com/volmit/iris/engine/object/spawners/IrisSpawner.java +++ b/src/main/java/com/volmit/iris/engine/object/spawners/IrisSpawner.java @@ -35,7 +35,6 @@ import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.Accessors; -import org.bukkit.Bukkit; import org.bukkit.World; @EqualsAndHashCode(callSuper = true) diff --git a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java index 36421379e..11ec5f9a0 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -29,13 +29,11 @@ import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.object.common.IrisWorld; import com.volmit.iris.engine.object.dimensional.IrisDimension; import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.format.C; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.io.ReactiveFolder; import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.Looper; -import com.volmit.iris.util.scheduling.PrecisionStopwatch; import lombok.Data; import lombok.EqualsAndHashCode; import org.bukkit.Bukkit; @@ -47,8 +45,6 @@ import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import org.jetbrains.annotations.NotNull; -import javax.management.RuntimeErrorException; -import javax.swing.text.TableView; import java.io.File; import java.util.List; import java.util.Random; @@ -100,13 +96,11 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun IrisData data = IrisData.get(dataLocation); IrisDimension dimension = data.getDimensionLoader().load(dimensionKey); - if(dimension == null) - { + if (dimension == null) { Iris.error("Oh No! There's no pack in " + data.getDataFolder().getPath() + " or... there's no dimension for the key " + dimensionKey); IrisDimension test = IrisData.loadAnyDimension(dimensionKey); - if(test != null) - { + if (test != null) { Iris.warn("Looks like " + dimensionKey + " exists in " + test.getLoadFile().getPath()); Iris.service(StudioSVC.class).installIntoWorld(Iris.getSender(), dimensionKey, dataLocation.getParentFile().getParentFile()); Iris.warn("Attempted to install into " + data.getDataFolder().getPath()); @@ -114,21 +108,14 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun data.clearLists(); test = data.getDimensionLoader().load(dimensionKey); - if(test != null) - { + if (test != null) { Iris.success("Woo! Patched the Engine!"); dimension = test; - } - - else - { + } else { Iris.error("Failed to patch dimension!"); throw new RuntimeException("Missing Dimension: " + dimensionKey); } - } - - else - { + } else { Iris.error("Nope, you don't have an installation containing " + dimensionKey + " try downloading it?"); throw new RuntimeException("Missing Dimension: " + dimensionKey); } @@ -161,8 +148,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun withExclusiveControl(() -> getEngine().hotload()); } - public void withExclusiveControl(Runnable r) - { + public void withExclusiveControl(Runnable r) { J.a(() -> { try { loadLock.acquire(LOAD_LOCKS); @@ -176,9 +162,10 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun @Override public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random ignored, int x, int z, @NotNull BiomeGrid biome) { + + try { - if(lastSeed != world.getSeed()) - { + if (lastSeed != world.getSeed()) { Iris.warn("Seed for engine " + lastSeed + " does not match world seed if " + world.getSeed()); lastSeed = world.getSeed(); engine.getTarget().getWorld().seed(lastSeed); @@ -196,29 +183,20 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun Iris.debug("Generated " + x + " " + z); loadLock.release(); return c; - } - - catch (WrongEngineBroException e) - { + } catch (WrongEngineBroException e) { Iris.warn("Trying to generate with a shut-down engine! Did you reload? Attempting to resolve this..."); - try - { + try { setupEngine(); Iris.success("Resolved! Should generate now!"); - } - - catch(Throwable fe) - { + } catch (Throwable fe) { Iris.error("FATAL! Iris cannot generate in this world since it was reloaded! This will cause a crash, with missing chunks, so we're crashing right now!"); Bukkit.shutdown(); throw new RuntimeException(); } return generateChunkData(world, ignored, x, z, biome); - } - - catch (Throwable e) { + } catch (Throwable e) { loadLock.release(); Iris.error("======================================"); e.printStackTrace(); diff --git a/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java b/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java index 82bd57971..9aea5b8f2 100644 --- a/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java @@ -19,7 +19,6 @@ package com.volmit.iris.engine.platform; import com.volmit.iris.Iris; -import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.nms.INMS; import com.volmit.iris.core.pregenerator.PregenListener; import com.volmit.iris.core.pregenerator.PregenTask; @@ -34,6 +33,7 @@ import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.documentation.RegionCoordinates; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.math.Position2; +import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.nbt.mca.MCAFile; import com.volmit.iris.util.nbt.mca.MCAUtil; import com.volmit.iris.util.nbt.mca.NBTWorld; @@ -56,12 +56,17 @@ public class HeadlessGenerator implements PlatformChunkGenerator { private final NBTWorld writer; private final MultiBurst burst; private final Engine engine; + private final long rkey = RNG.r.lmax(); public HeadlessGenerator(HeadlessWorld world) { + this(world, new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), world.isStudio())); + } + + public HeadlessGenerator(HeadlessWorld world, Engine engine) { + this.engine = engine; this.world = world; burst = MultiBurst.burst; writer = new NBTWorld(world.getWorld().worldFolder()); - engine = new IrisEngine(new EngineTarget(world.getWorld(), world.getDimension(), world.getDimension().getLoader()), isStudio()); } @ChunkCoordinates @@ -79,6 +84,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator { getEngine().generate(x * 16, z * 16, Hunk.view((ChunkGenerator.ChunkData) tc), Hunk.view((ChunkGenerator.BiomeGrid) tc), false); + chunk.cleanupPalettesAndBlockStates(); } catch (Throwable e) { Iris.error("======================================"); e.printStackTrace(); @@ -102,7 +108,7 @@ public class HeadlessGenerator implements PlatformChunkGenerator { @RegionCoordinates public void generateRegion(int x, int z, PregenListener listener) { BurstExecutor e = burst.burst(1024); - MCAFile f = writer.getMCA(x, x); + MCAFile f = writer.getMCA(x, z); PregenTask.iterateRegion(x, z, (ii, jj) -> e.queue(() -> { if (listener != null) { listener.onChunkGenerating(ii, jj); @@ -132,7 +138,6 @@ public class HeadlessGenerator implements PlatformChunkGenerator { } public void close() { - getEngine().close(); writer.close(); } diff --git a/src/main/java/com/volmit/iris/util/context/IrisContext.java b/src/main/java/com/volmit/iris/util/context/IrisContext.java index 001b978fb..155db0832 100644 --- a/src/main/java/com/volmit/iris/util/context/IrisContext.java +++ b/src/main/java/com/volmit/iris/util/context/IrisContext.java @@ -49,12 +49,10 @@ public class IrisContext { } public static void dereference() { - synchronized (context) - { + synchronized (context) { for (Thread i : context.k()) { if (!i.isAlive() || context.get(i).engine.isClosed()) { - if(context.get(i).engine.isClosed()) - { + if (context.get(i).engine.isClosed()) { Iris.debug("Dereferenced Context " + i.getName() + " " + i.getId()); } diff --git a/src/main/java/com/volmit/iris/util/data/B.java b/src/main/java/com/volmit/iris/util/data/B.java index 8b3d8ec94..ecb14eca4 100644 --- a/src/main/java/com/volmit/iris/util/data/B.java +++ b/src/main/java/com/volmit/iris/util/data/B.java @@ -21,7 +21,6 @@ package com.volmit.iris.util.data; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.scheduling.ChronoLatch; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; @@ -284,8 +283,7 @@ public class B { return Material.valueOf(bdx.trim().toUpperCase()); } catch (Throwable e) { Iris.reportError(e); - if(clw.flip()) - { + if (clw.flip()) { Iris.warn("Unknown Material: " + bdx); } return null; @@ -295,8 +293,7 @@ public class B { public static Material getMaterial(String bdx) { Material m = getMaterialOrNull(bdx); - if(m == null) - { + if (m == null) { return AIR_MATERIAL; } @@ -313,8 +310,7 @@ public class B { BlockData bdx = parseBlockData(bd); if (bdx == null) { - if(clw.flip()) - { + if (clw.flip()) { Iris.warn("Unknown Block Data '" + bd + "'"); } return AIR; @@ -324,8 +320,7 @@ public class B { } catch (Throwable e) { Iris.reportError(e); - if(clw.flip()) - { + if (clw.flip()) { Iris.warn("Unknown Block Data '" + bdxf + "'"); } } @@ -363,8 +358,7 @@ public class B { return bx; } catch (Throwable e) { - if(clw.flip()) - { + if (clw.flip()) { Iris.warn("Unknown Block Data: " + ix); } diff --git a/src/main/java/com/volmit/iris/util/data/IrisPackRepository.java b/src/main/java/com/volmit/iris/util/data/IrisPackRepository.java index 3b4620955..854e68f23 100644 --- a/src/main/java/com/volmit/iris/util/data/IrisPackRepository.java +++ b/src/main/java/com/volmit/iris/util/data/IrisPackRepository.java @@ -20,11 +20,9 @@ package com.volmit.iris.util.data; import com.volmit.iris.Iris; import com.volmit.iris.core.service.StudioSVC; -import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.jobs.DownloadJob; -import com.volmit.iris.util.scheduling.jobs.Job; import com.volmit.iris.util.scheduling.jobs.JobCollection; import com.volmit.iris.util.scheduling.jobs.SingleJob; import lombok.Builder; @@ -111,8 +109,7 @@ public class IrisPackRepository { public void install(VolmitSender sender) throws MalformedURLException { File pack = Iris.instance.getDataFolder(StudioSVC.WORKSPACE_NAME, getRepo()); - if(!pack.exists()) - { + if (!pack.exists()) { File dl = new File(Iris.getTemp(), "dltk-" + UUID.randomUUID() + ".zip"); File work = new File(Iris.getTemp(), "extk-" + UUID.randomUUID()); new JobCollection(Form.capitalize(getRepo()), diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java index 9a050d229..896de1713 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -44,18 +44,13 @@ public class DecreeParameter { public DecreeParameterHandler getHandler() { return handlerCache.aquire(() -> { - try - { - if(param.customHandler().equals(DummyHandler.class)) - { + try { + if (param.customHandler().equals(DummyHandler.class)) { return DecreeSystem.getHandler(getType()); } return param.customHandler().getConstructor().newInstance(); - } - - catch(Throwable e) - { + } catch (Throwable e) { e.printStackTrace(); } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java index c47b48f73..e980a0fba 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java @@ -32,8 +32,7 @@ public interface DecreeParameterHandler { */ KList getPossibilities(); - default boolean isDummy() - { + default boolean isDummy() { return false; } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java index 64550b482..fb31842e5 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.decree.DecreeSystem; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.Form; -import com.volmit.iris.util.math.M; import com.volmit.iris.util.plugin.VolmitSender; import org.bukkit.FluidCollisionMode; import org.bukkit.entity.Player; diff --git a/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java b/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java index 062d3b7d7..1e0949983 100644 --- a/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java @@ -29,8 +29,7 @@ public class DummyHandler implements DecreeParameterHandler { return null; } - public boolean isDummy() - { + public boolean isDummy() { return true; } diff --git a/src/main/java/com/volmit/iris/util/hunk/io/BooleanHunkIOAdapter.java b/src/main/java/com/volmit/iris/util/function/NastySupplier.java similarity index 62% rename from src/main/java/com/volmit/iris/util/hunk/io/BooleanHunkIOAdapter.java rename to src/main/java/com/volmit/iris/util/function/NastySupplier.java index aeaaaeb26..d1c1c0048 100644 --- a/src/main/java/com/volmit/iris/util/hunk/io/BooleanHunkIOAdapter.java +++ b/src/main/java/com/volmit/iris/util/function/NastySupplier.java @@ -16,21 +16,8 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.hunk.io; +package com.volmit.iris.util.function; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class BooleanHunkIOAdapter extends PaletteHunkIOAdapter { - - @Override - public void write(Boolean data, DataOutputStream dos) throws IOException { - dos.writeBoolean(data); - } - - @Override - public Boolean read(DataInputStream din) throws IOException { - return din.readBoolean(); - } +public interface NastySupplier { + T get() throws Throwable; } diff --git a/src/main/java/com/volmit/iris/util/hunk/Hunk.java b/src/main/java/com/volmit/iris/util/hunk/Hunk.java index 291b2b0e1..e5b0cff02 100644 --- a/src/main/java/com/volmit/iris/util/hunk/Hunk.java +++ b/src/main/java/com/volmit/iris/util/hunk/Hunk.java @@ -21,14 +21,12 @@ package com.volmit.iris.util.hunk; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.function.*; -import com.volmit.iris.util.hunk.io.HunkIOAdapter; import com.volmit.iris.util.hunk.storage.*; import com.volmit.iris.util.hunk.view.*; import com.volmit.iris.util.interpolation.InterpolationMethod; import com.volmit.iris.util.interpolation.InterpolationMethod3D; import com.volmit.iris.util.interpolation.IrisInterpolation; import com.volmit.iris.util.math.BlockPosition; -import com.volmit.iris.util.oldnbt.ByteArrayTag; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.stream.interpolation.Interpolated; @@ -38,9 +36,7 @@ import org.bukkit.block.data.BlockData; import org.bukkit.generator.ChunkGenerator.BiomeGrid; import org.bukkit.generator.ChunkGenerator.ChunkData; -import java.io.File; import java.io.IOException; -import java.io.OutputStream; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; @@ -229,18 +225,6 @@ public interface Hunk { return count.get(); } - default void write(OutputStream s, HunkIOAdapter h) throws IOException { - h.write(this, s); - } - - default ByteArrayTag writeByteArrayTag(HunkIOAdapter h, String name) throws IOException { - return h.writeByteArrayTag(this, name); - } - - default void write(File s, HunkIOAdapter h) throws IOException { - h.write(this, s); - } - default boolean isAtomic() { return false; } @@ -1450,8 +1434,7 @@ public interface Hunk { return false; } - default boolean contains(int x, int y, int z) - { + default boolean contains(int x, int y, int z) { return x < getWidth() && x >= 0 && y < getHeight() && y >= 0 && z < getDepth() && z >= 0; } } diff --git a/src/main/java/com/volmit/iris/util/hunk/io/BasicHunkIOAdapter.java b/src/main/java/com/volmit/iris/util/hunk/io/BasicHunkIOAdapter.java deleted file mode 100644 index 29971a726..000000000 --- a/src/main/java/com/volmit/iris/util/hunk/io/BasicHunkIOAdapter.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.hunk.io; - -import com.volmit.iris.Iris; -import com.volmit.iris.util.function.Function3; -import com.volmit.iris.util.hunk.Hunk; - -import java.io.*; -import java.util.concurrent.atomic.AtomicBoolean; - -public abstract class BasicHunkIOAdapter implements HunkIOAdapter { - @Override - public void write(Hunk t, OutputStream out) throws IOException { - DataOutputStream dos = new DataOutputStream(out); - dos.writeShort(t.getWidth() + Short.MIN_VALUE); - dos.writeShort(t.getHeight() + Short.MIN_VALUE); - dos.writeShort(t.getDepth() + Short.MIN_VALUE); - dos.writeInt(t.getNonNullEntries() + Integer.MIN_VALUE); - - AtomicBoolean failure = new AtomicBoolean(false); - t.iterate(0, (x, y, z, w) -> { - if (w != null) { - try { - dos.writeShort(x + Short.MIN_VALUE); - dos.writeShort(y + Short.MIN_VALUE); - dos.writeShort(z + Short.MIN_VALUE); - write(w, dos); - } catch (Throwable e) { - Iris.reportError(e); - e.printStackTrace(); - failure.set(true); - } - } - }); - - dos.close(); - } - - @Override - public Hunk read(Function3> factory, InputStream in) throws IOException { - DataInputStream din = new DataInputStream(in); - int w = din.readShort() - Short.MIN_VALUE; - int h = din.readShort() - Short.MIN_VALUE; - int d = din.readShort() - Short.MIN_VALUE; - int e = din.readInt() - Integer.MIN_VALUE; - Hunk t = factory.apply(w, h, d); - - for (int i = 0; i < e; i++) { - int x = din.readShort() - Short.MIN_VALUE; - int y = din.readShort() - Short.MIN_VALUE; - int z = din.readShort() - Short.MIN_VALUE; - T v = read(din); - - if (v == null) { - throw new IOException("NULL VALUE AT " + x + " " + y + " " + z); - } - - t.setRaw(x, y, z, v); - } - - in.close(); - return t; - } -} diff --git a/src/main/java/com/volmit/iris/util/hunk/io/HunkIOAdapter.java b/src/main/java/com/volmit/iris/util/hunk/io/HunkIOAdapter.java deleted file mode 100644 index 4348c2745..000000000 --- a/src/main/java/com/volmit/iris/util/hunk/io/HunkIOAdapter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.hunk.io; - -import com.volmit.iris.util.data.IOAdapter; -import com.volmit.iris.util.function.Function3; -import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.io.CustomOutputStream; -import com.volmit.iris.util.oldnbt.ByteArrayTag; - -import java.io.*; -import java.util.zip.GZIPInputStream; -import java.util.zip.GZIPOutputStream; - -public interface HunkIOAdapter extends IOAdapter { - void write(Hunk t, OutputStream out) throws IOException; - - Hunk read(Function3> factory, InputStream in) throws IOException; - - default void write(Hunk t, File f) throws IOException { - f.getParentFile().mkdirs(); - FileOutputStream fos = new FileOutputStream(f); - GZIPOutputStream gzo = new CustomOutputStream(fos, 6); - write(t, gzo); - } - - default Hunk read(Function3> factory, File f) throws IOException { - return read(factory, new GZIPInputStream(new FileInputStream(f))); - } - - default Hunk read(Function3> factory, ByteArrayTag f) throws IOException { - return read(factory, new ByteArrayInputStream(f.getValue())); - } - - default ByteArrayTag writeByteArrayTag(Hunk tHunk, String name) throws IOException { - ByteArrayOutputStream boas = new ByteArrayOutputStream(); - write(tHunk, boas); - return new ByteArrayTag(name, boas.toByteArray()); - } -} diff --git a/src/main/java/com/volmit/iris/util/hunk/io/HunkRegion.java b/src/main/java/com/volmit/iris/util/hunk/io/HunkRegion.java deleted file mode 100644 index 92e47bf38..000000000 --- a/src/main/java/com/volmit/iris/util/hunk/io/HunkRegion.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.hunk.io; - -import com.volmit.iris.Iris; -import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.oldnbt.CompoundTag; -import com.volmit.iris.util.oldnbt.NBTInputStream; -import com.volmit.iris.util.oldnbt.NBTOutputStream; -import com.volmit.iris.util.oldnbt.Tag; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Map; - -@SuppressWarnings("SynchronizeOnNonFinalField") -public class HunkRegion { - private final File folder; - private CompoundTag compound; - private final int x; - private final int z; - - public HunkRegion(File folder, int x, int z, CompoundTag compound) { - this.compound = fix(compound); - this.folder = folder; - this.x = x; - this.z = z; - folder.mkdirs(); - } - - public HunkRegion(File folder, int x, int z) { - this(folder, x, z, new CompoundTag(x + "." + z, new KMap<>())); - File f = getFile(); - - if (f.exists()) { - try { - NBTInputStream in = new NBTInputStream(new FileInputStream(f)); - compound = fix((CompoundTag) in.readTag()); - in.close(); - } catch (Throwable e) { - Iris.reportError(e); - - } - } - } - - public CompoundTag getCompound() { - return compound; - } - - private CompoundTag fix(CompoundTag readTag) { - Map v = readTag.getValue(); - - if (!(v instanceof KMap)) { - return new CompoundTag(readTag.getName(), new KMap<>(v)); - } - - return readTag; - } - - public File getFile() { - return new File(folder, x + "." + z + ".dat"); - } - - public void save() throws IOException { - synchronized (compound) { - File f = getFile(); - FileOutputStream fos = new FileOutputStream(f); - NBTOutputStream out = new NBTOutputStream(fos); - out.writeTag(compound); - out.close(); - } - } - - public int getX() { - return x; - } - - public int getZ() { - return z; - } - -} diff --git a/src/main/java/com/volmit/iris/util/hunk/io/HunkRegionSlice.java b/src/main/java/com/volmit/iris/util/hunk/io/HunkRegionSlice.java deleted file mode 100644 index c7d7b00f3..000000000 --- a/src/main/java/com/volmit/iris/util/hunk/io/HunkRegionSlice.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.hunk.io; - -import com.volmit.iris.Iris; -import com.volmit.iris.engine.object.tile.TileData; -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.function.Function2; -import com.volmit.iris.util.function.Function3; -import com.volmit.iris.util.hunk.Hunk; -import com.volmit.iris.util.math.M; -import com.volmit.iris.util.math.Position2; -import com.volmit.iris.util.oldnbt.ByteArrayTag; -import com.volmit.iris.util.oldnbt.CompoundTag; -import com.volmit.iris.util.oldnbt.Tag; -import com.volmit.iris.util.parallel.MultiBurst; -import org.bukkit.block.TileState; -import org.bukkit.block.data.BlockData; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicReference; - -public class HunkRegionSlice { - public static final Function2> BLOCKDATA = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BlockDataHunkIOAdapter(), c, "blockdata"); - public static final Function2>> TILE = (h, c) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new TileDataHunkIOAdapter(), c, "tile"); - public static final Function3> STRING = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new StringHunkIOAdapter(), c, t); - public static final Function3> BOOLEAN = (h, c, t) -> new HunkRegionSlice<>(h, Hunk::newMappedHunk, new BooleanHunkIOAdapter(), c, t); - private final Function3> factory; - private final HunkIOAdapter adapter; - private final CompoundTag compound; - private final String key; - private final KMap> loadedChunks; - private final KMap lastUse; - private final KSet save; - private final int height; - - public HunkRegionSlice(int height, Function3> factory, HunkIOAdapter adapter, CompoundTag compound, String key) { - this.height = height; - this.loadedChunks = new KMap<>(); - this.factory = factory; - this.adapter = adapter; - this.compound = compound; - this.save = new KSet<>(); - this.key = key; - this.lastUse = new KMap<>(); - } - - public synchronized int cleanup(long t) { - int v = 0; - if (loadedChunks.size() != lastUse.size()) { - Iris.warn("Incorrect chunk use counts in " + key + " region slice."); - - for (Position2 i : lastUse.k()) { - if (!loadedChunks.containsKey(i)) { - Iris.warn(" Missing LoadChunkKey " + i); - } - } - } - - for (Position2 i : lastUse.k()) { - Long l = lastUse.get(i); - if (l == null || M.ms() - l > t) { - v++; - MultiBurst.burst.lazy(() -> { - unload(i.getX(), i.getZ()); - }); - } - } - - return v; - } - - public synchronized void clear() { - for (String i : new KList<>(compound.getValue().keySet())) { - if (i.startsWith(key + ".")) { - compound.getValue().remove(i); - } - } - } - - public synchronized void save(MultiBurst burst) { - - try { - for (Position2 i : save.copy()) { - if (i == null) { - continue; - } - - save(i.getX(), i.getZ()); - - try { - save.remove(i); - } catch (Throwable eer) { - Iris.reportError(eer); - } - } - } catch (Throwable ee) { - Iris.reportError(ee); - } - } - - public boolean contains(int x, int z) { - return compound.getValue().containsKey(key(x, z)); - } - - public void delete(int x, int z) { - compound.getValue().remove(key(x, z)); - } - - public Hunk read(int x, int z) throws IOException { - AtomicReference e = new AtomicReference<>(); - Hunk xt = null; - - Tag t = compound.getValue().get(key(x, z)); - - if ((t instanceof ByteArrayTag)) { - try { - xt = adapter.read(factory, (ByteArrayTag) t); - } catch (IOException xe) { - Iris.reportError(xe); - e.set(xe); - } - } - - if (xt != null) { - return xt; - } - - if (e.get() != null) { - throw e.get(); - } - - return null; - } - - public void write(Hunk hunk, int x, int z) throws IOException { - compound.getValue().put(key(x, z), hunk.writeByteArrayTag(adapter, key(x, z))); - } - - public synchronized int unloadAll() { - int v = 0; - for (Position2 i : loadedChunks.k()) { - unload(i.getX(), i.getZ()); - v++; - } - - save.clear(); - loadedChunks.clear(); - lastUse.clear(); - return v; - } - - public void save(Hunk region, int x, int z) { - try { - write(region, x, z); - } catch (IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - - public boolean isLoaded(int x, int z) { - return loadedChunks.containsKey(new Position2(x, z)); - } - - public void save(int x, int z) { - if (isLoaded(x, z)) { - save(get(x, z), x, z); - } - } - - public void unload(int x, int z) { - Position2 key = new Position2(x, z); - if (isLoaded(x, z)) { - if (save.contains(key)) { - save(x, z); - save.remove(key); - } - - lastUse.remove(key); - loadedChunks.remove(key); - } - } - - public Hunk load(int x, int z) { - if (isLoaded(x, z)) { - return loadedChunks.get(new Position2(x, z)); - } - - Hunk v = null; - - if (contains(x, z)) { - try { - v = read(x, z); - } catch (IOException e) { - Iris.reportError(e); - e.printStackTrace(); - } - } - - if (v == null) { - v = factory.apply(16, height, 16); - } - - loadedChunks.put(new Position2(x, z), v); - - return v; - } - - public Hunk get(int x, int z) { - Position2 key = new Position2(x, z); - - Hunk c = loadedChunks.get(key); - - if (c == null) { - c = load(x, z); - } - - lastUse.put(new Position2(x, z), M.ms()); - - return c; - } - - public Hunk getR(int x, int z) { - return get(x, z).readOnly(); - } - - public Hunk getRW(int x, int z) { - save.add(new Position2(x, z)); - return get(x, z); - } - - private String key(int x, int z) { - if (x < 0 || x >= 32 || z < 0 || z >= 32) { - throw new IndexOutOfBoundsException("The chunk " + x + " " + z + " is out of bounds max is 31x31"); - } - - return key + "." + x + "." + z; - } - - public int getLoadCount() { - return loadedChunks.size(); - } -} diff --git a/src/main/java/com/volmit/iris/util/hunk/io/PaletteHunkIOAdapter.java b/src/main/java/com/volmit/iris/util/hunk/io/PaletteHunkIOAdapter.java deleted file mode 100644 index fc34f5de7..000000000 --- a/src/main/java/com/volmit/iris/util/hunk/io/PaletteHunkIOAdapter.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.hunk.io; - -import com.volmit.iris.Iris; -import com.volmit.iris.util.data.DataPalette; -import com.volmit.iris.util.function.Function3; -import com.volmit.iris.util.hunk.Hunk; - -import java.io.*; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -public abstract class PaletteHunkIOAdapter implements HunkIOAdapter { - @Override - public void write(Hunk t, OutputStream out) throws IOException { - DataOutputStream dos = new DataOutputStream(out); - dos.writeShort(t.getWidth() + Short.MIN_VALUE); - dos.writeShort(t.getHeight() + Short.MIN_VALUE); - dos.writeShort(t.getDepth() + Short.MIN_VALUE); - AtomicInteger nonNull = new AtomicInteger(0); - DataPalette palette = new DataPalette<>(); - - t.iterateSync((x, y, z, w) -> { - if (w != null) { - palette.getIndex(w); - nonNull.getAndAdd(1); - } - }); - - palette.write(this, dos); - dos.writeInt(nonNull.get() + Integer.MIN_VALUE); - AtomicBoolean failure = new AtomicBoolean(false); - t.iterateSync((x, y, z, w) -> { - if (w != null) { - try { - dos.writeShort(x + Short.MIN_VALUE); - dos.writeShort(y + Short.MIN_VALUE); - dos.writeShort(z + Short.MIN_VALUE); - dos.writeShort(palette.getIndex(w) + Short.MIN_VALUE); - } catch (Throwable e) { - Iris.reportError(e); - e.printStackTrace(); - failure.set(true); - } - } - }); - - dos.close(); - } - - @Override - public Hunk read(Function3> factory, InputStream in) throws IOException { - DataInputStream din = new DataInputStream(in); - int w = din.readShort() - Short.MIN_VALUE; - int h = din.readShort() - Short.MIN_VALUE; - int d = din.readShort() - Short.MIN_VALUE; - DataPalette palette = DataPalette.getPalette(this, din); - int e = din.readInt() - Integer.MIN_VALUE; - Hunk t = factory.apply(w, h, d); - - for (int i = 0; i < e; i++) { - int x = din.readShort() - Short.MIN_VALUE; - int y = din.readShort() - Short.MIN_VALUE; - int z = din.readShort() - Short.MIN_VALUE; - int vf = din.readShort() - Short.MIN_VALUE; - - T v = null; - if (palette.getPalette().hasIndex(vf)) { - v = palette.getPalette().get(vf); - } - - if (v != null) { - t.setRaw(x, y, z, v); - } - } - - in.close(); - return t; - } -} diff --git a/src/main/java/com/volmit/iris/util/hunk/io/TileDataHunkIOAdapter.java b/src/main/java/com/volmit/iris/util/hunk/io/TileDataHunkIOAdapter.java deleted file mode 100644 index 9490f570d..000000000 --- a/src/main/java/com/volmit/iris/util/hunk/io/TileDataHunkIOAdapter.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.hunk.io; - -import com.volmit.iris.Iris; -import com.volmit.iris.engine.object.tile.TileData; -import org.bukkit.block.TileState; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class TileDataHunkIOAdapter extends PaletteHunkIOAdapter> { - @Override - public void write(TileData data, DataOutputStream dos) throws IOException { - data.toBinary(dos); - } - - @Override - public TileData read(DataInputStream din) throws IOException { - try { - return TileData.read(din); - } catch (Throwable e) { - Iris.reportError(e); - e.printStackTrace(); - throw new IOException(); - } - } -} diff --git a/src/main/java/com/volmit/iris/util/hunk/storage/MappedSyncHunk.java b/src/main/java/com/volmit/iris/util/hunk/storage/MappedSyncHunk.java index ee2a79228..55dd06c94 100644 --- a/src/main/java/com/volmit/iris/util/hunk/storage/MappedSyncHunk.java +++ b/src/main/java/com/volmit/iris/util/hunk/storage/MappedSyncHunk.java @@ -18,7 +18,6 @@ package com.volmit.iris.util.hunk.storage; -import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.function.Consumer4; import com.volmit.iris.util.function.Consumer4IO; import com.volmit.iris.util.hunk.Hunk; @@ -49,15 +48,14 @@ public class MappedSyncHunk extends StorageHunk implements Hunk { } public boolean isEmpty() { - synchronized(data) - { + synchronized (data) { return data.isEmpty(); } } @Override public void setRaw(int x, int y, int z, T t) { - synchronized(data) { + synchronized (data) { if (t == null) { data.remove(index(x, y, z)); return; @@ -73,8 +71,7 @@ public class MappedSyncHunk extends StorageHunk implements Hunk { @Override public synchronized Hunk iterateSync(Consumer4 c) { - synchronized(data) - { + synchronized (data) { int idx, z; for (Map.Entry g : data.entrySet()) { @@ -90,8 +87,7 @@ public class MappedSyncHunk extends StorageHunk implements Hunk { @Override public synchronized Hunk iterateSyncIO(Consumer4IO c) throws IOException { - synchronized(data) - { + synchronized (data) { int idx, z; for (Map.Entry g : data.entrySet()) { @@ -107,16 +103,14 @@ public class MappedSyncHunk extends StorageHunk implements Hunk { @Override public void empty(T b) { - synchronized(data) - { + synchronized (data) { data.clear(); } } @Override public T getRaw(int x, int y, int z) { - synchronized(data) - { + synchronized (data) { return data.get(index(x, y, z)); } } diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index 078ce2d44..bac9f0d8f 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -45,7 +45,6 @@ import org.bukkit.util.Vector; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -90,10 +89,11 @@ public class Mantle { /** * Raise a flag if it is lowered currently, If the flag was raised, execute the runnable - * @param x the chunk x - * @param z the chunk z + * + * @param x the chunk x + * @param z the chunk z * @param flag the flag to raise - * @param r the runnable to fire if the flag is now raised (and was previously lowered) + * @param r the runnable to fire if the flag is now raised (and was previously lowered) */ @ChunkCoordinates public void raiseFlag(int x, int z, MantleFlag flag, Runnable r) { @@ -106,23 +106,24 @@ public class Mantle { /** * Obtain a cached writer which only contains cached chunks. * This avoids locking on regions when writing to lots of chunks - * @param x the x chunk - * @param z the z chunk + * + * @param x the x chunk + * @param z the z chunk * @param radius the radius chunks * @return the writer */ @ChunkCoordinates - public MantleWriter write(EngineMantle engineMantle, int x, int z, int radius) - { + public MantleWriter write(EngineMantle engineMantle, int x, int z, int radius) { return new MantleWriter(engineMantle, this, x, z, radius); } /** * Lower a flag if it is raised. If the flag was lowered (meaning it was previously raised), execute the runnable - * @param x the chunk x - * @param z the chunk z + * + * @param x the chunk x + * @param z the chunk z * @param flag the flag to lower - * @param r the runnable that is fired if the flag was raised but is now lowered + * @param r the runnable that is fired if the flag was raised but is now lowered */ @ChunkCoordinates public void lowerFlag(int x, int z, MantleFlag flag, Runnable r) { @@ -133,16 +134,16 @@ public class Mantle { } @ChunkCoordinates - public MantleChunk getChunk(int x, int z) - { - return get(x>>5, z>>5).getOrCreate(x & 31, z & 31); + public MantleChunk getChunk(int x, int z) { + return get(x >> 5, z >> 5).getOrCreate(x & 31, z & 31); } /** * Flag or unflag a chunk - * @param x the chunk x - * @param z the chunk z - * @param flag the flag + * + * @param x the chunk x + * @param z the chunk z + * @param flag the flag * @param flagged should it be set to flagged or not */ @ChunkCoordinates @@ -152,29 +153,29 @@ public class Mantle { /** * Check very quickly if a tectonic plate exists via cached or the file system + * * @param x the x region coordinate * @param z the z region coordinate * @return true if it exists */ @RegionCoordinates - public boolean hasTectonicPlate(int x, int z) - { + public boolean hasTectonicPlate(int x, int z) { Long k = key(x, z); return loadedRegions.containsKey(k) || fileForRegion(dataFolder, k).exists(); } /** * Iterate data in a chunk - * @param x the chunk x - * @param z the chunk z - * @param type the type of data to iterate + * + * @param x the chunk x + * @param z the chunk z + * @param type the type of data to iterate * @param iterator the iterator (x,y,z,data) -> do stuff - * @param the type of data to iterate + * @param the type of data to iterate */ @ChunkCoordinates public void iterateChunk(int x, int z, Class type, Consumer4 iterator) { - if(!hasTectonicPlate(x >> 5, z >> 5)) - { + if (!hasTectonicPlate(x >> 5, z >> 5)) { return; } @@ -183,15 +184,15 @@ public class Mantle { /** * Does this chunk have a flag on it? - * @param x the x - * @param z the z + * + * @param x the x + * @param z the z * @param flag the flag to test * @return true if it's flagged */ @ChunkCoordinates public boolean hasFlag(int x, int z, MantleFlag flag) { - if(!hasTectonicPlate(x >> 5, z >> 5)) - { + if (!hasTectonicPlate(x >> 5, z >> 5)) { return false; } @@ -222,14 +223,10 @@ public class Mantle { return; } - if(t instanceof IrisFeaturePositional) - { + if (t instanceof IrisFeaturePositional) { get((x >> 4) >> 5, (z >> 4) >> 5) .getOrCreate((x >> 4) & 31, (z >> 4) & 31).addFeature((IrisFeaturePositional) t); - } - - else - { + } else { Matter matter = get((x >> 4) >> 5, (z >> 4) >> 5) .getOrCreate((x >> 4) & 31, (z >> 4) & 31) .getOrCreate(y >> 4); @@ -260,8 +257,7 @@ public class Mantle { throw new RuntimeException("The Mantle is closed"); } - if(!hasTectonicPlate((x >> 4) >> 5, (z >> 4) >> 5)) - { + if (!hasTectonicPlate((x >> 4) >> 5, (z >> 4) >> 5)) { return null; } @@ -277,10 +273,10 @@ public class Mantle { /** * Is this mantle closed + * * @return true if it is */ - public boolean isClosed() - { + public boolean isClosed() { return closed.get(); } @@ -307,13 +303,9 @@ public class Mantle { }); } - try - { + try { b.complete(); - } - - catch(Throwable e) - { + } catch (Throwable e) { Iris.reportError(e); } @@ -457,9 +449,10 @@ public class Mantle { /** * Get the file for a region + * * @param folder the folder - * @param x the x coord - * @param z the z coord + * @param x the x coord + * @param z the z coord * @return the file */ public static File fileForRegion(File folder, int x, int z) { @@ -468,14 +461,14 @@ public class Mantle { /** * Get the file for the given region + * * @param folder the data folder - * @param key the region key + * @param key the region key * @return the file */ public static File fileForRegion(File folder, Long key) { File f = new File(folder, "p." + key + ".ttp"); - if(!f.getParentFile().exists()) - { + if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } return f; @@ -483,6 +476,7 @@ public class Mantle { /** * Get the long value representing a chunk or region coordinate + * * @param x the x * @param z the z * @return the value @@ -497,33 +491,33 @@ public class Mantle { /** * Set a sphere into the mantle - * @param cx the center x - * @param cy the center y - * @param cz the center z + * + * @param cx the center x + * @param cy the center y + * @param cz the center z * @param radius the radius of this sphere - * @param fill should it be filled? or just the outer shell? - * @param data the data to set - * @param the type of data to apply to the mantle + * @param fill should it be filled? or just the outer shell? + * @param data the data to set + * @param the type of data to apply to the mantle */ - public void setSphere(int cx, int cy, int cz, double radius, boolean fill, T data) - { + public void setSphere(int cx, int cy, int cz, double radius, boolean fill, T data) { setElipsoid(cx, cy, cz, radius, radius, radius, fill, data); } /** * Set an elipsoid into the mantle - * @param cx the center x - * @param cy the center y - * @param cz the center z - * @param rx the x radius - * @param ry the y radius - * @param rz the z radius + * + * @param cx the center x + * @param cy the center y + * @param cz the center z + * @param rx the x radius + * @param ry the y radius + * @param rz the z radius * @param fill should it be filled or just the outer shell? * @param data the data to set - * @param the type of data to apply to the mantle + * @param the type of data to apply to the mantle */ - public void setElipsoid(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, T data) - { + public void setElipsoid(int cx, int cy, int cz, double rx, double ry, double rz, boolean fill, T data) { rx += 0.5; ry += 0.5; rz += 0.5; @@ -535,11 +529,13 @@ public class Mantle { final int ceilRadiusZ = (int) Math.ceil(rz); double nextXn = 0; - forX: for (int x = 0; x <= ceilRadiusX; ++x) { + forX: + for (int x = 0; x <= ceilRadiusX; ++x) { final double xn = nextXn; nextXn = (x + 1) * invRadiusX; double nextYn = 0; - forY: for (int y = 0; y <= ceilRadiusY; ++y) { + forY: + for (int y = 0; y <= ceilRadiusY; ++y) { final double yn = nextYn; nextYn = (y + 1) * invRadiusY; double nextZn = 0; @@ -564,15 +560,15 @@ public class Mantle { } } - set(x + cx,y + cy,z + cz, data); - set(-x + cx,y + cy,z + cz, data); - set(x + cx,-y + cy,z + cz, data); - set(x + cx,y + cy,-z + cz, data); - set(-x + cx,y + cy,-z + cz, data); - set(-x + cx,-y + cy,z + cz, data); - set(x + cx,-y + cy,-z + cz, data); - set(-x + cx,y + cy,-z + cz, data); - set(-x + cx,-y + cy,-z + cz, data); + set(x + cx, y + cy, z + cz, data); + set(-x + cx, y + cy, z + cz, data); + set(x + cx, -y + cy, z + cz, data); + set(x + cx, y + cy, -z + cz, data); + set(-x + cx, y + cy, -z + cz, data); + set(-x + cx, -y + cy, z + cz, data); + set(x + cx, -y + cy, -z + cz, data); + set(-x + cx, y + cy, -z + cz, data); + set(-x + cx, -y + cy, -z + cz, data); } } } @@ -580,26 +576,23 @@ public class Mantle { /** * Set a cuboid of data in the mantle - * @param x1 the min x - * @param y1 the min y - * @param z1 the min z - * @param x2 the max x - * @param y2 the max y - * @param z2 the max z + * + * @param x1 the min x + * @param y1 the min y + * @param z1 the min z + * @param x2 the max x + * @param y2 the max y + * @param z2 the max z * @param data the data to set - * @param the type of data to apply to the mantle + * @param the type of data to apply to the mantle */ - public void setCuboid(int x1, int y1, int z1, int x2, int y2, int z2, T data) - { - int j,k; + public void setCuboid(int x1, int y1, int z1, int x2, int y2, int z2, T data) { + int j, k; - for(int i = x1; i <= x2; i++) - { - for(j = x1; j <= x2; j++) - { - for(k = x1; k <= x2; k++) - { - set(i,j,k,data); + for (int i = x1; i <= x2; i++) { + for (j = x1; j <= x2; j++) { + for (k = x1; k <= x2; k++) { + set(i, j, k, data); } } } @@ -607,13 +600,14 @@ public class Mantle { /** * Set a pyramid of data in the mantle - * @param cx the center x - * @param cy the base y - * @param cz the center z - * @param data the data to set - * @param size the size of the pyramid (width of base & height) + * + * @param cx the center x + * @param cy the base y + * @param cz the center z + * @param data the data to set + * @param size the size of the pyramid (width of base & height) * @param filled should it be filled or hollow - * @param the type of data to apply to the mantle + * @param the type of data to apply to the mantle */ @SuppressWarnings("ConstantConditions") public void setPyramid(int cx, int cy, int cz, T data, int size, boolean filled) { @@ -636,10 +630,11 @@ public class Mantle { /** * Set a 3d tube spline interpolated with Kochanek Bartels + * * @param nodevectors the vector points - * @param radius the radius - * @param filled if it should be filled or hollow - * @param data the data to set + * @param radius the radius + * @param filled if it should be filled or hollow + * @param data the data to set */ public void setSpline(List nodevectors, double radius, boolean filled, T data) { setSpline(nodevectors, 0, 0, 0, 10, radius, filled, data); @@ -647,15 +642,16 @@ public class Mantle { /** * Set a 3d tube spline interpolated with Kochanek Bartels + * * @param nodevectors the spline points - * @param tension the tension 0 - * @param bias the bias 0 - * @param continuity the continuity 0 - * @param quality the quality 10 - * @param radius the radius - * @param filled filled or hollow - * @param data the data to set - * @param the type of data to apply to the mantle + * @param tension the tension 0 + * @param bias the bias 0 + * @param continuity the continuity 0 + * @param quality the quality 10 + * @param radius the radius + * @param filled filled or hollow + * @param data the data to set + * @param the type of data to apply to the mantle */ public void setSpline(List nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled, T data) { Set vset = new KSet<>(); @@ -687,25 +683,26 @@ public class Mantle { /** * Set a 3d line - * @param a the first point - * @param b the second point + * + * @param a the first point + * @param b the second point * @param radius the radius * @param filled hollow or filled? - * @param data the data - * @param the type of data to apply to the mantle + * @param data the data + * @param the type of data to apply to the mantle */ - public void setLine(IrisPosition a, IrisPosition b, double radius, boolean filled, T data) - { + public void setLine(IrisPosition a, IrisPosition b, double radius, boolean filled, T data) { setLine(ImmutableList.of(a, b), radius, filled, data); } /** * Set lines for points + * * @param vectors the points - * @param radius the radius - * @param filled hollow or filled? - * @param data the data to set - * @param the type of data to apply to the mantle + * @param radius the radius + * @param filled hollow or filled? + * @param data the data to set + * @param the type of data to apply to the mantle */ public void setLine(List vectors, double radius, boolean filled, T data) { Set vset = new KSet<>(); @@ -770,28 +767,30 @@ public class Mantle { /** * Set a cylinder in the mantle - * @param cx the center x - * @param cy the base y - * @param cz the center z - * @param data the data to set + * + * @param cx the center x + * @param cy the base y + * @param cz the center z + * @param data the data to set * @param radius the radius * @param height the height of the cyl * @param filled filled or not */ - public void setCylinder(int cx, int cy, int cz, T data, double radius, int height, boolean filled){ + public void setCylinder(int cx, int cy, int cz, T data, double radius, int height, boolean filled) { setCylinder(cx, cy, cz, data, radius, radius, height, filled); } /** * Set a cylinder in the mantle - * @param cx the center x - * @param cy the base y - * @param cz the center z - * @param data the data to set + * + * @param cx the center x + * @param cy the base y + * @param cz the center z + * @param data the data to set * @param radiusX the x radius * @param radiusZ the z radius - * @param height the height of this cyl - * @param filled filled or hollow? + * @param height the height of this cyl + * @param filled filled or hollow? */ public void setCylinder(int cx, int cy, int cz, T data, double radiusX, double radiusZ, int height, boolean filled) { int affected = 0; @@ -817,7 +816,8 @@ public class Mantle { final int ceilRadiusZ = (int) Math.ceil(radiusZ); double nextXn = 0; - forX: for (int x = 0; x <= ceilRadiusX; ++x) { + forX: + for (int x = 0; x <= ceilRadiusX; ++x) { final double xn = nextXn; nextXn = (x + 1) * invRadiusX; double nextZn = 0; @@ -850,23 +850,18 @@ public class Mantle { } } - public void set(IrisPosition pos, T data) - { + public void set(IrisPosition pos, T data) { set(pos.getX(), pos.getY(), pos.getZ(), data); } - public void set(List positions, T data) - { - for(IrisPosition i : positions) - { + public void set(List positions, T data) { + for (IrisPosition i : positions) { set(i, data); } } - public void set(Set positions, T data) - { - for(IrisPosition i : positions) - { + public void set(Set positions, T data) { + for (IrisPosition i : positions) { set(i, data); } } diff --git a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java index 7675d78cc..162d514c6 100644 --- a/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java +++ b/src/main/java/com/volmit/iris/util/mantle/MantleChunk.java @@ -19,15 +19,12 @@ package com.volmit.iris.util.mantle; import com.volmit.iris.engine.object.feature.IrisFeaturePositional; -import com.volmit.iris.util.data.Varint; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.function.Consumer4; import com.volmit.iris.util.matter.IrisMatter; import com.volmit.iris.util.matter.Matter; import com.volmit.iris.util.matter.MatterSlice; import com.volmit.iris.util.matter.slices.ZoneMatter; -import com.volmit.iris.util.parallel.BurstExecutor; -import com.volmit.iris.util.parallel.MultiBurst; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -87,8 +84,7 @@ public class MantleChunk { short v = din.readShort(); - for(int i = 0; i < v; i++) - { + for (int i = 0; i < v; i++) { features.add(zm.readNode(din)); } } @@ -187,8 +183,7 @@ public class MantleChunk { dos.writeShort(features.size()); - for(IrisFeaturePositional i : features) - { + for (IrisFeaturePositional i : features) { zm.writeNode(i, dos); } } diff --git a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java index 6df695c21..b25d5ef14 100644 --- a/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java +++ b/src/main/java/com/volmit/iris/util/mantle/TectonicPlate.java @@ -23,7 +23,6 @@ import com.volmit.iris.engine.data.cache.Cache; 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.hunk.storage.ArrayHunk; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import java.io.*; diff --git a/src/main/java/com/volmit/iris/util/math/INode.java b/src/main/java/com/volmit/iris/util/math/INode.java index cb831d5b0..d0184c01f 100644 --- a/src/main/java/com/volmit/iris/util/math/INode.java +++ b/src/main/java/com/volmit/iris/util/math/INode.java @@ -30,7 +30,7 @@ public class INode { private double continuity; public INode() { - this(new Vector(0,0,0)); + this(new Vector(0, 0, 0)); } public INode(INode other) { diff --git a/src/main/java/com/volmit/iris/util/math/KochanekBartelsInterpolation.java b/src/main/java/com/volmit/iris/util/math/KochanekBartelsInterpolation.java index 75a01b205..ba0b2190f 100644 --- a/src/main/java/com/volmit/iris/util/math/KochanekBartelsInterpolation.java +++ b/src/main/java/com/volmit/iris/util/math/KochanekBartelsInterpolation.java @@ -89,15 +89,15 @@ public class KochanekBartelsInterpolation implements PathInterpolation { * Returns the linear combination of the given coefficients with the nodes adjacent to baseIndex. * * @param baseIndex node index - * @param f1 coefficient for baseIndex-1 - * @param f2 coefficient for baseIndex - * @param f3 coefficient for baseIndex+1 - * @param f4 coefficient for baseIndex+2 + * @param f1 coefficient for baseIndex-1 + * @param f2 coefficient for baseIndex + * @param f3 coefficient for baseIndex+1 + * @param f4 coefficient for baseIndex+2 * @return linear combination of nodes[n-1..n+2] with f1..4 */ private Vector linearCombination(int baseIndex, double f1, double f2, double f3, double f4) { final Vector r1 = retrieve(baseIndex - 1).multiply(f1); - final Vector r2 = retrieve(baseIndex ).multiply(f2); + final Vector r2 = retrieve(baseIndex).multiply(f2); final Vector r3 = retrieve(baseIndex + 1).multiply(f3); final Vector r4 = retrieve(baseIndex + 2).multiply(f4); @@ -108,7 +108,7 @@ public class KochanekBartelsInterpolation implements PathInterpolation { * Retrieves a node. Indexes are clamped to the valid range. * * @param index node index to retrieve - * @return nodes[clamp(0, nodes.length-1)] + * @return nodes[clamp(0, nodes.length - 1)] */ private Vector retrieve(int index) { if (index < 0) { @@ -204,11 +204,11 @@ public class KochanekBartelsInterpolation implements PathInterpolation { case 1: // This case is merely a speed-up for a very common case return arcLengthRecursive(indexLeft, remainderLeft, 1.0) - + arcLengthRecursive(indexRight, 0.0, remainderRight); + + arcLengthRecursive(indexRight, 0.0, remainderRight); default: return arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) - + arcLengthRecursive(indexRight, 0.0, remainderRight); + + arcLengthRecursive(indexRight, 0.0, remainderRight); } } diff --git a/src/main/java/com/volmit/iris/util/math/MathHelper.java b/src/main/java/com/volmit/iris/util/math/MathHelper.java index 0b4b9082d..808af818f 100644 --- a/src/main/java/com/volmit/iris/util/math/MathHelper.java +++ b/src/main/java/com/volmit/iris/util/math/MathHelper.java @@ -18,45 +18,60 @@ package com.volmit.iris.util.math; +import net.minecraft.SystemUtils; +import net.minecraft.core.BaseBlockPosition; +import net.minecraft.world.phys.AxisAlignedBB; +import net.minecraft.world.phys.Vec3D; +import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.math.NumberUtils; + import java.util.Random; import java.util.UUID; import java.util.function.Consumer; import java.util.function.IntPredicate; public class MathHelper { - public static final float a = MathHelper.c(2.0f); - private static final float[] b = (float[]) a((Object) new float[65536], var0 -> - { - for (int var1 = 0; var1 < ((float[]) var0).length; ++var1) { - ((float[]) var0)[var1] = (float) Math.sin((double) var1 * 3.141592653589793 * 2.0 / 65536.0); + private static final int h = 1024; + private static final float i = 1024.0F; + private static final long j = 61440L; + private static final long k = 16384L; + private static final long l = -4611686018427387904L; + private static final long m = -9223372036854775808L; + public static final float a = 3.1415927F; + public static final float b = 1.5707964F; + public static final float c = 6.2831855F; + public static final float d = 0.017453292F; + public static final float e = 57.295776F; + public static final float f = 1.0E-5F; + public static final float g = c(2.0F); + private static final float n = 10430.378F; + private static final float[] o = (float[]) SystemUtils.a(new float[65536], (var0x) -> { + for (int var1 = 0; var1 < var0x.length; ++var1) { + var0x[var1] = (float) Math.sin((double) var1 * 3.141592653589793D * 2.0D / 65536.0D); } - }); - public static T a(T var0, Consumer var1) { - var1.accept(var0); - return var0; + }); + private static final Random p = new Random(); + private static final int[] q = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; + private static final double r = 0.16666666666666666D; + private static final int s = 8; + private static final int t = 257; + private static final double u = Double.longBitsToDouble(4805340802404319232L); + private static final double[] v = new double[257]; + private static final double[] w = new double[257]; + + public MathHelper() { } - private static final Random c = new Random(); - private static final int[] d = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9}; - private static final double e = Double.longBitsToDouble(4805340802404319232L); - private static final double[] f = new double[257]; - private static final double[] g = new double[257]; - public static float sin(float var0) { - return b[(int) (var0 * 10430.378f) & 65535]; + return o[(int) (var0 * 10430.378F) & '\uffff']; } public static float cos(float var0) { - return b[(int) (var0 * 10430.378f + 16384.0f) & 65535]; + return o[(int) (var0 * 10430.378F + 16384.0F) & '\uffff']; } public static float c(float var0) { - return (float) Math.sqrt(var0); - } - - public static float sqrt(double var0) { - return (float) Math.sqrt(var0); + return (float) Math.sqrt((double) var0); } public static int d(float var0) { @@ -64,16 +79,24 @@ public class MathHelper { return var0 < (float) var1 ? var1 - 1 : var1; } + public static int a(double var0) { + return (int) (var0 + 1024.0D) - 1024; + } + public static int floor(double var0) { int var2 = (int) var0; return var0 < (double) var2 ? var2 - 1 : var2; } - public static long d(double var0) { + public static long c(double var0) { long var2 = (long) var0; return var0 < (double) var2 ? var2 - 1L : var2; } + public static int d(double var0) { + return (int) (var0 >= 0.0D ? var0 : -var0 + 1.0D); + } + public static float e(float var0) { return Math.abs(var0); } @@ -87,50 +110,77 @@ public class MathHelper { return var0 > (float) var1 ? var1 + 1 : var1; } - public static int f(double var0) { + public static int e(double var0) { int var2 = (int) var0; return var0 > (double) var2 ? var2 + 1 : var2; } + public static byte a(byte var0, byte var1, byte var2) { + if (var0 < var1) { + return var1; + } else { + return var0 > var2 ? var2 : var0; + } + } + public static int clamp(int var0, int var1, int var2) { if (var0 < var1) { return var1; + } else { + return var0 > var2 ? var2 : var0; + } + } + + public static long a(long var0, long var2, long var4) { + if (var0 < var2) { + return var2; + } else { + return var0 > var4 ? var4 : var0; } - return Math.min(var0, var2); } public static float a(float var0, float var1, float var2) { if (var0 < var1) { return var1; + } else { + return var0 > var2 ? var2 : var0; } - return Math.min(var0, var2); } public static double a(double var0, double var2, double var4) { if (var0 < var2) { return var2; + } else { + return var0 > var4 ? var4 : var0; } - return Math.min(var0, var4); } public static double b(double var0, double var2, double var4) { - if (var4 < 0.0) { + if (var4 < 0.0D) { return var0; + } else { + return var4 > 1.0D ? var2 : d(var4, var0, var2); } - if (var4 > 1.0) { - return var2; + } + + public static float b(float var0, float var1, float var2) { + if (var2 < 0.0F) { + return var0; + } else { + return var2 > 1.0F ? var1 : h(var2, var0, var1); } - return MathHelper.d(var4, var0, var2); } public static double a(double var0, double var2) { - if (var0 < 0.0) { + if (var0 < 0.0D) { var0 = -var0; } - if (var2 < 0.0) { + + if (var2 < 0.0D) { var2 = -var2; } - return Math.max(var0, var2); + + return var0 > var2 ? var0 : var2; } public static int a(int var0, int var1) { @@ -138,89 +188,131 @@ public class MathHelper { } public static int nextInt(Random var0, int var1, int var2) { - if (var1 >= var2) { - return var1; - } - return var0.nextInt(var2 - var1 + 1) + var1; + return var1 >= var2 ? var1 : var0.nextInt(var2 - var1 + 1) + var1; } public static float a(Random var0, float var1, float var2) { - if (var1 >= var2) { - return var1; - } - return var0.nextFloat() * (var2 - var1) + var1; + return var1 >= var2 ? var1 : var0.nextFloat() * (var2 - var1) + var1; } public static double a(Random var0, double var1, double var3) { - if (var1 >= var3) { - return var1; - } - return var0.nextDouble() * (var3 - var1) + var1; + return var1 >= var3 ? var1 : var0.nextDouble() * (var3 - var1) + var1; } public static double a(long[] var0) { long var1 = 0L; - for (long var6 : var0) { + long[] var3 = var0; + int var4 = var0.length; + + for (int var5 = 0; var5 < var4; ++var5) { + long var6 = var3[var5]; var1 += var6; } + return (double) var1 / (double) var0.length; } + public static boolean a(float var0, float var1) { + return Math.abs(var1 - var0) < 1.0E-5F; + } + public static boolean b(double var0, double var2) { - return Math.abs(var2 - var0) < 9.999999747378752E-6; + return Math.abs(var2 - var0) < 9.999999747378752E-6D; } public static int b(int var0, int var1) { return Math.floorMod(var0, var1); } - public static float g(float var0) { - float var1 = var0 % 360.0f; - if (var1 >= 180.0f) { - var1 -= 360.0f; + public static float b(float var0, float var1) { + return (var0 % var1 + var1) % var1; + } + + public static double c(double var0, double var2) { + return (var0 % var2 + var2) % var2; + } + + public static int b(int var0) { + int var1 = var0 % 360; + if (var1 >= 180) { + var1 -= 360; } - if (var1 < -180.0f) { - var1 += 360.0f; + + if (var1 < -180) { + var1 += 360; } + return var1; } - public static double g(double var0) { - double var2 = var0 % 360.0; - if (var2 >= 180.0) { - var2 -= 360.0; + public static float g(float var0) { + float var1 = var0 % 360.0F; + if (var1 >= 180.0F) { + var1 -= 360.0F; } - if (var2 < -180.0) { - var2 += 360.0; + + if (var1 < -180.0F) { + var1 += 360.0F; } + + return var1; + } + + public static double f(double var0) { + double var2 = var0 % 360.0D; + if (var2 >= 180.0D) { + var2 -= 360.0D; + } + + if (var2 < -180.0D) { + var2 += 360.0D; + } + return var2; } public static float c(float var0, float var1) { - return MathHelper.g(var1 - var0); + return g(var1 - var0); } public static float d(float var0, float var1) { - return MathHelper.e(MathHelper.c(var0, var1)); - } - - public static float b(float var0, float var1, float var2) { - float var3 = MathHelper.c(var0, var1); - float var4 = MathHelper.a(var3, -var2, var2); - return var1 - var4; + return e(c(var0, var1)); } public static float c(float var0, float var1, float var2) { - var2 = MathHelper.e(var2); - if (var0 < var1) { - return MathHelper.a(var0 + var2, var0, var1); - } - return MathHelper.a(var0 - var2, var1, var0); + float var3 = c(var0, var1); + float var4 = a(var3, -var2, var2); + return var1 - var4; } public static float d(float var0, float var1, float var2) { - float var3 = MathHelper.c(var0, var1); - return MathHelper.c(var0, var0 + var3, var2); + var2 = e(var2); + return var0 < var1 ? a(var0 + var2, var0, var1) : a(var0 - var2, var1, var0); + } + + public static float e(float var0, float var1, float var2) { + float var3 = c(var0, var1); + return d(var0, var0 + var3, var2); + } + + public static int a(String var0, int var1) { + return NumberUtils.toInt(var0, var1); + } + + public static int a(String var0, int var1, int var2) { + return Math.max(var2, a(var0, var1)); + } + + public static double a(String var0, double var1) { + try { + return Double.parseDouble(var0); + } catch (Throwable var4) { + return var1; + } + } + + public static double a(String var0, double var1, double var3) { + return Math.max(var3, a(var0, var1)); } public static int c(int var0) { @@ -238,166 +330,250 @@ public class MathHelper { } public static int e(int var0) { - var0 = MathHelper.d(var0) ? var0 : MathHelper.c(var0); - return d[(int) ((long) var0 * 125613361L >> 27) & 31]; + var0 = d(var0) ? var0 : c(var0); + return q[(int) ((long) var0 * 125613361L >> 27) & 31]; } public static int f(int var0) { - return MathHelper.e(var0) - (MathHelper.d(var0) ? 0 : 1); + return e(var0) - (d(var0) ? 0 : 1); + } + + public static int f(float var0, float var1, float var2) { + return b(d(var0 * 255.0F), d(var1 * 255.0F), d(var2 * 255.0F)); + } + + public static int b(int var0, int var1, int var2) { + int var3 = (var0 << 8) + var1; + var3 = (var3 << 8) + var2; + return var3; } public static int c(int var0, int var1) { - int var2; - if (var1 == 0) { - return 0; - } - if (var0 == 0) { - return var1; - } - if (var0 < 0) { - var1 *= -1; - } - if ((var2 = var0 % var1) == 0) { - return var0; - } - return var0 + var1 - var2; + int var2 = (var0 & 16711680) >> 16; + int var3 = (var1 & 16711680) >> 16; + int var4 = (var0 & '\uff00') >> 8; + int var5 = (var1 & '\uff00') >> 8; + int var6 = (var0 & 255) >> 0; + int var7 = (var1 & 255) >> 0; + int var8 = (int) ((float) var2 * (float) var3 / 255.0F); + int var9 = (int) ((float) var4 * (float) var5 / 255.0F); + int var10 = (int) ((float) var6 * (float) var7 / 255.0F); + return var0 & -16777216 | var8 << 16 | var9 << 8 | var10; + } + + public static int a(int var0, float var1, float var2, float var3) { + int var4 = (var0 & 16711680) >> 16; + int var5 = (var0 & '\uff00') >> 8; + int var6 = (var0 & 255) >> 0; + int var7 = (int) ((float) var4 * var1); + int var8 = (int) ((float) var5 * var2); + int var9 = (int) ((float) var6 * var3); + return var0 & -16777216 | var7 << 16 | var8 << 8 | var9; } public static float h(float var0) { - return var0 - (float) MathHelper.d(var0); + return var0 - (float) d(var0); } - public static double h(double var0) { - return var0 - (double) MathHelper.d(var0); + public static double g(double var0) { + return var0 - (double) c(var0); } - public static long a(BlockPosition var0) { + public static Vec3D a(Vec3D var0, Vec3D var1, Vec3D var2, Vec3D var3, double var4) { + double var6 = ((-var4 + 2.0D) * var4 - 1.0D) * var4 * 0.5D; + double var8 = ((3.0D * var4 - 5.0D) * var4 * var4 + 2.0D) * 0.5D; + double var10 = ((-3.0D * var4 + 4.0D) * var4 + 1.0D) * var4 * 0.5D; + double var12 = (var4 - 1.0D) * var4 * var4 * 0.5D; + return new Vec3D(var0.b * var6 + var1.b * var8 + var2.b * var10 + var3.b * var12, var0.c * var6 + var1.c * var8 + var2.c * var10 + var3.c * var12, var0.d * var6 + var1.d * var8 + var2.d * var10 + var3.d * var12); + } + + public static long a(BaseBlockPosition var0) { return c(var0.getX(), var0.getY(), var0.getZ()); } public static long c(int var0, int var1, int var2) { - long var3 = (var0 * 3129871L) ^ (long) var2 * 116129781L ^ (long) var1; + long var3 = (long) (var0 * 3129871) ^ (long) var2 * 116129781L ^ (long) var1; var3 = var3 * var3 * 42317861L + var3 * 11L; return var3 >> 16; } public static UUID a(Random var0) { long var1 = var0.nextLong() & -61441L | 16384L; - long var3 = var0.nextLong() & 0x3FFFFFFFFFFFFFFFL | Long.MIN_VALUE; + long var3 = var0.nextLong() & 4611686018427387903L | -9223372036854775808L; return new UUID(var1, var3); } public static UUID a() { - return MathHelper.a(c); + return a(p); } public static double c(double var0, double var2, double var4) { return (var0 - var2) / (var4 - var2); } - public static double d(double var0, double var2) { - double var9; - boolean var6; - boolean var7; - boolean var8; - double var4 = var2 * var2 + var0 * var0; - if (Double.isNaN(var4)) { - return Double.NaN; + public static boolean a(Vec3D var0, Vec3D var1, AxisAlignedBB var2) { + double var3 = (var2.a + var2.d) * 0.5D; + double var5 = (var2.d - var2.a) * 0.5D; + double var7 = var0.b - var3; + if (Math.abs(var7) > var5 && var7 * var1.b >= 0.0D) { + return false; + } else { + double var9 = (var2.b + var2.e) * 0.5D; + double var11 = (var2.e - var2.b) * 0.5D; + double var13 = var0.c - var9; + if (Math.abs(var13) > var11 && var13 * var1.c >= 0.0D) { + return false; + } else { + double var15 = (var2.c + var2.f) * 0.5D; + double var17 = (var2.f - var2.c) * 0.5D; + double var19 = var0.d - var15; + if (Math.abs(var19) > var17 && var19 * var1.d >= 0.0D) { + return false; + } else { + double var21 = Math.abs(var1.b); + double var23 = Math.abs(var1.c); + double var25 = Math.abs(var1.d); + double var27 = var1.c * var19 - var1.d * var13; + if (Math.abs(var27) > var11 * var25 + var17 * var23) { + return false; + } else { + var27 = var1.d * var7 - var1.b * var19; + if (Math.abs(var27) > var5 * var25 + var17 * var21) { + return false; + } else { + var27 = var1.b * var13 - var1.c * var7; + return Math.abs(var27) < var5 * var23 + var11 * var21; + } + } + } + } } - @SuppressWarnings("unused") - boolean bl = var6 = var0 < 0.0; - if (var6) { - var0 = -var0; - } - @SuppressWarnings("unused") - boolean bl2 = var7 = var2 < 0.0; - if (var7) { - var2 = -var2; - } - @SuppressWarnings("unused") - boolean bl3 = var8 = var0 > var2; - if (var8) { - var9 = var2; - var2 = var0; - var0 = var9; - } - var9 = MathHelper.i(var4); - double var11 = e + (var0 *= var9); - int var13 = (int) Double.doubleToRawLongBits(var11); - double var14 = f[var13]; - double var16 = g[var13]; - double var18 = var11 - e; - double var20 = var0 * var16 - (var2 *= var9) * var18; - double var22 = (6.0 + var20 * var20) * var20 * 0.16666666666666666; - double var24 = var14 + var22; - if (var8) { - var24 = 1.5707963267948966 - var24; - } - if (var7) { - var24 = 3.141592653589793 - var24; - } - if (var6) { - var24 = -var24; - } - return var24; } - public static double i(double var0) { - double var2 = 0.5 * var0; - long var4 = Double.doubleToRawLongBits(var0); - var4 = 6910469410427058090L - (var4 >> 1); - var0 = Double.longBitsToDouble(var4); - var0 *= 1.5 - var2 * var0 * var0; + public static double d(double var0, double var2) { + double var4 = var2 * var2 + var0 * var0; + if (Double.isNaN(var4)) { + return 0.0D / 0.0; + } else { + boolean var6 = var0 < 0.0D; + if (var6) { + var0 = -var0; + } + + boolean var7 = var2 < 0.0D; + if (var7) { + var2 = -var2; + } + + boolean var8 = var0 > var2; + double var9; + if (var8) { + var9 = var2; + var2 = var0; + var0 = var9; + } + + var9 = h(var4); + var2 *= var9; + var0 *= var9; + double var11 = u + var0; + int var13 = (int) Double.doubleToRawLongBits(var11); + double var14 = v[var13]; + double var16 = w[var13]; + double var18 = var11 - u; + double var20 = var0 * var16 - var2 * var18; + double var22 = (6.0D + var20 * var20) * var20 * 0.16666666666666666D; + double var24 = var14 + var22; + if (var8) { + var24 = 1.5707963267948966D - var24; + } + + if (var7) { + var24 = 3.141592653589793D - var24; + } + + if (var6) { + var24 = -var24; + } + + return var24; + } + } + + public static float i(float var0) { + float var1 = 0.5F * var0; + int var2 = Float.floatToIntBits(var0); + var2 = 1597463007 - (var2 >> 1); + var0 = Float.intBitsToFloat(var2); + var0 *= 1.5F - var1 * var0 * var0; return var0; } - public static int f(float var0, float var1, float var2) { - float var9; + public static double h(double var0) { + double var2 = 0.5D * var0; + long var4 = Double.doubleToRawLongBits(var0); + var4 = 6910469410427058090L - (var4 >> 1); + var0 = Double.longBitsToDouble(var4); + var0 *= 1.5D - var2 * var0 * var0; + return var0; + } + + public static float j(float var0) { + int var1 = Float.floatToIntBits(var0); + var1 = 1419967116 - var1 / 3; + float var2 = Float.intBitsToFloat(var1); + var2 = 0.6666667F * var2 + 1.0F / (3.0F * var2 * var2 * var0); + var2 = 0.6666667F * var2 + 1.0F / (3.0F * var2 * var2 * var0); + return var2; + } + + public static int g(float var0, float var1, float var2) { + int var3 = (int) (var0 * 6.0F) % 6; + float var4 = var0 * 6.0F - (float) var3; + float var5 = var2 * (1.0F - var1); + float var6 = var2 * (1.0F - var4 * var1); + float var7 = var2 * (1.0F - (1.0F - var4) * var1); float var8; + float var9; float var10; - int var3 = (int) (var0 * 6.0f) % 6; - float var4 = var0 * 6.0f - (float) var3; - float var5 = var2 * (1.0f - var1); - float var6 = var2 * (1.0f - var4 * var1); - float var7 = var2 * (1.0f - (1.0f - var4) * var1); switch (var3) { - case 0 -> { + case 0: var8 = var2; var9 = var7; var10 = var5; - } - case 1 -> { + break; + case 1: var8 = var6; var9 = var2; var10 = var5; - } - case 2 -> { + break; + case 2: var8 = var5; var9 = var2; var10 = var7; - } - case 3 -> { + break; + case 3: var8 = var5; var9 = var6; var10 = var2; - } - case 4 -> { + break; + case 4: var8 = var7; var9 = var5; var10 = var2; - } - case 5 -> { + break; + case 5: var8 = var2; var9 = var5; var10 = var6; - } - default -> { + break; + default: throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2); - } } - int var11 = MathHelper.clamp((int) (var8 * 255.0f), 0, 255); - int var12 = MathHelper.clamp((int) (var9 * 255.0f), 0, 255); - int var13 = MathHelper.clamp((int) (var10 * 255.0f), 0, 255); + + int var11 = clamp((int) (var8 * 255.0F), 0, 255); + int var12 = clamp((int) (var9 * 255.0F), 0, 255); + int var13 = clamp((int) (var10 * 255.0F), 0, 255); return var11 << 16 | var12 << 8 | var13; } @@ -410,22 +586,103 @@ public class MathHelper { return var0; } + public static long a(long var0) { + var0 ^= var0 >>> 33; + var0 *= -49064778989728563L; + var0 ^= var0 >>> 33; + var0 *= -4265267296055464877L; + var0 ^= var0 >>> 33; + return var0; + } + + public static double[] a(double... var0) { + float var1 = 0.0F; + double[] var2f = var0; + int var3 = var0.length; + + for (int var4 = 0; var4 < var3; ++var4) { + double var5 = var2f[var4]; + var1 = (float) ((double) var1 + var5); + } + + int var2; + for (var2 = 0; var2 < var0.length; ++var2) { + var0[var2] /= (double) var1; + } + + for (var2 = 0; var2 < var0.length; ++var2) { + var0[var2] += var2 == 0 ? 0.0D : var0[var2 - 1]; + } + + return var0; + } + + public static int a(Random var0, double[] var1) { + double var2 = var0.nextDouble(); + + for (int var4 = 0; var4 < var1.length; ++var4) { + if (var2 < var1[var4]) { + return var4; + } + } + + return var1.length; + } + + public static double[] a(double var0, double var2, double var4, int var6, int var7) { + double[] var8 = new double[var7 - var6 + 1]; + int var9 = 0; + + for (int var10 = var6; var10 <= var7; ++var10) { + var8[var9] = Math.max(0.0D, var0 * StrictMath.exp(-((double) var10 - var4) * ((double) var10 - var4) / (2.0D * var2 * var2))); + ++var9; + } + + return var8; + } + + public static double[] a(double var0, double var2, double var4, double var6, double var8, double var10, int var12, int var13) { + double[] var14 = new double[var13 - var12 + 1]; + int var15 = 0; + + for (int var16 = var12; var16 <= var13; ++var16) { + var14[var15] = Math.max(0.0D, var0 * StrictMath.exp(-((double) var16 - var4) * ((double) var16 - var4) / (2.0D * var2 * var2)) + var6 * StrictMath.exp(-((double) var16 - var10) * ((double) var16 - var10) / (2.0D * var8 * var8))); + ++var15; + } + + return var14; + } + + public static double[] a(double var0, double var2, int var4, int var5) { + double[] var6 = new double[var5 - var4 + 1]; + int var7 = 0; + + for (int var8 = var4; var8 <= var5; ++var8) { + var6[var7] = Math.max(var0 * StrictMath.log((double) var8) + var2, 0.0D); + ++var7; + } + + return var6; + } + public static int a(int var0, int var1, IntPredicate var2) { int var3 = var1 - var0; + while (var3 > 0) { int var4 = var3 / 2; int var5 = var0 + var4; if (var2.test(var5)) { var3 = var4; - continue; + } else { + var0 = var5 + 1; + var3 -= var4 + 1; } - var0 = var5 + 1; - var3 -= var4 + 1; } + return var0; } - public static float g(float var0, float var1, float var2) { + public static float h(float var0, float var1, float var2) { return var1 + var0 * (var2 - var1); } @@ -434,46 +691,118 @@ public class MathHelper { } public static double a(double var0, double var2, double var4, double var6, double var8, double var10) { - return MathHelper.d(var2, MathHelper.d(var0, var4, var6), MathHelper.d(var0, var8, var10)); + return d(var2, d(var0, var4, var6), d(var0, var8, var10)); } public static double a(double var0, double var2, double var4, double var6, double var8, double var10, double var12, double var14, double var16, double var18, double var20) { - return MathHelper.d(var4, MathHelper.a(var0, var2, var6, var8, var10, var12), MathHelper.a(var0, var2, var14, var16, var18, var20)); + return d(var4, a(var0, var2, var6, var8, var10, var12), a(var0, var2, var14, var16, var18, var20)); + } + + public static double i(double var0) { + return var0 * var0 * var0 * (var0 * (var0 * 6.0D - 15.0D) + 10.0D); } public static double j(double var0) { - return var0 * var0 * var0 * (var0 * (var0 * 6.0 - 15.0) + 10.0); + return 30.0D * var0 * var0 * (var0 - 1.0D) * (var0 - 1.0D); } public static int k(double var0) { - if (var0 == 0.0) { + if (var0 == 0.0D) { return 0; + } else { + return var0 > 0.0D ? 1 : -1; } - return var0 > 0.0 ? 1 : -1; + } + + public static float i(float var0, float var1, float var2) { + return var1 + var0 * g(var2 - var1); + } + + public static float j(float var0, float var1, float var2) { + return Math.min(var0 * var0 * 0.6F + var1 * var1 * ((3.0F + var1) / 4.0F) + var2 * var2 * 0.8F, 1.0F); } @Deprecated - public static float j(float var0, float var1, float var2) { + public static float k(float var0, float var1, float var2) { float var3; - for (var3 = var1 - var0; var3 < -180.0f; var3 += 360.0f) { + for (var3 = var1 - var0; var3 < -180.0F; var3 += 360.0F) { } - while (var3 >= 180.0f) { - var3 -= 360.0f; + + while (var3 >= 180.0F) { + var3 -= 360.0F; } + return var0 + var2 * var3; } + @Deprecated + public static float l(double var0) { + while (var0 >= 180.0D) { + var0 -= 360.0D; + } + + while (var0 < -180.0D) { + var0 += 360.0D; + } + + return (float) var0; + } + + public static float e(float var0, float var1) { + return (Math.abs(var0 % var1 - var1 * 0.5F) - var1 * 0.25F) / (var1 * 0.25F); + } + public static float k(float var0) { return var0 * var0; } + public static double m(double var0) { + return var0 * var0; + } + + public static int h(int var0) { + return var0 * var0; + } + + public static double a(double var0, double var2, double var4, double var6, double var8) { + return b(var6, var8, c(var0, var2, var4)); + } + + public static double b(double var0, double var2, double var4, double var6, double var8) { + return d(c(var0, var2, var4), var6, var8); + } + + public static double n(double var0) { + return var0 + (2.0D * (new Random((long) floor(var0 * 3000.0D))).nextDouble() - 1.0D) * 1.0E-7D / 2.0D; + } + + public static int d(int var0, int var1) { + return (var0 + var1 - 1) / var1 * var1; + } + + public static int b(Random var0, int var1, int var2) { + return var0.nextInt(var2 - var1 + 1) + var1; + } + + public static float b(Random var0, float var1, float var2) { + return var0.nextFloat() * (var2 - var1) + var1; + } + + public static float c(Random var0, float var1, float var2) { + return var1 + (float) var0.nextGaussian() * var2; + } + + public static double a(int var0, double var1, int var3) { + return Math.sqrt((double) (var0 * var0) + var1 * var1 + (double) (var3 * var3)); + } + static { - for (int var02 = 0; var02 < 257; ++var02) { - // TODO: WARNING HEIGHT - double var1 = (double) var02 / 256.0; + for (int var0 = 0; var0 < 257; ++var0) { + double var1 = (double) var0 / 256.0D; double var3 = Math.asin(var1); - MathHelper.g[var02] = Math.cos(var3); - MathHelper.f[var02] = var3; + w[var0] = Math.cos(var3); + v[var0] = var3; } + } } \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/matter/Matter.java b/src/main/java/com/volmit/iris/util/matter/Matter.java index 421c9fb3f..fdf7f2a5f 100644 --- a/src/main/java/com/volmit/iris/util/matter/Matter.java +++ b/src/main/java/com/volmit/iris/util/matter/Matter.java @@ -18,16 +18,13 @@ package com.volmit.iris.util.matter; -import com.volmit.iris.Iris; import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.data.Varint; -import com.volmit.iris.util.format.C; import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.math.BlockPosition; import org.bukkit.World; import org.bukkit.block.data.BlockData; -import org.bukkit.craftbukkit.v1_17_R1.block.data.type.CraftLeaves; import org.bukkit.entity.Entity; import java.io.*; @@ -190,13 +187,9 @@ public interface Matter { slice = (MatterSlice) createSlice(c, this); if (slice == null) { - try - { + try { throw new RuntimeException("Bad slice " + c.getCanonicalName()); - } - - catch(Throwable e) - { + } catch (Throwable e) { e.printStackTrace(); } diff --git a/src/main/java/com/volmit/iris/util/matter/slices/ZoneMatter.java b/src/main/java/com/volmit/iris/util/matter/slices/ZoneMatter.java index 652ac391f..6201b08f1 100644 --- a/src/main/java/com/volmit/iris/util/matter/slices/ZoneMatter.java +++ b/src/main/java/com/volmit/iris/util/matter/slices/ZoneMatter.java @@ -18,7 +18,6 @@ package com.volmit.iris.util.matter.slices; -import com.volmit.iris.Iris; import com.volmit.iris.engine.object.feature.IrisFeaturePositional; import com.volmit.iris.util.matter.Sliced; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java b/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java index 04125982e..1eb54740f 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java @@ -18,6 +18,8 @@ package com.volmit.iris.util.nbt.mca; +import com.volmit.iris.Iris; +import com.volmit.iris.util.io.IO; import com.volmit.iris.util.nbt.io.NBTDeserializer; import com.volmit.iris.util.nbt.io.NBTSerializer; import com.volmit.iris.util.nbt.io.NamedTag; @@ -658,11 +660,7 @@ public class Chunk { level.putInt("zPos", zPos); level.putLong("LastUpdate", lastUpdate); level.putLong("InhabitedTime", inhabitedTime); - if (dataVersion < 2202) { - if (biomes != null && biomes.length == 256) level.putIntArray("Biomes", biomes); - } else { - if (biomes != null && biomes.length == 1024) level.putIntArray("Biomes", biomes); - } + if (biomes != null && biomes.length == 1024) level.putIntArray("Biomes", biomes); if (heightMaps != null) level.put("Heightmaps", heightMaps); if (carvingMasks != null) level.put("CarvingMasks", carvingMasks); if (entities != null) level.put("Entities", entities); @@ -688,14 +686,4 @@ public class Chunk { public int sectionCount() { return sections.length(); } - - public void runLighting() { - for (int s = 15; s >= 0; s--) { - Section section = getSection(s); - - if (section != null) { - section.runLighting(); - } - } - } } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java b/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java index 42d3e1b5b..1695bbf47 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/MCAFile.java @@ -18,6 +18,7 @@ package com.volmit.iris.util.nbt.mca; +import com.volmit.iris.Iris; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.Position2; import com.volmit.iris.util.nbt.tag.CompoundTag; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java b/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java index a2b858f86..7bda6369d 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java @@ -28,7 +28,6 @@ import com.volmit.iris.util.math.M; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.StringTag; import com.volmit.iris.util.parallel.HyperLock; -import com.volmit.iris.util.scheduling.IrisLock; import org.bukkit.NamespacedKey; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -39,10 +38,38 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.util.function.Function; public class NBTWorld { private static final BlockData AIR = B.get("AIR"); - private static final Map blockDataCache = new KMap<>(); + private static final Map blockDataCache = new KMap<>(); + private static final Function BLOCK_DATA_COMPUTE = (blockData) -> { + CompoundTag s = new CompoundTag(); + String data = blockData.getAsString(true); + NamespacedKey key = blockData.getMaterial().getKey(); + s.putString("Name", key.getNamespace() + ":" + key.getKey()); + + if (data.contains("[")) { + String raw = data.split("\\Q[\\E")[1].replaceAll("\\Q]\\E", ""); + CompoundTag props = new CompoundTag(); + if (raw.contains(",")) { + for (String i : raw.split("\\Q,\\E")) { + String[] m = i.split("\\Q=\\E"); + String k = m[0]; + String v = m[1]; + props.put(k, new StringTag(v)); + } + } else { + String[] m = raw.split("\\Q=\\E"); + String k = m[0]; + String v = m[1]; + props.put(k, new StringTag(v)); + } + s.put("Properties", props); + } + + return s; + }; private static final Map biomeIds = computeBiomeIDs(); private final KMap loadedRegions; private final HyperLock hyperLock = new HyperLock(); @@ -184,38 +211,8 @@ public class NBTWorld { return b; } - public static CompoundTag getCompound(BlockData blockData) { - String data = blockData.getAsString(true); - - if (blockDataCache.containsKey(data)) { - return blockDataCache.get(data).clone(); - } - - CompoundTag s = new CompoundTag(); - NamespacedKey key = blockData.getMaterial().getKey(); - s.putString("Name", key.getNamespace() + ":" + key.getKey()); - - if (data.contains("[")) { - String raw = data.split("\\Q[\\E")[1].replaceAll("\\Q]\\E", ""); - CompoundTag props = new CompoundTag(); - if (raw.contains(",")) { - for (String i : raw.split("\\Q,\\E")) { - String[] m = i.split("\\Q=\\E"); - String k = m[0]; - String v = m[1]; - props.put(k, new StringTag(v)); - } - } else { - String[] m = raw.split("\\Q=\\E"); - String k = m[0]; - String v = m[1]; - props.put(k, new StringTag(v)); - } - s.put("Properties", props); - } - - blockDataCache.put(data, s.clone()); - return s; + public static CompoundTag getCompound(BlockData bd) { + return blockDataCache.computeIfAbsent(bd, BLOCK_DATA_COMPUTE).clone(); } public BlockData getBlockData(int x, int y, int z) { @@ -238,8 +235,7 @@ public class NBTWorld { getChunkSection(x >> 4, y >> 4, z >> 4).setBlockStateAt(x & 15, y & 15, z & 15, getCompound(data), false); } - public int getBiomeId(Biome b) - { + public int getBiomeId(Biome b) { return biomeIds.get(b); } @@ -259,8 +255,7 @@ public class NBTWorld { return s; } - public Chunk getChunk(int x, int z) - { + public Chunk getChunk(int x, int z) { return getChunk(getMCA(x >> 5, z >> 5), x, z); } @@ -275,11 +270,18 @@ public class NBTWorld { return c; } + public Chunk getNewChunk(MCAFile mca, int x, int z) { + Chunk c = Chunk.newChunk(); + mca.setChunk(x & 31, z & 31, c); + + return c; + } + public long getIdleDuration(int x, int z) { - return hyperLock.withResult(x, z, () -> { - Long l = lastUse.get(Cache.key(x, z)); - return l == null ? 0 : (M.ms() - l); - }); + return hyperLock.withResult(x, z, () -> { + Long l = lastUse.get(Cache.key(x, z)); + return l == null ? 0 : (M.ms() - l); + }); } public MCAFile getMCA(int x, int z) { diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/Section.java b/src/main/java/com/volmit/iris/util/nbt/mca/Section.java index 89ce29962..fd4865c1a 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/Section.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/Section.java @@ -18,26 +18,17 @@ package com.volmit.iris.util.nbt.mca; -import com.volmit.iris.Iris; -import com.volmit.iris.util.collection.KMap; +import com.volmit.iris.util.nbt.mca.palettes.DataPaletteBlock; import com.volmit.iris.util.nbt.tag.ByteArrayTag; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; import com.volmit.iris.util.nbt.tag.LongArrayTag; -import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicLongArray; public class Section { private CompoundTag data; - private Map> valueIndexedPalette = new KMap<>(); - private ListTag palette; + private DataPaletteBlock palette; private byte[] blockLight; - private AtomicLongArray blockStates; private byte[] skyLight; private int dataVersion; @@ -52,83 +43,18 @@ public class Section { if (rawPalette == null) { return; } - palette = rawPalette.asCompoundTagList(); - for (int i = 0; i < palette.size(); i++) { - CompoundTag data = palette.get(i); - putValueIndexedPalette(data, i); - } - - ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); + palette = new DataPaletteBlock(); LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); + palette.load((ListTag) rawPalette, blockStates.getValue()); + ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight"); - - if ((loadFlags & LoadFlags.BLOCK_LIGHTS) != 0) { - this.blockLight = blockLight != null ? blockLight.getValue() : null; - } - if ((loadFlags & LoadFlags.BLOCK_STATES) != 0) { - this.blockStates = blockStates != null ? new AtomicLongArray(blockStates.getValue()) : null; - } - if ((loadFlags & LoadFlags.SKY_LIGHT) != 0) { - this.skyLight = skyLight != null ? skyLight.getValue() : null; - } + this.blockLight = blockLight != null ? blockLight.getValue() : null; + this.skyLight = skyLight != null ? skyLight.getValue() : null; } Section() { } - void putValueIndexedPalette(CompoundTag data, int index) { - PaletteIndex leaf = new PaletteIndex(data, index); - String name = data.getString("Name"); - List leaves = valueIndexedPalette.get(name); - if (leaves == null) { - leaves = new ArrayList<>(1); - leaves.add(leaf); - valueIndexedPalette.put(name, leaves); - } else { - for (PaletteIndex pal : leaves) { - if (pal.data.equals(data)) { - return; - } - } - leaves.add(leaf); - } - } - - PaletteIndex getValueIndexedPalette(CompoundTag data) { - List leaves = valueIndexedPalette.get(data.getString("Name")); - if (leaves == null) { - return null; - } - for (PaletteIndex leaf : leaves) { - if (leaf.data.equals(data)) { - return leaf; - } - } - return null; - } - - public void runLighting() { - for (int x = 1; x < 14; x++) { - for (int z = 1; z < 14; z++) { - for (int y = 0; y < 16; y++) { - - } - } - } - } - - @SuppressWarnings("ClassCanBeRecord") - private static class PaletteIndex { - - final CompoundTag data; - final int index; - - PaletteIndex(CompoundTag data, int index) { - this.data = data; - this.index = index; - } - } - /** * Checks whether the data of this Section is empty. * @@ -147,17 +73,11 @@ public class Section { * @param blockZ The z-coordinate of the block in this Section * @return The block state data of this block. */ - public CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) { - try { - int index = getBlockIndex(blockX, blockY, blockZ); - int paletteIndex = getPaletteIndex(index); - return palette.get(paletteIndex); - } catch (Throwable ignored) { - Iris.reportError(ignored); - + public synchronized CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) { + synchronized (palette) + { + return palette.getBlock(blockX&15, blockY&15, blockZ&15); } - - return null; } /** @@ -167,116 +87,12 @@ public class Section { * @param blockY The y-coordinate of the block in this Section * @param blockZ The z-coordinate of the block in this Section * @param state The block state to be set - * @param cleanup When true, it will cleanup the palette of this section. - * This option should only be used moderately to avoid unnecessary recalculation of the palette indices. - * Recalculating the Palette should only be executed once right before saving the Section to file. */ public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) { - int paletteSizeBefore = palette.size(); - int paletteIndex = addToPalette(state); - //power of 2 --> bits must increase, but only if the palette size changed - //otherwise we would attempt to update all blockstates and the entire palette - //every time an existing blockstate was added while having 2^x blockstates in the palette - if (paletteSizeBefore != palette.size() && (paletteIndex & (paletteIndex - 1)) == 0) { - adjustBlockStateBits(null, blockStates); - cleanup = true; + synchronized (palette) + { + palette.setBlock(blockX&15, blockY&15, blockZ&15, state); } - - setPaletteIndex(getBlockIndex(blockX, blockY, blockZ), paletteIndex, blockStates); - - if (cleanup) { - cleanupPaletteAndBlockStates(); - } - } - - /** - * Returns the index of the block data in the palette. - * - * @param blockStateIndex The index of the block in this section, ranging from 0-4095. - * @return The index of the block data in the palette. - */ - public int getPaletteIndex(int blockStateIndex) { - int bits = blockStates.length() >> 6; - - if (dataVersion < 2527) { - double blockStatesIndex = blockStateIndex / (4096D / blockStates.length()); - int longIndex = (int) blockStatesIndex; - int startBit = (int) ((blockStatesIndex - Math.floor(blockStatesIndex)) * 64D); - if (startBit + bits > 64) { - long prev = bitRange(blockStates.get(longIndex), startBit, 64); - long next = bitRange(blockStates.get(longIndex + 1), 0, startBit + bits - 64); - return (int) ((next << 64 - startBit) + prev); - } else { - return (int) bitRange(blockStates.get(longIndex), startBit, startBit + bits); - } - } else { - int indicesPerLong = (int) (64D / bits); - int blockStatesIndex = blockStateIndex / indicesPerLong; - int startBit = (blockStateIndex % indicesPerLong) * bits; - return (int) bitRange(blockStates.get(blockStatesIndex), startBit, startBit + bits); - } - } - - /** - * Sets the index of the block data in the BlockStates. Does not adjust the size of the BlockStates array. - * - * @param blockIndex The index of the block in this section, ranging from 0-4095. - * @param paletteIndex The block state to be set (index of block data in the palette). - * @param blockStates The block states to be updated. - */ - public synchronized void setPaletteIndex(int blockIndex, int paletteIndex, AtomicLongArray blockStates) { - int bits = blockStates.length() >> 6; - - if (dataVersion < 2527) { - double blockStatesIndex = blockIndex / (4096D / blockStates.length()); - int longIndex = (int) blockStatesIndex; - int startBit = (int) ((blockStatesIndex - Math.floor(longIndex)) * 64D); - if (startBit + bits > 64) { - blockStates.set(longIndex, updateBits(blockStates.get(longIndex), paletteIndex, startBit, 64)); - blockStates.set(longIndex + 1, updateBits(blockStates.get(longIndex + 1), paletteIndex, startBit - 64, startBit + bits - 64)); - } else { - blockStates.set(longIndex, updateBits(blockStates.get(longIndex), paletteIndex, startBit, startBit + bits)); - } - } else { - int indicesPerLong = (int) (64D / bits); - int blockStatesIndex = blockIndex / indicesPerLong; - int startBit = (blockIndex % indicesPerLong) * bits; - blockStates.set(blockStatesIndex, updateBits(blockStates.get(blockStatesIndex), paletteIndex, startBit, startBit + bits)); - } - } - - /** - * Fetches the palette of this Section. - * - * @return The palette of this Section. - */ - public ListTag getPalette() { - return palette; - } - - synchronized int addToPalette(CompoundTag data) { - PaletteIndex index; - if ((index = getValueIndexedPalette(data)) != null) { - return index.index; - } - palette.add(data); - putValueIndexedPalette(data, palette.size() - 1); - return palette.size() - 1; - } - - int getBlockIndex(int blockX, int blockY, int blockZ) { - return (blockY & 0xF) * 256 + (blockZ & 0xF) * 16 + (blockX & 0xF); - } - - static long updateBits(long n, long m, int i, int j) { - //replace i to j in n with j - i bits of m - long mShifted = i > 0 ? (m & ((1L << j - i) - 1)) << i : (m & ((1L << j - i) - 1)) >>> -i; - return ((n & ((j > 63 ? 0 : (~0L << j)) | (i < 0 ? 0 : ((1L << i) - 1L)))) | mShifted); - } - - static long bitRange(long value, int from, int to) { - int waste = 64 - to; - return (value << waste) >>> (waste + from); } /** @@ -284,69 +100,14 @@ public class Section { * This should only be used moderately to avoid unnecessary recalculation of the palette indices. * Recalculating the Palette should only be executed once right before saving the Section to file. */ - public synchronized void cleanupPaletteAndBlockStates() { - Map oldToNewMapping = cleanupPalette(); - adjustBlockStateBits(oldToNewMapping, blockStates); - } + public void cleanupPaletteAndBlockStates() { - private synchronized Map cleanupPalette() { - //create index - palette mapping - Map allIndices = new Int2IntOpenHashMap(); - for (int i = 0; i < 4096; i++) { - int paletteIndex = getPaletteIndex(i); - allIndices.put(paletteIndex, paletteIndex); - } - //delete unused blocks from palette - //start at index 1 because we need to keep minecraft:air - int index = 1; - valueIndexedPalette = new HashMap<>(valueIndexedPalette.size()); - putValueIndexedPalette(palette.get(0), 0); - for (int i = 1; i < palette.size(); i++) { - if (!allIndices.containsKey(index)) { - palette.remove(i); - i--; - } else { - putValueIndexedPalette(palette.get(i), i); - allIndices.put(index, i); - } - index++; - } - - return allIndices; - } - - synchronized void adjustBlockStateBits(Map oldToNewMapping, AtomicLongArray blockStates) { - //increases or decreases the amount of bits used per BlockState - //based on the size of the palette. oldToNewMapping can be used to update indices - //if the palette had been cleaned up before using MCAFile#cleanupPalette(). - - int newBits = 32 - Integer.numberOfLeadingZeros(palette.size() - 1); - newBits = Math.max(newBits, 4); - - AtomicLongArray newBlockStates; - - if (dataVersion < 2527) { - newBlockStates = newBits == blockStates.length() / 64 ? blockStates : new AtomicLongArray(newBits * 64); - } else { - int newLength = (int) Math.ceil(4096D / (64D / newBits)); - newBlockStates = newBits == blockStates.length() / 64 ? blockStates : new AtomicLongArray(newLength); - } - if (oldToNewMapping != null) { - for (int i = 0; i < 4096; i++) { - setPaletteIndex(i, oldToNewMapping.get(getPaletteIndex(i)), newBlockStates); - } - } else { - for (int i = 0; i < 4096; i++) { - setPaletteIndex(i, getPaletteIndex(i), newBlockStates); - } - } - this.blockStates = newBlockStates; } /** * @return The block light array of this Section */ - public byte[] getBlockLight() { + public synchronized byte[] getBlockLight() { return blockLight; } @@ -356,40 +117,17 @@ public class Section { * @param blockLight The block light array * @throws IllegalArgumentException When the length of the array is not 2048 */ - public void setBlockLight(byte[] blockLight) { + public synchronized void setBlockLight(byte[] blockLight) { if (blockLight != null && blockLight.length != 2048) { throw new IllegalArgumentException("BlockLight array must have a length of 2048"); } this.blockLight = blockLight; } - /** - * @return The indices of the block states of this Section. - */ - public AtomicLongArray getBlockStates() { - return blockStates; - } - - /** - * Sets the block state indices to a custom value. - * - * @param blockStates The block state indices. - * @throws NullPointerException If blockStates is null - * @throws IllegalArgumentException When blockStates' length is < 256 or > 4096 and is not a multiple of 64 - */ - public synchronized void setBlockStates(AtomicLongArray blockStates) { - if (blockStates == null) { - throw new NullPointerException("BlockStates cannot be null"); - } else if (blockStates.length() % 64 != 0 || blockStates.length() < 256 || blockStates.length() > 4096) { - throw new IllegalArgumentException("BlockStates must have a length > 255 and < 4097 and must be divisible by 64"); - } - this.blockStates = blockStates; - } - /** * @return The sky light values of this Section */ - public byte[] getSkyLight() { + public synchronized byte[] getSkyLight() { return skyLight; } @@ -399,7 +137,7 @@ public class Section { * @param skyLight The custom sky light values * @throws IllegalArgumentException If the length of the array is not 2048 */ - public void setSkyLight(byte[] skyLight) { + public synchronized void setSkyLight(byte[] skyLight) { if (skyLight != null && skyLight.length != 2048) { throw new IllegalArgumentException("SkyLight array must have a length of 2048"); } @@ -413,11 +151,7 @@ public class Section { */ public static Section newSection() { Section s = new Section(); - s.blockStates = new AtomicLongArray(256); - s.palette = new ListTag<>(CompoundTag.class); - CompoundTag air = new CompoundTag(); - air.putString("Name", "minecraft:air"); - s.palette.add(air); + s.palette = new DataPaletteBlock(); s.data = new CompoundTag(); return s; } @@ -430,23 +164,18 @@ public class Section { * @param y The Y-value of this Section * @return A reference to the raw CompoundTag this Section is based on */ - public CompoundTag updateHandle(int y) { + public synchronized CompoundTag updateHandle(int y) { data.putByte("Y", (byte) y); + if (palette != null) { - data.put("Palette", palette); + synchronized (palette) + { + palette.save(data, "Palette", "BlockStates"); + } } if (blockLight != null) { data.putByteArray("BlockLight", blockLight); } - if (blockStates != null) { - long[] c = new long[blockStates.length()]; - - for (int i = 0; i < c.length; i++) { - c[i] = blockStates.get(i); - } - - data.putLongArray("BlockStates", c); - } if (skyLight != null) { data.putByteArray("SkyLight", skyLight); } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataBits.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataBits.java new file mode 100644 index 000000000..7755ddd1a --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataBits.java @@ -0,0 +1,125 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.nbt.mca.palettes; + +import org.apache.commons.lang3.Validate; + +import java.util.function.IntConsumer; + +public class DataBits { + private static final int[] a = new int[]{-1, -1, 0, -2147483648, 0, 0, 1431655765, 1431655765, 0, -2147483648, 0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756, 0, -2147483648, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0, 390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378, 306783378, 0, 286331153, 286331153, 0, -2147483648, 0, 3, 252645135, 252645135, 0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0, 204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970, 178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862, 0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0, 138547332, 138547332, 0, -2147483648, 0, 4, 130150524, 130150524, 0, 126322567, 126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197, 0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0, 104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893, 97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282, 0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0, 84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431, 79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303, 0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0, 70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, -2147483648, 0, 5}; + private final long[] data; + private final int c; + private final long paletteSize; + private final int blockSize; + private final int f; + private final int g; + private final int h; + private final int i; + + public DataBits(int var0, int var1) { + this(var0, var1, (long[]) null); + } + + public DataBits(int bitsPerBlock, int var1, long[] data) { + Validate.inclusiveBetween(1L, 32L, (long) bitsPerBlock); + this.blockSize = var1; + this.c = bitsPerBlock; + this.paletteSize = (1L << bitsPerBlock) - 1L; + this.f = (char) (64 / bitsPerBlock); + int var3 = 3 * (this.f - 1); + this.g = a[var3 + 0]; + this.h = a[var3 + 1]; + this.i = a[var3 + 2]; + int var4 = (var1 + this.f - 1) / this.f; + if (data != null) { + if (data.length != var4) { + throw new RuntimeException("Invalid length given for storage, got: " + data.length + " but expected: " + var4); + } + + this.data = data; + } else { + this.data = new long[var4]; + } + + } + + private int b(int var0) { + long var1 = Integer.toUnsignedLong(this.g); + long var3 = Integer.toUnsignedLong(this.h); + return (int) ((long) var0 * var1 + var3 >> 32 >> this.i); + } + + public int setBlockResulting(int blockIndex, int paletteIndex) { + Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex); + Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex); + int var2 = this.b(blockIndex); + long var3 = this.data[var2]; + int var5 = (blockIndex - var2 * this.f) * this.c; + int var6 = (int) (var3 >> var5 & this.paletteSize); + this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5; + return var6; + } + + public void setBlock(int blockIndex, int paletteIndex) { + Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex); + Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex); + int var2 = this.b(blockIndex); + long var3 = this.data[var2]; + int var5 = (blockIndex - var2 * this.f) * this.c; + this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5; + } + + public int getIndexFromPos(int var0) { + Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) var0); + int var1 = this.b(var0); + long var2 = this.data[var1]; + int var4 = (var0 - var1 * this.f) * this.c; + return (int) (var2 >> var4 & this.paletteSize); + } + + public long[] getData() { + return this.data; + } + + public int b() { + return this.blockSize; + } + + public int getBitsPerBlock() { + return this.c; + } + + public void a(IntConsumer var0) { + int var1 = 0; + long[] var3 = this.data; + int var4 = var3.length; + for (long l : var3) { + long var5 = l; + for (int j = 0; j < this.f; ++j) { + var0.accept((int) (var5 & this.paletteSize)); + var5 >>= this.c; + ++var1; + if (var1 >= this.blockSize) { + return; + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/hunk/io/StringHunkIOAdapter.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java similarity index 63% rename from src/main/java/com/volmit/iris/util/hunk/io/StringHunkIOAdapter.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java index f0ebbac37..f0d4e81e0 100644 --- a/src/main/java/com/volmit/iris/util/hunk/io/StringHunkIOAdapter.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java @@ -16,21 +16,21 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.hunk.io; +package com.volmit.iris.util.nbt.mca.palettes; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; -public class StringHunkIOAdapter extends PaletteHunkIOAdapter { +import java.util.function.Predicate; - @Override - public void write(String data, DataOutputStream dos) throws IOException { - dos.writeUTF(data); - } +public interface DataPalette { + int getIndex(CompoundTag block); - @Override - public String read(DataInputStream din) throws IOException { - return din.readUTF(); - } + boolean contains(Predicate predicate); + + CompoundTag getByIndex(int index); + + int size(); + + void replace(ListTag palette); } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java new file mode 100644 index 000000000..3f1155e13 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java @@ -0,0 +1,225 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.nbt.mca.palettes; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.nms.INMS; +import com.volmit.iris.engine.data.cache.AtomicCache; +import com.volmit.iris.util.math.MathHelper; +import com.volmit.iris.util.nbt.io.SNBTSerializer; +import com.volmit.iris.util.nbt.mca.NBTWorld; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import com.volmit.iris.util.scheduling.J; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import lombok.Getter; +import net.minecraft.world.level.chunk.ChunkSection; +import org.bukkit.Material; + +import java.io.IOException; +import java.util.HashSet; +import java.util.Map; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +@Getter +public class DataPaletteBlock implements DataPaletteExpandable { + private static final int d = 4096; + public static final int HASH_BITS = 9; + public static final int LINEAR_BITS = 4; + private final DataPalette globalPalette; + private final DataPaletteExpandable f = (var0x, var1x) -> 0; + private final RegistryBlockID stolenRegistry; + private final CompoundTag defAir; + private static final AtomicCache reg = new AtomicCache<>(); + private static final AtomicCache global = new AtomicCache<>(); + private static final CompoundTag air = NBTWorld.getCompound(Material.AIR.createBlockData()); + protected DataBits dataBits; + private DataPalette currentPalette; + private int bits = 0; + + public DataPaletteBlock() { + this(global(), registry(), air); + } + + public DataPaletteBlock(DataPalette var0, + RegistryBlockID var1, + CompoundTag airType) { + this.globalPalette = var0; + this.stolenRegistry = var1; + this.defAir = airType; + this.changeBitsTo(4); + } + + private static RegistryBlockID registry() + { + return ((DataPaletteGlobal) global()).getRegistry(); + } + + private static DataPalette global() { + return global.aquire(() -> new DataPaletteGlobal(J.attemptResult(() -> INMS.get().computeBlockIDRegistry()), air)); + } + + + private static int blockIndex(int x, int y, int z) { + return y << 8 | z << 4 | x; + } + + private void changeBitsTo(int newbits) { + if (newbits != bits) { + bits = newbits; + if (bits <= LINEAR_BITS) { + bits = LINEAR_BITS; + currentPalette = new DataPaletteLinear(bits, this); + } else if (bits < HASH_BITS) { + currentPalette = new DataPaletteHash(bits, this); + } else { + currentPalette = globalPalette; + bits = MathHelper.e(stolenRegistry.size()); + } + + currentPalette.getIndex(defAir); + dataBits = new DataBits(bits, 4096); + } + } + + public int onResize(int newBits, CompoundTag newData) { + DataBits oldBits = dataBits; + DataPalette oldPalette = currentPalette; + changeBitsTo(newBits); + + for (int i = 0; i < oldBits.b(); ++i) { + CompoundTag block = oldPalette.getByIndex(oldBits.getIndexFromPos(i)); + if (block != null) { + setBlockIndex(i, block); + } + } + + return currentPalette.getIndex(newData); + } + + @Deprecated + public CompoundTag setBlockAndReturn(int x, int y, int z, CompoundTag block) { + return setBlockIndexAndReturn(blockIndex(x, y, z), block); + } + + @Deprecated + private CompoundTag setBlockIndexAndReturn(int index, CompoundTag block) { + int paletteIndex = currentPalette.getIndex(block); + int res = dataBits.setBlockResulting(index, paletteIndex); + CompoundTag testBlock = currentPalette.getByIndex(res); + return testBlock == null ? defAir : testBlock; + } + + public void setBlock(int x, int y, int z, CompoundTag block) { + setBlockIndex(blockIndex(x, y, z), block); + } + + private void setBlockIndex(int blockIndex, CompoundTag block) { + int paletteIndex = currentPalette.getIndex(block); + dataBits.setBlock(blockIndex, paletteIndex); + } + + public CompoundTag getBlock(int x, int y, int z) { + return getByIndex(blockIndex(x, y, z)); + } + + protected CompoundTag getByIndex(int index) { + if(currentPalette == null) + { + return null; + } + + CompoundTag data = currentPalette.getByIndex(dataBits.getIndexFromPos(index)); + return data == null ? defAir : data; + } + + public void load(ListTag palettedata, long[] databits) { + int readBits = Math.max(4, MathHelper.e(palettedata.size())); + if (readBits != bits) { + changeBitsTo(readBits); + } + + currentPalette.replace(palettedata); + int dblen = databits.length * 64 / 4096; + if (currentPalette == globalPalette) { + DataPalette hashPalette = new DataPaletteHash(readBits, f); + hashPalette.replace(palettedata); + DataBits var5 = new DataBits(readBits, 4096, databits); + + for (int i = 0; i < 4096; ++i) { + dataBits.setBlock(i, globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(i)))); + } + } else if (dblen == bits) { + System.arraycopy(databits, 0, dataBits.getData(), 0, databits.length); + } else { + DataBits var4 = new DataBits(dblen, 4096, databits); + + for (int i = 0; i < 4096; ++i) { + dataBits.setBlock(i, var4.getIndexFromPos(i)); + } + } + } + + public void save(CompoundTag to, String paletteName, String blockStatesName) { + DataPaletteHash hashpal = new DataPaletteHash(bits, f); + CompoundTag cursor = defAir; + int palIndex = hashpal.getIndex(defAir); + int[] paletteIndex = new int[4096]; + int i; + for (i = 0; i < 4096; ++i) { + CompoundTag entry = getByIndex(i); + if (!entry.equals(cursor)) { + cursor = entry; + palIndex = hashpal.getIndex(entry); + } + + paletteIndex[i] = palIndex; + } + + ListTag npalette = (ListTag) ListTag.createUnchecked(CompoundTag.class); + hashpal.writePalette(npalette); + to.put(paletteName, npalette); + int bits = Math.max(4, MathHelper.e(npalette.size())); + DataBits writeBits = new DataBits(bits, 4096); + + for (i = 0; i < paletteIndex.length; ++i) { + writeBits.setBlock(i, paletteIndex[i]); + } + + to.putLongArray(blockStatesName, writeBits.getData()); + to.putString("DEBUG_PALETTE_MODE", currentPalette.getClass().getSimpleName()); + } + + public boolean contains(Predicate var0) { + return currentPalette.contains(var0); + } + + public void a(PaletteConsumer var0) { + Int2IntMap var1 = new Int2IntOpenHashMap(); + dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); + var1.int2IntEntrySet().forEach((var1x) -> var0.accept(currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue())); + } + + @FunctionalInterface + public interface PaletteConsumer { + void accept(T var1, int var2); + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/oldnbt/EndTag.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java similarity index 66% rename from src/main/java/com/volmit/iris/util/oldnbt/EndTag.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java index 4488e18ec..21281139f 100644 --- a/src/main/java/com/volmit/iris/util/oldnbt/EndTag.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java @@ -16,30 +16,10 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.oldnbt; +package com.volmit.iris.util.nbt.mca.palettes; -/** - * The TAG_End tag. - * - * @author Graham Edgecombe - */ -public final class EndTag extends Tag { - - /** - * Creates the tag. - */ - public EndTag() { - super(""); - } - - @Override - public Object getValue() { - return null; - } - - @Override - public String toString() { - return "TAG_End"; - } +import com.volmit.iris.util.nbt.tag.CompoundTag; +interface DataPaletteExpandable { + int onResize(int newBits, CompoundTag newData); } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteGlobal.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteGlobal.java new file mode 100644 index 000000000..f18e972fa --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteGlobal.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.nbt.mca.palettes; + +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.function.Predicate; + +@RequiredArgsConstructor +public class DataPaletteGlobal implements DataPalette { + @Getter + private final RegistryBlockID registry; + private final CompoundTag air; + + public int getIndex(CompoundTag block) { + int id = this.registry.getId(block); + return id == -1 ? 0 : id; + } + + public boolean contains(Predicate predicate) { + return true; + } + + public CompoundTag getByIndex(int index) { + CompoundTag block = registry.fromId(index); + return block == null ? air : block; + } + + public int size() { + return registry.size(); + } + + @Override + public void replace(ListTag palette) { + throw new UnsupportedOperationException("Cannot replace the global palette!"); + } +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java new file mode 100644 index 000000000..a2c66622e --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java @@ -0,0 +1,80 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.nbt.mca.palettes; + +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; + +import java.util.function.Predicate; + +public class DataPaletteHash implements DataPalette { + private final RegistryID registryId; + private final DataPaletteExpandable expander; + private final int bits; + + public DataPaletteHash(int bits, DataPaletteExpandable expander) { + this.bits = bits; + this.expander = expander; + this.registryId = new RegistryID(1 << bits); + } + + public int getIndex(CompoundTag block) { + int id = registryId.getId(block); + if (id == -1) { + id = registryId.c(block); + if (id >= 1 << bits) { + id = expander.onResize(bits + 1, block); + } + } + + return id; + } + + public boolean contains(Predicate predicate) { + for (int i = 0; i < size(); ++i) { + if (predicate.test(registryId.fromId(i))) { + return true; + } + } + + return false; + } + + public CompoundTag getByIndex(int index) { + return registryId.fromId(index); + } + + public int size() { + return registryId.size(); + } + + public void replace(ListTag palette) { + registryId.clear(); + + for (int i = 0; i < palette.size(); ++i) { + registryId.c(palette.get(i)); + } + } + + public void writePalette(ListTag list) { + for (int i = 0; i < size(); ++i) { + list.add(registryId.fromId(i)); + } + } +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java new file mode 100644 index 000000000..6a4900230 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java @@ -0,0 +1,82 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.nbt.mca.palettes; + +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; + +import java.util.function.Predicate; + +public class DataPaletteLinear implements DataPalette { + private final CompoundTag[] palette; + private final DataPaletteExpandable expander; + private final int e; + private int size; + + public DataPaletteLinear(int bits, DataPaletteExpandable expander) { + this.palette = new CompoundTag[1 << bits]; + this.e = bits; + this.expander = expander; + this.size = 0; + } + + public int getIndex(CompoundTag block) { + int i; + for (i = 0; i < size; ++i) { + if (palette[i].equals(block)) { + return i; + } + } + + i = size; + if (i < palette.length) { + palette[i] = block; + ++size; + return i; + } else { + return expander.onResize(e + 1, block); + } + } + + public boolean contains(Predicate predicate) { + for (int i = 0; i < this.size; ++i) { + if (predicate.test(palette[i])) { + return true; + } + } + + return false; + } + + public CompoundTag getByIndex(int index) { + return index >= 0 && index < size ? palette[index] : null; + } + + public int size() { + return size; + } + + public void replace(ListTag palette) { + for (int i = 0; i < palette.size(); ++i) { + this.palette[i] = palette.get(i); + } + + this.size = palette.size(); + } +} diff --git a/src/main/java/com/volmit/iris/util/hunk/io/BlockDataHunkIOAdapter.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java similarity index 57% rename from src/main/java/com/volmit/iris/util/hunk/io/BlockDataHunkIOAdapter.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java index 5c6f29339..db0c77550 100644 --- a/src/main/java/com/volmit/iris/util/hunk/io/BlockDataHunkIOAdapter.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java @@ -16,24 +16,12 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.hunk.io; +package com.volmit.iris.util.nbt.mca.palettes; -import com.volmit.iris.util.data.B; -import org.bukkit.block.data.BlockData; +import com.volmit.iris.util.nbt.tag.CompoundTag; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; +public interface Registry extends Iterable { + int getId(CompoundTag block); -public class BlockDataHunkIOAdapter extends PaletteHunkIOAdapter { - - @Override - public void write(BlockData blockData, DataOutputStream dos) throws IOException { - dos.writeUTF(blockData.getAsString(true)); - } - - @Override - public BlockData read(DataInputStream din) throws IOException { - return B.get(din.readUTF()); - } -} + CompoundTag fromId(int id); +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryBlockID.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryBlockID.java new file mode 100644 index 000000000..3b636d124 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryBlockID.java @@ -0,0 +1,65 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.nbt.mca.palettes; + +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; +import com.volmit.iris.util.nbt.tag.CompoundTag; + +import java.util.*; + +public class RegistryBlockID implements Registry { + private final Map indexMap; + private final List indexes; + + public RegistryBlockID(Map c, List d) { + this.indexMap = c; + this.indexes = d; + } + + public RegistryBlockID() { + this(512); + } + + public RegistryBlockID(int var0) { + this.indexes = Lists.newArrayListWithExpectedSize(var0); + this.indexMap = new HashMap<>(var0); + } + + public int getId(CompoundTag block) { + Integer var1 = this.indexMap.get(block); + return var1 == null ? -1 : var1; + } + + public final CompoundTag fromId(int id) { + return id >= 0 && id < this.indexes.size() ? this.indexes.get(id) : null; + } + + public Iterator iterator() { + return Iterators.filter(this.indexes.iterator(), Objects::nonNull); + } + + public boolean hasIndex(int var0) { + return this.fromId(var0) != null; + } + + public int size() { + return this.indexMap.size(); + } +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java new file mode 100644 index 000000000..416ccf252 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java @@ -0,0 +1,176 @@ +/* + * 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 . + */ + +package com.volmit.iris.util.nbt.mca.palettes; + +import com.google.common.collect.Iterators; +import com.volmit.iris.util.math.MathHelper; +import com.volmit.iris.util.nbt.tag.CompoundTag; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.Objects; + +public class RegistryID implements Registry { + public static final int a = -1; + private static final CompoundTag b = null; + private static final float c = 0.8F; + private CompoundTag[] d; + private int[] e; + private CompoundTag[] f; + private int g; + private int size; + + public RegistryID(int var0) { + var0 = (int) ((float) var0 / 0.8F); + this.d = new CompoundTag[var0]; + this.f = new CompoundTag[var0]; + this.e = new int[var0]; + } + + public int getId(CompoundTag block) { + return this.c(this.b(block, this.d(block))); + } + + public CompoundTag fromId(int id) { + return id >= 0 && id < this.f.length ? this.f[id] : null; + } + + private int c(int var0) { + return var0 == -1 ? -1 : this.e[var0]; + } + + public boolean b(CompoundTag var0) { + return this.getId(var0) != -1; + } + + public boolean b(int var0) { + return this.fromId(var0) != null; + } + + public int c(CompoundTag var0) { + int var1 = this.c(); + this.a(var0, var1); + return var1; + } + + private int c() { + while (this.g < this.f.length && this.f[this.g] != null) { + ++this.g; + } + + return this.g; + } + + private void d(int var0) { + CompoundTag[] var1 = this.d; + int[] var2 = this.e; + this.d = new CompoundTag[var0]; + this.e = new int[var0]; + this.f = new CompoundTag[var0]; + this.g = 0; + this.size = 0; + + for (int var3 = 0; var3 < var1.length; ++var3) { + if (var1[var3] != null) { + this.a(var1[var3], var2[var3]); + } + } + } + + public void a(CompoundTag var0, int var1) { + int var2 = Math.max(var1, this.size + 1); + int var3; + if ((float) var2 >= (float) this.d.length * 0.8F) { + for (var3 = this.d.length << 1; var3 < var1; var3 <<= 1) { + } + + this.d(var3); + } + + var3 = this.e(this.d(var0)); + this.d[var3] = var0; + this.e[var3] = var1; + this.f[var1] = var0; + ++this.size; + if (var1 == this.g) { + ++this.g; + } + } + + private int d(CompoundTag block) { + return (MathHelper.g(System.identityHashCode(block)) & 2147483647) % this.d.length; + } + + private int b(CompoundTag block, int var1) { + int var2; + for (var2 = var1; var2 < this.d.length; ++var2) { + if (this.d[var2] == null) { + return -1; + } + + if (this.d[var2].equals(block)) { + return var2; + } + } + + for (var2 = 0; var2 < var1; ++var2) { + if (this.d[var2] == null) { + return -1; + } + + if (this.d[var2].equals(block)) { + return var2; + } + } + + return -1; + } + + private int e(int var0) { + int var1; + for (var1 = var0; var1 < this.d.length; ++var1) { + if (this.d[var1] == null) { + return var1; + } + } + + for (var1 = 0; var1 < var0; ++var1) { + if (this.d[var1] == null) { + return var1; + } + } + + throw new RuntimeException("Overflowed :("); + } + + public Iterator iterator() { + return Iterators.filter(Iterators.forArray(this.f), Objects::nonNull); + } + + public void clear() { + Arrays.fill(this.d, null); + Arrays.fill(this.f, null); + this.g = 0; + this.size = 0; + } + + public int size() { + return this.size; + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java b/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java index de9193954..2bd18df08 100644 --- a/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java +++ b/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java @@ -22,6 +22,7 @@ import com.volmit.iris.engine.data.io.MaxDepthIO; import com.volmit.iris.util.collection.KList; import java.util.*; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Consumer; /** @@ -42,6 +43,11 @@ public class ListTag> extends Tag> implements Iterable< super(createEmptyValue(3)); } + public ListTag makeAtomic() { + setValue(new CopyOnWriteArrayList<>(getValue())); + return this; + } + @Override public byte getID() { return ID; @@ -302,7 +308,7 @@ public class ListTag> extends Tag> implements Iterable< @Override public int hashCode() { - return Objects.hash(getTypeClass().hashCode(), getValue().hashCode()); + return Objects.hash(getValue().hashCode()); } @Override diff --git a/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java b/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java index fedbe2586..f4faf2a9f 100644 --- a/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java +++ b/src/main/java/com/volmit/iris/util/nbt/tag/Tag.java @@ -94,7 +94,7 @@ public abstract class Tag implements Cloneable { /** * @return The value of this Tag. */ - protected T getValue() { + public T getValue() { return value; } diff --git a/src/main/java/com/volmit/iris/util/noise/Worm.java b/src/main/java/com/volmit/iris/util/noise/Worm.java index d21802e1d..02ef9449a 100644 --- a/src/main/java/com/volmit/iris/util/noise/Worm.java +++ b/src/main/java/com/volmit/iris/util/noise/Worm.java @@ -25,19 +25,16 @@ public class Worm { private double position; private double velocity; - public Worm(double startPosition, double startVelocity) - { + public Worm(double startPosition, double startVelocity) { this.position = startPosition; this.velocity = startVelocity; } - public void unstep() - { + public void unstep() { position -= velocity; } - public void step() - { + public void step() { position += velocity; } } diff --git a/src/main/java/com/volmit/iris/util/noise/Worm2.java b/src/main/java/com/volmit/iris/util/noise/Worm2.java index a062ea98b..7f72a9881 100644 --- a/src/main/java/com/volmit/iris/util/noise/Worm2.java +++ b/src/main/java/com/volmit/iris/util/noise/Worm2.java @@ -18,34 +18,28 @@ package com.volmit.iris.util.noise; -import com.volmit.iris.util.math.Position2; import lombok.Data; @Data -public class Worm2 -{ +public class Worm2 { private final Worm x; private final Worm z; - public Worm2(Worm x, Worm z) - { + public Worm2(Worm x, Worm z) { this.x = x; this.z = z; } - public Worm2(int x, int z, int vx, int vz) - { + public Worm2(int x, int z, int vx, int vz) { this(new Worm(x, vx), new Worm(z, vz)); } - public void step() - { + public void step() { x.step(); z.step(); } - public void unstep() - { + public void unstep() { x.unstep(); z.unstep(); } diff --git a/src/main/java/com/volmit/iris/util/noise/Worm3.java b/src/main/java/com/volmit/iris/util/noise/Worm3.java index 30c105ff4..e173af29f 100644 --- a/src/main/java/com/volmit/iris/util/noise/Worm3.java +++ b/src/main/java/com/volmit/iris/util/noise/Worm3.java @@ -21,33 +21,28 @@ package com.volmit.iris.util.noise; import lombok.Data; @Data -public class Worm3 -{ +public class Worm3 { private final Worm x; private final Worm y; private final Worm z; - public Worm3(Worm x,Worm y, Worm z) - { + public Worm3(Worm x, Worm y, Worm z) { this.x = x; this.y = y; this.z = z; } - public Worm3(int x, int y, int z, int vx, int vy, int vz) - { + public Worm3(int x, int y, int z, int vx, int vy, int vz) { this(new Worm(x, vx), new Worm(y, vy), new Worm(z, vz)); } - public void step() - { + public void step() { x.step(); y.step(); z.step(); } - public void unstep() - { + public void unstep() { x.unstep(); y.unstep(); z.unstep(); diff --git a/src/main/java/com/volmit/iris/util/noise/WormIterator2.java b/src/main/java/com/volmit/iris/util/noise/WormIterator2.java index 69655fde8..f3363e7e7 100644 --- a/src/main/java/com/volmit/iris/util/noise/WormIterator2.java +++ b/src/main/java/com/volmit/iris/util/noise/WormIterator2.java @@ -32,18 +32,15 @@ public class WormIterator2 { private int maxDistance; private int maxIterations; - public boolean hasNext() - { + public boolean hasNext() { double dist = maxDistance - (Math.max(Math.abs(worm.getX().getVelocity()), Math.abs(worm.getZ().getVelocity())) + 1); return maxIterations > 0 && ((x * x) - (worm.getX().getPosition() * worm.getX().getPosition())) - + ((z * z) - (worm.getZ().getPosition() * worm.getZ().getPosition())) < dist * dist; + + ((z * z) - (worm.getZ().getPosition() * worm.getZ().getPosition())) < dist * dist; } - public Worm2 next() - { - if(worm == null) - { + public Worm2 next() { + if (worm == null) { worm = new Worm2(x, z, 0, 0); return worm; } diff --git a/src/main/java/com/volmit/iris/util/noise/WormIterator3.java b/src/main/java/com/volmit/iris/util/noise/WormIterator3.java index dfe2b7e00..8b1083884 100644 --- a/src/main/java/com/volmit/iris/util/noise/WormIterator3.java +++ b/src/main/java/com/volmit/iris/util/noise/WormIterator3.java @@ -18,7 +18,6 @@ package com.volmit.iris.util.noise; -import com.volmit.iris.Iris; import com.volmit.iris.util.function.NoiseProvider; import lombok.Builder; import lombok.Data; @@ -34,28 +33,24 @@ public class WormIterator3 { private int maxDistance; private int maxIterations; - public boolean hasNext() - { - if(worm == null) - { + public boolean hasNext() { + if (worm == null) { return true; } double dist = maxDistance - (Math.max(Math.max(Math.abs(worm.getX().getVelocity()), - Math.abs(worm.getZ().getVelocity())), + Math.abs(worm.getZ().getVelocity())), Math.abs(worm.getY().getVelocity())) + 1); return maxIterations > 0 && ((x * x) - (worm.getX().getPosition() * worm.getX().getPosition())) - + ((y * y) - (worm.getY().getPosition() * worm.getY().getPosition())) - + ((z * z) - (worm.getZ().getPosition() * worm.getZ().getPosition())) < dist * dist; + + ((y * y) - (worm.getY().getPosition() * worm.getY().getPosition())) + + ((z * z) - (worm.getZ().getPosition() * worm.getZ().getPosition())) < dist * dist; } - public Worm3 next() - { + public Worm3 next() { maxIterations--; - if(worm == null) - { + if (worm == null) { worm = new Worm3(x, y, z, 0, 0, 0); return worm; } diff --git a/src/main/java/com/volmit/iris/util/oldnbt/ByteArrayTag.java b/src/main/java/com/volmit/iris/util/oldnbt/ByteArrayTag.java deleted file mode 100644 index 38ef3ff90..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/ByteArrayTag.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_Byte_Array tag. - * - * @author Graham Edgecombe - */ -public final class ByteArrayTag extends Tag { - - /** - * The value. - */ - private final byte[] value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public ByteArrayTag(String name, byte[] value) { - super(name); - this.value = value; - } - - @Override - public byte[] getValue() { - return value; - } - - @Override - public String toString() { - StringBuilder hex = new StringBuilder(); - for (byte b : value) { - String hexDigits = Integer.toHexString(b).toUpperCase(); - if (hexDigits.length() == 1) { - hex.append("0"); - } - hex.append(hexDigits).append(" "); - } - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Byte_Array" + append + ": " + hex; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/ByteTag.java b/src/main/java/com/volmit/iris/util/oldnbt/ByteTag.java deleted file mode 100644 index edb4bf2b6..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/ByteTag.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_Byte tag. - * - * @author Graham Edgecombe - */ -public final class ByteTag extends Tag { - - /** - * The value. - */ - private final byte value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public ByteTag(String name, byte value) { - super(name); - this.value = value; - } - - @Override - public Byte getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Byte" + append + ": " + value; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/CompoundTag.java b/src/main/java/com/volmit/iris/util/oldnbt/CompoundTag.java deleted file mode 100644 index 61d61d606..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/CompoundTag.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -import java.util.Map; - -/** - * The TAG_Compound tag. - * - * @author Graham Edgecombe - */ -public final class CompoundTag extends Tag { - - /** - * The value. - */ - private final Map value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public CompoundTag(String name, Map value) { - super(name); - this.value = value; - } - - @Override - public Map getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_Compound").append(append).append(": ").append(value.size()).append(" entries\r\n{\r\n"); - for (Map.Entry entry : value.entrySet()) { - bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); - } - bldr.append("}"); - return bldr.toString(); - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/DoubleTag.java b/src/main/java/com/volmit/iris/util/oldnbt/DoubleTag.java deleted file mode 100644 index c7d0eaa7b..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/DoubleTag.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_Double tag. - * - * @author Graham Edgecombe - */ -public final class DoubleTag extends Tag { - - /** - * The value. - */ - private final double value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public DoubleTag(String name, double value) { - super(name); - this.value = value; - } - - @Override - public Double getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Double" + append + ": " + value; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/FloatTag.java b/src/main/java/com/volmit/iris/util/oldnbt/FloatTag.java deleted file mode 100644 index 17833b557..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/FloatTag.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_Float tag. - * - * @author Graham Edgecombe - */ -public final class FloatTag extends Tag { - - /** - * The value. - */ - private final float value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public FloatTag(String name, float value) { - super(name); - this.value = value; - } - - @Override - public Float getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Float" + append + ": " + value; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/IntArrayTag.java b/src/main/java/com/volmit/iris/util/oldnbt/IntArrayTag.java deleted file mode 100644 index a2e9ebef4..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/IntArrayTag.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -import java.util.Arrays; - -/** - * The TAG_Int_Array tag. - * - * @author Neil Wightman - */ -public final class IntArrayTag extends Tag { - - /** - * The value. - */ - private final int[] value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public IntArrayTag(String name, int[] value) { - super(name); - this.value = value; - } - - @Override - public int[] getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Int_Array" + append + ": " + Arrays.toString(value); - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/IntTag.java b/src/main/java/com/volmit/iris/util/oldnbt/IntTag.java deleted file mode 100644 index 7f2537249..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/IntTag.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_Int tag. - * - * @author Graham Edgecombe - */ -public final class IntTag extends Tag { - - /** - * The value. - */ - private final int value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public IntTag(String name, int value) { - super(name); - this.value = value; - } - - @Override - public Integer getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Int" + append + ": " + value; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/ListTag.java b/src/main/java/com/volmit/iris/util/oldnbt/ListTag.java deleted file mode 100644 index 71d144d75..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/ListTag.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -import java.util.Collections; -import java.util.List; - -/** - * The TAG_List tag. - * - * @author Graham Edgecombe - */ -public final class ListTag extends Tag { - - /** - * The type. - */ - private final Class type; - - /** - * The value. - */ - private final List value; - - /** - * Creates the tag. - * - * @param name The name. - * @param type The type of item in the list. - * @param value The value. - */ - public ListTag(String name, Class type, List value) { - super(name); - this.type = type; - this.value = Collections.unmodifiableList(value); - } - - /** - * Gets the type of item in this list. - * - * @return The type of item in this list. - */ - public Class getType() { - return type; - } - - @Override - public List getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - StringBuilder bldr = new StringBuilder(); - bldr.append("TAG_List").append(append).append(": ").append(value.size()).append(" entries of type ").append(NBTUtils.getTypeName(type)).append("\r\n{\r\n"); - for (Tag t : value) { - bldr.append(" ").append(t.toString().replaceAll("\r\n", "\r\n ")).append("\r\n"); - } - bldr.append("}"); - return bldr.toString(); - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/LongTag.java b/src/main/java/com/volmit/iris/util/oldnbt/LongTag.java deleted file mode 100644 index 59671da6d..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/LongTag.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_Long tag. - * - * @author Graham Edgecombe - */ -public final class LongTag extends Tag { - - /** - * The value. - */ - private final long value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public LongTag(String name, long value) { - super(name); - this.value = value; - } - - @Override - public Long getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Long" + append + ": " + value; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/NBTConstants.java b/src/main/java/com/volmit/iris/util/oldnbt/NBTConstants.java deleted file mode 100644 index 690bf1514..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/NBTConstants.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -/* - Changes : Neil Wightman - Support 19133 Tag_Int_Array tag - */ - -/** - * A class which holds constant values. - * - * @author Graham Edgecombe - */ -public final class NBTConstants { - - /** - * The character set used by NBT (UTF-8). - */ - public static final Charset CHARSET = StandardCharsets.UTF_8; - - /** - * Tag type constants. - */ - public static final int TYPE_END = 0, - TYPE_BYTE = 1, - TYPE_SHORT = 2, - TYPE_INT = 3, - TYPE_LONG = 4, - TYPE_FLOAT = 5, - TYPE_DOUBLE = 6, - TYPE_BYTE_ARRAY = 7, - TYPE_STRING = 8, - TYPE_LIST = 9, - TYPE_COMPOUND = 10, - TYPE_INT_ARRAY = 11; - - /** - * Default private constructor. - */ - private NBTConstants() { - - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/NBTInputStream.java b/src/main/java/com/volmit/iris/util/oldnbt/NBTInputStream.java deleted file mode 100644 index 55d6b35f1..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/NBTInputStream.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -import java.io.Closeable; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.zip.GZIPInputStream; - -/* - Changes : - Neil Wightman - Support 19133 Tag_Int_Array tag - */ - -/** - *

- * This class reads NBT, or - * Named Binary Tag streams, and produces an object graph of subclasses of the Tag object.

- * - *

- * The NBT format was created by Markus Persson, and the specification may be found at - * http://www.minecraft.net/docs/NBT.txt.

- * - * @author Graham Edgecombe - */ -public final class NBTInputStream implements Closeable { - - /** - * The data input stream. - */ - private final DataInputStream is; - - /** - * Create a new NBTInputStream, which will source its data from the specified input stream. - * - * @param is The output stream - */ - public NBTInputStream(DataInputStream is) { - this.is = is; - } - - /** - * Creates a new NBTInputStream, which will source its data from the specified input stream. - * The stream will be decompressed using GZIP. - * - * @param is The input stream. - * @throws IOException if an I/O error occurs. - */ - public NBTInputStream(InputStream is) throws IOException { - this.is = new DataInputStream(new GZIPInputStream(is)); - } - - /** - * Reads an NBT tag from the stream. - * - * @return The tag that was read. - * @throws IOException if an I/O error occurs. - */ - public Tag readTag() throws IOException { - return readTag(0); - } - - /** - * Reads an NBT from the stream. - * - * @param depth The depth of this tag. - * @return The tag that was read. - * @throws IOException if an I/O error occurs. - */ - private Tag readTag(int depth) throws IOException { - int type = is.readByte() & 0xFF; - - String name; - if (type != NBTConstants.TYPE_END) { - int nameLength = is.readShort() & 0xFFFF; - byte[] nameBytes = new byte[nameLength]; - is.readFully(nameBytes); - name = new String(nameBytes, NBTConstants.CHARSET); - } else { - name = ""; - } - - return readTagPayload(type, name, depth); - } - - /** - * Reads the payload of a tag, given the name and type. - * - * @param type The type. - * @param name The name. - * @param depth The depth. - * @return The tag. - * @throws IOException if an I/O error occurs. - */ - private Tag readTagPayload(int type, String name, int depth) throws IOException { - switch (type) { - case NBTConstants.TYPE_END: - if (depth == 0) { - throw new IOException("TAG_End found without a TAG_Compound/TAG_List tag preceding it."); - } else { - return new EndTag(); - } - case NBTConstants.TYPE_BYTE: - return new ByteTag(name, is.readByte()); - case NBTConstants.TYPE_SHORT: - return new ShortTag(name, is.readShort()); - case NBTConstants.TYPE_INT: - return new IntTag(name, is.readInt()); - case NBTConstants.TYPE_LONG: - return new LongTag(name, is.readLong()); - case NBTConstants.TYPE_FLOAT: - return new FloatTag(name, is.readFloat()); - case NBTConstants.TYPE_DOUBLE: - return new DoubleTag(name, is.readDouble()); - case NBTConstants.TYPE_BYTE_ARRAY: - int length = is.readInt(); - byte[] bytes = new byte[length]; - is.readFully(bytes); - return new ByteArrayTag(name, bytes); - case NBTConstants.TYPE_STRING: - length = is.readShort(); - bytes = new byte[length]; - is.readFully(bytes); - return new StringTag(name, new String(bytes, NBTConstants.CHARSET)); - case NBTConstants.TYPE_LIST: - int childType = is.readByte(); - length = is.readInt(); - - List tagList = new ArrayList<>(); - for (int i = 0; i < length; i++) { - Tag tag = readTagPayload(childType, "", depth + 1); - if (tag instanceof EndTag) { - throw new IOException("TAG_End not permitted in a list."); - } - tagList.add(tag); - } - - return new ListTag(name, NBTUtils.getTypeClass(childType), tagList); - case NBTConstants.TYPE_COMPOUND: - Map tagMap = new HashMap<>(); - while (true) { - Tag tag = readTag(depth + 1); - if (tag instanceof EndTag) { - break; - } else { - tagMap.put(tag.getName(), tag); - } - } - - return new CompoundTag(name, tagMap); - case NBTConstants.TYPE_INT_ARRAY: - length = is.readInt(); - int[] value = new int[length]; - for (int i = 0; i < length; i++) { - value[i] = is.readInt(); - } - return new IntArrayTag(name, value); - default: - throw new IOException("Invalid tag type: " + type + "."); - } - } - - @Override - public void close() throws IOException { - is.close(); - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/NBTOutputStream.java b/src/main/java/com/volmit/iris/util/oldnbt/NBTOutputStream.java deleted file mode 100644 index d2f05da65..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/NBTOutputStream.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -import java.io.Closeable; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.List; -import java.util.zip.GZIPOutputStream; -/* - Changes : Neil Wightman - Support 19133 Tag_Int_Array tag - */ - -/** - *

- * This class writes NBT, or - * Named Binary Tag Tag objects to an underlying OutputStream.

- * - *

- * The NBT format was created by Markus Persson, and the specification may be found at - * http://www.minecraft.net/docs/NBT.txt.

- * - * @author Graham Edgecombe - */ -@SuppressWarnings({"EmptyMethod", "JavaDoc"}) -public final class NBTOutputStream implements Closeable { - - /** - * The output stream. - */ - private final DataOutputStream os; - - /** - * Create a new NBTOutputStream, which will write data to the specified underlying output stream. - * - * @param os The output stream - */ - public NBTOutputStream(DataOutputStream os) { - this.os = os; - } - - /** - * Creates a new NBTOutputStream, which will write data to the specified underlying output stream. - * the stream will be compressed using GZIP. - * - * @param os The output stream. - * @throws IOException if an I/O error occurs. - */ - public NBTOutputStream(OutputStream os) throws IOException { - this.os = new DataOutputStream(new GZIPOutputStream(os)); - } - - /** - * Writes a tag. - * - * @param tag The tag to write. - * @throws IOException if an I/O error occurs. - */ - public void writeTag(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); - String name = tag.getName(); - byte[] nameBytes = name.getBytes(NBTConstants.CHARSET); - - os.writeByte(type); - os.writeShort(nameBytes.length); - os.write(nameBytes); - - if (type == NBTConstants.TYPE_END) { - throw new IOException("Named TAG_End not permitted."); - } - - writeTagPayload(tag); - } - - /** - * Writes tag payload. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeTagPayload(Tag tag) throws IOException { - int type = NBTUtils.getTypeCode(tag.getClass()); - switch (type) { - case NBTConstants.TYPE_END -> writeEndTagPayload((EndTag) tag); - case NBTConstants.TYPE_BYTE -> writeByteTagPayload((ByteTag) tag); - case NBTConstants.TYPE_SHORT -> writeShortTagPayload((ShortTag) tag); - case NBTConstants.TYPE_INT -> writeIntTagPayload((IntTag) tag); - case NBTConstants.TYPE_LONG -> writeLongTagPayload((LongTag) tag); - case NBTConstants.TYPE_FLOAT -> writeFloatTagPayload((FloatTag) tag); - case NBTConstants.TYPE_DOUBLE -> writeDoubleTagPayload((DoubleTag) tag); - case NBTConstants.TYPE_BYTE_ARRAY -> writeByteArrayTagPayload((ByteArrayTag) tag); - case NBTConstants.TYPE_STRING -> writeStringTagPayload((StringTag) tag); - case NBTConstants.TYPE_LIST -> writeListTagPayload((ListTag) tag); - case NBTConstants.TYPE_COMPOUND -> writeCompoundTagPayload((CompoundTag) tag); - case NBTConstants.TYPE_INT_ARRAY -> writeIntArrayTagPayload((IntArrayTag) tag); - default -> throw new IOException("Invalid tag type: " + type + "."); - } - } - - /** - * Writes a TAG_Byte tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeByteTagPayload(ByteTag tag) throws IOException { - os.writeByte(tag.getValue()); - } - - /** - * Writes a TAG_Byte_Array tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeByteArrayTagPayload(ByteArrayTag tag) throws IOException { - byte[] bytes = tag.getValue(); - os.writeInt(bytes.length); - os.write(bytes); - } - - - /** - * Writes a TAG_Compound tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeCompoundTagPayload(CompoundTag tag) throws IOException { - for (Tag childTag : tag.getValue().values()) { - writeTag(childTag); - } - os.writeByte((byte) 0); // end tag - better way? - } - - /** - * Writes a TAG_List tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeListTagPayload(ListTag tag) throws IOException { - Class clazz = tag.getType(); - List tags = tag.getValue(); - int size = tags.size(); - - os.writeByte(NBTUtils.getTypeCode(clazz)); - os.writeInt(size); - for (Tag value : tags) { - writeTagPayload(value); - } - } - - /** - * Writes a TAG_String tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeStringTagPayload(StringTag tag) throws IOException { - byte[] bytes = tag.getValue().getBytes(NBTConstants.CHARSET); - os.writeShort(bytes.length); - os.write(bytes); - } - - /** - * Writes a TAG_Double tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeDoubleTagPayload(DoubleTag tag) throws IOException { - os.writeDouble(tag.getValue()); - } - - /** - * Writes a TAG_Float tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeFloatTagPayload(FloatTag tag) throws IOException { - os.writeFloat(tag.getValue()); - } - - /** - * Writes a TAG_Long tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeLongTagPayload(LongTag tag) throws IOException { - os.writeLong(tag.getValue()); - } - - /** - * Writes a TAG_Int tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeIntTagPayload(IntTag tag) throws IOException { - os.writeInt(tag.getValue()); - } - - /** - * Writes a TAG_Short tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeShortTagPayload(ShortTag tag) throws IOException { - os.writeShort(tag.getValue()); - } - - /** - * Writes a TAG_Empty tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeEndTagPayload(EndTag tag) { - /* empty */ - } - - /** - * Writes a TAG_Int_Array tag. - * - * @param tag The tag. - * @throws IOException if an I/O error occurs. - */ - private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException { - final int[] values = tag.getValue(); - os.writeInt(values.length); - for (final int value : values) { - os.writeInt(value); - } - } - - @Override - public void close() throws IOException { - os.close(); - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/NBTUtils.java b/src/main/java/com/volmit/iris/util/oldnbt/NBTUtils.java deleted file mode 100644 index 3062584a7..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/NBTUtils.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/* - Changes : Neil Wightman - Support 19133 Tag_Int_Array tag - */ - -/** - * A class which contains NBT-related utility methods. This currently supports reading 19133 but only writing 19132. - * - * @author Graham Edgecombe - */ -public final class NBTUtils { - - /** - * Gets the type name of a tag. - * - * @param clazz The tag class. - * @return The type name. - */ - public static String getTypeName(Class clazz) { - if (clazz.equals(ByteArrayTag.class)) { - return "TAG_Byte_Array"; - } else if (clazz.equals(ByteTag.class)) { - return "TAG_Byte"; - } else if (clazz.equals(CompoundTag.class)) { - return "TAG_Compound"; - } else if (clazz.equals(DoubleTag.class)) { - return "TAG_Double"; - } else if (clazz.equals(EndTag.class)) { - return "TAG_End"; - } else if (clazz.equals(FloatTag.class)) { - return "TAG_Float"; - } else if (clazz.equals(IntTag.class)) { - return "TAG_Int"; - } else if (clazz.equals(ListTag.class)) { - return "TAG_List"; - } else if (clazz.equals(LongTag.class)) { - return "TAG_Long"; - } else if (clazz.equals(ShortTag.class)) { - return "TAG_Short"; - } else if (clazz.equals(StringTag.class)) { - return "TAG_String"; - } else if (clazz.equals(IntArrayTag.class)) { - return "TAG_Int_Array"; - } else { - throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ")."); - } - } - - /** - * Gets the type code of a tag class. - * - * @param clazz The tag class. - * @return The type code. - * @throws IllegalArgumentException if the tag class is invalid. - */ - public static int getTypeCode(Class clazz) { - if (clazz.equals(ByteArrayTag.class)) { - return NBTConstants.TYPE_BYTE_ARRAY; - } else if (clazz.equals(ByteTag.class)) { - return NBTConstants.TYPE_BYTE; - } else if (clazz.equals(CompoundTag.class)) { - return NBTConstants.TYPE_COMPOUND; - } else if (clazz.equals(DoubleTag.class)) { - return NBTConstants.TYPE_DOUBLE; - } else if (clazz.equals(EndTag.class)) { - return NBTConstants.TYPE_END; - } else if (clazz.equals(FloatTag.class)) { - return NBTConstants.TYPE_FLOAT; - } else if (clazz.equals(IntTag.class)) { - return NBTConstants.TYPE_INT; - } else if (clazz.equals(ListTag.class)) { - return NBTConstants.TYPE_LIST; - } else if (clazz.equals(LongTag.class)) { - return NBTConstants.TYPE_LONG; - } else if (clazz.equals(ShortTag.class)) { - return NBTConstants.TYPE_SHORT; - } else if (clazz.equals(StringTag.class)) { - return NBTConstants.TYPE_STRING; - } else if (clazz.equals(IntArrayTag.class)) { - return NBTConstants.TYPE_INT_ARRAY; - } else { - throw new IllegalArgumentException("Invalid tag classs (" + clazz.getName() + ")."); - } - } - - /** - * Gets the class of a type of tag. - * - * @param type The type. - * @return The class. - * @throws IllegalArgumentException if the tag type is invalid. - */ - public static Class getTypeClass(int type) { - return switch (type) { - case NBTConstants.TYPE_END -> EndTag.class; - case NBTConstants.TYPE_BYTE -> ByteTag.class; - case NBTConstants.TYPE_SHORT -> ShortTag.class; - case NBTConstants.TYPE_INT -> IntTag.class; - case NBTConstants.TYPE_LONG -> LongTag.class; - case NBTConstants.TYPE_FLOAT -> FloatTag.class; - case NBTConstants.TYPE_DOUBLE -> DoubleTag.class; - case NBTConstants.TYPE_BYTE_ARRAY -> ByteArrayTag.class; - case NBTConstants.TYPE_STRING -> StringTag.class; - case NBTConstants.TYPE_LIST -> ListTag.class; - case NBTConstants.TYPE_COMPOUND -> CompoundTag.class; - case NBTConstants.TYPE_INT_ARRAY -> IntArrayTag.class; - default -> throw new IllegalArgumentException("Invalid tag type : " + type + "."); - }; - } - - /** - * Default private constructor. - */ - private NBTUtils() { - - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/ShortTag.java b/src/main/java/com/volmit/iris/util/oldnbt/ShortTag.java deleted file mode 100644 index e1239e016..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/ShortTag.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_Short tag. - * - * @author Graham Edgecombe - */ -public final class ShortTag extends Tag { - - /** - * The value. - */ - private final short value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public ShortTag(String name, short value) { - super(name); - this.value = value; - } - - @Override - public Short getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_Short" + append + ": " + value; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/StringTag.java b/src/main/java/com/volmit/iris/util/oldnbt/StringTag.java deleted file mode 100644 index 54ddce7da..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/StringTag.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * The TAG_String tag. - * - * @author Graham Edgecombe - */ -public final class StringTag extends Tag { - - /** - * The value. - */ - private final String value; - - /** - * Creates the tag. - * - * @param name The name. - * @param value The value. - */ - public StringTag(String name, String value) { - super(name); - this.value = value; - } - - @Override - public String getValue() { - return value; - } - - @Override - public String toString() { - String name = getName(); - String append = ""; - if (name != null && !name.equals("")) { - append = "(\"" + this.getName() + "\")"; - } - return "TAG_String" + append + ": " + value; - } - -} diff --git a/src/main/java/com/volmit/iris/util/oldnbt/Tag.java b/src/main/java/com/volmit/iris/util/oldnbt/Tag.java deleted file mode 100644 index d5fdac4ab..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/Tag.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 . - */ - -package com.volmit.iris.util.oldnbt; - -/** - * Represents a single NBT tag. - * - * @author Graham Edgecombe - */ -public abstract class Tag { - - /** - * The name of this tag. - */ - private final String name; - - /** - * Creates the tag with the specified name. - * - * @param name The name. - */ - public Tag(String name) { - this.name = name; - } - - /** - * Gets the name of this tag. - * - * @return The name of this tag. - */ - public final String getName() { - return name; - } - - /** - * Gets the value of this tag. - * - * @return The value of this tag. - */ - public abstract Object getValue(); - -} diff --git a/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java b/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java index c81e47f77..83aa394c4 100644 --- a/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java +++ b/src/main/java/com/volmit/iris/util/parallel/BurstExecutor.java @@ -23,7 +23,9 @@ import com.volmit.iris.util.collection.KList; import lombok.Setter; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; @SuppressWarnings("ALL") public class BurstExecutor { @@ -48,10 +50,8 @@ public class BurstExecutor { } public BurstExecutor queue(List r) { - if(!multicore) - { - for(Runnable i : new KList<>(r)) - { + if (!multicore) { + for (Runnable i : new KList<>(r)) { i.run(); } @@ -68,10 +68,8 @@ public class BurstExecutor { } public BurstExecutor queue(Runnable[] r) { - if(!multicore) - { - for(Runnable i : new KList<>(r)) - { + if (!multicore) { + for (Runnable i : new KList<>(r)) { i.run(); } @@ -88,8 +86,7 @@ public class BurstExecutor { } public void complete() { - if(!multicore) - { + if (!multicore) { return; } @@ -99,8 +96,7 @@ public class BurstExecutor { } try { - for(Future i : futures) - { + for (Future i : futures) { i.get(); } diff --git a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java index ce21c64f7..7eb1de959 100644 --- a/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java +++ b/src/main/java/com/volmit/iris/util/parallel/MultiBurst.java @@ -23,12 +23,10 @@ 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 org.jetbrains.annotations.NotNull; import java.util.List; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicLong; -import java.util.function.Supplier; public class MultiBurst { public static final MultiBurst burst = new MultiBurst(); @@ -74,13 +72,9 @@ public class MultiBurst { } public void burst(boolean multicore, Runnable... r) { - if(multicore) - { + if (multicore) { burst(r); - } - - else - { + } else { sync(r); } } @@ -90,19 +84,15 @@ public class MultiBurst { } public void burst(boolean multicore, List r) { - if(multicore) - { + if (multicore) { burst(r); - } - - else { + } else { sync(r); } } private void sync(List r) { - for(Runnable i : new KList<>(r)) - { + for (Runnable i : new KList<>(r)) { i.run(); } } diff --git a/src/main/java/com/volmit/iris/util/plugin/IrisService.java b/src/main/java/com/volmit/iris/util/plugin/IrisService.java index b9068f79e..e93e11326 100644 --- a/src/main/java/com/volmit/iris/util/plugin/IrisService.java +++ b/src/main/java/com/volmit/iris/util/plugin/IrisService.java @@ -26,8 +26,7 @@ public interface IrisService extends Listener { void onDisable(); - default void postShutdown(Runnable r) - { + default void postShutdown(Runnable r) { Iris.instance.postShutdown(r); } } diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 9b71d0aad..844f48430 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -426,7 +426,7 @@ public class VolmitSender implements CommandSender { } } - public void sendDecreeHelpNode(VirtualDecreeCommand i){ + public void sendDecreeHelpNode(VirtualDecreeCommand i) { if (isPlayer()) { String newline = "\n"; diff --git a/src/main/java/com/volmit/iris/util/scheduling/J.java b/src/main/java/com/volmit/iris/util/scheduling/J.java index b5a38442e..c64f30096 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/J.java +++ b/src/main/java/com/volmit/iris/util/scheduling/J.java @@ -23,6 +23,7 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.function.NastyFunction; import com.volmit.iris.util.function.NastyFuture; import com.volmit.iris.util.function.NastyRunnable; +import com.volmit.iris.util.function.NastySupplier; import com.volmit.iris.util.math.FinalInteger; import com.volmit.iris.util.parallel.MultiBurst; import org.bukkit.Bukkit; @@ -125,6 +126,18 @@ public class J { return attemptCatch(r) == null; } + public static T attemptResult(NastySupplier r) { + try + { + return r.get(); + } + + catch(Throwable e) + { + return null; + } + } + public static Throwable attemptCatch(NastyRunnable r) { try { r.run(); diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/ParallelQueueJob.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/ParallelQueueJob.java index 579b5303d..e136f56d0 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/ParallelQueueJob.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/ParallelQueueJob.java @@ -29,8 +29,7 @@ public abstract class ParallelQueueJob extends QueueJob { BurstExecutor b = MultiBurst.burst.burst(queue.size()); KList q = queue.copy(); queue.clear(); - for(T i : q) - { + for (T i : q) { b.queue(() -> { execute(i); completeWork(); diff --git a/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java b/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java index 6d0338b7e..0664f351d 100644 --- a/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java +++ b/src/main/java/com/volmit/iris/util/scheduling/jobs/QueueJob.java @@ -18,7 +18,6 @@ package com.volmit.iris.util.scheduling.jobs; -import com.sun.jna.platform.unix.X11; import com.volmit.iris.util.collection.KList; import java.util.concurrent.atomic.AtomicInteger; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 6163d903d..14d43c307 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -8,6 +8,7 @@ description: More than a Dimension! libraries: - com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2 - com.github.ben-manes.caffeine:caffeine:3.0.3 + - org.apache.commons:commons-lang3:3.12.0 - io.timeandspace:smoothie-map:2.0.2 - com.google.guava:guava:30.1.1-jre - com.google.code.gson:gson:2.8.7