From a335050332bada371c0a3caef3378e855333a5d7 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 06:32:43 -0400 Subject: [PATCH 1/8] Fixes --- .../java/com/volmit/iris/util/nbt/mca/Section.java | 13 +++++++------ .../util/nbt/mca/palettes/DataPaletteBlock.java | 4 ++++ .../iris/util/nbt/mca/palettes/RegistryID.java | 5 +++++ 3 files changed, 16 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 fd4865c1a..f48af5f83 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,6 +18,8 @@ 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; @@ -27,7 +29,7 @@ import com.volmit.iris.util.nbt.tag.LongArrayTag; public class Section { private CompoundTag data; - private DataPaletteBlock palette; + private PaletteAccess palette; private byte[] blockLight; private byte[] skyLight; private int dataVersion; @@ -43,9 +45,8 @@ public class Section { if (rawPalette == null) { return; } - palette = new DataPaletteBlock(); - LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates"); - palette.load((ListTag) rawPalette, blockStates.getValue()); + palette = INMS.get().createPalette(); + palette.readFromSection(sectionRoot); ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight"); ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight"); this.blockLight = blockLight != null ? blockLight.getValue() : null; @@ -151,8 +152,8 @@ public class Section { */ public static Section newSection() { Section s = new Section(); - s.palette = new DataPaletteBlock(); s.data = new CompoundTag(); + s.palette = INMS.get().createPalette(); return s; } @@ -170,7 +171,7 @@ public class Section { if (palette != null) { synchronized (palette) { - palette.save(data, "Palette", "BlockStates"); + palette.writeToSection(data); } } if (blockLight != null) { 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 3f1155e13..944b008cb 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 @@ -33,6 +33,7 @@ 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; @@ -90,8 +91,10 @@ public class DataPaletteBlock implements DataPaletteExpandable { 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()); } @@ -103,6 +106,7 @@ public class DataPaletteBlock implements DataPaletteExpandable { public int onResize(int newBits, CompoundTag newData) { DataBits oldBits = dataBits; DataPalette oldPalette = currentPalette; + changeBitsTo(newBits); for (int i = 0; i < oldBits.b(); ++i) { 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 416ccf252..064557945 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 @@ -19,8 +19,10 @@ 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; @@ -69,6 +71,7 @@ public class RegistryID implements Registry { return var1; } + private int c() { while (this.g < this.f.length && this.f[this.g] != null) { ++this.g; @@ -121,6 +124,7 @@ public class RegistryID implements Registry { int var2; for (var2 = var1; var2 < this.d.length; ++var2) { if (this.d[var2] == null) { + Iris.error("-1 because null!"); return -1; } @@ -131,6 +135,7 @@ public class RegistryID implements Registry { for (var2 = 0; var2 < var1; ++var2) { if (this.d[var2] == null) { + Iris.error("-1 because null!"); return -1; } From 19fa9390ff4c0337d2d4082aa51861bf15819385 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 06:32:50 -0400 Subject: [PATCH 2/8] EVEN MORE PALETTES --- .../util/nbt/mca/nmspalettes/BitStorage.java | 145 ++++ .../nbt/mca/nmspalettes/CountConsumer.java | 24 + .../CrudeIncrementalIntIdentityHashBiMap.java | 167 ++++ .../nbt/mca/nmspalettes/GlobalPalette.java | 54 ++ .../nbt/mca/nmspalettes/HashMapPalette.java | 85 ++ .../iris/util/nbt/mca/nmspalettes/IdMap.java | 25 + .../util/nbt/mca/nmspalettes/IdMapper.java | 88 +++ .../nbt/mca/nmspalettes/LinearPalette.java | 86 ++ .../iris/util/nbt/mca/nmspalettes/Mth.java | 733 ++++++++++++++++++ .../util/nbt/mca/nmspalettes/Palette.java | 35 + .../nbt/mca/nmspalettes/PaletteAccess.java | 33 + .../nbt/mca/nmspalettes/PaletteResize.java | 23 + .../mca/nmspalettes/PalettedContainer.java | 187 +++++ .../nmspalettes/WrappedPalettedContainer.java | 54 ++ 14 files changed, 1739 insertions(+) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/BitStorage.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CountConsumer.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CrudeIncrementalIntIdentityHashBiMap.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/GlobalPalette.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/HashMapPalette.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMap.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMapper.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/LinearPalette.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Mth.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Palette.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteAccess.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteResize.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PalettedContainer.java create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/WrappedPalettedContainer.java diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/BitStorage.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/BitStorage.java new file mode 100644 index 000000000..e509b87cc --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/BitStorage.java @@ -0,0 +1,145 @@ +/* + * 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.nmspalettes; + +import org.apache.commons.lang3.Validate; + +import java.util.function.IntConsumer; + +public class BitStorage { + private static final int[] MAGIC = new int[] { + -1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE, + 0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756, + 0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0, + 390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378, + 306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 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, Integer.MIN_VALUE, 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, Integer.MIN_VALUE, + 0, 5 }; + + private final long[] data; + + private final int bits; + + private final long mask; + + private final int size; + + private final int valuesPerLong; + + private final int divideMul; + + private final int divideAdd; + + private final int divideShift; + + public BitStorage(int var0, int var1) { + this(var0, var1, null); + } + + public BitStorage(int var0, int var1, long[] var2) { + Validate.inclusiveBetween(1L, 32L, var0); + this.size = var1; + this.bits = var0; + this.mask = (1L << var0) - 1L; + this.valuesPerLong = (char)(64 / var0); + int var3 = 3 * (this.valuesPerLong - 1); + this.divideMul = MAGIC[var3 + 0]; + this.divideAdd = MAGIC[var3 + 1]; + this.divideShift = MAGIC[var3 + 2]; + int var4 = (var1 + this.valuesPerLong - 1) / this.valuesPerLong; + if (var2 != null) { + if (var2.length != var4) + throw new RuntimeException("NO!"); + this.data = var2; + } else { + this.data = new long[var4]; + } + } + + private int cellIndex(int var0) { + long var1 = Integer.toUnsignedLong(this.divideMul); + long var3 = Integer.toUnsignedLong(this.divideAdd); + return (int)(var0 * var1 + var3 >> 32L >> this.divideShift); + } + + public int getAndSet(int var0, int var1) { + Validate.inclusiveBetween(0L, (this.size - 1), var0); + Validate.inclusiveBetween(0L, this.mask, var1); + int var2 = cellIndex(var0); + long var3 = this.data[var2]; + int var5 = (var0 - var2 * this.valuesPerLong) * this.bits; + int var6 = (int)(var3 >> var5 & this.mask); + this.data[var2] = var3 & (this.mask << var5 ^ 0xFFFFFFFFFFFFFFFFL) | (var1 & this.mask) << var5; + return var6; + } + + public void set(int var0, int var1) { + Validate.inclusiveBetween(0L, (this.size - 1), var0); + Validate.inclusiveBetween(0L, this.mask, var1); + int var2 = cellIndex(var0); + long var3 = this.data[var2]; + int var5 = (var0 - var2 * this.valuesPerLong) * this.bits; + this.data[var2] = var3 & (this.mask << var5 ^ 0xFFFFFFFFFFFFFFFFL) | (var1 & this.mask) << var5; + } + + public int get(int var0) { + Validate.inclusiveBetween(0L, (this.size - 1), var0); + int var1 = cellIndex(var0); + long var2 = this.data[var1]; + int var4 = (var0 - var1 * this.valuesPerLong) * this.bits; + return (int)(var2 >> var4 & this.mask); + } + + public long[] getRaw() { + return this.data; + } + + public int getSize() { + return this.size; + } + + public int getBits() { + return this.bits; + } + + public void getAll(IntConsumer var0) { + int var1 = 0; + for (long var5 : this.data) { + for (int var7 = 0; var7 < this.valuesPerLong; var7++) { + var0.accept((int)(var5 & this.mask)); + var5 >>= this.bits; + if (++var1 >= this.size) + return; + } + } + } +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CountConsumer.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CountConsumer.java new file mode 100644 index 000000000..ede8a5404 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CountConsumer.java @@ -0,0 +1,24 @@ +/* + * 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.nmspalettes; + +@FunctionalInterface +public interface CountConsumer { + void accept(T paramT, int paramInt); +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CrudeIncrementalIntIdentityHashBiMap.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CrudeIncrementalIntIdentityHashBiMap.java new file mode 100644 index 000000000..5c40c7aa5 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CrudeIncrementalIntIdentityHashBiMap.java @@ -0,0 +1,167 @@ +/* + * 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.nmspalettes; + +import com.google.common.base.Predicates; +import com.google.common.collect.Iterators; + +import java.util.Arrays; +import java.util.Iterator; + +public class CrudeIncrementalIntIdentityHashBiMap implements IdMap { + public static final int NOT_FOUND = -1; + + private static final Object EMPTY_SLOT = null; + + private static final float LOADFACTOR = 0.8F; + + private K[] keys; + + private int[] values; + + private K[] byId; + + private int nextId; + + private int size; + + public CrudeIncrementalIntIdentityHashBiMap(int var0) { + var0 = (int)(var0 / 0.8F); + this.keys = (K[])new Object[var0]; + this.values = new int[var0]; + this.byId = (K[])new Object[var0]; + } + + public int getId(K var0) { + return getValue(indexOf(var0, hash(var0))); + } + + + public K byId(int var0) { + if (var0 < 0 || var0 >= this.byId.length) + return null; + return this.byId[var0]; + } + + private int getValue(int var0) { + if (var0 == -1) + return -1; + return this.values[var0]; + } + + public boolean contains(K var0) { + return (getId(var0) != -1); + } + + public boolean contains(int var0) { + return (byId(var0) != null); + } + + public int add(K var0) { + int var1 = nextId(); + addMapping(var0, var1); + return var1; + } + + private int nextId() { + while (this.nextId < this.byId.length && this.byId[this.nextId] != null) + this.nextId++; + return this.nextId; + } + + private void grow(int var0) { + K[] var1 = this.keys; + int[] var2 = this.values; + this.keys = (K[])new Object[var0]; + this.values = new int[var0]; + this.byId = (K[])new Object[var0]; + this.nextId = 0; + this.size = 0; + for (int var3 = 0; var3 < var1.length; var3++) { + if (var1[var3] != null) + addMapping(var1[var3], var2[var3]); + } + } + + public void addMapping(K var0, int var1) { + int var2 = Math.max(var1, this.size + 1); + if (var2 >= this.keys.length * 0.8F) { + int i = this.keys.length << 1; + while (i < var1) + i <<= 1; + grow(i); + } + int var3 = findEmpty(hash(var0)); + this.keys[var3] = var0; + this.values[var3] = var1; + this.byId[var1] = var0; + this.size++; + if (var1 == this.nextId) + this.nextId++; + } + + private int hash( K var0) { + return (Mth.murmurHash3Mixer(System.identityHashCode(var0)) & Integer.MAX_VALUE) % this.keys.length; + } + + private int indexOf( K var0, int var1) { + int var2; + for (var2 = var1; var2 < this.keys.length; var2++) { + if (this.keys[var2] == var0) + return var2; + if (this.keys[var2] == EMPTY_SLOT) + return -1; + } + for (var2 = 0; var2 < var1; var2++) { + if (this.keys[var2] == var0) + return var2; + if (this.keys[var2] == EMPTY_SLOT) + return -1; + } + return -1; + } + + private int findEmpty(int var0) { + int var1; + for (var1 = var0; var1 < this.keys.length; var1++) { + if (this.keys[var1] == EMPTY_SLOT) + return var1; + } + for (var1 = 0; var1 < var0; var1++) { + if (this.keys[var1] == EMPTY_SLOT) + return var1; + } + throw new RuntimeException("Overflowed :("); + } + + public Iterator iterator() { + return (Iterator) Iterators.filter((Iterator)Iterators.forArray((Object[])this.byId), Predicates.notNull()); + } + + public void clear() { + Arrays.fill((Object[])this.keys, (Object)null); + Arrays.fill((Object[])this.byId, (Object)null); + this.nextId = 0; + this.size = 0; + } + + public int size() { + return this.size; + } +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/GlobalPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/GlobalPalette.java new file mode 100644 index 000000000..82d59dad0 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/GlobalPalette.java @@ -0,0 +1,54 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.nbt.mca.nmspalettes; + +import com.volmit.iris.util.nbt.tag.ListTag; + +import java.util.function.Predicate; + +public class GlobalPalette implements Palette { + private final IdMapper registry; + + private final T defaultValue; + + public GlobalPalette(IdMapper var0, T var1) { + this.registry = var0; + this.defaultValue = var1; + } + + public int idFor(T var0) { + int var1 = this.registry.getId(var0); + return (var1 == -1) ? 0 : var1; + } + + public boolean maybeHas(Predicate var0) { + return true; + } + + public T valueFor(int var0) { + T var1 = (T)this.registry.byId(var0); + return (var1 == null) ? this.defaultValue : var1; + } + + public int getSize() { + return this.registry.size(); + } + + public void read(ListTag var0) {} +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/HashMapPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/HashMapPalette.java new file mode 100644 index 000000000..09b77f912 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/HashMapPalette.java @@ -0,0 +1,85 @@ +/* + * 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.nmspalettes; + +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; + +import java.util.function.Function; +import java.util.function.Predicate; + +public class HashMapPalette implements Palette { + private final IdMapper registry; + + private final CrudeIncrementalIntIdentityHashBiMap values; + + private final PaletteResize resizeHandler; + + private final Function reader; + + private final Function writer; + + private final int bits; + + public HashMapPalette(IdMapper var0, int var1, PaletteResize var2, Function var3, Function var4) { + this.registry = var0; + this.bits = var1; + this.resizeHandler = var2; + this.reader = var3; + this.writer = var4; + this.values = new CrudeIncrementalIntIdentityHashBiMap(1 << var1); + } + + public int idFor(T var0) { + int var1 = this.values.getId(var0); + if (var1 == -1) { + var1 = this.values.add(var0); + if (var1 >= 1 << this.bits) + var1 = this.resizeHandler.onResize(this.bits + 1, var0); + } + return var1; + } + + public boolean maybeHas(Predicate var0) { + for (int var1 = 0; var1 < getSize(); var1++) { + if (var0.test((T)this.values.byId(var1))) + return true; + } + return false; + } + + public T valueFor(int var0) { + return (T)this.values.byId(var0); + } + + public int getSize() { + return this.values.size(); + } + + public void read(ListTag var0) { + this.values.clear(); + for (int var1 = 0; var1 < var0.size(); var1++) + this.values.add(this.reader.apply((CompoundTag) var0.get(var1))); + } + + public void write(ListTag var0) { + for (int var1 = 0; var1 < getSize(); var1++) + var0.add(this.writer.apply((T)this.values.byId(var1))); + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMap.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMap.java new file mode 100644 index 000000000..d3d63ea54 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMap.java @@ -0,0 +1,25 @@ +/* + * 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.nmspalettes; + +public interface IdMap extends Iterable { + int getId(T paramT); + + T byId(int paramInt); +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMapper.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMapper.java new file mode 100644 index 000000000..469e1c3c6 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMapper.java @@ -0,0 +1,88 @@ +/* + * 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.nmspalettes; + +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 IdMapper implements IdMap { + public static final int DEFAULT = -1; + + private int nextId; + + private final IdentityHashMap tToId; + + private final List idToT; + + public IdMapper(IdentityHashMap tToId, List idToT, int nextId) { + this.tToId = tToId; + this.idToT = idToT; + this.nextId = nextId; + } + + public IdMapper() { + this(512); + } + + public IdMapper(int var0) { + this.idToT = Lists.newArrayListWithExpectedSize(var0); + this.tToId = new IdentityHashMap<>(var0); + } + + public void addMapping(T var0, int var1) { + this.tToId.put(var0, Integer.valueOf(var1)); + while (this.idToT.size() <= var1) + this.idToT.add(null); + this.idToT.set(var1, var0); + if (this.nextId <= var1) + this.nextId = var1 + 1; + } + + public void add(T var0) { + addMapping(var0, this.nextId); + } + + public int getId(T var0) { + Integer var1 = this.tToId.get(var0); + return (var1 == null) ? -1 : var1.intValue(); + } + + public final T byId(int var0) { + if (var0 >= 0 && var0 < this.idToT.size()) + return this.idToT.get(var0); + return null; + } + + public Iterator iterator() { + return (Iterator) Iterators.filter(this.idToT.iterator(), Predicates.notNull()); + } + + public boolean contains(int var0) { + return (byId(var0) != null); + } + + public int size() { + return this.tToId.size(); + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/LinearPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/LinearPalette.java new file mode 100644 index 000000000..b7ba0e48b --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/LinearPalette.java @@ -0,0 +1,86 @@ +/* + * 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.nmspalettes; + +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; + +import java.util.function.Function; +import java.util.function.Predicate; + +public class LinearPalette implements Palette { + private final IdMapper registry; + + private final T[] values; + + private final PaletteResize resizeHandler; + + private final Function reader; + + private final int bits; + + private int size; + + public LinearPalette(IdMapper var0, int var1, PaletteResize var2, Function var3) { + this.registry = var0; + this.values = (T[])new Object[1 << var1]; + this.bits = var1; + this.resizeHandler = var2; + this.reader = var3; + } + + public int idFor(T var0) { + int var1; + for (var1 = 0; var1 < this.size; var1++) { + if (this.values[var1] == var0) + return var1; + } + var1 = this.size; + if (var1 < this.values.length) { + this.values[var1] = var0; + this.size++; + return var1; + } + return this.resizeHandler.onResize(this.bits + 1, var0); + } + + public boolean maybeHas(Predicate var0) { + for (int var1 = 0; var1 < this.size; var1++) { + if (var0.test(this.values[var1])) + return true; + } + return false; + } + + public T valueFor(int var0) { + if (var0 >= 0 && var0 < this.size) + return this.values[var0]; + return null; + } + + public int getSize() { + return this.size; + } + + public void read(ListTag var0) { + for (int var1 = 0; var1 < var0.size(); var1++) + this.values[var1] = this.reader.apply((CompoundTag) var0.get(var1)); + this.size = var0.size(); + } +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Mth.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Mth.java new file mode 100644 index 000000000..1c40f8f0b --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Mth.java @@ -0,0 +1,733 @@ +/* + * 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.nmspalettes; + +import java.util.Random; +import java.util.UUID; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class Mth { + private static final int BIG_ENOUGH_INT = 1024; + + private static final float BIG_ENOUGH_FLOAT = 1024.0F; + + private static final long UUID_VERSION = 61440L; + + private static final long UUID_VERSION_TYPE_4 = 16384L; + + private static final long UUID_VARIANT = -4611686018427387904L; + + private static final long UUID_VARIANT_2 = -9223372036854775808L; + + public static final float PI = 3.1415927F; + + public static final float HALF_PI = 1.5707964F; + + public static final float TWO_PI = 6.2831855F; + + public static final float DEG_TO_RAD = 0.017453292F; + + public static final float RAD_TO_DEG = 57.295776F; + + public static final float EPSILON = 1.0E-5F; + + public static final float SQRT_OF_TWO = sqrt(2.0F); + + private static final float SIN_SCALE = 10430.378F; + + private static final float[] SIN; + + static { + SIN = (float[])make(new float[65536], var0 -> { + for (int var1 = 0; var1 < var0.length; var1++) + var0[var1] = (float)Math.sin(var1 * Math.PI * 2.0D / 65536.0D); + }); + } + + public static T make(Supplier var0) { + return var0.get(); + } + + public static T make(T var0, Consumer var1) { + var1.accept(var0); + return var0; + } + + private static final Random RANDOM = new Random(); + + public static float sin(float var0) { + return SIN[(int)(var0 * 10430.378F) & 0xFFFF]; + } + + public static float cos(float var0) { + return SIN[(int)(var0 * 10430.378F + 16384.0F) & 0xFFFF]; + } + + public static float sqrt(float var0) { + return (float)Math.sqrt(var0); + } + + public static int floor(float var0) { + int var1 = (int)var0; + return (var0 < var1) ? (var1 - 1) : var1; + } + + public static int fastFloor(double var0) { + return (int)(var0 + 1024.0D) - 1024; + } + + public static int floor(double var0) { + int var2 = (int)var0; + return (var0 < var2) ? (var2 - 1) : var2; + } + + public static long lfloor(double var0) { + long var2 = (long)var0; + return (var0 < var2) ? (var2 - 1L) : var2; + } + + public static int absFloor(double var0) { + return (int)((var0 >= 0.0D) ? var0 : (-var0 + 1.0D)); + } + + public static float abs(float var0) { + return Math.abs(var0); + } + + public static int abs(int var0) { + return Math.abs(var0); + } + + public static int ceil(float var0) { + int var1 = (int)var0; + return (var0 > var1) ? (var1 + 1) : var1; + } + + public static int ceil(double var0) { + int var2 = (int)var0; + return (var0 > var2) ? (var2 + 1) : var2; + } + + public static byte clamp(byte var0, byte var1, byte var2) { + if (var0 < var1) + return var1; + if (var0 > var2) + return var2; + return var0; + } + + public static int clamp(int var0, int var1, int var2) { + if (var0 < var1) + return var1; + if (var0 > var2) + return var2; + return var0; + } + + public static long clamp(long var0, long var2, long var4) { + if (var0 < var2) + return var2; + if (var0 > var4) + return var4; + return var0; + } + + public static float clamp(float var0, float var1, float var2) { + if (var0 < var1) + return var1; + if (var0 > var2) + return var2; + return var0; + } + + public static double clamp(double var0, double var2, double var4) { + if (var0 < var2) + return var2; + if (var0 > var4) + return var4; + return var0; + } + + public static double clampedLerp(double var0, double var2, double var4) { + if (var4 < 0.0D) + return var0; + if (var4 > 1.0D) + return var2; + return lerp(var4, var0, var2); + } + + public static float clampedLerp(float var0, float var1, float var2) { + if (var2 < 0.0F) + return var0; + if (var2 > 1.0F) + return var1; + return lerp(var2, var0, var1); + } + + public static double absMax(double var0, double var2) { + if (var0 < 0.0D) + var0 = -var0; + if (var2 < 0.0D) + var2 = -var2; + return (var0 > var2) ? var0 : var2; + } + + public static int intFloorDiv(int var0, int var1) { + return Math.floorDiv(var0, var1); + } + + public static int nextInt(Random var0, int var1, int var2) { + if (var1 >= var2) + return var1; + return var0.nextInt(var2 - var1 + 1) + var1; + } + + public static float nextFloat(Random var0, float var1, float var2) { + if (var1 >= var2) + return var1; + return var0.nextFloat() * (var2 - var1) + var1; + } + + public static double nextDouble(Random var0, double var1, double var3) { + if (var1 >= var3) + return var1; + return var0.nextDouble() * (var3 - var1) + var1; + } + + public static double average(long[] var0) { + long var1 = 0L; + for (long var6 : var0) + var1 += var6; + return var1 / var0.length; + } + + public static boolean equal(float var0, float var1) { + return (Math.abs(var1 - var0) < 1.0E-5F); + } + + public static boolean equal(double var0, double var2) { + return (Math.abs(var2 - var0) < 9.999999747378752E-6D); + } + + public static int positiveModulo(int var0, int var1) { + return Math.floorMod(var0, var1); + } + + public static float positiveModulo(float var0, float var1) { + return (var0 % var1 + var1) % var1; + } + + public static double positiveModulo(double var0, double var2) { + return (var0 % var2 + var2) % var2; + } + + public static int wrapDegrees(int var0) { + int var1 = var0 % 360; + if (var1 >= 180) + var1 -= 360; + if (var1 < -180) + var1 += 360; + return var1; + } + + public static float wrapDegrees(float var0) { + float var1 = var0 % 360.0F; + if (var1 >= 180.0F) + var1 -= 360.0F; + if (var1 < -180.0F) + var1 += 360.0F; + return var1; + } + + public static double wrapDegrees(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 degreesDifference(float var0, float var1) { + return wrapDegrees(var1 - var0); + } + + public static float degreesDifferenceAbs(float var0, float var1) { + return abs(degreesDifference(var0, var1)); + } + + public static float rotateIfNecessary(float var0, float var1, float var2) { + float var3 = degreesDifference(var0, var1); + float var4 = clamp(var3, -var2, var2); + return var1 - var4; + } + + public static float approach(float var0, float var1, float var2) { + var2 = abs(var2); + if (var0 < var1) + return clamp(var0 + var2, var0, var1); + return clamp(var0 - var2, var1, var0); + } + + public static float approachDegrees(float var0, float var1, float var2) { + float var3 = degreesDifference(var0, var1); + return approach(var0, var0 + var3, var2); + } + + public static int getInt(String var0, int var1) { + return Integer.valueOf(var0, var1); + } + + public static int getInt(String var0, int var1, int var2) { + return Math.max(var2, getInt(var0, var1)); + } + + public static double getDouble(String var0, double var1) { + try { + return Double.parseDouble(var0); + } catch (Throwable var3) { + return var1; + } + } + + public static double getDouble(String var0, double var1, double var3) { + return Math.max(var3, getDouble(var0, var1)); + } + + public static int smallestEncompassingPowerOfTwo(int var0) { + int var1 = var0 - 1; + var1 |= var1 >> 1; + var1 |= var1 >> 2; + var1 |= var1 >> 4; + var1 |= var1 >> 8; + var1 |= var1 >> 16; + return var1 + 1; + } + + public static boolean isPowerOfTwo(int var0) { + return (var0 != 0 && (var0 & var0 - 1) == 0); + } + + private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = 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 ONE_SIXTH = 0.16666666666666666D; + + private static final int FRAC_EXP = 8; + + private static final int LUT_SIZE = 257; + + public static int ceillog2(int var0) { + var0 = isPowerOfTwo(var0) ? var0 : smallestEncompassingPowerOfTwo(var0); + return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)(var0 * 125613361L >> 27L) & 0x1F]; + } + + public static int log2(int var0) { + return ceillog2(var0) - (isPowerOfTwo(var0) ? 0 : 1); + } + + public static int color(float var0, float var1, float var2) { + return color(floor(var0 * 255.0F), floor(var1 * 255.0F), floor(var2 * 255.0F)); + } + + public static int color(int var0, int var1, int var2) { + int var3 = var0; + var3 = (var3 << 8) + var1; + var3 = (var3 << 8) + var2; + return var3; + } + + public static int colorMultiply(int var0, int var1) { + int var2 = (var0 & 0xFF0000) >> 16; + int var3 = (var1 & 0xFF0000) >> 16; + int var4 = (var0 & 0xFF00) >> 8; + int var5 = (var1 & 0xFF00) >> 8; + int var6 = (var0 & 0xFF) >> 0; + int var7 = (var1 & 0xFF) >> 0; + int var8 = (int)(var2 * var3 / 255.0F); + int var9 = (int)(var4 * var5 / 255.0F); + int var10 = (int)(var6 * var7 / 255.0F); + return var0 & 0xFF000000 | var8 << 16 | var9 << 8 | var10; + } + + public static int colorMultiply(int var0, float var1, float var2, float var3) { + int var4 = (var0 & 0xFF0000) >> 16; + int var5 = (var0 & 0xFF00) >> 8; + int var6 = (var0 & 0xFF) >> 0; + int var7 = (int)(var4 * var1); + int var8 = (int)(var5 * var2); + int var9 = (int)(var6 * var3); + return var0 & 0xFF000000 | var7 << 16 | var8 << 8 | var9; + } + + public static float frac(float var0) { + return var0 - floor(var0); + } + + public static double frac(double var0) { + return var0 - lfloor(var0); + } + + public static long getSeed(int var0, int var1, int var2) { + long var3 = (var0 * 3129871) ^ var2 * 116129781L ^ var1; + var3 = var3 * var3 * 42317861L + var3 * 11L; + return var3 >> 16L; + } + + public static UUID createInsecureUUID(Random var0) { + long var1 = var0.nextLong() & 0xFFFFFFFFFFFF0FFFL | 0x4000L; + long var3 = var0.nextLong() & 0x3FFFFFFFFFFFFFFFL | Long.MIN_VALUE; + return new UUID(var1, var3); + } + + public static UUID createInsecureUUID() { + return createInsecureUUID(RANDOM); + } + + public static double inverseLerp(double var0, double var2, double var4) { + return (var0 - var2) / (var4 - var2); + } + + public static double atan2(double var0, double var2) { + double var4 = var2 * var2 + var0 * var0; + if (Double.isNaN(var4)) + return Double.NaN; + boolean var6 = (var0 < 0.0D); + if (var6) + var0 = -var0; + boolean var7 = (var2 < 0.0D); + if (var7) + var2 = -var2; + boolean var8 = (var0 > var2); + if (var8) { + double d = var2; + var2 = var0; + var0 = d; + } + double var9 = fastInvSqrt(var4); + var2 *= var9; + var0 *= var9; + double var11 = FRAC_BIAS + var0; + int var13 = (int)Double.doubleToRawLongBits(var11); + double var14 = ASIN_TAB[var13]; + double var16 = COS_TAB[var13]; + double var18 = var11 - FRAC_BIAS; + 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 = Math.PI - var24; + if (var6) + var24 = -var24; + return var24; + } + + public static float fastInvSqrt(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 double fastInvSqrt(double var0) { + double var2 = 0.5D * var0; + long var4 = Double.doubleToRawLongBits(var0); + var4 = 6910469410427058090L - (var4 >> 1L); + var0 = Double.longBitsToDouble(var4); + var0 *= 1.5D - var2 * var0 * var0; + return var0; + } + + public static float fastInvCubeRoot(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; + } + + private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L); + + private static final double[] ASIN_TAB = new double[257]; + + private static final double[] COS_TAB = new double[257]; + + static { + for (int var0 = 0; var0 < 257; var0++) { + double var1 = var0 / 256.0D; + double var3 = Math.asin(var1); + COS_TAB[var0] = Math.cos(var3); + ASIN_TAB[var0] = var3; + } + } + + public static int hsvToRgb(float var0, float var1, float var2) { + float var8, var9, var10; + int var11, var12, var13, var3 = (int)(var0 * 6.0F) % 6; + float var4 = var0 * 6.0F - 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: + var8 = var2; + var9 = var7; + var10 = var5; + var11 = clamp((int)(var8 * 255.0F), 0, 255); + var12 = clamp((int)(var9 * 255.0F), 0, 255); + var13 = clamp((int)(var10 * 255.0F), 0, 255); + return var11 << 16 | var12 << 8 | var13; + case 1: + var8 = var6; + var9 = var2; + var10 = var5; + var11 = clamp((int)(var8 * 255.0F), 0, 255); + var12 = clamp((int)(var9 * 255.0F), 0, 255); + var13 = clamp((int)(var10 * 255.0F), 0, 255); + return var11 << 16 | var12 << 8 | var13; + case 2: + var8 = var5; + var9 = var2; + var10 = var7; + var11 = clamp((int)(var8 * 255.0F), 0, 255); + var12 = clamp((int)(var9 * 255.0F), 0, 255); + var13 = clamp((int)(var10 * 255.0F), 0, 255); + return var11 << 16 | var12 << 8 | var13; + case 3: + var8 = var5; + var9 = var6; + var10 = var2; + var11 = clamp((int)(var8 * 255.0F), 0, 255); + var12 = clamp((int)(var9 * 255.0F), 0, 255); + var13 = clamp((int)(var10 * 255.0F), 0, 255); + return var11 << 16 | var12 << 8 | var13; + case 4: + var8 = var7; + var9 = var5; + var10 = var2; + var11 = clamp((int)(var8 * 255.0F), 0, 255); + var12 = clamp((int)(var9 * 255.0F), 0, 255); + var13 = clamp((int)(var10 * 255.0F), 0, 255); + return var11 << 16 | var12 << 8 | var13; + case 5: + var8 = var2; + var9 = var5; + var10 = var6; + var11 = clamp((int)(var8 * 255.0F), 0, 255); + var12 = clamp((int)(var9 * 255.0F), 0, 255); + var13 = clamp((int)(var10 * 255.0F), 0, 255); + return var11 << 16 | var12 << 8 | var13; + } + throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2); + } + + public static int murmurHash3Mixer(int var0) { + var0 ^= var0 >>> 16; + var0 *= -2048144789; + var0 ^= var0 >>> 13; + var0 *= -1028477387; + var0 ^= var0 >>> 16; + return var0; + } + + public static long murmurHash3Mixer(long var0) { + var0 ^= var0 >>> 33L; + var0 *= -49064778989728563L; + var0 ^= var0 >>> 33L; + var0 *= -4265267296055464877L; + var0 ^= var0 >>> 33L; + return var0; + } + + public static double[] cumulativeSum(double... var0) { + float var1 = 0.0F; + for (double var5 : var0) + var1 = (float)(var1 + var5); + int var2; + for (var2 = 0; var2 < var0.length; var2++) + var0[var2] = var0[var2] / var1; + for (var2 = 0; var2 < var0.length; var2++) + var0[var2] = ((var2 == 0) ? 0.0D : var0[var2 - 1]) + var0[var2]; + return var0; + } + + public static int getRandomForDistributionIntegral(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[] binNormalDistribution(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(-(var10 - var4) * (var10 - var4) / 2.0D * var2 * var2)); + var9++; + } + return var8; + } + + public static double[] binBiModalNormalDistribution(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(-(var16 - var4) * (var16 - var4) / 2.0D * var2 * var2) + var6 * + StrictMath.exp(-(var16 - var10) * (var16 - var10) / 2.0D * var8 * var8)); + var15++; + } + return var14; + } + + public static double[] binLogDistribution(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(var8) + var2, 0.0D); + var7++; + } + return var6; + } + + public static float lerp(float var0, float var1, float var2) { + return var1 + var0 * (var2 - var1); + } + + public static double lerp(double var0, double var2, double var4) { + return var2 + var0 * (var4 - var2); + } + + public static double lerp2(double var0, double var2, double var4, double var6, double var8, double var10) { + return lerp(var2, + + lerp(var0, var4, var6), + lerp(var0, var8, var10)); + } + + public static double lerp3(double var0, double var2, double var4, double var6, double var8, double var10, double var12, double var14, double var16, double var18, double var20) { + return lerp(var4, + + lerp2(var0, var2, var6, var8, var10, var12), + lerp2(var0, var2, var14, var16, var18, var20)); + } + + public static double smoothstep(double var0) { + return var0 * var0 * var0 * (var0 * (var0 * 6.0D - 15.0D) + 10.0D); + } + + public static double smoothstepDerivative(double var0) { + return 30.0D * var0 * var0 * (var0 - 1.0D) * (var0 - 1.0D); + } + + public static int sign(double var0) { + if (var0 == 0.0D) + return 0; + return (var0 > 0.0D) ? 1 : -1; + } + + public static float rotLerp(float var0, float var1, float var2) { + return var1 + var0 * wrapDegrees(var2 - var1); + } + + public static float diffuseLight(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 rotlerp(float var0, float var1, float var2) { + float var3 = var1 - var0; + while (var3 < -180.0F) + var3 += 360.0F; + while (var3 >= 180.0F) + var3 -= 360.0F; + return var0 + var2 * var3; + } + + @Deprecated + public static float rotWrap(double var0) { + while (var0 >= 180.0D) + var0 -= 360.0D; + while (var0 < -180.0D) + var0 += 360.0D; + return (float)var0; + } + + public static float triangleWave(float var0, float var1) { + return (Math.abs(var0 % var1 - var1 * 0.5F) - var1 * 0.25F) / var1 * 0.25F; + } + + public static float square(float var0) { + return var0 * var0; + } + + public static double square(double var0) { + return var0 * var0; + } + + public static int square(int var0) { + return var0 * var0; + } + + public static double clampedMap(double var0, double var2, double var4, double var6, double var8) { + return clampedLerp(var6, var8, inverseLerp(var0, var2, var4)); + } + + public static double map(double var0, double var2, double var4, double var6, double var8) { + return lerp(inverseLerp(var0, var2, var4), var6, var8); + } + + public static double wobble(double var0) { + return var0 + (2.0D * (new Random(floor(var0 * 3000.0D))).nextDouble() - 1.0D) * 1.0E-7D / 2.0D; + } + + public static int roundToward(int var0, int var1) { + return (var0 + var1 - 1) / var1 * var1; + } + + public static int randomBetweenInclusive(Random var0, int var1, int var2) { + return var0.nextInt(var2 - var1 + 1) + var1; + } + + public static float randomBetween(Random var0, float var1, float var2) { + return var0.nextFloat() * (var2 - var1) + var1; + } + + public static float normal(Random var0, float var1, float var2) { + return var1 + (float)var0.nextGaussian() * var2; + } + + public static double length(int var0, double var1, int var3) { + return Math.sqrt((var0 * var0) + var1 * var1 + (var3 * var3)); + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Palette.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Palette.java new file mode 100644 index 000000000..886dbf861 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Palette.java @@ -0,0 +1,35 @@ +/* + * 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.nmspalettes; + +import com.volmit.iris.util.nbt.tag.ListTag; + +import java.util.function.Predicate; + +public interface Palette { + int idFor(T paramT); + + boolean maybeHas(Predicate paramPredicate); + + T valueFor(int paramInt); + + int getSize(); + + void read(ListTag paramListTag); +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteAccess.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteAccess.java new file mode 100644 index 000000000..cdf5ae3a6 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteAccess.java @@ -0,0 +1,33 @@ +/* + * 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.nmspalettes; + +import com.volmit.iris.util.nbt.mca.NBTWorld; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import org.bukkit.block.data.BlockData; + +public interface PaletteAccess { + public void setBlock(int x, int y, int z, CompoundTag data); + + public CompoundTag getBlock(int x, int y, int z); + + public void writeToSection(CompoundTag tag); + + public void readFromSection(CompoundTag tag); +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteResize.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteResize.java new file mode 100644 index 000000000..dc5fe8d71 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteResize.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.nbt.mca.nmspalettes; + +interface PaletteResize { + int onResize(int paramInt, T paramT); +} diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PalettedContainer.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PalettedContainer.java new file mode 100644 index 000000000..7039c5975 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PalettedContainer.java @@ -0,0 +1,187 @@ +/* + * 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.nmspalettes; + +import com.volmit.iris.util.nbt.tag.CompoundTag; +import com.volmit.iris.util.nbt.tag.ListTag; +import it.unimi.dsi.fastutil.Pair; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import net.minecraft.util.DebugBuffer; +import net.minecraft.util.ThreadingDetector; + +import java.util.concurrent.Semaphore; +import java.util.function.Function; +import java.util.function.Predicate; + +public class PalettedContainer implements PaletteResize { + private static final int SIZE = 4096; + + public static final int GLOBAL_PALETTE_BITS = 9; + + public static final int MIN_PALETTE_SIZE = 4; + + private final Palette globalPalette; + + private final PaletteResize dummyPaletteResize = (var0, var1) -> 0; + + private final IdMapper registry; + + private final Function reader; + + private final Function writer; + + private final T defaultValue; + + protected BitStorage storage; + + private Palette palette; + + private int bits; + + public PalettedContainer(Palette var0, IdMapper var1, Function var2, Function var3, T var4) { + this.globalPalette = var0; + this.registry = var1; + this.reader = var2; + this.writer = var3; + this.defaultValue = var4; + setBits(4); + } + + private static int getIndex(int var0, int var1, int var2) { + return var1 << 8 | var2 << 4 | var0; + } + + private void setBits(int var0) { + if (var0 == this.bits) + return; + this.bits = var0; + if (this.bits <= 4) { + this.bits = 4; + this.palette = new LinearPalette<>(this.registry, this.bits, this, this.reader); + } else if (this.bits < 9) { + this.palette = new HashMapPalette<>(this.registry, this.bits, this, this.reader, this.writer); + } else { + this.palette = this.globalPalette; + this.bits = Mth.ceillog2(this.registry.size()); + } + this.palette.idFor(this.defaultValue); + this.storage = new BitStorage(this.bits, 4096); + } + + public int onResize(int var0, T var1) { + BitStorage var2 = this.storage; + Palette var3 = this.palette; + setBits(var0); + for (int var4 = 0; var4 < var2.getSize(); var4++) { + T var5 = var3.valueFor(var2.get(var4)); + if (var5 != null) + set(var4, var5); + } + return this.palette.idFor(var1); + } + + public T getAndSet(int var0, int var1, int var2, T var3) { + return getAndSet(getIndex(var0, var1, var2), var3); + } + + public T getAndSetUnchecked(int var0, int var1, int var2, T var3) { + return getAndSet(getIndex(var0, var1, var2), var3); + } + + private T getAndSet(int var0, T var1) { + int var2 = this.palette.idFor(var1); + int var3 = this.storage.getAndSet(var0, var2); + T var4 = this.palette.valueFor(var3); + return (var4 == null) ? this.defaultValue : var4; + } + + public void set(int var0, int var1, int var2, T var3) { + set(getIndex(var0, var1, var2), var3); + } + + private void set(int var0, T var1) { + int var2 = this.palette.idFor(var1); + this.storage.set(var0, var2); + } + + public T get(int var0, int var1, int var2) { + return get(getIndex(var0, var1, var2)); + } + + protected T get(int var0) { + T var1 = this.palette.valueFor(this.storage.get(var0)); + return (var1 == null) ? this.defaultValue : var1; + } + + public void read(ListTag var0, long[] var1) { + int var2 = Math.max(4, Mth.ceillog2(var0.size())); + if (var2 != this.bits) + setBits(var2); + this.palette.read(var0); + int var3 = var1.length * 64 / 4096; + if (this.palette == this.globalPalette) { + Palette var4 = new HashMapPalette<>(this.registry, var2, this.dummyPaletteResize, this.reader, this.writer); + var4.read(var0); + BitStorage var5 = new BitStorage(var2, 4096, var1); + for (int var6 = 0; var6 < 4096; var6++) + this.storage.set(var6, this.globalPalette.idFor(var4.valueFor(var5.get(var6)))); + } else if (var3 == this.bits) { + System.arraycopy(var1, 0, this.storage.getRaw(), 0, var1.length); + } else { + BitStorage var4 = new BitStorage(var3, 4096, var1); + for (int var5 = 0; var5 < 4096; var5++) + this.storage.set(var5, var4.get(var5)); + } + } + + public void write(CompoundTag var0, String var1, String var2) { + HashMapPalette var3 = new HashMapPalette<>(this.registry, this.bits, this.dummyPaletteResize, this.reader, this.writer); + T var4 = this.defaultValue; + int var5 = var3.idFor(this.defaultValue); + int[] var6 = new int[4096]; + for (int i = 0; i < 4096; i++) { + T t = get(i); + if (t != var4) { + var4 = t; + var5 = var3.idFor(t); + } + var6[i] = var5; + } + ListTag paletteList = (ListTag) ListTag.createUnchecked(CompoundTag.class); + var3.write(paletteList); + var0.put(var1, paletteList); + int var8 = Math.max(4, Mth.ceillog2(paletteList.size())); + BitStorage var9 = new BitStorage(var8, 4096); + for (int var10 = 0; var10 < var6.length; var10++) + { + var9.set(var10, var6[var10]); + } + var0.putLongArray(var2, var9.getRaw()); + } + + public boolean maybeHas(Predicate var0) { + return this.palette.maybeHas(var0); + } + + public void count(CountConsumer var0) { + Int2IntOpenHashMap int2IntOpenHashMap = new Int2IntOpenHashMap(); + this.storage.getAll(var1 -> int2IntOpenHashMap.put(var1, int2IntOpenHashMap.get(var1) + 1)); + int2IntOpenHashMap.int2IntEntrySet().forEach(var1 -> var0.accept(this.palette.valueFor(var1.getIntKey()), var1.getIntValue())); + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/WrappedPalettedContainer.java b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/WrappedPalettedContainer.java new file mode 100644 index 000000000..db6dfc651 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/WrappedPalettedContainer.java @@ -0,0 +1,54 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.nbt.mca.nmspalettes; + +import com.volmit.iris.util.nbt.mca.MCAUtil; +import com.volmit.iris.util.nbt.mca.NBTWorld; +import com.volmit.iris.util.nbt.tag.CompoundTag; +import lombok.RequiredArgsConstructor; +import org.bukkit.block.data.BlockData; + +import java.util.function.Function; + +@RequiredArgsConstructor +public class WrappedPalettedContainer implements PaletteAccess { + private final PalettedContainer container; + private final Function reader; + private final Function writer; + + public void setBlock(int x, int y, int z, CompoundTag data) + { + container.set(x,y,z,writer.apply(data)); + } + + public CompoundTag getBlock(int x, int y, int z) + { + return reader.apply(container.get(x,y,z)); + } + + public void writeToSection(CompoundTag tag) + { + container.write(tag, "Palette", "BlockStates"); + } + + public void readFromSection(CompoundTag tag) + { + container.read(tag.getListTag("Palette"), tag.getLongArrayTag("BlockStates").getValue()); + } +} From 1524866432811e2a94dd13dfdf1f91762e402b59 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 06:32:54 -0400 Subject: [PATCH 3/8] HELP ME --- src/main/java/com/volmit/iris/Iris.java | 2 +- .../com/volmit/iris/core/nms/INMSBinding.java | 3 +- .../iris/core/nms/v17_1/NMSBinding17_1.java | 43 ++++++++++++------- .../iris/core/nms/v1X/NMSBinding1X.java | 3 +- .../iris/engine/data/cache/AtomicCache.java | 16 +++++++ 5 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/volmit/iris/Iris.java b/src/main/java/com/volmit/iris/Iris.java index a9b0a0a7e..a013ee464 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 = 6; + int forceBits = 5; 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/INMSBinding.java b/src/main/java/com/volmit/iris/core/nms/INMSBinding.java index f6c218166..f4b3f83e0 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.nmspalettes.PaletteAccess; import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID; import com.volmit.iris.util.nbt.tag.CompoundTag; import org.bukkit.Location; @@ -76,5 +77,5 @@ public interface INMSBinding { return false; } - RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException; + PaletteAccess createPalette(); } 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 9c83a05ac..685c4a8ab 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 @@ -20,9 +20,11 @@ package com.volmit.iris.core.nms.v17_1; import com.volmit.iris.Iris; import com.volmit.iris.core.nms.INMSBinding; +import com.volmit.iris.engine.data.cache.AtomicCache; 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; @@ -46,6 +48,7 @@ import net.minecraft.world.level.chunk.Chunk; import net.minecraft.world.level.chunk.ChunkSection; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -66,7 +69,10 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; public class NMSBinding17_1 implements INMSBinding { + private final BlockData AIR = Material.AIR.createBlockData(); private final KMap baseBiomeCache = new KMap<>(); + private final AtomicCache> registryCache = new AtomicCache<>(); + private final AtomicCache> globalCache = new AtomicCache<>(); private Field biomeStorageCache = null; public boolean supportsDataPacks() { @@ -74,21 +80,28 @@ public class NMSBinding17_1 implements INMSBinding { } @Override - public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { - Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c"); - Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d"); - cf.setAccessible(true); - df.setAccessible(true); - net.minecraft.core.RegistryBlockID blockData = Block.p; - IdentityHashMap c = (IdentityHashMap) cf.get(blockData); - List d = (List) df.get(blockData); - List realTags = new ArrayList<>(); - HashMap realMap = new HashMap<>(512); - d.forEach((i) -> realTags.add(NBTWorld.getCompound(CraftBlockData.fromData(i)))); - c.forEach((k,v) -> realMap.put(NBTWorld.getCompound(CraftBlockData.fromData(k)), v)); - RegistryBlockID registry = new RegistryBlockID(realMap, realTags); - Iris.info("INMS: Stole Global Palette: " + realTags.size() + " Tags, " + realMap.size() + " Mapped"); - return registry; + public PaletteAccess createPalette() { + IdMapper registry = registryCache.aquireNasty(() -> { + 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; + int b = bf.getInt(blockData); + IdentityHashMap c = (IdentityHashMap) cf.get(blockData); + List d = (List) df.get(blockData); + return new IdMapper<>(c, d, b); + }); + Palette global = globalCache.aquireNasty(() -> new GlobalPalette<>(registry, ((CraftBlockData)AIR).getState())); + PalettedContainer container = new PalettedContainer<>(global, registry, + i -> ((CraftBlockData)NBTWorld.getBlockData(i)).getState(), + i -> NBTWorld.getCompound(CraftBlockData.fromData(i)), + ((CraftBlockData) AIR).getState()); + return new WrappedPalettedContainer<>(container, + i -> NBTWorld.getCompound(CraftBlockData.fromData(i)), + i -> ((CraftBlockData)NBTWorld.getBlockData(i)).getState()); } private Object getBiomeStorage(ChunkGenerator.BiomeGrid 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 ba07fadcb..610229938 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 @@ -20,6 +20,7 @@ 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; @@ -146,7 +147,7 @@ public class NMSBinding1X implements INMSBinding { } @Override - public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException { + public PaletteAccess createPalette() { Iris.error("Cannot use the global data palette! Iris is incapable of using MCA generation on this version of minecraft!"); return null; } diff --git a/src/main/java/com/volmit/iris/engine/data/cache/AtomicCache.java b/src/main/java/com/volmit/iris/engine/data/cache/AtomicCache.java index 27341de5d..1ace0fb27 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 @@ -19,6 +19,7 @@ package com.volmit.iris.engine.data.cache; import com.volmit.iris.Iris; +import com.volmit.iris.util.function.NastySupplier; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -50,6 +51,21 @@ public class AtomicCache { } } + public T aquireNasty(NastySupplier t) + { + return aquire(() -> { + try + { + return t.get(); + } + + catch(Throwable e) + { + return null; + } + }); + } + public T aquire(Supplier t) { if (this.t.get() != null) { return this.t.get(); From fd434e8b216a48852af2781c9ab3f1951ffeee6b Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 06:34:03 -0400 Subject: [PATCH 4/8] 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 From 125a3fdc5e94d883c074049ca507a001154e9aa9 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 07:09:57 -0400 Subject: [PATCH 5/8] Rename pkg --- .../util/nbt/mca/{nmspalettes => palette}/BitStorage.java | 2 +- .../nbt/mca/{nmspalettes => palette}/CountConsumer.java | 2 +- .../CrudeIncrementalIntIdentityHashBiMap.java | 2 +- .../nbt/mca/{nmspalettes => palette}/GlobalPalette.java | 2 +- .../nbt/mca/{nmspalettes => palette}/HashMapPalette.java | 2 +- .../iris/util/nbt/mca/{nmspalettes => palette}/IdMap.java | 2 +- .../util/nbt/mca/{nmspalettes => palette}/IdMapper.java | 2 +- .../nbt/mca/{nmspalettes => palette}/LinearPalette.java | 2 +- .../iris/util/nbt/mca/{nmspalettes => palette}/Mth.java | 2 +- .../iris/util/nbt/mca/{nmspalettes => palette}/Palette.java | 2 +- .../nbt/mca/{nmspalettes => palette}/PaletteAccess.java | 4 +--- .../nbt/mca/{nmspalettes => palette}/PaletteResize.java | 2 +- .../nbt/mca/{nmspalettes => palette}/PalettedContainer.java | 6 +----- .../{nmspalettes => palette}/WrappedPalettedContainer.java | 5 +---- 14 files changed, 14 insertions(+), 23 deletions(-) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/BitStorage.java (99%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/CountConsumer.java (94%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/CrudeIncrementalIntIdentityHashBiMap.java (98%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/GlobalPalette.java (96%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/HashMapPalette.java (98%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/IdMap.java (94%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/IdMapper.java (97%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/LinearPalette.java (97%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/Mth.java (99%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/Palette.java (95%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/PaletteAccess.java (88%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/PaletteResize.java (94%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/PalettedContainer.java (96%) rename src/main/java/com/volmit/iris/util/nbt/mca/{nmspalettes => palette}/WrappedPalettedContainer.java (90%) diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/BitStorage.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/BitStorage.java similarity index 99% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/BitStorage.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/BitStorage.java index e509b87cc..921cc77f4 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/BitStorage.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/BitStorage.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import org.apache.commons.lang3.Validate; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CountConsumer.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/CountConsumer.java similarity index 94% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CountConsumer.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/CountConsumer.java index ede8a5404..e13256217 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CountConsumer.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/CountConsumer.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; @FunctionalInterface public interface CountConsumer { diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CrudeIncrementalIntIdentityHashBiMap.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/CrudeIncrementalIntIdentityHashBiMap.java similarity index 98% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CrudeIncrementalIntIdentityHashBiMap.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/CrudeIncrementalIntIdentityHashBiMap.java index 5c40c7aa5..4d83d0ee5 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/CrudeIncrementalIntIdentityHashBiMap.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/CrudeIncrementalIntIdentityHashBiMap.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import com.google.common.base.Predicates; import com.google.common.collect.Iterators; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/GlobalPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/GlobalPalette.java similarity index 96% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/GlobalPalette.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/GlobalPalette.java index 82d59dad0..56a8e77d2 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/GlobalPalette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/GlobalPalette.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import com.volmit.iris.util.nbt.tag.ListTag; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/HashMapPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/HashMapPalette.java similarity index 98% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/HashMapPalette.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/HashMapPalette.java index 09b77f912..e8cab650c 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/HashMapPalette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/HashMapPalette.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMap.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMap.java similarity index 94% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMap.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMap.java index d3d63ea54..513f50f72 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMap.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMap.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; public interface IdMap extends Iterable { int getId(T paramT); diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMapper.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMapper.java similarity index 97% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMapper.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMapper.java index 469e1c3c6..3e2d37bb5 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/IdMapper.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/IdMapper.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import com.google.common.base.Predicates; import com.google.common.collect.Iterators; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/LinearPalette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/LinearPalette.java similarity index 97% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/LinearPalette.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/LinearPalette.java index b7ba0e48b..e6e0fe3a5 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/LinearPalette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/LinearPalette.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Mth.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java similarity index 99% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Mth.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java index 1c40f8f0b..0d793d784 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Mth.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import java.util.Random; import java.util.UUID; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Palette.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/Palette.java similarity index 95% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Palette.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/Palette.java index 886dbf861..526d0ed63 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/Palette.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/Palette.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import com.volmit.iris.util.nbt.tag.ListTag; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteAccess.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PaletteAccess.java similarity index 88% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteAccess.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/PaletteAccess.java index cdf5ae3a6..6879030dd 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteAccess.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PaletteAccess.java @@ -16,11 +16,9 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; -import com.volmit.iris.util.nbt.mca.NBTWorld; import com.volmit.iris.util.nbt.tag.CompoundTag; -import org.bukkit.block.data.BlockData; public interface PaletteAccess { public void setBlock(int x, int y, int z, CompoundTag data); diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteResize.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PaletteResize.java similarity index 94% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteResize.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/PaletteResize.java index dc5fe8d71..d4f64bcd0 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PaletteResize.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PaletteResize.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; interface PaletteResize { int onResize(int paramInt, T paramT); diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PalettedContainer.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PalettedContainer.java similarity index 96% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PalettedContainer.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/PalettedContainer.java index 7039c5975..0c15e7a01 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/PalettedContainer.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/PalettedContainer.java @@ -16,16 +16,12 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; -import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import net.minecraft.util.DebugBuffer; -import net.minecraft.util.ThreadingDetector; -import java.util.concurrent.Semaphore; import java.util.function.Function; import java.util.function.Predicate; diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/WrappedPalettedContainer.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/WrappedPalettedContainer.java similarity index 90% rename from src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/WrappedPalettedContainer.java rename to src/main/java/com/volmit/iris/util/nbt/mca/palette/WrappedPalettedContainer.java index db6dfc651..4b1be8282 100644 --- a/src/main/java/com/volmit/iris/util/nbt/mca/nmspalettes/WrappedPalettedContainer.java +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/WrappedPalettedContainer.java @@ -16,13 +16,10 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.nbt.mca.nmspalettes; +package com.volmit.iris.util.nbt.mca.palette; -import com.volmit.iris.util.nbt.mca.MCAUtil; -import com.volmit.iris.util.nbt.mca.NBTWorld; import com.volmit.iris.util.nbt.tag.CompoundTag; import lombok.RequiredArgsConstructor; -import org.bukkit.block.data.BlockData; import java.util.function.Function; From afd67d2f0024b3e14aeb94c9aceeb91ed3b713ce Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 07:10:07 -0400 Subject: [PATCH 6/8] Biome storage format --- .../nbt/mca/palette/ChunkBiomeContainer.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palette/ChunkBiomeContainer.java diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palette/ChunkBiomeContainer.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/ChunkBiomeContainer.java new file mode 100644 index 000000000..4fc319876 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/ChunkBiomeContainer.java @@ -0,0 +1,96 @@ +/* + * 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.palette; + +import net.minecraft.world.level.LevelHeightAccessor; +import net.minecraft.world.level.biome.BiomeBase; +import net.minecraft.world.level.biome.BiomeManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.bukkit.block.Biome; + +import java.util.Arrays; + +public class ChunkBiomeContainer { + private static final Logger LOGGER = LogManager.getLogger(); + private static final int WIDTH_BITS = Mth.ceillog2(16) - 2; + private static final int HORIZONTAL_MASK = (1 << WIDTH_BITS) - 1; + private static final int PACKED_X_LENGTH = 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000)); + private static final int PACKED_Z_LENGTH = PACKED_X_LENGTH; + public static final int PACKED_Y_LENGTH = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH; + public static final int MAX_SIZE = 1 << WIDTH_BITS + WIDTH_BITS + PACKED_Y_LENGTH - 2; + + public final IdMap biomeRegistry; + + private final T[] biomes; + + private final int quartMinY; + + private final int quartHeight; + + protected ChunkBiomeContainer(IdMap registry, int minHeight, int maxHeight, T[] abiomebase) { + this.biomeRegistry = registry; + this.biomes = abiomebase; + this.quartMinY = QuartPos.fromBlock(minHeight); + this.quartHeight = QuartPos.fromBlock(maxHeight) - 1; + } + + public ChunkBiomeContainer(IdMap registry, int minHeight, int maxHeight, int[] aint) { + this(registry, minHeight, maxHeight, (T[])new Object[aint.length]); + int i = -1; + for (int j = 0; j < this.biomes.length; j++) { + int k = aint[j]; + T biomebase = registry.byId(k); + if (biomebase == null) { + if (i == -1) + i = j; + this.biomes[j] = (T)registry.byId(0); + } else { + this.biomes[j] = biomebase; + } + } + if (i != -1) + LOGGER.warn("Invalid biome data received, starting from {}: {}", Integer.valueOf(i), Arrays.toString(aint)); + } + + private static int ceilDiv(int i, int j) { + return (i + j - 1) / j; + } + + public int[] writeBiomes() { + int[] aint = new int[this.biomes.length]; + for (int i = 0; i < this.biomes.length; i++) + aint[i] = this.biomeRegistry.getId(this.biomes[i]); + return aint; + } + + public T getBiome(int i, int j, int k) { + int l = i & HORIZONTAL_MASK; + int i1 = Mth.clamp(j - this.quartMinY, 0, this.quartHeight); + int j1 = k & HORIZONTAL_MASK; + return this.biomes[i1 << WIDTH_BITS + WIDTH_BITS | j1 << WIDTH_BITS | l]; + } + + public void setBiome(int i, int j, int k, T biome) { + int l = i & HORIZONTAL_MASK; + int i1 = Mth.clamp(j - this.quartMinY, 0, this.quartHeight); + int j1 = k & HORIZONTAL_MASK; + this.biomes[i1 << WIDTH_BITS + WIDTH_BITS | j1 << WIDTH_BITS | l] = biome; + } +} \ No newline at end of file From 5c8b600cb15be5f63d36991ec00360173fee706d Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 07:10:15 -0400 Subject: [PATCH 7/8] QPos & utils --- .../iris/util/nbt/mca/palette/QuartPos.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/com/volmit/iris/util/nbt/mca/palette/QuartPos.java diff --git a/src/main/java/com/volmit/iris/util/nbt/mca/palette/QuartPos.java b/src/main/java/com/volmit/iris/util/nbt/mca/palette/QuartPos.java new file mode 100644 index 000000000..52bf61ff8 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/nbt/mca/palette/QuartPos.java @@ -0,0 +1,43 @@ +/* + * 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.palette; + +public final class QuartPos { + public static final int BITS = 2; + + public static final int SIZE = 4; + + private static final int SECTION_TO_QUARTS_BITS = 2; + + public static int fromBlock(int var0) { + return var0 >> 2; + } + + public static int toBlock(int var0) { + return var0 << 2; + } + + public static int fromSection(int var0) { + return var0 << 2; + } + + public static int toSection(int var0) { + return var0 >> 2; + } +} From 8586d44d7e2ea6047441f008a48385a59d079c18 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Wed, 25 Aug 2021 07:10:31 -0400 Subject: [PATCH 8/8] Integrate real 1.17 chunks --- .../com/volmit/iris/core/nms/INMSBinding.java | 2 +- .../iris/core/nms/v17_1/NMSBinding17_1.java | 5 +---- .../iris/core/nms/v1X/NMSBinding1X.java | 2 +- .../com/volmit/iris/util/nbt/mca/Chunk.java | 21 ++++++++++++------- .../com/volmit/iris/util/nbt/mca/Section.java | 2 +- 5 files changed, 17 insertions(+), 15 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 26e791b07..731852fdd 100644 --- a/src/main/java/com/volmit/iris/core/nms/INMSBinding.java +++ b/src/main/java/com/volmit/iris/core/nms/INMSBinding.java @@ -18,7 +18,7 @@ package com.volmit.iris.core.nms; -import com.volmit.iris.util.nbt.mca.nmspalettes.PaletteAccess; +import com.volmit.iris.util.nbt.mca.palette.PaletteAccess; 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 b128d977b..71472740b 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 @@ -24,7 +24,7 @@ import com.volmit.iris.engine.data.cache.AtomicCache; 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.palette.*; import com.volmit.iris.util.nbt.tag.CompoundTag; import net.minecraft.core.BlockPosition; import net.minecraft.core.IRegistry; @@ -39,7 +39,6 @@ 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; @@ -61,8 +60,6 @@ import org.bukkit.generator.ChunkGenerator; import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; import java.util.IdentityHashMap; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; 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 da03a904a..795d9104a 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 @@ -20,7 +20,7 @@ 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.palette.PaletteAccess; 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/Chunk.java b/src/main/java/com/volmit/iris/util/nbt/mca/Chunk.java index 1eb54740f..f8b0e4a93 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 @@ -25,6 +25,7 @@ import com.volmit.iris.util.nbt.io.NBTSerializer; import com.volmit.iris.util.nbt.io.NamedTag; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag; +import com.volmit.iris.util.nbt.tag.Tag; import java.io.*; import java.util.Arrays; @@ -33,15 +34,10 @@ import java.util.concurrent.atomic.AtomicReferenceArray; import static com.volmit.iris.util.nbt.mca.LoadFlags.*; public class Chunk { - - public static final int DEFAULT_DATA_VERSION = 1628; - + public static final int DEFAULT_DATA_VERSION = 2730; private boolean partial; - private int lastMCAUpdate; - private CompoundTag data; - private int dataVersion; private long lastUpdate; private long inhabitedTime; @@ -72,6 +68,7 @@ public class Chunk { public Chunk(CompoundTag data) { this.data = data; initReferences(ALL_DATA); + setStatus("full"); } private void initReferences(long loadFlags) { @@ -163,6 +160,7 @@ public class Chunk { try (BufferedOutputStream nbtOut = new BufferedOutputStream(CompressionType.ZLIB.compress(baos))) { new NBTSerializer(false).toStream(new NamedTag(null, updateHandle(xPos, zPos)), nbtOut); } + byte[] rawData = baos.toByteArray(); raf.writeInt(rawData.length + 1); // including the byte to store the compression type raf.writeByte(CompressionType.ZLIB.getID()); @@ -648,11 +646,18 @@ public class Chunk { Chunk c = new Chunk(0); c.dataVersion = DEFAULT_DATA_VERSION; c.data = new CompoundTag(); - c.data.put("Level", new CompoundTag()); - c.status = "mobs_spawned"; + c.data.put("Level", defaultLevel()); + c.status = "full"; return c; } + private static CompoundTag defaultLevel() { + CompoundTag level = new CompoundTag(); + level.putString("Status", "full"); + level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion()); + return level; + } + public CompoundTag updateHandle(int xPos, int zPos) { data.putInt("DataVersion", dataVersion); CompoundTag level = data.getCompoundTag("Level"); 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 2ea9151ca..b337f2616 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 @@ -19,7 +19,7 @@ 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.palette.PaletteAccess; import com.volmit.iris.util.nbt.tag.ByteArrayTag; import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.ListTag;