More cleanup

This commit is contained in:
cyberpwn 2021-08-25 05:18:13 -04:00
parent ba31a56949
commit ef02e5169d
9 changed files with 235 additions and 341 deletions

View File

@ -24,10 +24,10 @@ import java.util.function.IntConsumer;
public class DataBits { 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 static final int[] a = new int[]{-1, -1, 0, -2147483648, 0, 0, 1431655765, 1431655765, 0, -2147483648, 0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756, 0, -2147483648, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0, 390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378, 306783378, 0, 286331153, 286331153, 0, -2147483648, 0, 3, 252645135, 252645135, 0, 238609294, 238609294, 0, 226050910, 226050910, 0, 214748364, 214748364, 0, 204522252, 204522252, 0, 195225786, 195225786, 0, 186737708, 186737708, 0, 178956970, 178956970, 0, 171798691, 171798691, 0, 165191049, 165191049, 0, 159072862, 159072862, 0, 153391689, 153391689, 0, 148102320, 148102320, 0, 143165576, 143165576, 0, 138547332, 138547332, 0, -2147483648, 0, 4, 130150524, 130150524, 0, 126322567, 126322567, 0, 122713351, 122713351, 0, 119304647, 119304647, 0, 116080197, 116080197, 0, 113025455, 113025455, 0, 110127366, 110127366, 0, 107374182, 107374182, 0, 104755299, 104755299, 0, 102261126, 102261126, 0, 99882960, 99882960, 0, 97612893, 97612893, 0, 95443717, 95443717, 0, 93368854, 93368854, 0, 91382282, 91382282, 0, 89478485, 89478485, 0, 87652393, 87652393, 0, 85899345, 85899345, 0, 84215045, 84215045, 0, 82595524, 82595524, 0, 81037118, 81037118, 0, 79536431, 79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303, 0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0, 70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, -2147483648, 0, 5};
private final long[] b; private final long[] data;
private final int c; private final int c;
private final long d; private final long paletteSize;
private final int e; private final int blockSize;
private final int f; private final int f;
private final int g; private final int g;
private final int h; private final int h;
@ -37,25 +37,25 @@ public class DataBits {
this(var0, var1, (long[]) null); this(var0, var1, (long[]) null);
} }
public DataBits(int var0, int var1, long[] var2) { public DataBits(int bitsPerBlock, int var1, long[] data) {
Validate.inclusiveBetween(1L, 32L, (long) var0); Validate.inclusiveBetween(1L, 32L, (long) bitsPerBlock);
this.e = var1; this.blockSize = var1;
this.c = var0; this.c = bitsPerBlock;
this.d = (1L << var0) - 1L; this.paletteSize = (1L << bitsPerBlock) - 1L;
this.f = (char) (64 / var0); this.f = (char) (64 / bitsPerBlock);
int var3 = 3 * (this.f - 1); int var3 = 3 * (this.f - 1);
this.g = a[var3 + 0]; this.g = a[var3 + 0];
this.h = a[var3 + 1]; this.h = a[var3 + 1];
this.i = a[var3 + 2]; this.i = a[var3 + 2];
int var4 = (var1 + this.f - 1) / this.f; int var4 = (var1 + this.f - 1) / this.f;
if (var2 != null) { if (data != null) {
if (var2.length != var4) { if (data.length != var4) {
throw new RuntimeException("Invalid length given for storage, got: " + var2.length + " but expected: " + var4); throw new RuntimeException("Invalid length given for storage, got: " + data.length + " but expected: " + var4);
} }
this.b = var2; this.data = data;
} else { } else {
this.b = new long[var4]; this.data = new long[var4];
} }
} }
@ -66,57 +66,57 @@ public class DataBits {
return (int) ((long) var0 * var1 + var3 >> 32 >> this.i); return (int) ((long) var0 * var1 + var3 >> 32 >> this.i);
} }
public int a(int var0, int var1) { public int setBlockResulting(int blockIndex, int paletteIndex) {
Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex);
Validate.inclusiveBetween(0L, this.d, (long) var1); Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex);
int var2 = this.b(var0); int var2 = this.b(blockIndex);
long var3 = this.b[var2]; long var3 = this.data[var2];
int var5 = (var0 - var2 * this.f) * this.c; int var5 = (blockIndex - var2 * this.f) * this.c;
int var6 = (int) (var3 >> var5 & this.d); int var6 = (int) (var3 >> var5 & this.paletteSize);
this.b[var2] = var3 & ~(this.d << var5) | ((long) var1 & this.d) << var5; this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5;
return var6; return var6;
} }
public void b(int var0, int var1) { public void setBlock(int blockIndex, int paletteIndex) {
Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex);
Validate.inclusiveBetween(0L, this.d, (long) var1); Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex);
int var2 = this.b(var0); int var2 = this.b(blockIndex);
long var3 = this.b[var2]; long var3 = this.data[var2];
int var5 = (var0 - var2 * this.f) * this.c; int var5 = (blockIndex - var2 * this.f) * this.c;
this.b[var2] = var3 & ~(this.d << var5) | ((long) var1 & this.d) << var5; this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5;
} }
public int getIndexFromPos(int var0) { public int getIndexFromPos(int var0) {
Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0); Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) var0);
int var1 = this.b(var0); int var1 = this.b(var0);
long var2 = this.b[var1]; long var2 = this.data[var1];
int var4 = (var0 - var1 * this.f) * this.c; int var4 = (var0 - var1 * this.f) * this.c;
return (int) (var2 >> var4 & this.d); return (int) (var2 >> var4 & this.paletteSize);
} }
public long[] getData() { public long[] getData() {
return this.b; return this.data;
} }
public int b() { public int b() {
return this.e; return this.blockSize;
} }
public int c() { public int getBitsPerBlock() {
return this.c; return this.c;
} }
public void a(IntConsumer var0) { public void a(IntConsumer var0) {
int var1 = 0; int var1 = 0;
long[] var3 = this.b; long[] var3 = this.data;
int var4 = var3.length; int var4 = var3.length;
for (long l : var3) { for (long l : var3) {
long var5 = l; long var5 = l;
for (int j = 0; j < this.f; ++j) { for (int j = 0; j < this.f; ++j) {
var0.accept((int) (var5 & this.d)); var0.accept((int) (var5 & this.paletteSize));
var5 >>= this.c; var5 >>= this.c;
++var1; ++var1;
if (var1 >= this.e) { if (var1 >= this.blockSize) {
return; return;
} }
} }

View File

@ -24,17 +24,13 @@ import com.volmit.iris.util.nbt.tag.ListTag;
import java.util.function.Predicate; import java.util.function.Predicate;
public interface DataPalette { public interface DataPalette {
int getIndex(CompoundTag var1); int getIndex(CompoundTag block);
boolean a(Predicate<CompoundTag> var1); boolean contains(Predicate<CompoundTag> predicate);
CompoundTag getByIndex(int var1); CompoundTag getByIndex(int index);
int a(); int size();
int b(); void replace(ListTag<CompoundTag> palette);
void replace(ListTag<CompoundTag> t);
ListTag<CompoundTag> getPalette();
} }

View File

@ -18,9 +18,11 @@
package com.volmit.iris.util.nbt.mca.palettes; package com.volmit.iris.util.nbt.mca.palettes;
import com.volmit.iris.Iris;
import com.volmit.iris.core.nms.INMS; import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.data.cache.AtomicCache;
import com.volmit.iris.util.math.MathHelper; 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.mca.NBTWorld;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.ListTag; import com.volmit.iris.util.nbt.tag.ListTag;
@ -28,10 +30,14 @@ import com.volmit.iris.util.scheduling.J;
import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap;
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
import lombok.Getter; import lombok.Getter;
import net.minecraft.network.PacketDataSerializer; import net.minecraft.world.level.chunk.ChunkSection;
import org.bukkit.Material; import org.bukkit.Material;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors;
@Getter @Getter
public class DataPaletteBlock implements DataPaletteExpandable { public class DataPaletteBlock implements DataPaletteExpandable {
@ -53,15 +59,6 @@ public class DataPaletteBlock implements DataPaletteExpandable {
this(global(), registry(), air); this(global(), registry(), air);
} }
private static <T> RegistryBlockID registry()
{
return ((DataPaletteGlobal) global()).getRegistry();
}
private static <T> DataPalette global() {
return (DataPalette) global.aquire(() -> new DataPaletteGlobal(J.attemptResult(() -> INMS.get().computeBlockIDRegistry()), air));
}
public DataPaletteBlock(DataPalette var0, public DataPaletteBlock(DataPalette var0,
RegistryBlockID var1, RegistryBlockID var1,
CompoundTag airType) { CompoundTag airType) {
@ -71,146 +68,154 @@ public class DataPaletteBlock implements DataPaletteExpandable {
this.changeBitsTo(4); this.changeBitsTo(4);
} }
private static int blockIndex(int var0, int var1, int var2) { private static RegistryBlockID registry()
return var1 << 8 | var2 << 4 | var0; {
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) { private void changeBitsTo(int newbits) {
if (newbits != this.bits) { if (newbits != bits) {
this.bits = newbits; bits = newbits;
if (this.bits <= LINEAR_BITS) { if (bits <= LINEAR_BITS) {
this.bits = LINEAR_BITS; bits = LINEAR_BITS;
this.currentPalette = new DataPaletteLinear(this.stolenRegistry, this.bits, this); currentPalette = new DataPaletteLinear(bits, this);
} else if (this.bits < HASH_BITS) { } else if (bits < HASH_BITS) {
this.currentPalette = new DataPaletteHash(this.stolenRegistry, this.bits, this); currentPalette = new DataPaletteHash(bits, this);
} else { } else {
this.currentPalette = this.globalPalette; currentPalette = globalPalette;
this.bits = MathHelper.e(this.stolenRegistry.size()); bits = MathHelper.e(stolenRegistry.size());
} }
this.currentPalette.getIndex(this.defAir); currentPalette.getIndex(defAir);
this.dataBits = new DataBits(this.bits, 4096); dataBits = new DataBits(bits, 4096);
} }
} }
public int onResize(int newBits, CompoundTag newData) { public int onResize(int newBits, CompoundTag newData) {
DataBits var2 = this.dataBits; DataBits oldBits = dataBits;
DataPalette var3 = this.currentPalette; DataPalette oldPalette = currentPalette;
this.changeBitsTo(newBits); changeBitsTo(newBits);
for (int var4 = 0; var4 < var2.b(); ++var4) { for (int i = 0; i < oldBits.b(); ++i) {
CompoundTag var5 = var3.getByIndex(var2.getIndexFromPos(var4)); CompoundTag block = oldPalette.getByIndex(oldBits.getIndexFromPos(i));
if (var5 != null) { if (block != null) {
this.setBlockIndex(var4, var5); setBlockIndex(i, block);
} }
} }
return this.currentPalette.getIndex(newData); return currentPalette.getIndex(newData);
} }
public CompoundTag setBlock(int var0, int var1, int var2, CompoundTag var3) { @Deprecated
return this.a(blockIndex(var0, var1, var2), var3); public CompoundTag setBlockAndReturn(int x, int y, int z, CompoundTag block) {
return setBlockIndexAndReturn(blockIndex(x, y, z), block);
} }
private CompoundTag a(int var0, CompoundTag var1) { @Deprecated
int var2 = this.currentPalette.getIndex(var1); private CompoundTag setBlockIndexAndReturn(int index, CompoundTag block) {
int var3 = this.dataBits.a(var0, var2); int paletteIndex = currentPalette.getIndex(block);
CompoundTag var4 = this.currentPalette.getByIndex(var3); int res = dataBits.setBlockResulting(index, paletteIndex);
return var4 == null ? this.defAir : var4; CompoundTag testBlock = currentPalette.getByIndex(res);
return testBlock == null ? defAir : testBlock;
} }
public void c(int var0, int var1, int var2, CompoundTag var3) { public void setBlock(int x, int y, int z, CompoundTag block) {
this.setBlockIndex(blockIndex(var0, var1, var2), var3); setBlockIndex(blockIndex(x, y, z), block);
} }
private void setBlockIndex(int var0, CompoundTag var1) { private void setBlockIndex(int blockIndex, CompoundTag block) {
int var2 = this.currentPalette.getIndex(var1); int paletteIndex = currentPalette.getIndex(block);
this.dataBits.b(var0, var2); dataBits.setBlock(blockIndex, paletteIndex);
} }
public CompoundTag getBlock(int var0, int var1, int var2) { public CompoundTag getBlock(int x, int y, int z) {
return this.getByIndex(blockIndex(var0, var1, var2)); return getByIndex(blockIndex(x, y, z));
} }
protected CompoundTag getByIndex(int var0) { protected CompoundTag getByIndex(int index) {
if(this.currentPalette == null) if(currentPalette == null)
{ {
return null; return null;
} }
CompoundTag data = this.currentPalette.getByIndex(this.dataBits.getIndexFromPos(var0)); CompoundTag data = currentPalette.getByIndex(dataBits.getIndexFromPos(index));
return data == null ? this.defAir : data; return data == null ? defAir : data;
} }
public void load(ListTag<CompoundTag> palettedata, long[] databits) { public void load(ListTag<CompoundTag> palettedata, long[] databits) {
int readBits = Math.max(4, MathHelper.e(palettedata.size())); int readBits = Math.max(4, MathHelper.e(palettedata.size()));
if (readBits != this.bits) { if (readBits != bits) {
this.changeBitsTo(readBits); changeBitsTo(readBits);
} }
this.currentPalette.replace(palettedata); currentPalette.replace(palettedata);
int dblen = databits.length * 64 / 4096; int dblen = databits.length * 64 / 4096;
if (this.currentPalette == this.globalPalette) { if (currentPalette == globalPalette) {
DataPalette hashPalette = new DataPaletteHash(this.stolenRegistry, readBits, this.f); DataPalette hashPalette = new DataPaletteHash(readBits, f);
hashPalette.replace(palettedata); hashPalette.replace(palettedata);
DataBits var5 = new DataBits(readBits, 4096, databits); DataBits var5 = new DataBits(readBits, 4096, databits);
for (int var6 = 0; var6 < 4096; ++var6) { for (int i = 0; i < 4096; ++i) {
this.dataBits.b(var6, this.globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(var6)))); dataBits.setBlock(i, globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(i))));
} }
} else if (dblen == this.bits) { } else if (dblen == bits) {
System.arraycopy(databits, 0, this.dataBits.getData(), 0, databits.length); System.arraycopy(databits, 0, dataBits.getData(), 0, databits.length);
} else { } else {
DataBits var4 = new DataBits(dblen, 4096, databits); DataBits var4 = new DataBits(dblen, 4096, databits);
for (int var5 = 0; var5 < 4096; ++var5) { for (int i = 0; i < 4096; ++i) {
this.dataBits.b(var5, var4.getIndexFromPos(var5)); dataBits.setBlock(i, var4.getIndexFromPos(i));
} }
} }
} }
public void save(CompoundTag to, String paletteName, String blockStatesName) { public void save(CompoundTag to, String paletteName, String blockStatesName) {
DataPaletteHash hashpal = new DataPaletteHash(this.stolenRegistry, bits, this.f); DataPaletteHash hashpal = new DataPaletteHash(bits, f);
CompoundTag cursor = this.defAir; CompoundTag cursor = defAir;
int palIndex = hashpal.getIndex(this.defAir); int palIndex = hashpal.getIndex(defAir);
int[] var6 = new int[4096]; int[] paletteIndex = new int[4096];
int i;
for (int var7 = 0; var7 < 4096; ++var7) { for (i = 0; i < 4096; ++i) {
CompoundTag entry = this.getByIndex(var7); CompoundTag entry = getByIndex(i);
if (!entry.equals(cursor)) { if (!entry.equals(cursor)) {
cursor = entry; cursor = entry;
palIndex = hashpal.getIndex(entry); palIndex = hashpal.getIndex(entry);
} }
var6[var7] = palIndex; paletteIndex[i] = palIndex;
} }
ListTag<CompoundTag> npalette = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class); ListTag<CompoundTag> npalette = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
hashpal.writePalette(npalette); hashpal.writePalette(npalette);
to.put(paletteName, npalette); to.put(paletteName, npalette);
int var8 = Math.max(4, MathHelper.e(npalette.size())); int bits = Math.max(4, MathHelper.e(npalette.size()));
DataBits writeBits = new DataBits(var8, 4096); DataBits writeBits = new DataBits(bits, 4096);
for (int var10 = 0; var10 < var6.length; ++var10) { for (i = 0; i < paletteIndex.length; ++i) {
writeBits.b(var10, var6[var10]); writeBits.setBlock(i, paletteIndex[i]);
} }
to.putLongArray(blockStatesName, writeBits.getData()); to.putLongArray(blockStatesName, writeBits.getData());
to.putString("DEBUG_PALETTE_MODE", this.currentPalette.getClass().getSimpleName()); to.putString("DEBUG_PALETTE_MODE", currentPalette.getClass().getSimpleName());
}
public int c() {
return 1 + this.currentPalette.a() + PacketDataSerializer.a(this.dataBits.b()) + this.dataBits.getData().length * 8;
} }
public boolean contains(Predicate<CompoundTag> var0) { public boolean contains(Predicate<CompoundTag> var0) {
return this.currentPalette.a(var0); return currentPalette.contains(var0);
} }
public void a(PaletteConsumer<CompoundTag> var0) { public void a(PaletteConsumer<CompoundTag> var0) {
Int2IntMap var1 = new Int2IntOpenHashMap(); Int2IntMap var1 = new Int2IntOpenHashMap();
this.dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1)); dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1));
var1.int2IntEntrySet().forEach((var1x) -> var0.accept(this.currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue())); var1.int2IntEntrySet().forEach((var1x) -> var0.accept(currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue()));
} }
@FunctionalInterface @FunctionalInterface

View File

@ -31,45 +31,26 @@ public class DataPaletteGlobal implements DataPalette {
private final RegistryBlockID registry; private final RegistryBlockID registry;
private final CompoundTag air; private final CompoundTag air;
public int getIndex(CompoundTag var0) { public int getIndex(CompoundTag block) {
int var1 = this.registry.getId(var0); int id = this.registry.getId(block);
return var1 == -1 ? 0 : var1; return id == -1 ? 0 : id;
} }
public boolean a(Predicate<CompoundTag> var0) { public boolean contains(Predicate<CompoundTag> predicate) {
return true; return true;
} }
public CompoundTag getByIndex(int var0) { public CompoundTag getByIndex(int index) {
CompoundTag var1 = this.registry.fromId(var0); CompoundTag block = registry.fromId(index);
return var1 == null ? this.air : var1; return block == null ? air : block;
} }
public static int aa(int i) { public int size() {
for(int j = 1; j < 5; ++j) { return registry.size();
if ((i & -1 << j * 7) == 0) {
return j;
}
}
return 5;
}
public int a() {
return aa(0);
}
public int b() {
return this.registry.size();
} }
@Override @Override
public void replace(ListTag<CompoundTag> t) { public void replace(ListTag<CompoundTag> palette) {
throw new UnsupportedOperationException("Cannot replace the global palette!");
}
@Override
public ListTag<CompoundTag> getPalette() {
return null;
} }
} }

View File

@ -20,39 +20,35 @@ package com.volmit.iris.util.nbt.mca.palettes;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.ListTag; import com.volmit.iris.util.nbt.tag.ListTag;
import net.minecraft.network.PacketDataSerializer;
import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
public class DataPaletteHash implements DataPalette { public class DataPaletteHash implements DataPalette {
private final RegistryBlockID registryBlock;
private final RegistryID registryId; private final RegistryID registryId;
private final DataPaletteExpandable expander; private final DataPaletteExpandable expander;
private final int bits; private final int bits;
public DataPaletteHash(RegistryBlockID var0, int bits, DataPaletteExpandable expander) { public DataPaletteHash(int bits, DataPaletteExpandable expander) {
this.registryBlock = var0;
this.bits = bits; this.bits = bits;
this.expander = expander; this.expander = expander;
this.registryId = new RegistryID(1 << bits); this.registryId = new RegistryID(1 << bits);
} }
public int getIndex(CompoundTag var0) { public int getIndex(CompoundTag block) {
int var1 = this.registryId.getId(var0); int id = registryId.getId(block);
if (var1 == -1) { if (id == -1) {
var1 = this.registryId.c(var0); id = registryId.c(block);
if (var1 >= 1 << this.bits) { if (id >= 1 << bits) {
var1 = this.expander.onResize(this.bits + 1, var0); id = expander.onResize(bits + 1, block);
} }
} }
return var1; return id;
} }
public boolean a(Predicate<CompoundTag> var0) { public boolean contains(Predicate<CompoundTag> predicate) {
for (int var1 = 0; var1 < this.b(); ++var1) { for (int i = 0; i < size(); ++i) {
if (var0.test(this.registryId.fromId(var1))) { if (predicate.test(registryId.fromId(i))) {
return true; return true;
} }
} }
@ -60,61 +56,25 @@ public class DataPaletteHash implements DataPalette {
return false; return false;
} }
public CompoundTag getByIndex(int var0) { public CompoundTag getByIndex(int index) {
return this.registryId.fromId(var0); return registryId.fromId(index);
} }
public void a(PacketDataSerializer var0) { public int size() {
this.registryId.a(); return registryId.size();
int var1 = var0.j();
for (int var2 = 0; var2 < var1; ++var2) {
this.registryId.c(this.registryBlock.fromId(var0.j()));
}
} }
public void b(PacketDataSerializer var0) { public void replace(ListTag<CompoundTag> palette) {
int var1 = this.b(); registryId.clear();
var0.d(var1);
for (int var2 = 0; var2 < var1; ++var2) { for (int i = 0; i < palette.size(); ++i) {
var0.d(this.registryBlock.getId(this.registryId.fromId(var2))); registryId.c(palette.get(i));
}
}
public int a() {
int var0 = PacketDataSerializer.a(this.b());
for (int var1 = 0; var1 < this.b(); ++var1) {
var0 += PacketDataSerializer.a(this.registryBlock.getId(this.registryId.fromId(var1)));
}
return var0;
}
public int b() {
return this.registryId.b();
}
public void replace(ListTag<CompoundTag> var0) {
this.registryId.a();
for (int var1 = 0; var1 < var0.size(); ++var1) {
this.registryId.c(var0.get(var1));
} }
} }
@Override public void writePalette(ListTag<CompoundTag> list) {
public ListTag<CompoundTag> getPalette() { for (int i = 0; i < size(); ++i) {
return null; list.add(registryId.fromId(i));
}
public void writePalette(ListTag<CompoundTag> var0) {
for (int var1 = 0; var1 < this.b(); ++var1) {
var0.add((CompoundTag) this.registryId.fromId(var1));
} }
} }
} }

View File

@ -20,46 +20,43 @@ package com.volmit.iris.util.nbt.mca.palettes;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
import com.volmit.iris.util.nbt.tag.ListTag; import com.volmit.iris.util.nbt.tag.ListTag;
import net.minecraft.network.PacketDataSerializer;
import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
public class DataPaletteLinear implements DataPalette { public class DataPaletteLinear implements DataPalette {
private final RegistryBlockID a; private final CompoundTag[] palette;
private final CompoundTag[] b; private final DataPaletteExpandable expander;
private final DataPaletteExpandable c;
private final int e; private final int e;
private int f; private int size;
public DataPaletteLinear(RegistryBlockID var0, int var1, DataPaletteExpandable var2) { public DataPaletteLinear(int bits, DataPaletteExpandable expander) {
this.a = var0; this.palette = new CompoundTag[1 << bits];
this.b = (CompoundTag[]) new Object[1 << var1]; this.e = bits;
this.e = var1; this.expander = expander;
this.c = var2; this.size = 0;
} }
public int getIndex(CompoundTag var0) { public int getIndex(CompoundTag block) {
int var1; int i;
for (var1 = 0; var1 < this.f; ++var1) { for (i = 0; i < size; ++i) {
if (this.b[var1].equals(var0)) { if (palette[i].equals(block)) {
return var1; return i;
} }
} }
var1 = this.f; i = size;
if (var1 < this.b.length) { if (i < palette.length) {
this.b[var1] = var0; palette[i] = block;
++this.f; ++size;
return var1; return i;
} else { } else {
return this.c.onResize(this.e + 1, var0); return expander.onResize(e + 1, block);
} }
} }
public boolean a(Predicate<CompoundTag> var0) { public boolean contains(Predicate<CompoundTag> predicate) {
for (int var1 = 0; var1 < this.f; ++var1) { for (int i = 0; i < this.size; ++i) {
if (var0.test(this.b[var1])) { if (predicate.test(palette[i])) {
return true; return true;
} }
} }
@ -67,58 +64,19 @@ public class DataPaletteLinear implements DataPalette {
return false; return false;
} }
public CompoundTag getByIndex(int var0) { public CompoundTag getByIndex(int index) {
return var0 >= 0 && var0 < this.f ? this.b[var0] : null; return index >= 0 && index < size ? palette[index] : null;
} }
public void a(PacketDataSerializer var0) { public int size() {
this.f = var0.j(); return size;
}
for (int var1 = 0; var1 < this.f; ++var1) { public void replace(ListTag<CompoundTag> palette) {
this.b[var1] = this.a.fromId(var0.j()); for (int i = 0; i < palette.size(); ++i) {
this.palette[i] = palette.get(i);
} }
} this.size = palette.size();
public void b(PacketDataSerializer var0) {
var0.d(this.f);
for (int var1 = 0; var1 < this.f; ++var1) {
var0.d(this.a.getId(this.b[var1]));
}
}
public int a() {
int var0 = PacketDataSerializer.a(this.b());
for (int var1 = 0; var1 < this.b(); ++var1) {
var0 += PacketDataSerializer.a(this.a.getId(this.b[var1]));
}
return var0;
}
public int b() {
return this.f;
}
public void replace(ListTag<CompoundTag> var0) {
for (int var1 = 0; var1 < var0.size(); ++var1) {
this.b[var1] = var0.get(var1);
}
this.f = var0.size();
}
@Override
public ListTag<CompoundTag> getPalette() {
ListTag<CompoundTag> c = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
for(CompoundTag i : b)
{
c.add(i);
}
return c;
} }
} }

View File

@ -21,7 +21,7 @@ package com.volmit.iris.util.nbt.mca.palettes;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
public interface Registry extends Iterable<CompoundTag> { public interface Registry extends Iterable<CompoundTag> {
int getId(CompoundTag var1); int getId(CompoundTag block);
CompoundTag fromId(int var1); CompoundTag fromId(int id);
} }

View File

@ -18,7 +18,6 @@
package com.volmit.iris.util.nbt.mca.palettes; package com.volmit.iris.util.nbt.mca.palettes;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
@ -26,15 +25,12 @@ import com.volmit.iris.util.nbt.tag.CompoundTag;
import java.util.*; import java.util.*;
public class RegistryBlockID implements Registry { public class RegistryBlockID implements Registry {
public static final int a = -1;
private int b;
private final Map<CompoundTag, Integer> indexMap; private final Map<CompoundTag, Integer> indexMap;
private final List<CompoundTag> indexes; private final List<CompoundTag> indexes;
public RegistryBlockID(Map<CompoundTag, Integer> c, List<CompoundTag> d, int b) { public RegistryBlockID(Map<CompoundTag, Integer> c, List<CompoundTag> d) {
this.indexMap = c; this.indexMap = c;
this.indexes = d; this.indexes = d;
this.b = b;
} }
public RegistryBlockID() { public RegistryBlockID() {
@ -46,17 +42,17 @@ public class RegistryBlockID implements Registry {
this.indexMap = new HashMap<>(var0); this.indexMap = new HashMap<>(var0);
} }
public int getId(CompoundTag var0) { public int getId(CompoundTag block) {
Integer var1 = this.indexMap.get(var0); Integer var1 = this.indexMap.get(block);
return var1 == null ? -1 : var1; return var1 == null ? -1 : var1;
} }
public final CompoundTag fromId(int var0) { public final CompoundTag fromId(int id) {
return var0 >= 0 && var0 < this.indexes.size() ? this.indexes.get(var0) : null; return id >= 0 && id < this.indexes.size() ? this.indexes.get(id) : null;
} }
public Iterator<CompoundTag> iterator() { public Iterator<CompoundTag> iterator() {
return Iterators.filter(this.indexes.iterator(), Predicates.notNull()); return Iterators.filter(this.indexes.iterator(), Objects::nonNull);
} }
public boolean hasIndex(int var0) { public boolean hasIndex(int var0) {

View File

@ -18,37 +18,37 @@
package com.volmit.iris.util.nbt.mca.palettes; package com.volmit.iris.util.nbt.mca.palettes;
import com.google.common.base.Predicates;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.volmit.iris.util.math.MathHelper; import com.volmit.iris.util.math.MathHelper;
import com.volmit.iris.util.nbt.tag.CompoundTag; import com.volmit.iris.util.nbt.tag.CompoundTag;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.Objects;
public class RegistryID implements Registry { public class RegistryID implements Registry {
public static final int a = -1; public static final int a = -1;
private static final Object b = null; private static final CompoundTag b = null;
private static final float c = 0.8F; private static final float c = 0.8F;
private CompoundTag[] d; private CompoundTag[] d;
private int[] e; private int[] e;
private CompoundTag[] f; private CompoundTag[] f;
private int g; private int g;
private int h; private int size;
public RegistryID(int var0) { public RegistryID(int var0) {
var0 = (int) ((float) var0 / 0.8F); var0 = (int) ((float) var0 / 0.8F);
this.d = (CompoundTag[]) new Object[var0]; this.d = new CompoundTag[var0];
this.f = new CompoundTag[var0];
this.e = new int[var0]; this.e = new int[var0];
this.f = (CompoundTag[]) new Object[var0];
} }
public int getId(CompoundTag var0) { public int getId(CompoundTag block) {
return this.c(this.b(var0, this.d(var0))); return this.c(this.b(block, this.d(block)));
} }
public CompoundTag fromId(int var0) { public CompoundTag fromId(int id) {
return var0 >= 0 && var0 < this.f.length ? this.f[var0] : null; return id >= 0 && id < this.f.length ? this.f[id] : null;
} }
private int c(int var0) { private int c(int var0) {
@ -80,22 +80,21 @@ public class RegistryID implements Registry {
private void d(int var0) { private void d(int var0) {
CompoundTag[] var1 = this.d; CompoundTag[] var1 = this.d;
int[] var2 = this.e; int[] var2 = this.e;
this.d = (CompoundTag[]) new Object[var0]; this.d = new CompoundTag[var0];
this.e = new int[var0]; this.e = new int[var0];
this.f = (CompoundTag[]) new Object[var0]; this.f = new CompoundTag[var0];
this.g = 0; this.g = 0;
this.h = 0; this.size = 0;
for (int var3 = 0; var3 < var1.length; ++var3) { for (int var3 = 0; var3 < var1.length; ++var3) {
if (var1[var3] != null) { if (var1[var3] != null) {
this.a(var1[var3], var2[var3]); this.a(var1[var3], var2[var3]);
} }
} }
} }
public void a(CompoundTag var0, int var1) { public void a(CompoundTag var0, int var1) {
int var2 = Math.max(var1, this.h + 1); int var2 = Math.max(var1, this.size + 1);
int var3; int var3;
if ((float) var2 >= (float) this.d.length * 0.8F) { if ((float) var2 >= (float) this.d.length * 0.8F) {
for (var3 = this.d.length << 1; var3 < var1; var3 <<= 1) { for (var3 = this.d.length << 1; var3 < var1; var3 <<= 1) {
@ -108,36 +107,35 @@ public class RegistryID implements Registry {
this.d[var3] = var0; this.d[var3] = var0;
this.e[var3] = var1; this.e[var3] = var1;
this.f[var1] = var0; this.f[var1] = var0;
++this.h; ++this.size;
if (var1 == this.g) { if (var1 == this.g) {
++this.g; ++this.g;
} }
} }
private int d(CompoundTag var0) { private int d(CompoundTag block) {
return (MathHelper.g(System.identityHashCode(var0)) & 2147483647) % this.d.length; return (MathHelper.g(System.identityHashCode(block)) & 2147483647) % this.d.length;
} }
private int b(CompoundTag var0, int var1) { private int b(CompoundTag block, int var1) {
int var2; int var2;
for (var2 = var1; var2 < this.d.length; ++var2) { for (var2 = var1; var2 < this.d.length; ++var2) {
if (this.d[var2] == var0) { if (this.d[var2] == null) {
return var2; return -1;
} }
if (this.d[var2] == b) { if (this.d[var2].equals(block)) {
return -1; return var2;
} }
} }
for (var2 = 0; var2 < var1; ++var2) { for (var2 = 0; var2 < var1; ++var2) {
if (this.d[var2] == var0) { if (this.d[var2] == null) {
return var2; return -1;
} }
if (this.d[var2] == b) { if (this.d[var2].equals(block)) {
return -1; return var2;
} }
} }
@ -147,13 +145,13 @@ public class RegistryID implements Registry {
private int e(int var0) { private int e(int var0) {
int var1; int var1;
for (var1 = var0; var1 < this.d.length; ++var1) { for (var1 = var0; var1 < this.d.length; ++var1) {
if (this.d[var1] == b) { if (this.d[var1] == null) {
return var1; return var1;
} }
} }
for (var1 = 0; var1 < var0; ++var1) { for (var1 = 0; var1 < var0; ++var1) {
if (this.d[var1] == b) { if (this.d[var1] == null) {
return var1; return var1;
} }
} }
@ -162,17 +160,17 @@ public class RegistryID implements Registry {
} }
public Iterator<CompoundTag> iterator() { public Iterator<CompoundTag> iterator() {
return Iterators.filter(Iterators.forArray(this.f), Predicates.notNull()); return Iterators.filter(Iterators.forArray(this.f), Objects::nonNull);
} }
public void a() { public void clear() {
Arrays.fill(this.d, (Object) null); Arrays.fill(this.d, null);
Arrays.fill(this.f, (Object) null); Arrays.fill(this.f, null);
this.g = 0; this.g = 0;
this.h = 0; this.size = 0;
} }
public int b() { public int size() {
return this.h; return this.size;
} }
} }