From 6dc3e74607b8bca7000d99b71d263f497b6c5475 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 04:09:26 -0400 Subject: [PATCH 01/29] Atomic NBT List --- src/main/java/com/volmit/iris/util/nbt/mca/Section.java | 7 ++++--- src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) 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..9123f999f 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 @@ -58,6 +58,7 @@ public class Section { putValueIndexedPalette(data, i); } + palette.makeAtomic(); ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight"); @@ -171,9 +172,9 @@ public class 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(); + public void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) { int paletteIndex = addToPalette(state); + int paletteSizeBefore = palette.size(); //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 @@ -377,7 +378,7 @@ public class Section { * @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) { + public 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) { 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..e3929e467 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,12 @@ 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; From 7b6405fba796b0c8c4647d9848f586d2533059ee Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 08:24:36 -0400 Subject: [PATCH 02/29] Prepatch --- build.gradle | 2 + .../volmit/iris/core/tools/IrisToolbelt.java | 3 +- .../com/volmit/iris/engine/IrisEngine.java | 49 ++++--- .../iris/engine/data/cache/AtomicCache.java | 125 +++++++----------- .../iris/engine/object/biome/IrisBiome.java | 4 +- .../engine/object/common/HeadlessWorld.java | 22 ++- .../iris/engine/object/common/IrisWorld.java | 19 +++ .../engine/platform/BukkitChunkGenerator.java | 2 + .../engine/platform/HeadlessGenerator.java | 15 ++- .../volmit/iris/util/nbt/mca/NBTWorld.java | 73 +++++----- .../com/volmit/iris/util/nbt/mca/Section.java | 14 +- 11 files changed, 189 insertions(+), 139 deletions(-) diff --git a/build.gradle b/build.gradle index 9560a1d0c..3397282db 100644 --- a/build.gradle +++ b/build.gradle @@ -167,6 +167,7 @@ shadowJar include(dependency('io.papermc:paperlib')) include(dependency('com.dfsek:Paralithic')) include(dependency('net.kyori:')) + include(dependency('com.github.Querz:NBT')) } } @@ -185,6 +186,7 @@ dependencies { implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT" implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" implementation 'net.kyori:adventure-api:4.8.1' + implementation 'com.github.Querz:NBT:6.1' // Dynamically Loaded implementation 'io.timeandspace:smoothie-map:2.0.2' 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/IrisEngine.java b/src/main/java/com/volmit/iris/engine/IrisEngine.java index 3e6e735f6..5460564f6 100644 --- a/src/main/java/com/volmit/iris/engine/IrisEngine.java +++ b/src/main/java/com/volmit/iris/engine/IrisEngine.java @@ -54,7 +54,10 @@ import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.scheduling.PrecisionStopwatch; import lombok.Data; import lombok.EqualsAndHashCode; +import net.minecraft.world.level.block.state.IBlockData; +import org.bukkit.Bukkit; import org.bukkit.Chunk; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -405,26 +408,42 @@ public class IrisEngine implements Engine { 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); + + 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) + ); + } - 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) - ); getMetrics().getTotal().put(p.getMilliseconds()); generated.incrementAndGet(); 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..dc9981faf 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,82 @@ 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(); } - if (this.t != null && validations > 1000) { - return this.t; + else if(nullSupport && set.get()) + { + return null; } - if (this.t != null && M.ms() - a > 1000) { - if (this.t != null) { - //noinspection NonAtomicOperationOnVolatileField - validations++; + lock.lock(); + + if(this.t.get() != null) + { + lock.unlock(); + return this.t.get(); + } + + else if(nullSupport && set.get()) + { + lock.unlock(); + return null; + } + + try + { + this.t.set(t.get()); + + if(nullSupport) + { + set.set(true); } - - return this.t; } - check.lock(); - - if (this.t == null) { - write.lock(); - this.t = t.get(); - - time.lock(); - - if (a == -1) { - a = M.ms(); - } - - time.unlock(); - write.unlock(); + catch(Throwable e) + { + Iris.error("Atomic cache failure!"); + e.printStackTrace(); } - check.unlock(); - return this.t; - } + lock.unlock(); - 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 t.get(); } } 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..c54c01a09 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 @@ -198,8 +198,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/common/HeadlessWorld.java b/src/main/java/com/volmit/iris/engine/object/common/HeadlessWorld.java index d5629b3c0..913c3689d 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,24 @@ 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 +98,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..7ba56f9c6 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,24 @@ 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/platform/BukkitChunkGenerator.java b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java index 36421379e..00de5822d 100644 --- a/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/BukkitChunkGenerator.java @@ -176,6 +176,8 @@ 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()) { 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..239e96d05 100644 --- a/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java +++ b/src/main/java/com/volmit/iris/engine/platform/HeadlessGenerator.java @@ -24,16 +24,20 @@ import com.volmit.iris.core.nms.INMS; import com.volmit.iris.core.pregenerator.PregenListener; import com.volmit.iris.core.pregenerator.PregenTask; import com.volmit.iris.engine.IrisEngine; +import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.data.chunk.MCATerrainChunk; import com.volmit.iris.engine.data.chunk.TerrainChunk; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineTarget; +import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.object.common.HeadlessWorld; import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.documentation.RegionCoordinates; import com.volmit.iris.util.hunk.Hunk; 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 +60,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 +88,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 +112,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 +142,6 @@ public class HeadlessGenerator implements PlatformChunkGenerator { } public void close() { - getEngine().close(); writer.close(); } 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..cc76ab1e2 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,21 +28,49 @@ 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; +import javax.management.RuntimeErrorException; import java.io.File; import java.io.IOException; 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 +212,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) { @@ -275,6 +273,13 @@ 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)); 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 9123f999f..ec6df11f1 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 @@ -25,6 +25,7 @@ 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 net.minecraft.world.level.chunk.DataPaletteGlobal; import java.util.ArrayList; import java.util.HashMap; @@ -148,7 +149,7 @@ 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) { + public synchronized CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) { try { int index = getBlockIndex(blockX, blockY, blockZ); int paletteIndex = getPaletteIndex(index); @@ -172,7 +173,7 @@ public class 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 void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) { + public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) { int paletteIndex = addToPalette(state); int paletteSizeBefore = palette.size(); //power of 2 --> bits must increase, but only if the palette size changed @@ -184,7 +185,6 @@ public class Section { } setPaletteIndex(getBlockIndex(blockX, blockY, blockZ), paletteIndex, blockStates); - if (cleanup) { cleanupPaletteAndBlockStates(); } @@ -196,7 +196,7 @@ public class Section { * @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) { + public synchronized int getPaletteIndex(int blockStateIndex) { int bits = blockStates.length() >> 6; if (dataVersion < 2527) { @@ -251,7 +251,7 @@ public class Section { * * @return The palette of this Section. */ - public ListTag getPalette() { + public synchronized ListTag getPalette() { return palette; } @@ -367,7 +367,7 @@ public class Section { /** * @return The indices of the block states of this Section. */ - public AtomicLongArray getBlockStates() { + public synchronized AtomicLongArray getBlockStates() { return blockStates; } @@ -431,7 +431,7 @@ 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); From 401ed0a7a5061e7d3a9e53f69ee51c4caab386d2 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 22:26:22 -0400 Subject: [PATCH 03/29] Remove hunk writers & old nbt --- .../java/com/volmit/iris/util/hunk/Hunk.java | 15 +- .../iris/util/hunk/io/BasicHunkIOAdapter.java | 81 ------ .../iris/util/hunk/io/HunkIOAdapter.java | 56 ---- .../volmit/iris/util/hunk/io/HunkRegion.java | 101 ------- .../iris/util/hunk/io/HunkRegionSlice.java | 262 ------------------ .../util/hunk/io/PaletteHunkIOAdapter.java | 97 ------- .../util/hunk/io/TileDataHunkIOAdapter.java | 45 --- .../volmit/iris/util/oldnbt/ByteArrayTag.java | 67 ----- .../com/volmit/iris/util/oldnbt/ByteTag.java | 59 ---- .../volmit/iris/util/oldnbt/CompoundTag.java | 67 ----- .../volmit/iris/util/oldnbt/DoubleTag.java | 59 ---- .../com/volmit/iris/util/oldnbt/EndTag.java | 45 --- .../com/volmit/iris/util/oldnbt/FloatTag.java | 59 ---- .../volmit/iris/util/oldnbt/IntArrayTag.java | 61 ---- .../com/volmit/iris/util/oldnbt/IntTag.java | 59 ---- .../com/volmit/iris/util/oldnbt/ListTag.java | 84 ------ .../com/volmit/iris/util/oldnbt/LongTag.java | 59 ---- .../volmit/iris/util/oldnbt/NBTConstants.java | 63 ----- .../iris/util/oldnbt/NBTInputStream.java | 189 ------------- .../iris/util/oldnbt/NBTOutputStream.java | 262 ------------------ .../com/volmit/iris/util/oldnbt/NBTUtils.java | 137 --------- .../com/volmit/iris/util/oldnbt/ShortTag.java | 59 ---- .../volmit/iris/util/oldnbt/StringTag.java | 59 ---- .../java/com/volmit/iris/util/oldnbt/Tag.java | 58 ---- 24 files changed, 1 insertion(+), 2102 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/util/hunk/io/BasicHunkIOAdapter.java delete mode 100644 src/main/java/com/volmit/iris/util/hunk/io/HunkIOAdapter.java delete mode 100644 src/main/java/com/volmit/iris/util/hunk/io/HunkRegion.java delete mode 100644 src/main/java/com/volmit/iris/util/hunk/io/HunkRegionSlice.java delete mode 100644 src/main/java/com/volmit/iris/util/hunk/io/PaletteHunkIOAdapter.java delete mode 100644 src/main/java/com/volmit/iris/util/hunk/io/TileDataHunkIOAdapter.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/ByteArrayTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/ByteTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/CompoundTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/DoubleTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/EndTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/FloatTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/IntArrayTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/IntTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/ListTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/LongTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/NBTConstants.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/NBTInputStream.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/NBTOutputStream.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/NBTUtils.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/ShortTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/StringTag.java delete mode 100644 src/main/java/com/volmit/iris/util/oldnbt/Tag.java 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..6d92d609c 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,13 @@ 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.nbt.tag.ByteArrayTag; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.stream.interpolation.Interpolated; @@ -229,18 +228,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; } 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/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/EndTag.java b/src/main/java/com/volmit/iris/util/oldnbt/EndTag.java deleted file mode 100644 index 4488e18ec..000000000 --- a/src/main/java/com/volmit/iris/util/oldnbt/EndTag.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.oldnbt; - -/** - * 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"; - } - -} 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(); - -} From 432e95e4ecd41831e5663421b5b0611dbaa8b5bb Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 22:26:29 -0400 Subject: [PATCH 04/29] Commons lang3 --- build.gradle | 3 +-- src/main/resources/plugin.yml | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 3397282db..1a8b92f54 100644 --- a/build.gradle +++ b/build.gradle @@ -167,7 +167,6 @@ shadowJar include(dependency('io.papermc:paperlib')) include(dependency('com.dfsek:Paralithic')) include(dependency('net.kyori:')) - include(dependency('com.github.Querz:NBT')) } } @@ -186,7 +185,6 @@ dependencies { implementation "net.kyori:adventure-text-minimessage:4.1.0-SNAPSHOT" implementation "net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT" implementation 'net.kyori:adventure-api:4.8.1' - implementation 'com.github.Querz:NBT:6.1' // Dynamically Loaded implementation 'io.timeandspace:smoothie-map:2.0.2' @@ -199,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/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 From 8df789ae34943a80b9d5c134e63208f58c48a80d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 22:28:33 -0400 Subject: [PATCH 05/29] Cleanup --- build.gradle | 30 +- src/main/java/com/volmit/iris/Iris.java | 45 +-- .../com/volmit/iris/core/IrisSettings.java | 6 +- .../object/CommandIrisObjectAnalyze.java | 10 - .../studio/CommandIrisStudioCompile.java | 6 +- .../com/volmit/iris/core/decrees/DecIris.java | 8 +- .../volmit/iris/core/decrees/DecObject.java | 29 +- .../volmit/iris/core/decrees/DecStudio.java | 1 - .../methods/AsyncPregenMethod.java | 1 - .../volmit/iris/core/project/IrisPack.java | 6 +- .../volmit/iris/core/project/IrisProject.java | 27 +- .../iris/core/project/SchemaBuilder.java | 1 - .../iris/core/project/loader/IrisData.java | 54 ++-- .../volmit/iris/core/service/CommandSVC.java | 1 - .../iris/core/service/PreservationSVC.java | 40 +-- .../volmit/iris/core/service/StudioSVC.java | 7 +- .../com/volmit/iris/engine/IrisComplex.java | 5 - .../com/volmit/iris/engine/IrisEngine.java | 40 +-- .../volmit/iris/engine/IrisEngineMantle.java | 9 - .../volmit/iris/engine/IrisWorldManager.java | 10 +- .../engine/actuator/IrisBiomeActuator.java | 2 - .../engine/actuator/IrisDecorantActuator.java | 8 +- .../actuator/IrisTerrainNormalActuator.java | 7 +- .../iris/engine/data/cache/AtomicCache.java | 30 +- .../engine/data/chunk/MCATerrainChunk.java | 3 +- .../decorator/IrisSeaSurfaceDecorator.java | 1 - .../iris/engine/framework/BlockUpdater.java | 2 - .../volmit/iris/engine/framework/Engine.java | 24 +- .../framework/EngineAssignedActuator.java | 1 - .../framework/EngineAssignedModifier.java | 1 - .../framework/EngineAssignedWorldManager.java | 3 +- .../engine/framework/EngineComponent.java | 3 +- .../iris/engine/framework/EngineTarget.java | 1 - .../iris/engine/jigsaw/PlannedStructure.java | 25 +- .../iris/engine/mantle/EngineMantle.java | 10 +- .../iris/engine/mantle/MantleWriter.java | 33 +- .../engine/modifier/IrisDepositModifier.java | 3 - .../engine/modifier/IrisPostModifier.java | 14 - .../engine/object/basic/IrisPosition.java | 3 +- .../iris/engine/object/biome/IrisBiome.java | 1 - .../iris/engine/object/cave/IrisCave.java | 10 - .../engine/object/cave/IrisCavePlacer.java | 17 +- .../engine/object/common/HeadlessWorld.java | 9 +- .../iris/engine/object/common/IrisWorld.java | 9 +- .../object/deposits/IrisDepositGenerator.java | 1 - .../object/dimensional/IrisDimension.java | 1 - .../engine/object/entity/IrisEntitySpawn.java | 17 +- .../object/feature/IrisFeaturePositional.java | 8 +- .../engine/object/noise/IrisGenerator.java | 1 - .../object/noise/IrisGeneratorStyle.java | 1 - .../iris/engine/object/noise/IrisWorm.java | 18 +- .../engine/object/regional/IrisRegion.java | 1 - .../engine/object/spawners/IrisSpawner.java | 1 - .../engine/platform/BukkitChunkGenerator.java | 46 +-- .../engine/platform/HeadlessGenerator.java | 4 - .../volmit/iris/util/context/IrisContext.java | 6 +- .../java/com/volmit/iris/util/data/B.java | 16 +- .../iris/util/data/IrisPackRepository.java | 5 +- .../iris/util/decree/DecreeParameter.java | 11 +- .../util/decree/DecreeParameterHandler.java | 3 +- .../util/decree/handlers/VectorHandler.java | 1 - .../decree/specialhandlers/DummyHandler.java | 3 +- .../java/com/volmit/iris/util/hunk/Hunk.java | 6 +- .../util/hunk/storage/MappedSyncHunk.java | 18 +- .../com/volmit/iris/util/mantle/Mantle.java | 283 +++++++++--------- .../volmit/iris/util/mantle/MantleChunk.java | 9 +- .../iris/util/mantle/TectonicPlate.java | 1 - .../java/com/volmit/iris/util/math/INode.java | 2 +- .../math/KochanekBartelsInterpolation.java | 16 +- .../com/volmit/iris/util/matter/Matter.java | 11 +- .../iris/util/matter/slices/ZoneMatter.java | 1 - .../volmit/iris/util/nbt/mca/NBTWorld.java | 15 +- .../com/volmit/iris/util/nbt/tag/ListTag.java | 3 +- .../java/com/volmit/iris/util/noise/Worm.java | 9 +- .../com/volmit/iris/util/noise/Worm2.java | 16 +- .../com/volmit/iris/util/noise/Worm3.java | 15 +- .../volmit/iris/util/noise/WormIterator2.java | 11 +- .../volmit/iris/util/noise/WormIterator3.java | 19 +- .../iris/util/parallel/BurstExecutor.java | 22 +- .../volmit/iris/util/parallel/MultiBurst.java | 20 +- .../volmit/iris/util/plugin/IrisService.java | 3 +- .../volmit/iris/util/plugin/VolmitSender.java | 6 +- .../scheduling/jobs/ParallelQueueJob.java | 3 +- .../iris/util/scheduling/jobs/QueueJob.java | 1 - 84 files changed, 404 insertions(+), 786 deletions(-) diff --git a/build.gradle b/build.gradle index 1a8b92f54..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 diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index da8360e3f..634e1be71 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; @@ -52,7 +51,10 @@ import com.volmit.iris.util.math.RNG; 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; @@ -132,8 +134,7 @@ public class Iris extends VolmitPlugin implements Listener { services.values().forEach(this::registerListener); } - public void postShutdown(Runnable r) - { + public void postShutdown(Runnable r) { postShutdown.add(r); } @@ -437,18 +438,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 +485,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 +730,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 +751,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 b86d1dc8f..d68168086 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecIris.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecIris.java @@ -28,13 +28,8 @@ import com.volmit.iris.util.decree.DecreeOrigin; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.format.C; -import com.volmit.iris.util.math.M; 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 { @@ -122,7 +117,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 d428238eb..feef11c9e 100644 --- a/src/main/java/com/volmit/iris/core/decrees/DecObject.java +++ b/src/main/java/com/volmit/iris/core/decrees/DecObject.java @@ -23,7 +23,6 @@ import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.block.TileState; import org.bukkit.block.data.BlockData; -import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.text.NumberFormat; @@ -36,7 +35,7 @@ public class DecObject implements DecreeExecutor { @Decree(description = "Check the composition of an object") public void analyze( @Param(description = "The object to analyze") - IrisObject object + IrisObject object ) { sender().sendMessage("Object Size: " + object.getW() + " * " + object.getH() + " * " + object.getD() + ""); sender().sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(object.getBlocks().size())); @@ -109,8 +108,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; @@ -134,8 +133,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; @@ -160,7 +159,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; @@ -180,23 +179,25 @@ 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") - IrisObject object, + IrisObject 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, + double scale, @Param(description = "The scale interpolator to use", defaultValue = "none") - IrisObjectPlacementScaleInterpolator interpolator - ){ + IrisObjectPlacementScaleInterpolator interpolator + ) { double maxScale = Double.max(10 - object.getBlocks().size() / 10000d, 1); - if (scale < maxScale){ + if (scale < maxScale) { sender().sendMessage(C.YELLOW + "Indicated scale exceeds maximum. Downscaled to maximum: " + maxScale); scale = maxScale; } 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 6c4cbe873..26e535feb 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/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/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 5460564f6..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,22 +44,16 @@ 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 net.minecraft.world.level.block.state.IBlockData; -import org.bukkit.Bukkit; -import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; @@ -65,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; @@ -136,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(); @@ -156,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); @@ -174,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(); } @@ -400,8 +390,7 @@ 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(); } @@ -412,17 +401,13 @@ public class IrisEngine implements Engine { PrecisionStopwatch p = PrecisionStopwatch.start(); Hunk blocks = vblocks.listen((xx, y, zz, t) -> catchBlockUpdates(x + xx, y + getMinHeight(), z + zz, t)); - if(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 - { + } else { getMantle().generateMatter(x >> 4, z >> 4, multicore); burst().burst(multicore, @@ -444,7 +429,6 @@ public class IrisEngine implements Engine { } - getMetrics().getTotal().put(p.getMilliseconds()); generated.incrementAndGet(); recycle(); 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 dc9981faf..19289c809 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 @@ -45,49 +45,35 @@ public class AtomicCache { public void reset() { t.set(null); - if(nullSupport) - { + if (nullSupport) { set.set(false); } } public T aquire(Supplier t) { - if(this.t.get() != null) - { + if (this.t.get() != null) { return this.t.get(); - } - - else if(nullSupport && set.get()) - { + } else if (nullSupport && set.get()) { return null; } lock.lock(); - if(this.t.get() != null) - { + if (this.t.get() != null) { lock.unlock(); return this.t.get(); - } - - else if(nullSupport && set.get()) - { + } else if (nullSupport && set.get()) { lock.unlock(); return null; } - try - { + try { this.t.set(t.get()); - if(nullSupport) - { + if (nullSupport) { set.set(true); } - } - - catch(Throwable e) - { + } catch (Throwable e) { Iris.error("Atomic cache failure!"); e.printStackTrace(); } 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 c54c01a09..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; 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 913c3689d..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 @@ -70,16 +70,13 @@ public class HeadlessWorld { public HeadlessGenerator generate() { Engine e = null; - if(getWorld().tryGetRealWorld()) - { - if(IrisToolbelt.isIrisWorld(getWorld().realWorld())) - { + if (getWorld().tryGetRealWorld()) { + if (IrisToolbelt.isIrisWorld(getWorld().realWorld())) { e = IrisToolbelt.access(getWorld().realWorld()).getEngine(); } } - if(e != null) - { + if (e != null) { Iris.info("Using Existing Engine " + getWorld().name() + " for Headless Pregeneration."); } 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 7ba56f9c6..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 @@ -62,17 +62,14 @@ public class IrisWorld { .environment(world.getEnvironment()); } - public boolean tryGetRealWorld() - { - if(hasRealWorld()) - { + public boolean tryGetRealWorld() { + if (hasRealWorld()) { return true; } World w = Bukkit.getWorld(name); - if(w != null) - { + if (w != null) { realWorld = w; return true; } 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 00de5822d..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); @@ -179,8 +165,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun 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); @@ -198,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 239e96d05..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,20 +19,16 @@ 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; import com.volmit.iris.engine.IrisEngine; -import com.volmit.iris.engine.data.cache.Cache; import com.volmit.iris.engine.data.chunk.MCATerrainChunk; import com.volmit.iris.engine.data.chunk.TerrainChunk; import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.engine.framework.EngineTarget; -import com.volmit.iris.engine.framework.WrongEngineBroException; import com.volmit.iris.engine.object.common.HeadlessWorld; import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.documentation.RegionCoordinates; import com.volmit.iris.util.hunk.Hunk; 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/Hunk.java b/src/main/java/com/volmit/iris/util/hunk/Hunk.java index 6d92d609c..e5b0cff02 100644 --- a/src/main/java/com/volmit/iris/util/hunk/Hunk.java +++ b/src/main/java/com/volmit/iris/util/hunk/Hunk.java @@ -27,7 +27,6 @@ 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.nbt.tag.ByteArrayTag; import com.volmit.iris.util.parallel.BurstExecutor; import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.stream.interpolation.Interpolated; @@ -37,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; @@ -1437,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/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/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/NBTWorld.java b/src/main/java/com/volmit/iris/util/nbt/mca/NBTWorld.java index cc76ab1e2..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 @@ -32,7 +32,6 @@ import org.bukkit.NamespacedKey; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; -import javax.management.RuntimeErrorException; import java.io.File; import java.io.IOException; import java.util.Map; @@ -236,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); } @@ -257,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); } @@ -281,10 +278,10 @@ public class NBTWorld { } 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/tag/ListTag.java b/src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java index e3929e467..0fbaff2e6 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 @@ -43,8 +43,7 @@ public class ListTag> extends Tag> implements Iterable< super(createEmptyValue(3)); } - public ListTag makeAtomic() - { + public ListTag makeAtomic() { setValue(new CopyOnWriteArrayList<>(getValue())); return this; } 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/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 c74811b2a..c4b174a28 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -424,11 +424,11 @@ public class VolmitSender implements CommandSender { } } - public void sendDecreeHelpNode(VirtualDecreeCommand i){ + public void sendDecreeHelpNode(VirtualDecreeCommand i) { if (isPlayer()) { //@builder String s = ( - " "<#42ecf5>" + f).toString(", ") + "\n" + "<#3fe05a>✎ <#6ad97d>" + i.getDescription() + "\n" + "<#bbe03f>✒ <#a8e0a2>" + (i.isNode() @@ -458,7 +458,7 @@ public class VolmitSender implements CommandSender { + (f.isRequired() ? "<#db4321>⚠ <#faa796>This parameter is required." : (f.hasDefault() - ? "<#2181db>✔ <#78dcf0>Defaults to \""+f.getParam().defaultValue()+"\" if undefined." + ? "<#2181db>✔ <#78dcf0>Defaults to \"" + f.getParam().defaultValue() + "\" if undefined." : "<#a73abd>✔ <#78dcf0>This parameter is optional.")) + "\n" + (f.isContextual() ? "<#ff9900>➱ <#ffcc00>The value may be derived from environment context \n" : "") + "<#cc00ff>✢ <#ff33cc>This parameter is of type " + f.getType().getSimpleName() 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; From 23ac209c052d6b4d504f00d5a5b5d030bb50dc56 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 22:28:39 -0400 Subject: [PATCH 06/29] f --- .github/workflows/gradlebuild.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 From 861e11a71396782677b2d3ac2398a784e29d88e6 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 22:37:55 -0400 Subject: [PATCH 07/29] Data Palette stuff for 1.17 mca --- .../iris/util/nbt/mca/palettes/DataBits.java | 125 ++++++++++ .../mca/palettes/DataPalette.java} | 28 ++- .../nbt/mca/palettes/DataPaletteBlock.java | 230 ++++++++++++++++++ .../mca/palettes/DataPaletteExpandable.java} | 19 +- .../nbt/mca/palettes/DataPaletteHash.java | 119 +++++++++ .../nbt/mca/palettes/DataPaletteLinear.java | 115 +++++++++ .../mca/palettes/Registry.java} | 24 +- .../nbt/mca/palettes/RegistryBlockID.java | 82 +++++++ .../util/nbt/mca/palettes/RegistryID.java | 177 ++++++++++++++ 9 files changed, 871 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataBits.java rename src/main/java/com/volmit/iris/util/{hunk/io/StringHunkIOAdapter.java => nbt/mca/palettes/DataPalette.java} (63%) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java rename src/main/java/com/volmit/iris/util/{hunk/io/BooleanHunkIOAdapter.java => nbt/mca/palettes/DataPaletteExpandable.java} (62%) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java rename src/main/java/com/volmit/iris/util/{hunk/io/BlockDataHunkIOAdapter.java => nbt/mca/palettes/Registry.java} (57%) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryBlockID.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java 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..f1ac3b3d1 --- /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[] b; + private final int c; + private final long d; + private final int e; + 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 var0, int var1, long[] var2) { + Validate.inclusiveBetween(1L, 32L, (long) var0); + this.e = var1; + this.c = var0; + this.d = (1L << var0) - 1L; + this.f = (char) (64 / var0); + 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 (var2 != null) { + if (var2.length != var4) { + throw new RuntimeException("Invalid length given for storage, got: " + var2.length + " but expected: " + var4); + } + + this.b = var2; + } else { + this.b = 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 a(int var0, int var1) { + Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); + Validate.inclusiveBetween(0L, this.d, (long) var1); + int var2 = this.b(var0); + long var3 = this.b[var2]; + int var5 = (var0 - var2 * this.f) * this.c; + int var6 = (int) (var3 >> var5 & this.d); + this.b[var2] = var3 & ~(this.d << var5) | ((long) var1 & this.d) << var5; + return var6; + } + + public void b(int var0, int var1) { + Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); + Validate.inclusiveBetween(0L, this.d, (long) var1); + int var2 = this.b(var0); + long var3 = this.b[var2]; + int var5 = (var0 - var2 * this.f) * this.c; + this.b[var2] = var3 & ~(this.d << var5) | ((long) var1 & this.d) << var5; + } + + public int a(int var0) { + Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); + int var1 = this.b(var0); + long var2 = this.b[var1]; + int var4 = (var0 - var1 * this.f) * this.c; + return (int) (var2 >> var4 & this.d); + } + + public long[] a() { + return this.b; + } + + public int b() { + return this.e; + } + + public int c() { + return this.c; + } + + public void a(IntConsumer var0) { + int var1 = 0; + long[] var3 = this.b; + int var4 = var3.length; + for (long l : var3) { + long var5 = l; + for (int j = 0; j < this.f; ++j) { + var0.accept((int) (var5 & this.d)); + var5 >>= this.c; + ++var1; + if (var1 >= this.e) { + 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..b29da7adc 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,23 @@ * 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 a(T var1); - @Override - public String read(DataInputStream din) throws IOException { - return din.readUTF(); - } + boolean a(Predicate var1); + + T a(int var1); + + int a(); + + int b(); + + void a(ListTag t); } 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..bbd43a2e7 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java @@ -0,0 +1,230 @@ +/* + * 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.math.MathHelper; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import net.minecraft.network.PacketDataSerializer; + +import java.util.concurrent.Semaphore; +import java.util.function.Function; +import java.util.function.Predicate; + +public class DataPaletteBlock implements DataPaletteExpandable { + private static final int d = 4096; + public static final int a = 9; + public static final int b = 4; + private final DataPalette e; + private final DataPaletteExpandable f = (var0x, var1x) -> { + return 0; + }; + private final RegistryBlockID g; + private final Function h; + private final Function i; + private final T j; + protected DataBits c; + private DataPalette k; + private int l; + private final Semaphore m = new Semaphore(1); + + public void b() { + this.m.release(); + } + + public DataPaletteBlock(DataPalette var0, RegistryBlockID var1, Function var2, Function var3, T var4) { + this.e = var0; + this.g = var1; + this.h = var2; + this.i = var3; + this.j = var4; + this.b(4); + } + + private static int b(int var0, int var1, int var2) { + return var1 << 8 | var2 << 4 | var0; + } + + private void b(int var0) { + if (var0 != this.l) { + this.l = var0; + if (this.l <= 4) { + this.l = 4; + this.k = new DataPaletteLinear(this.g, this.l, this, this.h); + } else if (this.l < 9) { + this.k = new DataPaletteHash(this.g, this.l, this, this.h, this.i); + } else { + this.k = this.e; + this.l = MathHelper.e(this.g.a()); + } + + this.k.a(this.j); + this.c = new DataBits(this.l, 4096); + } + } + + public int onResize(int var0, T var1) { + DataBits var2 = this.c; + DataPalette var3 = this.k; + this.b(var0); + + for (int var4 = 0; var4 < var2.b(); ++var4) { + T var5 = var3.a(var2.a(var4)); + if (var5 != null) { + this.setBlockIndex(var4, var5); + } + } + + return this.k.a(var1); + } + + public T setBlock(int var0, int var1, int var2, T var3) { + T var6; + try { + var6 = this.a(b(var0, var1, var2), var3); + } finally { + this.b(); + } + + return var6; + } + + public T b(int var0, int var1, int var2, T var3) { + return this.a(b(var0, var1, var2), var3); + } + + private T a(int var0, T var1) { + int var2 = this.k.a(var1); + int var3 = this.c.a(var0, var2); + T var4 = this.k.a(var3); + return var4 == null ? this.j : var4; + } + + public void c(int var0, int var1, int var2, T var3) { + try { + this.setBlockIndex(b(var0, var1, var2), var3); + } finally { + this.b(); + } + } + + private void setBlockIndex(int var0, T var1) { + int var2 = this.k.a(var1); + this.c.b(var0, var2); + } + + public T a(int var0, int var1, int var2) { + return this.a(b(var0, var1, var2)); + } + + protected T a(int var0) { + T var1 = this.k.a(this.c.a(var0)); + return var1 == null ? this.j : var1; + } + + public void a(ListTag var0, long[] var1) { + try { + int var2 = Math.max(4, MathHelper.e(var0.size())); + if (var2 != this.l) { + this.b(var2); + } + + this.k.a(var0); + int var3 = var1.length * 64 / 4096; + if (this.k == this.e) { + DataPalette var4 = new DataPaletteHash(this.g, var2, this.f, this.h, this.i); + var4.a(var0); + DataBits var5 = new DataBits(var2, 4096, var1); + + for (int var6 = 0; var6 < 4096; ++var6) { + this.c.b(var6, this.e.a(var4.a(var5.a(var6)))); + } + } else if (var3 == this.l) { + System.arraycopy(var1, 0, this.c.a(), 0, var1.length); + } else { + DataBits var4 = new DataBits(var3, 4096, var1); + + for (int var5 = 0; var5 < 4096; ++var5) { + this.c.b(var5, var4.a(var5)); + } + } + } finally { + this.b(); + } + + } + + public void a(CompoundTag var0, String var1, String var2) { + try { + DataPaletteHash var3 = new DataPaletteHash(this.g, this.l, this.f, this.h, this.i); + T var4 = this.j; + int var5 = var3.a(this.j); + int[] var6 = new int[4096]; + + for (int var7 = 0; var7 < 4096; ++var7) { + T var8 = this.a(var7); + if (var8 != var4) { + var4 = var8; + var5 = var3.a(var8); + } + + var6[var7] = var5; + } + + ListTag var7 = (ListTag) ListTag.createUnchecked(CompoundTag.class); + var3.b(var7); + var0.put(var1, var7); + int var8 = Math.max(4, MathHelper.e(var7.size())); + DataBits var9 = new DataBits(var8, 4096); + + for (int var10 = 0; var10 < var6.length; ++var10) { + var9.b(var10, var6[var10]); + } + + var0.putLongArray(var2, var9.a()); + } finally { + this.b(); + } + } + + public int c() { + return 1 + this.k.a() + PacketDataSerializer.a(this.c.b()) + this.c.a().length * 8; + } + + public boolean contains(Predicate var0) { + return this.k.a(var0); + } + + public void a(DataPaletteBlock.a var0) { + Int2IntMap var1 = new Int2IntOpenHashMap(); + this.c.a((var1x) -> { + var1.put(var1x, var1.get(var1x) + 1); + }); + var1.int2IntEntrySet().forEach((var1x) -> { + var0.accept(this.k.a(var1x.getIntKey()), var1x.getIntValue()); + }); + } + + @FunctionalInterface + public interface a { + void accept(T var1, int var2); + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/hunk/io/BooleanHunkIOAdapter.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.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/nbt/mca/palettes/DataPaletteExpandable.java index aeaaaeb26..ca1ac6d5b 100644 --- a/src/main/java/com/volmit/iris/util/hunk/io/BooleanHunkIOAdapter.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java @@ -16,21 +16,8 @@ * 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; - -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(); - } +interface DataPaletteExpandable { + int onResize(int var1, T var2); } 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..4b9719527 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java @@ -0,0 +1,119 @@ +/* + * 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 net.minecraft.network.PacketDataSerializer; + +import java.util.function.Function; +import java.util.function.Predicate; + +public class DataPaletteHash implements DataPalette { + private final RegistryBlockID a; + private final RegistryID b; + private final DataPaletteExpandable c; + private final Function d; + private final Function e; + private final int f; + + public DataPaletteHash(RegistryBlockID var0, int var1, DataPaletteExpandable var2, Function var3, Function var4) { + this.a = var0; + this.f = var1; + this.c = var2; + this.d = var3; + this.e = var4; + this.b = new RegistryID(1 << var1); + } + + public int a(T var0) { + int var1 = this.b.getId(var0); + if (var1 == -1) { + var1 = this.b.c(var0); + if (var1 >= 1 << this.f) { + var1 = this.c.onResize(this.f + 1, var0); + } + } + + return var1; + } + + public boolean a(Predicate var0) { + for (int var1 = 0; var1 < this.b(); ++var1) { + if (var0.test(this.b.fromId(var1))) { + return true; + } + } + + return false; + } + + public T a(int var0) { + return this.b.fromId(var0); + } + + public void a(PacketDataSerializer var0) { + this.b.a(); + int var1 = var0.j(); + + for (int var2 = 0; var2 < var1; ++var2) { + this.b.c(this.a.fromId(var0.j())); + } + + } + + public void b(PacketDataSerializer var0) { + int var1 = this.b(); + var0.d(var1); + + for (int var2 = 0; var2 < var1; ++var2) { + var0.d(this.a.getId(this.b.fromId(var2))); + } + + } + + public int a() { + int var0 = PacketDataSerializer.a(this.b()); + + for (int var1 = 0; var1 < this.b(); ++var1) { + var0 += PacketDataSerializer.a(this.a.getId(this.b.fromId(var1))); + } + + return var0; + } + + public int b() { + return this.b.b(); + } + + public void a(ListTag var0) { + this.b.a(); + + for (int var1 = 0; var1 < var0.size(); ++var1) { + this.b.c(this.d.apply(var0.get(var1))); + } + } + + public void b(ListTag var0) { + for (int var1 = 0; var1 < this.b(); ++var1) { + var0.add(this.e.apply(this.b.fromId(var1))); + } + + } +} 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..20cd59d6a --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java @@ -0,0 +1,115 @@ +/* + * 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 net.minecraft.network.PacketDataSerializer; + +import java.util.function.Function; +import java.util.function.Predicate; + +public class DataPaletteLinear implements DataPalette { + private final RegistryBlockID a; + private final T[] b; + private final DataPaletteExpandable c; + private final Function d; + private final int e; + private int f; + + public DataPaletteLinear(RegistryBlockID var0, int var1, DataPaletteExpandable var2, Function var3) { + this.a = var0; + this.b = (T[]) new Object[1 << var1]; + this.e = var1; + this.c = var2; + this.d = var3; + } + + public int a(T var0) { + int var1; + for (var1 = 0; var1 < this.f; ++var1) { + if (this.b[var1] == var0) { + return var1; + } + } + + var1 = this.f; + if (var1 < this.b.length) { + this.b[var1] = var0; + ++this.f; + return var1; + } else { + return this.c.onResize(this.e + 1, var0); + } + } + + public boolean a(Predicate var0) { + for (int var1 = 0; var1 < this.f; ++var1) { + if (var0.test(this.b[var1])) { + return true; + } + } + + return false; + } + + public T a(int var0) { + return var0 >= 0 && var0 < this.f ? this.b[var0] : null; + } + + public void a(PacketDataSerializer var0) { + this.f = var0.j(); + + for (int var1 = 0; var1 < this.f; ++var1) { + this.b[var1] = this.a.fromId(var0.j()); + } + + } + + public void b(PacketDataSerializer var0) { + var0.d(this.f); + + for (int var1 = 0; var1 < this.f; ++var1) { + var0.d(this.a.getId(this.b[var1])); + } + + } + + public int a() { + int var0 = PacketDataSerializer.a(this.b()); + + for (int var1 = 0; var1 < this.b(); ++var1) { + var0 += PacketDataSerializer.a(this.a.getId(this.b[var1])); + } + + return var0; + } + + public int b() { + return this.f; + } + + public void a(ListTag var0) { + for (int var1 = 0; var1 < var0.size(); ++var1) { + this.b[var1] = this.d.apply(var0.get(var1)); + } + + this.f = var0.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..116185714 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,10 @@ * 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; +public interface Registry extends Iterable { + int getId(T var1); -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -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()); - } -} + T fromId(int var1); +} \ 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..dd63f5f48 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryBlockID.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.google.common.base.Predicates; +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; + +import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.List; + +public class RegistryBlockID implements Registry { + public static final int a = -1; + private int b; + private final IdentityHashMap c; + private final List d; + + public RegistryBlockID() { + this(512); + } + + public RegistryBlockID(int var0) { + this.d = Lists.newArrayListWithExpectedSize(var0); + this.c = new IdentityHashMap(var0); + } + + public void a(T var0, int var1) { + this.c.put(var0, var1); + + while (this.d.size() <= var1) { + this.d.add(null); + } + + this.d.set(var1, var0); + if (this.b <= var1) { + this.b = var1 + 1; + } + + } + + public void b(T var0) { + this.a(var0, this.b); + } + + public int getId(T var0) { + Integer var1 = (Integer) this.c.get(var0); + return var1 == null ? -1 : var1; + } + + public final T fromId(int var0) { + return var0 >= 0 && var0 < this.d.size() ? this.d.get(var0) : null; + } + + public Iterator iterator() { + return Iterators.filter(this.d.iterator(), Predicates.notNull()); + } + + public boolean b(int var0) { + return this.fromId(var0) != null; + } + + public int a() { + return this.c.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..334c21371 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java @@ -0,0 +1,177 @@ +/* + * 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.base.Predicates; +import com.google.common.collect.Iterators; +import com.volmit.iris.util.math.MathHelper; + +import java.util.Arrays; +import java.util.Iterator; + +public class RegistryID implements Registry { + public static final int a = -1; + private static final Object b = null; + private static final float c = 0.8F; + private K[] d; + private int[] e; + private K[] f; + private int g; + private int h; + + public RegistryID(int var0) { + var0 = (int) ((float) var0 / 0.8F); + this.d = (K[]) new Object[var0]; + this.e = new int[var0]; + this.f = (K[]) new Object[var0]; + } + + public int getId(K var0) { + return this.c(this.b(var0, this.d(var0))); + } + + public K fromId(int var0) { + return var0 >= 0 && var0 < this.f.length ? this.f[var0] : null; + } + + private int c(int var0) { + return var0 == -1 ? -1 : this.e[var0]; + } + + public boolean b(K var0) { + return this.getId(var0) != -1; + } + + public boolean b(int var0) { + return this.fromId(var0) != null; + } + + public int c(K 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) { + K[] var1 = this.d; + int[] var2 = this.e; + this.d = (K[]) new Object[var0]; + this.e = new int[var0]; + this.f = (K[]) new Object[var0]; + this.g = 0; + this.h = 0; + + for (int var3 = 0; var3 < var1.length; ++var3) { + if (var1[var3] != null) { + this.a(var1[var3], var2[var3]); + } + } + + } + + public void a(K var0, int var1) { + int var2 = Math.max(var1, this.h + 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.h; + if (var1 == this.g) { + ++this.g; + } + + } + + private int d(K var0) { + return (MathHelper.g(System.identityHashCode(var0)) & 2147483647) % this.d.length; + } + + private int b(K var0, int var1) { + int var2; + for (var2 = var1; var2 < this.d.length; ++var2) { + if (this.d[var2] == var0) { + return var2; + } + + if (this.d[var2] == b) { + return -1; + } + } + + for (var2 = 0; var2 < var1; ++var2) { + if (this.d[var2] == var0) { + return var2; + } + + if (this.d[var2] == b) { + return -1; + } + } + + return -1; + } + + private int e(int var0) { + int var1; + for (var1 = var0; var1 < this.d.length; ++var1) { + if (this.d[var1] == b) { + return var1; + } + } + + for (var1 = 0; var1 < var0; ++var1) { + if (this.d[var1] == b) { + return var1; + } + } + + throw new RuntimeException("Overflowed :("); + } + + public Iterator iterator() { + return Iterators.filter(Iterators.forArray(this.f), Predicates.notNull()); + } + + public void a() { + Arrays.fill(this.d, (Object) null); + Arrays.fill(this.f, (Object) null); + this.g = 0; + this.h = 0; + } + + public int b() { + return this.h; + } +} \ No newline at end of file From d5da8e4e2b9f23e8ef109eb1a91ae2d97672ec48 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 24 Aug 2021 23:16:01 -0400 Subject: [PATCH 08/29] Forcefully integrate a mangled DataPalette from NMS into a NBTMCA API --- .../com/volmit/iris/util/nbt/mca/Chunk.java | 10 - .../com/volmit/iris/util/nbt/mca/Section.java | 248 ++---------------- .../util/nbt/mca/palettes/DataPalette.java | 2 + .../nbt/mca/palettes/DataPaletteBlock.java | 69 ++--- .../nbt/mca/palettes/DataPaletteHash.java | 5 + .../nbt/mca/palettes/DataPaletteLinear.java | 11 + 6 files changed, 77 insertions(+), 268 deletions(-) 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..23bf1ac99 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 @@ -688,14 +688,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/Section.java b/src/main/java/com/volmit/iris/util/nbt/mca/Section.java index ec6df11f1..2e95af170 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 @@ -20,12 +20,13 @@ 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 net.minecraft.world.level.chunk.DataPaletteGlobal; +import net.minecraft.world.level.chunk.Chunk; import java.util.ArrayList; import java.util.HashMap; @@ -35,10 +36,8 @@ 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; @@ -53,72 +52,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); - } - - palette.makeAtomic(); - ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); + palette = new DataPaletteBlock<>(); LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); + palette.a((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 { @@ -150,16 +95,7 @@ public class Section { * @return The block state data of this block. */ public synchronized 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); - - } - - return null; + return palette.a(blockX, blockY, blockZ); } /** @@ -169,52 +105,17 @@ 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 paletteIndex = addToPalette(state); - int paletteSizeBefore = palette.size(); - //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; + + if(cleanup) + { + palette.setBlock(blockX, blockY, blockZ, 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 synchronized 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); + else + { + palette.b(blockX, blockY, blockZ, state); } } @@ -246,25 +147,6 @@ public class Section { } } - /** - * Fetches the palette of this Section. - * - * @return The palette of this Section. - */ - public synchronized 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); } @@ -285,63 +167,8 @@ 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; } /** @@ -364,29 +191,6 @@ public class Section { this.blockLight = blockLight; } - /** - * @return The indices of the block states of this Section. - */ - public synchronized 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 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 */ @@ -414,11 +218,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; } @@ -434,20 +234,12 @@ public class Section { public synchronized CompoundTag updateHandle(int y) { data.putByte("Y", (byte) y); if (palette != null) { - data.put("Palette", palette); + data.put("Palette", palette.getK().getPalette()); + data.putLongArray("BlockStates", palette.getC().a()); } 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/DataPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java index b29da7adc..0b5a07fec 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java @@ -35,4 +35,6 @@ public interface DataPalette { int b(); void a(ListTag t); + + ListTag getPalette(); } 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 index bbd43a2e7..65d943fc0 100644 --- 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 @@ -19,16 +19,20 @@ package com.volmit.iris.util.nbt.mca.palettes; import com.volmit.iris.util.math.MathHelper; +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 it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import lombok.Getter; import net.minecraft.network.PacketDataSerializer; +import org.bukkit.Material; import java.util.concurrent.Semaphore; import java.util.function.Function; import java.util.function.Predicate; +@Getter public class DataPaletteBlock implements DataPaletteExpandable { private static final int d = 4096; public static final int a = 9; @@ -41,16 +45,26 @@ public class DataPaletteBlock implements DataPaletteExpandable { private final Function h; private final Function i; private final T j; + private static final RegistryBlockID registry = new RegistryBlockID<>(); + private static final CompoundTag air = NBTWorld.getCompound(Material.AIR.createBlockData()); protected DataBits c; private DataPalette k; - private int l; + private int bits; private final Semaphore m = new Semaphore(1); public void b() { this.m.release(); } - public DataPaletteBlock(DataPalette var0, RegistryBlockID var1, Function var2, Function var3, T var4) { + public DataPaletteBlock() { + this(null, (RegistryBlockID) registry, (i) -> (T) i, (i) -> (CompoundTag) i, (T) air); + } + + public DataPaletteBlock(DataPalette var0, + RegistryBlockID var1, + Function var2, + Function var3, + T var4) { this.e = var0; this.g = var1; this.h = var2; @@ -64,20 +78,20 @@ public class DataPaletteBlock implements DataPaletteExpandable { } private void b(int var0) { - if (var0 != this.l) { - this.l = var0; - if (this.l <= 4) { - this.l = 4; - this.k = new DataPaletteLinear(this.g, this.l, this, this.h); - } else if (this.l < 9) { - this.k = new DataPaletteHash(this.g, this.l, this, this.h, this.i); + if (var0 != this.bits) { + this.bits = var0; + if (this.bits <= 4) { + this.bits = 4; + this.k = new DataPaletteLinear(this.g, this.bits, this, this.h); + } else if (this.bits < 9) { + this.k = new DataPaletteHash(this.g, this.bits, this, this.h, this.i); } else { this.k = this.e; - this.l = MathHelper.e(this.g.a()); + this.bits = MathHelper.e(this.g.a()); } this.k.a(this.j); - this.c = new DataBits(this.l, 4096); + this.c = new DataBits(this.bits, 4096); } } @@ -140,27 +154,27 @@ public class DataPaletteBlock implements DataPaletteExpandable { return var1 == null ? this.j : var1; } - public void a(ListTag var0, long[] var1) { + public void a(ListTag palettedata, long[] databits) { try { - int var2 = Math.max(4, MathHelper.e(var0.size())); - if (var2 != this.l) { + int var2 = Math.max(4, MathHelper.e(palettedata.size())); + if (var2 != this.bits) { this.b(var2); } - this.k.a(var0); - int var3 = var1.length * 64 / 4096; + this.k.a(palettedata); + int var3 = databits.length * 64 / 4096; if (this.k == this.e) { - DataPalette var4 = new DataPaletteHash(this.g, var2, this.f, this.h, this.i); - var4.a(var0); - DataBits var5 = new DataBits(var2, 4096, var1); + DataPalette var4 = new DataPaletteHash(this.g, var2, this.f, this.h, this.i); + var4.a(palettedata); + DataBits var5 = new DataBits(var2, 4096, databits); for (int var6 = 0; var6 < 4096; ++var6) { this.c.b(var6, this.e.a(var4.a(var5.a(var6)))); } - } else if (var3 == this.l) { - System.arraycopy(var1, 0, this.c.a(), 0, var1.length); + } else if (var3 == this.bits) { + System.arraycopy(databits, 0, this.c.a(), 0, databits.length); } else { - DataBits var4 = new DataBits(var3, 4096, var1); + DataBits var4 = new DataBits(var3, 4096, databits); for (int var5 = 0; var5 < 4096; ++var5) { this.c.b(var5, var4.a(var5)); @@ -169,12 +183,11 @@ public class DataPaletteBlock implements DataPaletteExpandable { } finally { this.b(); } - } public void a(CompoundTag var0, String var1, String var2) { try { - DataPaletteHash var3 = new DataPaletteHash(this.g, this.l, this.f, this.h, this.i); + DataPaletteHash var3 = new DataPaletteHash(this.g, this.bits, this.f, this.h, this.i); T var4 = this.j; int var5 = var3.a(this.j); int[] var6 = new int[4096]; @@ -215,12 +228,8 @@ public class DataPaletteBlock implements DataPaletteExpandable { public void a(DataPaletteBlock.a var0) { Int2IntMap var1 = new Int2IntOpenHashMap(); - this.c.a((var1x) -> { - var1.put(var1x, var1.get(var1x) + 1); - }); - var1.int2IntEntrySet().forEach((var1x) -> { - var0.accept(this.k.a(var1x.getIntKey()), var1x.getIntValue()); - }); + this.c.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); + var1.int2IntEntrySet().forEach((var1x) -> var0.accept(this.k.a(var1x.getIntKey()), var1x.getIntValue())); } @FunctionalInterface 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 index 4b9719527..060646e6e 100644 --- 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 @@ -110,6 +110,11 @@ public class DataPaletteHash implements DataPalette { } } + @Override + public ListTag getPalette() { + return null; + } + public void b(ListTag var0) { for (int var1 = 0; var1 < this.b(); ++var1) { var0.add(this.e.apply(this.b.fromId(var1))); 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 index 20cd59d6a..7823d40e7 100644 --- 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 @@ -112,4 +112,15 @@ public class DataPaletteLinear implements DataPalette { this.f = var0.size(); } + + @Override + public ListTag getPalette() { + ListTag c = (ListTag) ListTag.createUnchecked(CompoundTag.class); + for(T i : b) + { + c.add((CompoundTag) i); + } + + return c; + } } From a95c61c1d89d939249603ae9de14cb39e7af60cd Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:40:42 -0400 Subject: [PATCH 09/29] DP Tests --- src/main/java/com/volmit/iris/Iris.java | 130 ++++++++++++++++++++++++ 1 file changed, 130 insertions(+) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 634e1be71..6d34bfe11 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -48,6 +48,7 @@ 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; @@ -58,21 +59,27 @@ 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 { @@ -119,6 +126,128 @@ public class Iris extends VolmitPlugin implements Listener { }).start(); } + private void testmca() { + try + { + int forceBits = 9; + 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); @@ -132,6 +261,7 @@ 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) { From a746720a6e997590ee709683ad73bd0c68b01dd3 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:40:51 -0400 Subject: [PATCH 10/29] Update math helper --- .../com/volmit/iris/util/math/MathHelper.java | 711 +++++++++++++----- 1 file changed, 520 insertions(+), 191 deletions(-) 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 From 9b3013c51a48d18552214692353836054cfabc60 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:41:13 -0400 Subject: [PATCH 11/29] Deobf datapalette --- .../java/com/volmit/iris/util/nbt/mca/palettes/DataBits.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 index f1ac3b3d1..016302d1d 100644 --- 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 @@ -86,7 +86,7 @@ public class DataBits { this.b[var2] = var3 & ~(this.d << var5) | ((long) var1 & this.d) << var5; } - public int a(int var0) { + public int getIndexFromPos(int var0) { Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); int var1 = this.b(var0); long var2 = this.b[var1]; @@ -94,7 +94,7 @@ public class DataBits { return (int) (var2 >> var4 & this.d); } - public long[] a() { + public long[] getData() { return this.b; } From c1ba176e2739da35c0c54a0a985b886f28733223 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:41:24 -0400 Subject: [PATCH 12/29] Deobf dbits --- .../com/volmit/iris/util/nbt/mca/palettes/DataPalette.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java index 0b5a07fec..4426e4286 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java @@ -24,17 +24,17 @@ import com.volmit.iris.util.nbt.tag.ListTag; import java.util.function.Predicate; public interface DataPalette { - int a(T var1); + int getIndex(T var1); boolean a(Predicate var1); - T a(int var1); + T getByIndex(int var1); int a(); int b(); - void a(ListTag t); + void replace(ListTag t); ListTag getPalette(); } From f45d643739b3305a5f75afa684a4e16c12c1c496 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:41:37 -0400 Subject: [PATCH 13/29] Deobf datapalette block & fix a ton of issues --- .../nbt/mca/palettes/DataPaletteBlock.java | 247 +++++++++--------- 1 file changed, 122 insertions(+), 125 deletions(-) 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 index 65d943fc0..eef62b14d 100644 --- 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 @@ -18,6 +18,8 @@ package com.volmit.iris.util.nbt.mca.palettes; +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.mca.NBTWorld; import com.volmit.iris.util.nbt.tag.CompoundTag; @@ -28,36 +30,49 @@ import lombok.Getter; import net.minecraft.network.PacketDataSerializer; import org.bukkit.Material; -import java.util.concurrent.Semaphore; import java.util.function.Function; import java.util.function.Predicate; @Getter public class DataPaletteBlock implements DataPaletteExpandable { private static final int d = 4096; - public static final int a = 9; - public static final int b = 4; - private final DataPalette e; - private final DataPaletteExpandable f = (var0x, var1x) -> { - return 0; - }; - private final RegistryBlockID g; + 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 Function h; private final Function i; - private final T j; - private static final RegistryBlockID registry = new RegistryBlockID<>(); + private final T 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 c; - private DataPalette k; - private int bits; - private final Semaphore m = new Semaphore(1); - - public void b() { - this.m.release(); - } + protected DataBits dataBits; + private DataPalette currentPalette; + private int bits = 0; public DataPaletteBlock() { - this(null, (RegistryBlockID) registry, (i) -> (T) i, (i) -> (CompoundTag) i, (T) air); + this((DataPalette) global.aquire(() -> + new DataPaletteGlobal<>(reg.aquire(() -> { + try { + return INMS.get().computeBlockIDRegistry(); + } catch (NoSuchFieldException ex) { + ex.printStackTrace(); + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + } + return null; + }), air) + ), (RegistryBlockID) reg.aquire(() -> { + try { + return INMS.get().computeBlockIDRegistry(); + } catch (NoSuchFieldException ex) { + ex.printStackTrace(); + } catch (IllegalAccessException ex) { + ex.printStackTrace(); + } + return null; + }), (i) -> (T) i, (i) -> (CompoundTag) i, (T) air); } public DataPaletteBlock(DataPalette var0, @@ -65,171 +80,153 @@ public class DataPaletteBlock implements DataPaletteExpandable { Function var2, Function var3, T var4) { - this.e = var0; - this.g = var1; + this.globalPalette = var0; + this.stolenRegistry = var1; this.h = var2; this.i = var3; - this.j = var4; - this.b(4); + this.defAir = var4; + this.changeBitsTo(4); } - private static int b(int var0, int var1, int var2) { + private static int blockIndex(int var0, int var1, int var2) { return var1 << 8 | var2 << 4 | var0; } - private void b(int var0) { - if (var0 != this.bits) { - this.bits = var0; - if (this.bits <= 4) { - this.bits = 4; - this.k = new DataPaletteLinear(this.g, this.bits, this, this.h); - } else if (this.bits < 9) { - this.k = new DataPaletteHash(this.g, this.bits, this, this.h, this.i); + private void changeBitsTo(int newbits) { + if (newbits != this.bits) { + this.bits = newbits; + if (this.bits <= LINEAR_BITS) { + this.bits = LINEAR_BITS; + this.currentPalette = new DataPaletteLinear(this.stolenRegistry, this.bits, this, this.h); + } else if (this.bits < HASH_BITS) { + this.currentPalette = new DataPaletteHash(this.stolenRegistry, this.bits, this, this.h, this.i); } else { - this.k = this.e; - this.bits = MathHelper.e(this.g.a()); + this.currentPalette = this.globalPalette; + this.bits = MathHelper.e(this.stolenRegistry.size()); } - this.k.a(this.j); - this.c = new DataBits(this.bits, 4096); + this.currentPalette.getIndex(this.defAir); + this.dataBits = new DataBits(this.bits, 4096); } } public int onResize(int var0, T var1) { - DataBits var2 = this.c; - DataPalette var3 = this.k; - this.b(var0); + DataBits var2 = this.dataBits; + DataPalette var3 = this.currentPalette; + this.changeBitsTo(var0); for (int var4 = 0; var4 < var2.b(); ++var4) { - T var5 = var3.a(var2.a(var4)); + T var5 = var3.getByIndex(var2.getIndexFromPos(var4)); if (var5 != null) { this.setBlockIndex(var4, var5); } } - return this.k.a(var1); + return this.currentPalette.getIndex(var1); } public T setBlock(int var0, int var1, int var2, T var3) { - T var6; - try { - var6 = this.a(b(var0, var1, var2), var3); - } finally { - this.b(); - } - - return var6; - } - - public T b(int var0, int var1, int var2, T var3) { - return this.a(b(var0, var1, var2), var3); + return this.a(blockIndex(var0, var1, var2), var3); } private T a(int var0, T var1) { - int var2 = this.k.a(var1); - int var3 = this.c.a(var0, var2); - T var4 = this.k.a(var3); - return var4 == null ? this.j : var4; + int var2 = this.currentPalette.getIndex(var1); + int var3 = this.dataBits.a(var0, var2); + T var4 = this.currentPalette.getByIndex(var3); + return var4 == null ? this.defAir : var4; } public void c(int var0, int var1, int var2, T var3) { - try { - this.setBlockIndex(b(var0, var1, var2), var3); - } finally { - this.b(); - } + this.setBlockIndex(blockIndex(var0, var1, var2), var3); } private void setBlockIndex(int var0, T var1) { - int var2 = this.k.a(var1); - this.c.b(var0, var2); + int var2 = this.currentPalette.getIndex(var1); + this.dataBits.b(var0, var2); } - public T a(int var0, int var1, int var2) { - return this.a(b(var0, var1, var2)); + public T getBlock(int var0, int var1, int var2) { + return this.getByIndex(blockIndex(var0, var1, var2)); } - protected T a(int var0) { - T var1 = this.k.a(this.c.a(var0)); - return var1 == null ? this.j : var1; + protected T getByIndex(int var0) { + if(this.currentPalette == null) + { + return null; + } + + T data = this.currentPalette.getByIndex(this.dataBits.getIndexFromPos(var0)); + return data == null ? this.defAir : data; } - public void a(ListTag palettedata, long[] databits) { - try { - int var2 = Math.max(4, MathHelper.e(palettedata.size())); - if (var2 != this.bits) { - this.b(var2); + public void load(ListTag palettedata, long[] databits) { + int readBits = Math.max(4, MathHelper.e(palettedata.size())); + if (readBits != this.bits) { + this.changeBitsTo(readBits); + } + + this.currentPalette.replace(palettedata); + int dblen = databits.length * 64 / 4096; + if (this.currentPalette == this.globalPalette) { + DataPalette hashPalette = new DataPaletteHash(this.stolenRegistry, readBits, this.f, this.h, this.i); + hashPalette.replace(palettedata); + DataBits var5 = new DataBits(readBits, 4096, databits); + + for (int var6 = 0; var6 < 4096; ++var6) { + this.dataBits.b(var6, this.globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(var6)))); } + } else if (dblen == this.bits) { + System.arraycopy(databits, 0, this.dataBits.getData(), 0, databits.length); + } else { + DataBits var4 = new DataBits(dblen, 4096, databits); - this.k.a(palettedata); - int var3 = databits.length * 64 / 4096; - if (this.k == this.e) { - DataPalette var4 = new DataPaletteHash(this.g, var2, this.f, this.h, this.i); - var4.a(palettedata); - DataBits var5 = new DataBits(var2, 4096, databits); - - for (int var6 = 0; var6 < 4096; ++var6) { - this.c.b(var6, this.e.a(var4.a(var5.a(var6)))); - } - } else if (var3 == this.bits) { - System.arraycopy(databits, 0, this.c.a(), 0, databits.length); - } else { - DataBits var4 = new DataBits(var3, 4096, databits); - - for (int var5 = 0; var5 < 4096; ++var5) { - this.c.b(var5, var4.a(var5)); - } + for (int var5 = 0; var5 < 4096; ++var5) { + this.dataBits.b(var5, var4.getIndexFromPos(var5)); } - } finally { - this.b(); } } - public void a(CompoundTag var0, String var1, String var2) { - try { - DataPaletteHash var3 = new DataPaletteHash(this.g, this.bits, this.f, this.h, this.i); - T var4 = this.j; - int var5 = var3.a(this.j); - int[] var6 = new int[4096]; + public void save(CompoundTag to, String paletteName, String blockStatesName) { + DataPaletteHash hashpal = new DataPaletteHash(this.stolenRegistry, bits, this.f, this.h, this.i); + T cursor = this.defAir; + int palIndex = hashpal.getIndex(this.defAir); + int[] var6 = new int[4096]; - for (int var7 = 0; var7 < 4096; ++var7) { - T var8 = this.a(var7); - if (var8 != var4) { - var4 = var8; - var5 = var3.a(var8); - } - - var6[var7] = var5; + for (int var7 = 0; var7 < 4096; ++var7) { + T entry = this.getByIndex(var7); + if (!entry.equals(cursor)) { + cursor = entry; + palIndex = hashpal.getIndex(entry); } - ListTag var7 = (ListTag) ListTag.createUnchecked(CompoundTag.class); - var3.b(var7); - var0.put(var1, var7); - int var8 = Math.max(4, MathHelper.e(var7.size())); - DataBits var9 = new DataBits(var8, 4096); - - for (int var10 = 0; var10 < var6.length; ++var10) { - var9.b(var10, var6[var10]); - } - - var0.putLongArray(var2, var9.a()); - } finally { - this.b(); + var6[var7] = palIndex; } + + ListTag npalette = (ListTag) ListTag.createUnchecked(CompoundTag.class); + hashpal.writePalette(npalette); + to.put(paletteName, npalette); + int var8 = Math.max(4, MathHelper.e(npalette.size())); + DataBits writeBits = new DataBits(var8, 4096); + + for (int var10 = 0; var10 < var6.length; ++var10) { + writeBits.b(var10, var6[var10]); + } + + to.putLongArray(blockStatesName, writeBits.getData()); } public int c() { - return 1 + this.k.a() + PacketDataSerializer.a(this.c.b()) + this.c.a().length * 8; + return 1 + this.currentPalette.a() + PacketDataSerializer.a(this.dataBits.b()) + this.dataBits.getData().length * 8; } public boolean contains(Predicate var0) { - return this.k.a(var0); + return this.currentPalette.a(var0); } public void a(DataPaletteBlock.a var0) { Int2IntMap var1 = new Int2IntOpenHashMap(); - this.c.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); - var1.int2IntEntrySet().forEach((var1x) -> var0.accept(this.k.a(var1x.getIntKey()), var1x.getIntValue())); + this.dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); + var1.int2IntEntrySet().forEach((var1x) -> var0.accept(this.currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue())); } @FunctionalInterface From 5876598ca02cc42f34783a191091da4ceaf545b0 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:41:42 -0400 Subject: [PATCH 14/29] DP Global --- .../nbt/mca/palettes/DataPaletteGlobal.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteGlobal.java 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..67e4a9a6d --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteGlobal.java @@ -0,0 +1,76 @@ +/* + * 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 DataPaletteGlobal implements DataPalette { + private final RegistryBlockID a; + private final T b; + + public DataPaletteGlobal(RegistryBlockID var0, T var1) { + this.a = var0; + this.b = var1; + } + + public int getIndex(T var0) { + int var1 = this.a.getId(var0); + return var1 == -1 ? 0 : var1; + } + + public boolean a(Predicate var0) { + return true; + } + + public T getByIndex(int var0) { + T var1 = this.a.fromId(var0); + return var1 == null ? this.b : var1; + } + + public static int aa(int i) { + for(int j = 1; j < 5; ++j) { + if ((i & -1 << j * 7) == 0) { + return j; + } + } + + return 5; + } + + public int a() { + return aa(0); + } + + public int b() { + return this.a.size(); + } + + @Override + public void replace(ListTag t) { + + } + + @Override + public ListTag getPalette() { + return null; + } +} From a09c9f4a2ea4eda914e9db8011c965004426529e Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:41:50 -0400 Subject: [PATCH 15/29] DataPalette Hash fixes --- .../iris/util/nbt/mca/palettes/DataPaletteHash.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 index 060646e6e..ba41ba69a 100644 --- 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 @@ -18,9 +18,11 @@ package com.volmit.iris.util.nbt.mca.palettes; +import com.volmit.iris.Iris; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; import net.minecraft.network.PacketDataSerializer; +import net.minecraft.world.level.chunk.ChunkSection; import java.util.function.Function; import java.util.function.Predicate; @@ -42,7 +44,7 @@ public class DataPaletteHash implements DataPalette { this.b = new RegistryID(1 << var1); } - public int a(T var0) { + public int getIndex(T var0) { int var1 = this.b.getId(var0); if (var1 == -1) { var1 = this.b.c(var0); @@ -64,7 +66,7 @@ public class DataPaletteHash implements DataPalette { return false; } - public T a(int var0) { + public T getByIndex(int var0) { return this.b.fromId(var0); } @@ -102,7 +104,7 @@ public class DataPaletteHash implements DataPalette { return this.b.b(); } - public void a(ListTag var0) { + public void replace(ListTag var0) { this.b.a(); for (int var1 = 0; var1 < var0.size(); ++var1) { @@ -115,9 +117,9 @@ public class DataPaletteHash implements DataPalette { return null; } - public void b(ListTag var0) { + public void writePalette(ListTag var0) { for (int var1 = 0; var1 < this.b(); ++var1) { - var0.add(this.e.apply(this.b.fromId(var1))); + var0.add((CompoundTag) this.b.fromId(var1)); } } From babefc7bd36643f0fd6f0ef23be56d698013265b Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:41:55 -0400 Subject: [PATCH 16/29] Linear deobf --- .../iris/util/nbt/mca/palettes/DataPaletteLinear.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index 7823d40e7..7b9f5362e 100644 --- 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 @@ -41,10 +41,10 @@ public class DataPaletteLinear implements DataPalette { this.d = var3; } - public int a(T var0) { + public int getIndex(T var0) { int var1; for (var1 = 0; var1 < this.f; ++var1) { - if (this.b[var1] == var0) { + if (this.b[var1].equals(var0)) { return var1; } } @@ -69,7 +69,7 @@ public class DataPaletteLinear implements DataPalette { return false; } - public T a(int var0) { + public T getByIndex(int var0) { return var0 >= 0 && var0 < this.f ? this.b[var0] : null; } @@ -105,7 +105,7 @@ public class DataPaletteLinear implements DataPalette { return this.f; } - public void a(ListTag var0) { + public void replace(ListTag var0) { for (int var1 = 0; var1 < var0.size(); ++var1) { this.b[var1] = this.d.apply(var0.get(var1)); } From 62f6917d811077e110613b67a20af22ace95056d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:42:01 -0400 Subject: [PATCH 17/29] Regid fixes --- .../nbt/mca/palettes/RegistryBlockID.java | 45 +++++++------------ 1 file changed, 17 insertions(+), 28 deletions(-) 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 index dd63f5f48..e40dbc936 100644 --- 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 @@ -22,6 +22,7 @@ import com.google.common.base.Predicates; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; +import java.util.HashMap; import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; @@ -29,54 +30,42 @@ import java.util.List; public class RegistryBlockID implements Registry { public static final int a = -1; private int b; - private final IdentityHashMap c; - private final List d; + private final HashMap indexMap; + private final List indexes; + + public RegistryBlockID(IdentityHashMap c, List d, int b) { + this.indexMap = new HashMap<>(c); + this.indexes = d; + this.b = b; + } public RegistryBlockID() { this(512); } public RegistryBlockID(int var0) { - this.d = Lists.newArrayListWithExpectedSize(var0); - this.c = new IdentityHashMap(var0); - } - - public void a(T var0, int var1) { - this.c.put(var0, var1); - - while (this.d.size() <= var1) { - this.d.add(null); - } - - this.d.set(var1, var0); - if (this.b <= var1) { - this.b = var1 + 1; - } - - } - - public void b(T var0) { - this.a(var0, this.b); + this.indexes = Lists.newArrayListWithExpectedSize(var0); + this.indexMap = new HashMap<>(var0); } public int getId(T var0) { - Integer var1 = (Integer) this.c.get(var0); + Integer var1 = this.indexMap.get(var0); return var1 == null ? -1 : var1; } public final T fromId(int var0) { - return var0 >= 0 && var0 < this.d.size() ? this.d.get(var0) : null; + return var0 >= 0 && var0 < this.indexes.size() ? this.indexes.get(var0) : null; } public Iterator iterator() { - return Iterators.filter(this.d.iterator(), Predicates.notNull()); + return Iterators.filter(this.indexes.iterator(), Predicates.notNull()); } - public boolean b(int var0) { + public boolean hasIndex(int var0) { return this.fromId(var0) != null; } - public int a() { - return this.c.size(); + public int size() { + return this.indexMap.size(); } } From e7c1f31315841f9913f8f6b707410bc3bb56a888 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:42:26 -0400 Subject: [PATCH 18/29] Drop chunk support for 1.13 and below --- src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 23bf1ac99..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); From 04a54dbc2a03400ca75f14d5c53fc1f3c2702160 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:42:42 -0400 Subject: [PATCH 19/29] Integrate DP with sections --- .../com/volmit/iris/util/nbt/mca/MCAFile.java | 1 + .../com/volmit/iris/util/nbt/mca/Section.java | 91 ++----------------- 2 files changed, 10 insertions(+), 82 deletions(-) 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/Section.java b/src/main/java/com/volmit/iris/util/nbt/mca/Section.java index 2e95af170..1af31794e 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,21 +18,12 @@ 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 net.minecraft.world.level.chunk.Chunk; -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; @@ -54,7 +45,7 @@ public class Section { } palette = new DataPaletteBlock<>(); LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); - palette.a((ListTag) rawPalette, blockStates.getValue()); + palette.load((ListTag) rawPalette, blockStates.getValue()); ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight"); this.blockLight = blockLight != null ? blockLight.getValue() : null; @@ -64,18 +55,6 @@ public class Section { Section() { } - @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. * @@ -95,7 +74,7 @@ public class Section { * @return The block state data of this block. */ public synchronized CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) { - return palette.a(blockX, blockY, blockZ); + return palette.getBlock(blockX&15, blockY&15, blockZ&15); } /** @@ -107,59 +86,7 @@ public class Section { * @param state The block state to be set */ public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) { - - if(cleanup) - { - palette.setBlock(blockX, blockY, blockZ, state); - } - - else - { - palette.b(blockX, blockY, blockZ, state); - } - } - - /** - * 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)); - } - } - - 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); + palette.setBlock(blockX&15, blockY&15, blockZ&15, state); } /** @@ -174,7 +101,7 @@ public class Section { /** * @return The block light array of this Section */ - public byte[] getBlockLight() { + public synchronized byte[] getBlockLight() { return blockLight; } @@ -184,7 +111,7 @@ 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"); } @@ -194,7 +121,7 @@ public class Section { /** * @return The sky light values of this Section */ - public byte[] getSkyLight() { + public synchronized byte[] getSkyLight() { return skyLight; } @@ -204,7 +131,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"); } @@ -233,9 +160,9 @@ public class Section { */ public synchronized CompoundTag updateHandle(int y) { data.putByte("Y", (byte) y); + if (palette != null) { - data.put("Palette", palette.getK().getPalette()); - data.putLongArray("BlockStates", palette.getC().a()); + palette.save(data, "Palette", "BlockStates"); } if (blockLight != null) { data.putByteArray("BlockLight", blockLight); From c1b04ace780fa9e93c0b1d3f8134b8ebc4ecaa3d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:42:50 -0400 Subject: [PATCH 20/29] Fix atomic cache issues --- .../java/com/volmit/iris/engine/data/cache/AtomicCache.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 19289c809..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 @@ -80,6 +80,6 @@ public class AtomicCache { lock.unlock(); - return t.get(); + return this.t.get(); } } From 2929800a9f3c6bf9bd6659acd7201601b201351c Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 02:43:00 -0400 Subject: [PATCH 21/29] Global palette theft --- .../com/volmit/iris/core/nms/INMSBinding.java | 3 ++ .../iris/core/nms/v17_1/NMSBinding17_1.java | 31 +++++++++++++++++++ .../iris/core/nms/v1X/NMSBinding1X.java | 8 +++++ 3 files changed, 42 insertions(+) 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..90ce686c0 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..e98382053 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,9 @@ 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.IdentityHashMap; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class NMSBinding17_1 implements INMSBinding { @@ -63,6 +72,28 @@ 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"); + Field bf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("b"); + cf.setAccessible(true); + df.setAccessible(true); + bf.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<>(); + IdentityHashMap realMap = new IdentityHashMap<>(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, bf.getInt(blockData)); + + 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..ca986c8df 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; + } } From 2683c2433bc9d0dce2faffab4fe0d5e52f40cd7d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 03:55:25 -0400 Subject: [PATCH 22/29] Nasty suppliers --- .../java/com/volmit/iris/util/scheduling/J.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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(); From 1dce68212f3c76bba80b9ee38bb852e11cb8f972 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 03:55:39 -0400 Subject: [PATCH 23/29] No generics in the palette. --- .../iris/util/function/NastySupplier.java | 23 ++++ .../util/nbt/mca/palettes/DataPalette.java | 8 +- .../nbt/mca/palettes/DataPaletteBlock.java | 108 ++++++++---------- .../mca/palettes/DataPaletteExpandable.java | 6 +- .../nbt/mca/palettes/DataPaletteGlobal.java | 29 +++-- .../nbt/mca/palettes/DataPaletteHash.java | 60 +++++----- .../nbt/mca/palettes/DataPaletteLinear.java | 26 ++--- .../iris/util/nbt/mca/palettes/Registry.java | 8 +- .../nbt/mca/palettes/RegistryBlockID.java | 22 ++-- .../util/nbt/mca/palettes/RegistryID.java | 33 +++--- 10 files changed, 162 insertions(+), 161 deletions(-) create mode 100644 src/main/java/com/volmit/iris/util/function/NastySupplier.java diff --git a/src/main/java/com/volmit/iris/util/function/NastySupplier.java b/src/main/java/com/volmit/iris/util/function/NastySupplier.java new file mode 100644 index 000000000..d1c1c0048 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/function/NastySupplier.java @@ -0,0 +1,23 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.function; + +public interface NastySupplier { + T get() throws Throwable; +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java index 4426e4286..100947f30 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java @@ -23,12 +23,12 @@ import com.volmit.iris.util.nbt.tag.ListTag; import java.util.function.Predicate; -public interface DataPalette { - int getIndex(T var1); +public interface DataPalette { + int getIndex(CompoundTag var1); - boolean a(Predicate var1); + boolean a(Predicate var1); - T getByIndex(int var1); + CompoundTag getByIndex(int var1); int a(); 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 index eef62b14d..5f3b53c7c 100644 --- 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 @@ -24,67 +24,50 @@ import com.volmit.iris.util.math.MathHelper; 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.network.PacketDataSerializer; import org.bukkit.Material; -import java.util.function.Function; import java.util.function.Predicate; @Getter -public class DataPaletteBlock implements DataPaletteExpandable { +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 Function h; - private final Function i; - private final T defAir; - private static final AtomicCache> reg = new AtomicCache<>(); - private static final AtomicCache> global = new AtomicCache<>(); + 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 DataPalette currentPalette; private int bits = 0; public DataPaletteBlock() { - this((DataPalette) global.aquire(() -> - new DataPaletteGlobal<>(reg.aquire(() -> { - try { - return INMS.get().computeBlockIDRegistry(); - } catch (NoSuchFieldException ex) { - ex.printStackTrace(); - } catch (IllegalAccessException ex) { - ex.printStackTrace(); - } - return null; - }), air) - ), (RegistryBlockID) reg.aquire(() -> { - try { - return INMS.get().computeBlockIDRegistry(); - } catch (NoSuchFieldException ex) { - ex.printStackTrace(); - } catch (IllegalAccessException ex) { - ex.printStackTrace(); - } - return null; - }), (i) -> (T) i, (i) -> (CompoundTag) i, (T) air); + this(global(), registry(), air); } - public DataPaletteBlock(DataPalette var0, - RegistryBlockID var1, - Function var2, - Function var3, - T var4) { + private static RegistryBlockID registry() + { + return ((DataPaletteGlobal) global()).getRegistry(); + } + + private static DataPalette global() { + return (DataPalette) global.aquire(() -> new DataPaletteGlobal(J.attemptResult(() -> INMS.get().computeBlockIDRegistry()), air)); + } + + public DataPaletteBlock(DataPalette var0, + RegistryBlockID var1, + CompoundTag airType) { this.globalPalette = var0; this.stolenRegistry = var1; - this.h = var2; - this.i = var3; - this.defAir = var4; + this.defAir = airType; this.changeBitsTo(4); } @@ -97,9 +80,9 @@ public class DataPaletteBlock implements DataPaletteExpandable { this.bits = newbits; if (this.bits <= LINEAR_BITS) { this.bits = LINEAR_BITS; - this.currentPalette = new DataPaletteLinear(this.stolenRegistry, this.bits, this, this.h); + this.currentPalette = new DataPaletteLinear(this.stolenRegistry, this.bits, this); } else if (this.bits < HASH_BITS) { - this.currentPalette = new DataPaletteHash(this.stolenRegistry, this.bits, this, this.h, this.i); + this.currentPalette = new DataPaletteHash(this.stolenRegistry, this.bits, this); } else { this.currentPalette = this.globalPalette; this.bits = MathHelper.e(this.stolenRegistry.size()); @@ -110,52 +93,52 @@ public class DataPaletteBlock implements DataPaletteExpandable { } } - public int onResize(int var0, T var1) { + public int onResize(int newBits, CompoundTag newData) { DataBits var2 = this.dataBits; - DataPalette var3 = this.currentPalette; - this.changeBitsTo(var0); + DataPalette var3 = this.currentPalette; + this.changeBitsTo(newBits); for (int var4 = 0; var4 < var2.b(); ++var4) { - T var5 = var3.getByIndex(var2.getIndexFromPos(var4)); + CompoundTag var5 = var3.getByIndex(var2.getIndexFromPos(var4)); if (var5 != null) { this.setBlockIndex(var4, var5); } } - return this.currentPalette.getIndex(var1); + return this.currentPalette.getIndex(newData); } - public T setBlock(int var0, int var1, int var2, T var3) { + public CompoundTag setBlock(int var0, int var1, int var2, CompoundTag var3) { return this.a(blockIndex(var0, var1, var2), var3); } - private T a(int var0, T var1) { + private CompoundTag a(int var0, CompoundTag var1) { int var2 = this.currentPalette.getIndex(var1); int var3 = this.dataBits.a(var0, var2); - T var4 = this.currentPalette.getByIndex(var3); + CompoundTag var4 = this.currentPalette.getByIndex(var3); return var4 == null ? this.defAir : var4; } - public void c(int var0, int var1, int var2, T var3) { + public void c(int var0, int var1, int var2, CompoundTag var3) { this.setBlockIndex(blockIndex(var0, var1, var2), var3); } - private void setBlockIndex(int var0, T var1) { + private void setBlockIndex(int var0, CompoundTag var1) { int var2 = this.currentPalette.getIndex(var1); this.dataBits.b(var0, var2); } - public T getBlock(int var0, int var1, int var2) { + public CompoundTag getBlock(int var0, int var1, int var2) { return this.getByIndex(blockIndex(var0, var1, var2)); } - protected T getByIndex(int var0) { + protected CompoundTag getByIndex(int var0) { if(this.currentPalette == null) { return null; } - T data = this.currentPalette.getByIndex(this.dataBits.getIndexFromPos(var0)); + CompoundTag data = this.currentPalette.getByIndex(this.dataBits.getIndexFromPos(var0)); return data == null ? this.defAir : data; } @@ -168,7 +151,7 @@ public class DataPaletteBlock implements DataPaletteExpandable { this.currentPalette.replace(palettedata); int dblen = databits.length * 64 / 4096; if (this.currentPalette == this.globalPalette) { - DataPalette hashPalette = new DataPaletteHash(this.stolenRegistry, readBits, this.f, this.h, this.i); + DataPalette hashPalette = new DataPaletteHash(this.stolenRegistry, readBits, this.f); hashPalette.replace(palettedata); DataBits var5 = new DataBits(readBits, 4096, databits); @@ -187,13 +170,13 @@ public class DataPaletteBlock implements DataPaletteExpandable { } public void save(CompoundTag to, String paletteName, String blockStatesName) { - DataPaletteHash hashpal = new DataPaletteHash(this.stolenRegistry, bits, this.f, this.h, this.i); - T cursor = this.defAir; + DataPaletteHash hashpal = new DataPaletteHash(this.stolenRegistry, bits, this.f); + CompoundTag cursor = this.defAir; int palIndex = hashpal.getIndex(this.defAir); int[] var6 = new int[4096]; for (int var7 = 0; var7 < 4096; ++var7) { - T entry = this.getByIndex(var7); + CompoundTag entry = this.getByIndex(var7); if (!entry.equals(cursor)) { cursor = entry; palIndex = hashpal.getIndex(entry); @@ -213,24 +196,25 @@ public class DataPaletteBlock implements DataPaletteExpandable { } to.putLongArray(blockStatesName, writeBits.getData()); + to.putString("DEBUG_PALETTE_MODE", this.currentPalette.getClass().getSimpleName()); } public int c() { return 1 + this.currentPalette.a() + PacketDataSerializer.a(this.dataBits.b()) + this.dataBits.getData().length * 8; } - public boolean contains(Predicate var0) { + public boolean contains(Predicate var0) { return this.currentPalette.a(var0); } - public void a(DataPaletteBlock.a var0) { + public void a(PaletteConsumer var0) { Int2IntMap var1 = new Int2IntOpenHashMap(); this.dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); var1.int2IntEntrySet().forEach((var1x) -> var0.accept(this.currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue())); } @FunctionalInterface - public interface a { + 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/nbt/mca/palettes/DataPaletteExpandable.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java index ca1ac6d5b..21281139f 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java @@ -18,6 +18,8 @@ package com.volmit.iris.util.nbt.mca.palettes; -interface DataPaletteExpandable { - int onResize(int var1, T var2); +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 index 67e4a9a6d..673560465 100644 --- 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 @@ -20,30 +20,29 @@ 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; -public class DataPaletteGlobal implements DataPalette { - private final RegistryBlockID a; - private final T b; +@RequiredArgsConstructor +public class DataPaletteGlobal implements DataPalette { + @Getter + private final RegistryBlockID registry; + private final CompoundTag air; - public DataPaletteGlobal(RegistryBlockID var0, T var1) { - this.a = var0; - this.b = var1; - } - - public int getIndex(T var0) { - int var1 = this.a.getId(var0); + public int getIndex(CompoundTag var0) { + int var1 = this.registry.getId(var0); return var1 == -1 ? 0 : var1; } - public boolean a(Predicate var0) { + public boolean a(Predicate var0) { return true; } - public T getByIndex(int var0) { - T var1 = this.a.fromId(var0); - return var1 == null ? this.b : var1; + public CompoundTag getByIndex(int var0) { + CompoundTag var1 = this.registry.fromId(var0); + return var1 == null ? this.air : var1; } public static int aa(int i) { @@ -61,7 +60,7 @@ public class DataPaletteGlobal implements DataPalette { } public int b() { - return this.a.size(); + return this.registry.size(); } @Override 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 index ba41ba69a..a0fe4bf87 100644 --- 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 @@ -18,47 +18,41 @@ package com.volmit.iris.util.nbt.mca.palettes; -import com.volmit.iris.Iris; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; import net.minecraft.network.PacketDataSerializer; -import net.minecraft.world.level.chunk.ChunkSection; import java.util.function.Function; import java.util.function.Predicate; -public class DataPaletteHash implements DataPalette { - private final RegistryBlockID a; - private final RegistryID b; - private final DataPaletteExpandable c; - private final Function d; - private final Function e; - private final int f; +public class DataPaletteHash implements DataPalette { + private final RegistryBlockID registryBlock; + private final RegistryID registryId; + private final DataPaletteExpandable expander; + private final int bits; - public DataPaletteHash(RegistryBlockID var0, int var1, DataPaletteExpandable var2, Function var3, Function var4) { - this.a = var0; - this.f = var1; - this.c = var2; - this.d = var3; - this.e = var4; - this.b = new RegistryID(1 << var1); + public DataPaletteHash(RegistryBlockID var0, int bits, DataPaletteExpandable expander) { + this.registryBlock = var0; + this.bits = bits; + this.expander = expander; + this.registryId = new RegistryID(1 << bits); } - public int getIndex(T var0) { - int var1 = this.b.getId(var0); + public int getIndex(CompoundTag var0) { + int var1 = this.registryId.getId(var0); if (var1 == -1) { - var1 = this.b.c(var0); - if (var1 >= 1 << this.f) { - var1 = this.c.onResize(this.f + 1, var0); + var1 = this.registryId.c(var0); + if (var1 >= 1 << this.bits) { + var1 = this.expander.onResize(this.bits + 1, var0); } } return var1; } - public boolean a(Predicate var0) { + public boolean a(Predicate var0) { for (int var1 = 0; var1 < this.b(); ++var1) { - if (var0.test(this.b.fromId(var1))) { + if (var0.test(this.registryId.fromId(var1))) { return true; } } @@ -66,16 +60,16 @@ public class DataPaletteHash implements DataPalette { return false; } - public T getByIndex(int var0) { - return this.b.fromId(var0); + public CompoundTag getByIndex(int var0) { + return this.registryId.fromId(var0); } public void a(PacketDataSerializer var0) { - this.b.a(); + this.registryId.a(); int var1 = var0.j(); for (int var2 = 0; var2 < var1; ++var2) { - this.b.c(this.a.fromId(var0.j())); + this.registryId.c(this.registryBlock.fromId(var0.j())); } } @@ -85,7 +79,7 @@ public class DataPaletteHash implements DataPalette { var0.d(var1); for (int var2 = 0; var2 < var1; ++var2) { - var0.d(this.a.getId(this.b.fromId(var2))); + var0.d(this.registryBlock.getId(this.registryId.fromId(var2))); } } @@ -94,21 +88,21 @@ public class DataPaletteHash implements DataPalette { int var0 = PacketDataSerializer.a(this.b()); for (int var1 = 0; var1 < this.b(); ++var1) { - var0 += PacketDataSerializer.a(this.a.getId(this.b.fromId(var1))); + var0 += PacketDataSerializer.a(this.registryBlock.getId(this.registryId.fromId(var1))); } return var0; } public int b() { - return this.b.b(); + return this.registryId.b(); } public void replace(ListTag var0) { - this.b.a(); + this.registryId.a(); for (int var1 = 0; var1 < var0.size(); ++var1) { - this.b.c(this.d.apply(var0.get(var1))); + this.registryId.c(var0.get(var1)); } } @@ -119,7 +113,7 @@ public class DataPaletteHash implements DataPalette { public void writePalette(ListTag var0) { for (int var1 = 0; var1 < this.b(); ++var1) { - var0.add((CompoundTag) this.b.fromId(var1)); + var0.add((CompoundTag) this.registryId.fromId(var1)); } } 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 index 7b9f5362e..274e91bf6 100644 --- 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 @@ -25,23 +25,21 @@ import net.minecraft.network.PacketDataSerializer; import java.util.function.Function; import java.util.function.Predicate; -public class DataPaletteLinear implements DataPalette { - private final RegistryBlockID a; - private final T[] b; - private final DataPaletteExpandable c; - private final Function d; +public class DataPaletteLinear implements DataPalette { + private final RegistryBlockID a; + private final CompoundTag[] b; + private final DataPaletteExpandable c; private final int e; private int f; - public DataPaletteLinear(RegistryBlockID var0, int var1, DataPaletteExpandable var2, Function var3) { + public DataPaletteLinear(RegistryBlockID var0, int var1, DataPaletteExpandable var2) { this.a = var0; - this.b = (T[]) new Object[1 << var1]; + this.b = (CompoundTag[]) new Object[1 << var1]; this.e = var1; this.c = var2; - this.d = var3; } - public int getIndex(T var0) { + public int getIndex(CompoundTag var0) { int var1; for (var1 = 0; var1 < this.f; ++var1) { if (this.b[var1].equals(var0)) { @@ -59,7 +57,7 @@ public class DataPaletteLinear implements DataPalette { } } - public boolean a(Predicate var0) { + public boolean a(Predicate var0) { for (int var1 = 0; var1 < this.f; ++var1) { if (var0.test(this.b[var1])) { return true; @@ -69,7 +67,7 @@ public class DataPaletteLinear implements DataPalette { return false; } - public T getByIndex(int var0) { + public CompoundTag getByIndex(int var0) { return var0 >= 0 && var0 < this.f ? this.b[var0] : null; } @@ -107,7 +105,7 @@ public class DataPaletteLinear implements DataPalette { public void replace(ListTag var0) { for (int var1 = 0; var1 < var0.size(); ++var1) { - this.b[var1] = this.d.apply(var0.get(var1)); + this.b[var1] = var0.get(var1); } this.f = var0.size(); @@ -116,9 +114,9 @@ public class DataPaletteLinear implements DataPalette { @Override public ListTag getPalette() { ListTag c = (ListTag) ListTag.createUnchecked(CompoundTag.class); - for(T i : b) + for(CompoundTag i : b) { - c.add((CompoundTag) i); + c.add(i); } return c; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java index 116185714..ad5898524 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java @@ -18,8 +18,10 @@ package com.volmit.iris.util.nbt.mca.palettes; -public interface Registry extends Iterable { - int getId(T var1); +import com.volmit.iris.util.nbt.tag.CompoundTag; - T fromId(int var1); +public interface Registry extends Iterable { + int getId(CompoundTag var1); + + CompoundTag fromId(int var1); } \ 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 index e40dbc936..21e5077aa 100644 --- 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 @@ -21,20 +21,18 @@ package com.volmit.iris.util.nbt.mca.palettes; import com.google.common.base.Predicates; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; +import com.volmit.iris.util.nbt.tag.CompoundTag; -import java.util.HashMap; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.List; +import java.util.*; -public class RegistryBlockID implements Registry { +public class RegistryBlockID implements Registry { public static final int a = -1; private int b; - private final HashMap indexMap; - private final List indexes; + private final Map indexMap; + private final List indexes; - public RegistryBlockID(IdentityHashMap c, List d, int b) { - this.indexMap = new HashMap<>(c); + public RegistryBlockID(Map c, List d, int b) { + this.indexMap = c; this.indexes = d; this.b = b; } @@ -48,16 +46,16 @@ public class RegistryBlockID implements Registry { this.indexMap = new HashMap<>(var0); } - public int getId(T var0) { + public int getId(CompoundTag var0) { Integer var1 = this.indexMap.get(var0); return var1 == null ? -1 : var1; } - public final T fromId(int var0) { + public final CompoundTag fromId(int var0) { return var0 >= 0 && var0 < this.indexes.size() ? this.indexes.get(var0) : null; } - public Iterator iterator() { + public Iterator iterator() { return Iterators.filter(this.indexes.iterator(), Predicates.notNull()); } 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 index 334c21371..30f4be9d8 100644 --- 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 @@ -21,32 +21,33 @@ package com.volmit.iris.util.nbt.mca.palettes; import com.google.common.base.Predicates; 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; -public class RegistryID implements Registry { +public class RegistryID implements Registry { public static final int a = -1; private static final Object b = null; private static final float c = 0.8F; - private K[] d; + private CompoundTag[] d; private int[] e; - private K[] f; + private CompoundTag[] f; private int g; private int h; public RegistryID(int var0) { var0 = (int) ((float) var0 / 0.8F); - this.d = (K[]) new Object[var0]; + this.d = (CompoundTag[]) new Object[var0]; this.e = new int[var0]; - this.f = (K[]) new Object[var0]; + this.f = (CompoundTag[]) new Object[var0]; } - public int getId(K var0) { + public int getId(CompoundTag var0) { return this.c(this.b(var0, this.d(var0))); } - public K fromId(int var0) { + public CompoundTag fromId(int var0) { return var0 >= 0 && var0 < this.f.length ? this.f[var0] : null; } @@ -54,7 +55,7 @@ public class RegistryID implements Registry { return var0 == -1 ? -1 : this.e[var0]; } - public boolean b(K var0) { + public boolean b(CompoundTag var0) { return this.getId(var0) != -1; } @@ -62,7 +63,7 @@ public class RegistryID implements Registry { return this.fromId(var0) != null; } - public int c(K var0) { + public int c(CompoundTag var0) { int var1 = this.c(); this.a(var0, var1); return var1; @@ -77,11 +78,11 @@ public class RegistryID implements Registry { } private void d(int var0) { - K[] var1 = this.d; + CompoundTag[] var1 = this.d; int[] var2 = this.e; - this.d = (K[]) new Object[var0]; + this.d = (CompoundTag[]) new Object[var0]; this.e = new int[var0]; - this.f = (K[]) new Object[var0]; + this.f = (CompoundTag[]) new Object[var0]; this.g = 0; this.h = 0; @@ -93,7 +94,7 @@ public class RegistryID implements Registry { } - public void a(K var0, int var1) { + public void a(CompoundTag var0, int var1) { int var2 = Math.max(var1, this.h + 1); int var3; if ((float) var2 >= (float) this.d.length * 0.8F) { @@ -114,11 +115,11 @@ public class RegistryID implements Registry { } - private int d(K var0) { + private int d(CompoundTag var0) { return (MathHelper.g(System.identityHashCode(var0)) & 2147483647) % this.d.length; } - private int b(K var0, int var1) { + private int b(CompoundTag var0, int var1) { int var2; for (var2 = var1; var2 < this.d.length; ++var2) { if (this.d[var2] == var0) { @@ -160,7 +161,7 @@ public class RegistryID implements Registry { throw new RuntimeException("Overflowed :("); } - public Iterator iterator() { + public Iterator iterator() { return Iterators.filter(Iterators.forArray(this.f), Predicates.notNull()); } From ca228ca23ef5ee4d9c7b54ec1ec805370f64b971 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 03:55:47 -0400 Subject: [PATCH 24/29] Fix palettes --- .../com/volmit/iris/util/nbt/mca/Section.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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 1af31794e..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 @@ -27,7 +27,7 @@ import com.volmit.iris.util.nbt.tag.LongArrayTag; public class Section { private CompoundTag data; - private DataPaletteBlock palette; + private DataPaletteBlock palette; private byte[] blockLight; private byte[] skyLight; private int dataVersion; @@ -43,7 +43,7 @@ public class Section { if (rawPalette == null) { return; } - palette = new DataPaletteBlock<>(); + palette = new DataPaletteBlock(); LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); palette.load((ListTag) rawPalette, blockStates.getValue()); ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); @@ -74,7 +74,10 @@ public class Section { * @return The block state data of this block. */ public synchronized CompoundTag getBlockStateAt(int blockX, int blockY, int blockZ) { - return palette.getBlock(blockX&15, blockY&15, blockZ&15); + synchronized (palette) + { + return palette.getBlock(blockX&15, blockY&15, blockZ&15); + } } /** @@ -86,7 +89,10 @@ public class Section { * @param state The block state to be set */ public synchronized void setBlockStateAt(int blockX, int blockY, int blockZ, CompoundTag state, boolean cleanup) { - palette.setBlock(blockX&15, blockY&15, blockZ&15, state); + synchronized (palette) + { + palette.setBlock(blockX&15, blockY&15, blockZ&15, state); + } } /** @@ -145,7 +151,7 @@ public class Section { */ public static Section newSection() { Section s = new Section(); - s.palette = new DataPaletteBlock<>(); + s.palette = new DataPaletteBlock(); s.data = new CompoundTag(); return s; } @@ -162,7 +168,10 @@ public class Section { data.putByte("Y", (byte) y); if (palette != null) { - palette.save(data, "Palette", "BlockStates"); + synchronized (palette) + { + palette.save(data, "Palette", "BlockStates"); + } } if (blockLight != null) { data.putByteArray("BlockLight", blockLight); From 013d6625d597ca80991627debbed400a896c9763 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 03:55:54 -0400 Subject: [PATCH 25/29] More fixes --- src/main/java/com/volmit/iris/core/nms/INMSBinding.java | 2 +- src/main/java/com/volmit/iris/core/nms/v1X/NMSBinding1X.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 90ce686c0..f6c218166 100644 --- a/src/main/java/com/volmit/iris/core/nms/INMSBinding.java +++ b/src/main/java/com/volmit/iris/core/nms/INMSBinding.java @@ -76,5 +76,5 @@ public interface INMSBinding { return false; } - RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException; + RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException; } 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 ca986c8df..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 @@ -146,7 +146,7 @@ public class NMSBinding1X implements INMSBinding { } @Override - public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { + 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; } From 6b7bd75b18e3323eeb8c4a1208282c8c84d8cebe Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 03:56:00 -0400 Subject: [PATCH 26/29] DONT USE IDENTITY! --- .../com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 e98382053..1868126d0 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 @@ -60,6 +60,7 @@ 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; @@ -73,7 +74,7 @@ public class NMSBinding17_1 implements INMSBinding { } @Override - public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { + public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c"); Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d"); Field bf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("b"); @@ -84,13 +85,11 @@ public class NMSBinding17_1 implements INMSBinding { IdentityHashMap c = (IdentityHashMap) cf.get(blockData); List d = (List) df.get(blockData); List realTags = new ArrayList<>(); - IdentityHashMap realMap = new IdentityHashMap<>(512); + 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, bf.getInt(blockData)); - + RegistryBlockID registry = new RegistryBlockID(realMap, realTags, bf.getInt(blockData)); Iris.info("INMS: Stole Global Palette: " + realTags.size() + " Tags, " + realMap.size() + " Mapped"); - return registry; } From ba31a569493d4645c81015b6c6823c74586e28ac Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 05:18:07 -0400 Subject: [PATCH 27/29] Allow get value on tags --- src/main/java/com/volmit/iris/util/nbt/tag/ListTag.java | 2 +- src/main/java/com/volmit/iris/util/nbt/tag/Tag.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 0fbaff2e6..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 @@ -308,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; } From ef02e5169d06c04d99837490c75debd234cf8955 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 05:18:13 -0400 Subject: [PATCH 28/29] More cleanup --- .../iris/util/nbt/mca/palettes/DataBits.java | 76 ++++---- .../util/nbt/mca/palettes/DataPalette.java | 14 +- .../nbt/mca/palettes/DataPaletteBlock.java | 167 +++++++++--------- .../nbt/mca/palettes/DataPaletteGlobal.java | 41 ++--- .../nbt/mca/palettes/DataPaletteHash.java | 84 +++------ .../nbt/mca/palettes/DataPaletteLinear.java | 104 ++++------- .../iris/util/nbt/mca/palettes/Registry.java | 4 +- .../nbt/mca/palettes/RegistryBlockID.java | 16 +- .../util/nbt/mca/palettes/RegistryID.java | 70 ++++---- 9 files changed, 235 insertions(+), 341 deletions(-) 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 index 016302d1d..7755ddd1a 100644 --- 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 @@ -24,10 +24,10 @@ 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[] b; + private final long[] data; private final int c; - private final long d; - private final int e; + private final long paletteSize; + private final int blockSize; private final int f; private final int g; private final int h; @@ -37,25 +37,25 @@ public class DataBits { this(var0, var1, (long[]) null); } - public DataBits(int var0, int var1, long[] var2) { - Validate.inclusiveBetween(1L, 32L, (long) var0); - this.e = var1; - this.c = var0; - this.d = (1L << var0) - 1L; - this.f = (char) (64 / var0); + 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 (var2 != null) { - if (var2.length != var4) { - throw new RuntimeException("Invalid length given for storage, got: " + var2.length + " but expected: " + var4); + if (data != null) { + if (data.length != var4) { + throw new RuntimeException("Invalid length given for storage, got: " + data.length + " but expected: " + var4); } - this.b = var2; + this.data = data; } else { - this.b = new long[var4]; + this.data = new long[var4]; } } @@ -66,57 +66,57 @@ public class DataBits { return (int) ((long) var0 * var1 + var3 >> 32 >> this.i); } - public int a(int var0, int var1) { - Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); - Validate.inclusiveBetween(0L, this.d, (long) var1); - int var2 = this.b(var0); - long var3 = this.b[var2]; - int var5 = (var0 - var2 * this.f) * this.c; - int var6 = (int) (var3 >> var5 & this.d); - this.b[var2] = var3 & ~(this.d << var5) | ((long) var1 & this.d) << var5; + 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 b(int var0, int var1) { - Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); - Validate.inclusiveBetween(0L, this.d, (long) var1); - int var2 = this.b(var0); - long var3 = this.b[var2]; - int var5 = (var0 - var2 * this.f) * this.c; - this.b[var2] = var3 & ~(this.d << var5) | ((long) var1 & this.d) << var5; + 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.e - 1), (long) var0); + Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) var0); int var1 = this.b(var0); - long var2 = this.b[var1]; + long var2 = this.data[var1]; int var4 = (var0 - var1 * this.f) * this.c; - return (int) (var2 >> var4 & this.d); + return (int) (var2 >> var4 & this.paletteSize); } public long[] getData() { - return this.b; + return this.data; } public int b() { - return this.e; + return this.blockSize; } - public int c() { + public int getBitsPerBlock() { return this.c; } public void a(IntConsumer var0) { int var1 = 0; - long[] var3 = this.b; + 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.d)); + var0.accept((int) (var5 & this.paletteSize)); var5 >>= this.c; ++var1; - if (var1 >= this.e) { + if (var1 >= this.blockSize) { return; } } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java index 100947f30..f0d4e81e0 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java @@ -24,17 +24,13 @@ import com.volmit.iris.util.nbt.tag.ListTag; import java.util.function.Predicate; public interface DataPalette { - int getIndex(CompoundTag var1); + int getIndex(CompoundTag block); - boolean a(Predicate var1); + boolean contains(Predicate predicate); - CompoundTag getByIndex(int var1); + CompoundTag getByIndex(int index); - int a(); + int size(); - int b(); - - void replace(ListTag t); - - ListTag getPalette(); + 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 index 5f3b53c7c..3f1155e13 100644 --- 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 @@ -18,9 +18,11 @@ 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; @@ -28,10 +30,14 @@ 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.network.PacketDataSerializer; +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 { @@ -52,16 +58,7 @@ public class DataPaletteBlock implements DataPaletteExpandable { public DataPaletteBlock() { this(global(), registry(), air); } - - private static RegistryBlockID registry() - { - return ((DataPaletteGlobal) global()).getRegistry(); - } - - private static DataPalette global() { - return (DataPalette) global.aquire(() -> new DataPaletteGlobal(J.attemptResult(() -> INMS.get().computeBlockIDRegistry()), air)); - } - + public DataPaletteBlock(DataPalette var0, RegistryBlockID var1, CompoundTag airType) { @@ -71,146 +68,154 @@ public class DataPaletteBlock implements DataPaletteExpandable { this.changeBitsTo(4); } - private static int blockIndex(int var0, int var1, int var2) { - return var1 << 8 | var2 << 4 | var0; + 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 != this.bits) { - this.bits = newbits; - if (this.bits <= LINEAR_BITS) { - this.bits = LINEAR_BITS; - this.currentPalette = new DataPaletteLinear(this.stolenRegistry, this.bits, this); - } else if (this.bits < HASH_BITS) { - this.currentPalette = new DataPaletteHash(this.stolenRegistry, this.bits, this); + 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 { - this.currentPalette = this.globalPalette; - this.bits = MathHelper.e(this.stolenRegistry.size()); + currentPalette = globalPalette; + bits = MathHelper.e(stolenRegistry.size()); } - this.currentPalette.getIndex(this.defAir); - this.dataBits = new DataBits(this.bits, 4096); + currentPalette.getIndex(defAir); + dataBits = new DataBits(bits, 4096); } } public int onResize(int newBits, CompoundTag newData) { - DataBits var2 = this.dataBits; - DataPalette var3 = this.currentPalette; - this.changeBitsTo(newBits); + DataBits oldBits = dataBits; + DataPalette oldPalette = currentPalette; + changeBitsTo(newBits); - for (int var4 = 0; var4 < var2.b(); ++var4) { - CompoundTag var5 = var3.getByIndex(var2.getIndexFromPos(var4)); - if (var5 != null) { - this.setBlockIndex(var4, var5); + for (int i = 0; i < oldBits.b(); ++i) { + CompoundTag block = oldPalette.getByIndex(oldBits.getIndexFromPos(i)); + if (block != null) { + setBlockIndex(i, block); } } - return this.currentPalette.getIndex(newData); + return currentPalette.getIndex(newData); } - public CompoundTag setBlock(int var0, int var1, int var2, CompoundTag var3) { - return this.a(blockIndex(var0, var1, var2), var3); + @Deprecated + public CompoundTag setBlockAndReturn(int x, int y, int z, CompoundTag block) { + return setBlockIndexAndReturn(blockIndex(x, y, z), block); } - private CompoundTag a(int var0, CompoundTag var1) { - int var2 = this.currentPalette.getIndex(var1); - int var3 = this.dataBits.a(var0, var2); - CompoundTag var4 = this.currentPalette.getByIndex(var3); - return var4 == null ? this.defAir : var4; + @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 c(int var0, int var1, int var2, CompoundTag var3) { - this.setBlockIndex(blockIndex(var0, var1, var2), var3); + public void setBlock(int x, int y, int z, CompoundTag block) { + setBlockIndex(blockIndex(x, y, z), block); } - private void setBlockIndex(int var0, CompoundTag var1) { - int var2 = this.currentPalette.getIndex(var1); - this.dataBits.b(var0, var2); + private void setBlockIndex(int blockIndex, CompoundTag block) { + int paletteIndex = currentPalette.getIndex(block); + dataBits.setBlock(blockIndex, paletteIndex); } - public CompoundTag getBlock(int var0, int var1, int var2) { - return this.getByIndex(blockIndex(var0, var1, var2)); + public CompoundTag getBlock(int x, int y, int z) { + return getByIndex(blockIndex(x, y, z)); } - protected CompoundTag getByIndex(int var0) { - if(this.currentPalette == null) + protected CompoundTag getByIndex(int index) { + if(currentPalette == null) { return null; } - CompoundTag data = this.currentPalette.getByIndex(this.dataBits.getIndexFromPos(var0)); - return data == null ? this.defAir : data; + 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 != this.bits) { - this.changeBitsTo(readBits); + if (readBits != bits) { + changeBitsTo(readBits); } - this.currentPalette.replace(palettedata); + currentPalette.replace(palettedata); int dblen = databits.length * 64 / 4096; - if (this.currentPalette == this.globalPalette) { - DataPalette hashPalette = new DataPaletteHash(this.stolenRegistry, readBits, this.f); + if (currentPalette == globalPalette) { + DataPalette hashPalette = new DataPaletteHash(readBits, f); hashPalette.replace(palettedata); DataBits var5 = new DataBits(readBits, 4096, databits); - for (int var6 = 0; var6 < 4096; ++var6) { - this.dataBits.b(var6, this.globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(var6)))); + for (int i = 0; i < 4096; ++i) { + dataBits.setBlock(i, globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(i)))); } - } else if (dblen == this.bits) { - System.arraycopy(databits, 0, this.dataBits.getData(), 0, databits.length); + } else if (dblen == bits) { + System.arraycopy(databits, 0, dataBits.getData(), 0, databits.length); } else { DataBits var4 = new DataBits(dblen, 4096, databits); - for (int var5 = 0; var5 < 4096; ++var5) { - this.dataBits.b(var5, var4.getIndexFromPos(var5)); + 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(this.stolenRegistry, bits, this.f); - CompoundTag cursor = this.defAir; - int palIndex = hashpal.getIndex(this.defAir); - int[] var6 = new int[4096]; - - for (int var7 = 0; var7 < 4096; ++var7) { - CompoundTag entry = this.getByIndex(var7); + 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); } - var6[var7] = palIndex; + paletteIndex[i] = palIndex; } ListTag npalette = (ListTag) ListTag.createUnchecked(CompoundTag.class); hashpal.writePalette(npalette); to.put(paletteName, npalette); - int var8 = Math.max(4, MathHelper.e(npalette.size())); - DataBits writeBits = new DataBits(var8, 4096); + int bits = Math.max(4, MathHelper.e(npalette.size())); + DataBits writeBits = new DataBits(bits, 4096); - for (int var10 = 0; var10 < var6.length; ++var10) { - writeBits.b(var10, var6[var10]); + for (i = 0; i < paletteIndex.length; ++i) { + writeBits.setBlock(i, paletteIndex[i]); } to.putLongArray(blockStatesName, writeBits.getData()); - to.putString("DEBUG_PALETTE_MODE", this.currentPalette.getClass().getSimpleName()); - } - - public int c() { - return 1 + this.currentPalette.a() + PacketDataSerializer.a(this.dataBits.b()) + this.dataBits.getData().length * 8; + to.putString("DEBUG_PALETTE_MODE", currentPalette.getClass().getSimpleName()); } public boolean contains(Predicate var0) { - return this.currentPalette.a(var0); + return currentPalette.contains(var0); } public void a(PaletteConsumer var0) { Int2IntMap var1 = new Int2IntOpenHashMap(); - this.dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); - var1.int2IntEntrySet().forEach((var1x) -> var0.accept(this.currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue())); + dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); + var1.int2IntEntrySet().forEach((var1x) -> var0.accept(currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue())); } @FunctionalInterface 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 index 673560465..f18e972fa 100644 --- 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 @@ -31,45 +31,26 @@ public class DataPaletteGlobal implements DataPalette { private final RegistryBlockID registry; private final CompoundTag air; - public int getIndex(CompoundTag var0) { - int var1 = this.registry.getId(var0); - return var1 == -1 ? 0 : var1; + public int getIndex(CompoundTag block) { + int id = this.registry.getId(block); + return id == -1 ? 0 : id; } - public boolean a(Predicate var0) { + public boolean contains(Predicate predicate) { return true; } - public CompoundTag getByIndex(int var0) { - CompoundTag var1 = this.registry.fromId(var0); - return var1 == null ? this.air : var1; + public CompoundTag getByIndex(int index) { + CompoundTag block = registry.fromId(index); + return block == null ? air : block; } - public static int aa(int i) { - for(int j = 1; j < 5; ++j) { - if ((i & -1 << j * 7) == 0) { - return j; - } - } - - return 5; - } - - public int a() { - return aa(0); - } - - public int b() { - return this.registry.size(); + public int size() { + return registry.size(); } @Override - public void replace(ListTag t) { - - } - - @Override - public ListTag getPalette() { - return null; + 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 index a0fe4bf87..a2c66622e 100644 --- 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 @@ -20,39 +20,35 @@ 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 net.minecraft.network.PacketDataSerializer; -import java.util.function.Function; import java.util.function.Predicate; public class DataPaletteHash implements DataPalette { - private final RegistryBlockID registryBlock; private final RegistryID registryId; private final DataPaletteExpandable expander; private final int bits; - public DataPaletteHash(RegistryBlockID var0, int bits, DataPaletteExpandable expander) { - this.registryBlock = var0; + public DataPaletteHash(int bits, DataPaletteExpandable expander) { this.bits = bits; this.expander = expander; this.registryId = new RegistryID(1 << bits); } - public int getIndex(CompoundTag var0) { - int var1 = this.registryId.getId(var0); - if (var1 == -1) { - var1 = this.registryId.c(var0); - if (var1 >= 1 << this.bits) { - var1 = this.expander.onResize(this.bits + 1, var0); + 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 var1; + return id; } - public boolean a(Predicate var0) { - for (int var1 = 0; var1 < this.b(); ++var1) { - if (var0.test(this.registryId.fromId(var1))) { + public boolean contains(Predicate predicate) { + for (int i = 0; i < size(); ++i) { + if (predicate.test(registryId.fromId(i))) { return true; } } @@ -60,61 +56,25 @@ public class DataPaletteHash implements DataPalette { return false; } - public CompoundTag getByIndex(int var0) { - return this.registryId.fromId(var0); + public CompoundTag getByIndex(int index) { + return registryId.fromId(index); } - public void a(PacketDataSerializer var0) { - this.registryId.a(); - int var1 = var0.j(); - - for (int var2 = 0; var2 < var1; ++var2) { - this.registryId.c(this.registryBlock.fromId(var0.j())); - } - + public int size() { + return registryId.size(); } - public void b(PacketDataSerializer var0) { - int var1 = this.b(); - var0.d(var1); + public void replace(ListTag palette) { + registryId.clear(); - for (int var2 = 0; var2 < var1; ++var2) { - var0.d(this.registryBlock.getId(this.registryId.fromId(var2))); - } - - } - - public int a() { - int var0 = PacketDataSerializer.a(this.b()); - - for (int var1 = 0; var1 < this.b(); ++var1) { - var0 += PacketDataSerializer.a(this.registryBlock.getId(this.registryId.fromId(var1))); - } - - return var0; - } - - public int b() { - return this.registryId.b(); - } - - public void replace(ListTag var0) { - this.registryId.a(); - - for (int var1 = 0; var1 < var0.size(); ++var1) { - this.registryId.c(var0.get(var1)); + for (int i = 0; i < palette.size(); ++i) { + registryId.c(palette.get(i)); } } - @Override - public ListTag getPalette() { - return null; - } - - public void writePalette(ListTag var0) { - for (int var1 = 0; var1 < this.b(); ++var1) { - var0.add((CompoundTag) this.registryId.fromId(var1)); + 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 index 274e91bf6..6a4900230 100644 --- 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 @@ -20,46 +20,43 @@ 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 net.minecraft.network.PacketDataSerializer; -import java.util.function.Function; import java.util.function.Predicate; public class DataPaletteLinear implements DataPalette { - private final RegistryBlockID a; - private final CompoundTag[] b; - private final DataPaletteExpandable c; + private final CompoundTag[] palette; + private final DataPaletteExpandable expander; private final int e; - private int f; + private int size; - public DataPaletteLinear(RegistryBlockID var0, int var1, DataPaletteExpandable var2) { - this.a = var0; - this.b = (CompoundTag[]) new Object[1 << var1]; - this.e = var1; - this.c = var2; + 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 var0) { - int var1; - for (var1 = 0; var1 < this.f; ++var1) { - if (this.b[var1].equals(var0)) { - return var1; + public int getIndex(CompoundTag block) { + int i; + for (i = 0; i < size; ++i) { + if (palette[i].equals(block)) { + return i; } } - var1 = this.f; - if (var1 < this.b.length) { - this.b[var1] = var0; - ++this.f; - return var1; + i = size; + if (i < palette.length) { + palette[i] = block; + ++size; + return i; } else { - return this.c.onResize(this.e + 1, var0); + return expander.onResize(e + 1, block); } } - public boolean a(Predicate var0) { - for (int var1 = 0; var1 < this.f; ++var1) { - if (var0.test(this.b[var1])) { + public boolean contains(Predicate predicate) { + for (int i = 0; i < this.size; ++i) { + if (predicate.test(palette[i])) { return true; } } @@ -67,58 +64,19 @@ public class DataPaletteLinear implements DataPalette { return false; } - public CompoundTag getByIndex(int var0) { - return var0 >= 0 && var0 < this.f ? this.b[var0] : null; + public CompoundTag getByIndex(int index) { + return index >= 0 && index < size ? palette[index] : null; } - public void a(PacketDataSerializer var0) { - this.f = var0.j(); + public int size() { + return size; + } - for (int var1 = 0; var1 < this.f; ++var1) { - this.b[var1] = this.a.fromId(var0.j()); + public void replace(ListTag palette) { + for (int i = 0; i < palette.size(); ++i) { + this.palette[i] = palette.get(i); } - } - - public void b(PacketDataSerializer var0) { - var0.d(this.f); - - for (int var1 = 0; var1 < this.f; ++var1) { - var0.d(this.a.getId(this.b[var1])); - } - - } - - public int a() { - int var0 = PacketDataSerializer.a(this.b()); - - for (int var1 = 0; var1 < this.b(); ++var1) { - var0 += PacketDataSerializer.a(this.a.getId(this.b[var1])); - } - - return var0; - } - - public int b() { - return this.f; - } - - public void replace(ListTag var0) { - for (int var1 = 0; var1 < var0.size(); ++var1) { - this.b[var1] = var0.get(var1); - } - - this.f = var0.size(); - } - - @Override - public ListTag getPalette() { - ListTag c = (ListTag) ListTag.createUnchecked(CompoundTag.class); - for(CompoundTag i : b) - { - c.add(i); - } - - return c; + this.size = palette.size(); } } diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java index ad5898524..db0c77550 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java @@ -21,7 +21,7 @@ package com.volmit.iris.util.nbt.mca.palettes; import com.volmit.iris.util.nbt.tag.CompoundTag; public interface Registry extends Iterable { - int getId(CompoundTag var1); + int getId(CompoundTag block); - CompoundTag fromId(int var1); + 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 index 21e5077aa..3b636d124 100644 --- 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 @@ -18,7 +18,6 @@ package com.volmit.iris.util.nbt.mca.palettes; -import com.google.common.base.Predicates; import com.google.common.collect.Iterators; import com.google.common.collect.Lists; import com.volmit.iris.util.nbt.tag.CompoundTag; @@ -26,15 +25,12 @@ import com.volmit.iris.util.nbt.tag.CompoundTag; import java.util.*; public class RegistryBlockID implements Registry { - public static final int a = -1; - private int b; private final Map indexMap; private final List indexes; - public RegistryBlockID(Map c, List d, int b) { + public RegistryBlockID(Map c, List d) { this.indexMap = c; this.indexes = d; - this.b = b; } public RegistryBlockID() { @@ -46,17 +42,17 @@ public class RegistryBlockID implements Registry { this.indexMap = new HashMap<>(var0); } - public int getId(CompoundTag var0) { - Integer var1 = this.indexMap.get(var0); + public int getId(CompoundTag block) { + Integer var1 = this.indexMap.get(block); return var1 == null ? -1 : var1; } - public final CompoundTag fromId(int var0) { - return var0 >= 0 && var0 < this.indexes.size() ? this.indexes.get(var0) : null; + 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(), Predicates.notNull()); + return Iterators.filter(this.indexes.iterator(), Objects::nonNull); } public boolean hasIndex(int var0) { 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 index 30f4be9d8..416ccf252 100644 --- 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 @@ -18,37 +18,37 @@ package com.volmit.iris.util.nbt.mca.palettes; -import com.google.common.base.Predicates; 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 Object b = null; + 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 h; + private int size; public RegistryID(int var0) { var0 = (int) ((float) var0 / 0.8F); - this.d = (CompoundTag[]) new Object[var0]; + this.d = new CompoundTag[var0]; + this.f = new CompoundTag[var0]; this.e = new int[var0]; - this.f = (CompoundTag[]) new Object[var0]; } - public int getId(CompoundTag var0) { - return this.c(this.b(var0, this.d(var0))); + public int getId(CompoundTag block) { + return this.c(this.b(block, this.d(block))); } - public CompoundTag fromId(int var0) { - return var0 >= 0 && var0 < this.f.length ? this.f[var0] : null; + public CompoundTag fromId(int id) { + return id >= 0 && id < this.f.length ? this.f[id] : null; } private int c(int var0) { @@ -80,22 +80,21 @@ public class RegistryID implements Registry { private void d(int var0) { CompoundTag[] var1 = this.d; int[] var2 = this.e; - this.d = (CompoundTag[]) new Object[var0]; + this.d = new CompoundTag[var0]; this.e = new int[var0]; - this.f = (CompoundTag[]) new Object[var0]; + this.f = new CompoundTag[var0]; this.g = 0; - this.h = 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.h + 1); + 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) { @@ -108,36 +107,35 @@ public class RegistryID implements Registry { this.d[var3] = var0; this.e[var3] = var1; this.f[var1] = var0; - ++this.h; + ++this.size; if (var1 == this.g) { ++this.g; } - } - private int d(CompoundTag var0) { - return (MathHelper.g(System.identityHashCode(var0)) & 2147483647) % this.d.length; + private int d(CompoundTag block) { + return (MathHelper.g(System.identityHashCode(block)) & 2147483647) % this.d.length; } - private int b(CompoundTag var0, int var1) { + private int b(CompoundTag block, int var1) { int var2; for (var2 = var1; var2 < this.d.length; ++var2) { - if (this.d[var2] == var0) { - return var2; + if (this.d[var2] == null) { + return -1; } - if (this.d[var2] == b) { - return -1; + if (this.d[var2].equals(block)) { + return var2; } } for (var2 = 0; var2 < var1; ++var2) { - if (this.d[var2] == var0) { - return var2; + if (this.d[var2] == null) { + return -1; } - if (this.d[var2] == b) { - return -1; + if (this.d[var2].equals(block)) { + return var2; } } @@ -147,13 +145,13 @@ public class RegistryID implements Registry { private int e(int var0) { int var1; for (var1 = var0; var1 < this.d.length; ++var1) { - if (this.d[var1] == b) { + if (this.d[var1] == null) { return var1; } } for (var1 = 0; var1 < var0; ++var1) { - if (this.d[var1] == b) { + if (this.d[var1] == null) { return var1; } } @@ -162,17 +160,17 @@ public class RegistryID implements Registry { } public Iterator iterator() { - return Iterators.filter(Iterators.forArray(this.f), Predicates.notNull()); + return Iterators.filter(Iterators.forArray(this.f), Objects::nonNull); } - public void a() { - Arrays.fill(this.d, (Object) null); - Arrays.fill(this.f, (Object) null); + public void clear() { + Arrays.fill(this.d, null); + Arrays.fill(this.f, null); this.g = 0; - this.h = 0; + this.size = 0; } - public int b() { - return this.h; + public int size() { + return this.size; } } \ No newline at end of file From 8aa9ecffc5504eae508752dc46927cec46f2cb2c Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 05:18:16 -0400 Subject: [PATCH 29/29] Fixes --- src/main/java/com/volmit/iris/Iris.java | 2 +- .../java/com/volmit/iris/core/nms/v17_1/NMSBinding17_1.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index 6d34bfe11..a9b0a0a7e 100644 --- a/src/main/java/com/volmit/iris/Iris.java +++ b/src/main/java/com/volmit/iris/Iris.java @@ -129,7 +129,7 @@ public class Iris extends VolmitPlugin implements Listener { private void testmca() { try { - int forceBits = 9; + int forceBits = 6; int possibilities = (int) (Math.pow(2, forceBits) - 1); KList bp = new KList<>(); Set bf = new KSet<>(); 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 1868126d0..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 @@ -77,10 +77,8 @@ public class NMSBinding17_1 implements INMSBinding { public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c"); Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d"); - Field bf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("b"); cf.setAccessible(true); df.setAccessible(true); - bf.setAccessible(true); net.minecraft.core.RegistryBlockID blockData = Block.p; IdentityHashMap c = (IdentityHashMap) cf.get(blockData); List d = (List) df.get(blockData); @@ -88,7 +86,7 @@ public class NMSBinding17_1 implements INMSBinding { 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, bf.getInt(blockData)); + RegistryBlockID registry = new RegistryBlockID(realMap, realTags); Iris.info("INMS: Stole Global Palette: " + realTags.size() + " Tags, " + realMap.size() + " Mapped"); return registry; }