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