From fd434e8b216a48852af2781c9ab3f1951ffeee6b Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 06:34:03 -0400 Subject: [PATCH] Remove old palettes --- .../com/volmit/iris/core/nms/INMSBinding.java | 1 - .../iris/core/nms/v17_1/NMSBinding17_1.java | 1 - .../iris/core/nms/v1X/NMSBinding1X.java | 1 - .../com/volmit/iris/util/nbt/mca/Section.java | 2 - .../iris/util/nbt/mca/palettes/DataBits.java | 125 ---------- .../util/nbt/mca/palettes/DataPalette.java | 36 --- .../nbt/mca/palettes/DataPaletteBlock.java | 229 ------------------ .../mca/palettes/DataPaletteExpandable.java | 25 -- .../nbt/mca/palettes/DataPaletteGlobal.java | 56 ----- .../nbt/mca/palettes/DataPaletteHash.java | 80 ------ .../nbt/mca/palettes/DataPaletteLinear.java | 82 ------- .../iris/util/nbt/mca/palettes/Registry.java | 27 --- .../nbt/mca/palettes/RegistryBlockID.java | 65 ----- .../util/nbt/mca/palettes/RegistryID.java | 181 -------------- 14 files changed, 911 deletions(-) delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataBits.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteGlobal.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryBlockID.java delete mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java 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 f4b3f83e0..26e791b07 100644 --- a/src/main/java/com/volmit/iris/core/nms/INMSBinding.java +++ b/src/main/java/com/volmit/iris/core/nms/INMSBinding.java @@ -19,7 +19,6 @@ package com.volmit.iris.core.nms; import com.volmit.iris.util.nbt.mca.nmspalettes.PaletteAccess; -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; 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 685c4a8ab..b128d977b 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 @@ -25,7 +25,6 @@ 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.nmspalettes.*; -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; 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 610229938..da03a904a 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 @@ -21,7 +21,6 @@ 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.nmspalettes.PaletteAccess; -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; 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 f48af5f83..2ea9151ca 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,11 +20,9 @@ package com.volmit.iris.util.nbt.mca; import com.volmit.iris.core.nms.INMS; import com.volmit.iris.util.nbt.mca.nmspalettes.PaletteAccess; -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; public class Section { 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 deleted file mode 100644 index 7755ddd1a..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataBits.java +++ /dev/null @@ -1,125 +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.nbt.mca.palettes; - -import org.apache.commons.lang3.Validate; - -import java.util.function.IntConsumer; - -public class DataBits { - private static final int[] a = new int[]{-1, -1, 0, -2147483648, 0, 0, 1431655765, 1431655765, 0, -2147483648, 0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756, 0, -2147483648, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0, 390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378, 306783378, 0, 286331153, 286331153, 0, -2147483648, 0, 3, 252645135, 252645135, 0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0, 204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970, 178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862, 0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0, 138547332, 138547332, 0, -2147483648, 0, 4, 130150524, 130150524, 0, 126322567, 126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197, 0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0, 104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893, 97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282, 0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0, 84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431, 79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303, 0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0, 70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, -2147483648, 0, 5}; - private final long[] data; - private final int c; - private final long paletteSize; - private final int blockSize; - private final int f; - private final int g; - private final int h; - private final int i; - - public DataBits(int var0, int var1) { - this(var0, var1, (long[]) null); - } - - public DataBits(int bitsPerBlock, int var1, long[] data) { - Validate.inclusiveBetween(1L, 32L, (long) bitsPerBlock); - this.blockSize = var1; - this.c = bitsPerBlock; - this.paletteSize = (1L << bitsPerBlock) - 1L; - this.f = (char) (64 / bitsPerBlock); - int var3 = 3 * (this.f - 1); - this.g = a[var3 + 0]; - this.h = a[var3 + 1]; - this.i = a[var3 + 2]; - int var4 = (var1 + this.f - 1) / this.f; - if (data != null) { - if (data.length != var4) { - throw new RuntimeException("Invalid length given for storage, got: " + data.length + " but expected: " + var4); - } - - this.data = data; - } else { - this.data = new long[var4]; - } - - } - - private int b(int var0) { - long var1 = Integer.toUnsignedLong(this.g); - long var3 = Integer.toUnsignedLong(this.h); - return (int) ((long) var0 * var1 + var3 >> 32 >> this.i); - } - - public int setBlockResulting(int blockIndex, int paletteIndex) { - Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex); - Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex); - int var2 = this.b(blockIndex); - long var3 = this.data[var2]; - int var5 = (blockIndex - var2 * this.f) * this.c; - int var6 = (int) (var3 >> var5 & this.paletteSize); - this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5; - return var6; - } - - public void setBlock(int blockIndex, int paletteIndex) { - Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex); - Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex); - int var2 = this.b(blockIndex); - long var3 = this.data[var2]; - int var5 = (blockIndex - var2 * this.f) * this.c; - this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5; - } - - public int getIndexFromPos(int var0) { - Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) var0); - int var1 = this.b(var0); - long var2 = this.data[var1]; - int var4 = (var0 - var1 * this.f) * this.c; - return (int) (var2 >> var4 & this.paletteSize); - } - - public long[] getData() { - return this.data; - } - - public int b() { - return this.blockSize; - } - - public int getBitsPerBlock() { - return this.c; - } - - public void a(IntConsumer var0) { - int var1 = 0; - long[] var3 = this.data; - int var4 = var3.length; - for (long l : var3) { - long var5 = l; - for (int j = 0; j < this.f; ++j) { - var0.accept((int) (var5 & this.paletteSize)); - var5 >>= this.c; - ++var1; - if (var1 >= this.blockSize) { - return; - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java deleted file mode 100644 index f0d4e81e0..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPalette.java +++ /dev/null @@ -1,36 +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.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 interface DataPalette { - int getIndex(CompoundTag block); - - boolean contains(Predicate predicate); - - CompoundTag getByIndex(int index); - - int size(); - - void replace(ListTag palette); -} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java deleted file mode 100644 index 944b008cb..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteBlock.java +++ /dev/null @@ -1,229 +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.nbt.mca.palettes; - -import com.volmit.iris.Iris; -import com.volmit.iris.core.nms.INMS; -import com.volmit.iris.engine.data.cache.AtomicCache; -import com.volmit.iris.util.math.MathHelper; -import com.volmit.iris.util.nbt.io.SNBTSerializer; -import com.volmit.iris.util.nbt.mca.NBTWorld; -import com.volmit.iris.util.nbt.tag.CompoundTag; -import com.volmit.iris.util.nbt.tag.ListTag; -import com.volmit.iris.util.scheduling.J; -import it.unimi.dsi.fastutil.ints.Int2IntMap; -import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import lombok.Getter; -import net.minecraft.world.level.chunk.ChunkSection; -import org.bukkit.Material; - -import javax.management.RuntimeErrorException; -import java.io.IOException; -import java.util.HashSet; -import java.util.Map; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@Getter -public class DataPaletteBlock implements DataPaletteExpandable { - private static final int d = 4096; - public static final int HASH_BITS = 9; - public static final int LINEAR_BITS = 4; - private final DataPalette globalPalette; - private final DataPaletteExpandable f = (var0x, var1x) -> 0; - private final RegistryBlockID stolenRegistry; - private final CompoundTag defAir; - private static final AtomicCache reg = new AtomicCache<>(); - private static final AtomicCache global = new AtomicCache<>(); - private static final CompoundTag air = NBTWorld.getCompound(Material.AIR.createBlockData()); - protected DataBits dataBits; - private DataPalette currentPalette; - private int bits = 0; - - public DataPaletteBlock() { - this(global(), registry(), air); - } - - public DataPaletteBlock(DataPalette var0, - RegistryBlockID var1, - CompoundTag airType) { - this.globalPalette = var0; - this.stolenRegistry = var1; - this.defAir = airType; - this.changeBitsTo(4); - } - - private static RegistryBlockID registry() - { - return ((DataPaletteGlobal) global()).getRegistry(); - } - - private static DataPalette global() { - return global.aquire(() -> new DataPaletteGlobal(J.attemptResult(() -> INMS.get().computeBlockIDRegistry()), air)); - } - - - private static int blockIndex(int x, int y, int z) { - return y << 8 | z << 4 | x; - } - - private void changeBitsTo(int newbits) { - if (newbits != bits) { - bits = newbits; - if (bits <= LINEAR_BITS) { - bits = LINEAR_BITS; - currentPalette = new DataPaletteLinear(bits, this); - } else if (bits < HASH_BITS) { - currentPalette = new DataPaletteHash(bits, this); - Iris.info("Upgraded to hash bits"); - } else { - currentPalette = globalPalette; - Iris.info("Upgraded to global bits because " + bits + " >= " + HASH_BITS); - bits = MathHelper.e(stolenRegistry.size()); - } - - currentPalette.getIndex(defAir); - dataBits = new DataBits(bits, 4096); - } - } - - public int onResize(int newBits, CompoundTag newData) { - DataBits oldBits = dataBits; - DataPalette oldPalette = currentPalette; - - changeBitsTo(newBits); - - for (int i = 0; i < oldBits.b(); ++i) { - CompoundTag block = oldPalette.getByIndex(oldBits.getIndexFromPos(i)); - if (block != null) { - setBlockIndex(i, block); - } - } - - return currentPalette.getIndex(newData); - } - - @Deprecated - public CompoundTag setBlockAndReturn(int x, int y, int z, CompoundTag block) { - return setBlockIndexAndReturn(blockIndex(x, y, z), block); - } - - @Deprecated - private CompoundTag setBlockIndexAndReturn(int index, CompoundTag block) { - int paletteIndex = currentPalette.getIndex(block); - int res = dataBits.setBlockResulting(index, paletteIndex); - CompoundTag testBlock = currentPalette.getByIndex(res); - return testBlock == null ? defAir : testBlock; - } - - public void setBlock(int x, int y, int z, CompoundTag block) { - setBlockIndex(blockIndex(x, y, z), block); - } - - private void setBlockIndex(int blockIndex, CompoundTag block) { - int paletteIndex = currentPalette.getIndex(block); - dataBits.setBlock(blockIndex, paletteIndex); - } - - public CompoundTag getBlock(int x, int y, int z) { - return getByIndex(blockIndex(x, y, z)); - } - - protected CompoundTag getByIndex(int index) { - if(currentPalette == null) - { - return null; - } - - CompoundTag data = currentPalette.getByIndex(dataBits.getIndexFromPos(index)); - return data == null ? defAir : data; - } - - public void load(ListTag palettedata, long[] databits) { - int readBits = Math.max(4, MathHelper.e(palettedata.size())); - if (readBits != bits) { - changeBitsTo(readBits); - } - - currentPalette.replace(palettedata); - int dblen = databits.length * 64 / 4096; - if (currentPalette == globalPalette) { - DataPalette hashPalette = new DataPaletteHash(readBits, f); - hashPalette.replace(palettedata); - DataBits var5 = new DataBits(readBits, 4096, databits); - - for (int i = 0; i < 4096; ++i) { - dataBits.setBlock(i, globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(i)))); - } - } else if (dblen == bits) { - System.arraycopy(databits, 0, dataBits.getData(), 0, databits.length); - } else { - DataBits var4 = new DataBits(dblen, 4096, databits); - - for (int i = 0; i < 4096; ++i) { - dataBits.setBlock(i, var4.getIndexFromPos(i)); - } - } - } - - public void save(CompoundTag to, String paletteName, String blockStatesName) { - DataPaletteHash hashpal = new DataPaletteHash(bits, f); - CompoundTag cursor = defAir; - int palIndex = hashpal.getIndex(defAir); - int[] paletteIndex = new int[4096]; - int i; - for (i = 0; i < 4096; ++i) { - CompoundTag entry = getByIndex(i); - if (!entry.equals(cursor)) { - cursor = entry; - palIndex = hashpal.getIndex(entry); - } - - paletteIndex[i] = palIndex; - } - - ListTag npalette = (ListTag) ListTag.createUnchecked(CompoundTag.class); - hashpal.writePalette(npalette); - to.put(paletteName, npalette); - int bits = Math.max(4, MathHelper.e(npalette.size())); - DataBits writeBits = new DataBits(bits, 4096); - - for (i = 0; i < paletteIndex.length; ++i) { - writeBits.setBlock(i, paletteIndex[i]); - } - - to.putLongArray(blockStatesName, writeBits.getData()); - to.putString("DEBUG_PALETTE_MODE", currentPalette.getClass().getSimpleName()); - } - - public boolean contains(Predicate var0) { - return currentPalette.contains(var0); - } - - public void a(PaletteConsumer var0) { - Int2IntMap var1 = new Int2IntOpenHashMap(); - dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); - var1.int2IntEntrySet().forEach((var1x) -> var0.accept(currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue())); - } - - @FunctionalInterface - public interface PaletteConsumer { - void accept(T var1, int var2); - } -} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java deleted file mode 100644 index 21281139f..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteExpandable.java +++ /dev/null @@ -1,25 +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.nbt.mca.palettes; - -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 deleted file mode 100644 index f18e972fa..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteGlobal.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.nbt.mca.palettes; - -import com.volmit.iris.util.nbt.tag.CompoundTag; -import com.volmit.iris.util.nbt.tag.ListTag; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -import java.util.function.Predicate; - -@RequiredArgsConstructor -public class DataPaletteGlobal implements DataPalette { - @Getter - private final RegistryBlockID registry; - private final CompoundTag air; - - public int getIndex(CompoundTag block) { - int id = this.registry.getId(block); - return id == -1 ? 0 : id; - } - - public boolean contains(Predicate predicate) { - return true; - } - - public CompoundTag getByIndex(int index) { - CompoundTag block = registry.fromId(index); - return block == null ? air : block; - } - - public int size() { - return registry.size(); - } - - @Override - public void replace(ListTag palette) { - throw new UnsupportedOperationException("Cannot replace the global palette!"); - } -} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java deleted file mode 100644 index a2c66622e..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteHash.java +++ /dev/null @@ -1,80 +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.nbt.mca.palettes; - -import com.volmit.iris.util.nbt.tag.CompoundTag; -import com.volmit.iris.util.nbt.tag.ListTag; - -import java.util.function.Predicate; - -public class DataPaletteHash implements DataPalette { - private final RegistryID registryId; - private final DataPaletteExpandable expander; - private final int bits; - - public DataPaletteHash(int bits, DataPaletteExpandable expander) { - this.bits = bits; - this.expander = expander; - this.registryId = new RegistryID(1 << bits); - } - - public int getIndex(CompoundTag block) { - int id = registryId.getId(block); - if (id == -1) { - id = registryId.c(block); - if (id >= 1 << bits) { - id = expander.onResize(bits + 1, block); - } - } - - return id; - } - - public boolean contains(Predicate predicate) { - for (int i = 0; i < size(); ++i) { - if (predicate.test(registryId.fromId(i))) { - return true; - } - } - - return false; - } - - public CompoundTag getByIndex(int index) { - return registryId.fromId(index); - } - - public int size() { - return registryId.size(); - } - - public void replace(ListTag palette) { - registryId.clear(); - - for (int i = 0; i < palette.size(); ++i) { - registryId.c(palette.get(i)); - } - } - - public void writePalette(ListTag list) { - for (int i = 0; i < size(); ++i) { - list.add(registryId.fromId(i)); - } - } -} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java deleted file mode 100644 index 6a4900230..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/DataPaletteLinear.java +++ /dev/null @@ -1,82 +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.nbt.mca.palettes; - -import com.volmit.iris.util.nbt.tag.CompoundTag; -import com.volmit.iris.util.nbt.tag.ListTag; - -import java.util.function.Predicate; - -public class DataPaletteLinear implements DataPalette { - private final CompoundTag[] palette; - private final DataPaletteExpandable expander; - private final int e; - private int size; - - public DataPaletteLinear(int bits, DataPaletteExpandable expander) { - this.palette = new CompoundTag[1 << bits]; - this.e = bits; - this.expander = expander; - this.size = 0; - } - - public int getIndex(CompoundTag block) { - int i; - for (i = 0; i < size; ++i) { - if (palette[i].equals(block)) { - return i; - } - } - - i = size; - if (i < palette.length) { - palette[i] = block; - ++size; - return i; - } else { - return expander.onResize(e + 1, block); - } - } - - public boolean contains(Predicate predicate) { - for (int i = 0; i < this.size; ++i) { - if (predicate.test(palette[i])) { - return true; - } - } - - return false; - } - - public CompoundTag getByIndex(int index) { - return index >= 0 && index < size ? palette[index] : null; - } - - public int size() { - return size; - } - - public void replace(ListTag palette) { - for (int i = 0; i < palette.size(); ++i) { - this.palette[i] = palette.get(i); - } - - this.size = palette.size(); - } -} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java deleted file mode 100644 index db0c77550..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/Registry.java +++ /dev/null @@ -1,27 +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.nbt.mca.palettes; - -import com.volmit.iris.util.nbt.tag.CompoundTag; - -public interface Registry extends Iterable { - int getId(CompoundTag block); - - 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 deleted file mode 100644 index 3b636d124..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryBlockID.java +++ /dev/null @@ -1,65 +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.nbt.mca.palettes; - -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import com.volmit.iris.util.nbt.tag.CompoundTag; - -import java.util.*; - -public class RegistryBlockID implements Registry { - private final Map indexMap; - private final List indexes; - - public RegistryBlockID(Map c, List d) { - this.indexMap = c; - this.indexes = d; - } - - public RegistryBlockID() { - this(512); - } - - public RegistryBlockID(int var0) { - this.indexes = Lists.newArrayListWithExpectedSize(var0); - this.indexMap = new HashMap<>(var0); - } - - public int getId(CompoundTag block) { - Integer var1 = this.indexMap.get(block); - return var1 == null ? -1 : var1; - } - - public final CompoundTag fromId(int id) { - return id >= 0 && id < this.indexes.size() ? this.indexes.get(id) : null; - } - - public Iterator iterator() { - return Iterators.filter(this.indexes.iterator(), Objects::nonNull); - } - - public boolean hasIndex(int var0) { - return this.fromId(var0) != null; - } - - public int size() { - return this.indexMap.size(); - } -} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java b/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java deleted file mode 100644 index 064557945..000000000 --- a/src/main/java/com/volmit/iris/util/nbt/mca/palettes/RegistryID.java +++ /dev/null @@ -1,181 +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.nbt.mca.palettes; - -import com.google.common.collect.Iterators; -import com.volmit.iris.Iris; -import com.volmit.iris.util.math.MathHelper; -import com.volmit.iris.util.nbt.tag.CompoundTag; -import net.minecraft.world.level.chunk.DataPaletteBlock; - -import java.util.Arrays; -import java.util.Iterator; -import java.util.Objects; - -public class RegistryID implements Registry { - public static final int a = -1; - private static final CompoundTag b = null; - private static final float c = 0.8F; - private CompoundTag[] d; - private int[] e; - private CompoundTag[] f; - private int g; - private int size; - - public RegistryID(int var0) { - var0 = (int) ((float) var0 / 0.8F); - this.d = new CompoundTag[var0]; - this.f = new CompoundTag[var0]; - this.e = new int[var0]; - } - - public int getId(CompoundTag block) { - return this.c(this.b(block, this.d(block))); - } - - public CompoundTag fromId(int id) { - return id >= 0 && id < this.f.length ? this.f[id] : null; - } - - private int c(int var0) { - return var0 == -1 ? -1 : this.e[var0]; - } - - public boolean b(CompoundTag var0) { - return this.getId(var0) != -1; - } - - public boolean b(int var0) { - return this.fromId(var0) != null; - } - - public int c(CompoundTag var0) { - int var1 = this.c(); - this.a(var0, var1); - return var1; - } - - - private int c() { - while (this.g < this.f.length && this.f[this.g] != null) { - ++this.g; - } - - return this.g; - } - - private void d(int var0) { - CompoundTag[] var1 = this.d; - int[] var2 = this.e; - this.d = new CompoundTag[var0]; - this.e = new int[var0]; - this.f = new CompoundTag[var0]; - this.g = 0; - this.size = 0; - - for (int var3 = 0; var3 < var1.length; ++var3) { - if (var1[var3] != null) { - this.a(var1[var3], var2[var3]); - } - } - } - - public void a(CompoundTag var0, int var1) { - int var2 = Math.max(var1, this.size + 1); - int var3; - if ((float) var2 >= (float) this.d.length * 0.8F) { - for (var3 = this.d.length << 1; var3 < var1; var3 <<= 1) { - } - - this.d(var3); - } - - var3 = this.e(this.d(var0)); - this.d[var3] = var0; - this.e[var3] = var1; - this.f[var1] = var0; - ++this.size; - if (var1 == this.g) { - ++this.g; - } - } - - private int d(CompoundTag block) { - return (MathHelper.g(System.identityHashCode(block)) & 2147483647) % this.d.length; - } - - private int b(CompoundTag block, int var1) { - int var2; - for (var2 = var1; var2 < this.d.length; ++var2) { - if (this.d[var2] == null) { - Iris.error("-1 because null!"); - return -1; - } - - if (this.d[var2].equals(block)) { - return var2; - } - } - - for (var2 = 0; var2 < var1; ++var2) { - if (this.d[var2] == null) { - Iris.error("-1 because null!"); - return -1; - } - - if (this.d[var2].equals(block)) { - return var2; - } - } - - return -1; - } - - private int e(int var0) { - int var1; - for (var1 = var0; var1 < this.d.length; ++var1) { - if (this.d[var1] == null) { - return var1; - } - } - - for (var1 = 0; var1 < var0; ++var1) { - if (this.d[var1] == null) { - return var1; - } - } - - throw new RuntimeException("Overflowed :("); - } - - public Iterator iterator() { - return Iterators.filter(Iterators.forArray(this.f), Objects::nonNull); - } - - public void clear() { - Arrays.fill(this.d, null); - Arrays.fill(this.f, null); - this.g = 0; - this.size = 0; - } - - public int size() { - return this.size; - } -} \ No newline at end of file