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

View File

@ -24,17 +24,13 @@ import com.volmit.iris.util.nbt.tag.ListTag;
import java.util.function.Predicate;
public interface DataPalette {
int getIndex(CompoundTag var1);
int getIndex(CompoundTag block);
boolean a(Predicate<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> t);
ListTag<CompoundTag> getPalette();
void replace(ListTag<CompoundTag> palette);
}

View File

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

View File

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

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.ListTag;
import net.minecraft.network.PacketDataSerializer;
import java.util.function.Function;
import java.util.function.Predicate;
public class DataPaletteHash implements DataPalette {
private final RegistryBlockID registryBlock;
private final RegistryID registryId;
private final DataPaletteExpandable expander;
private final int bits;
public DataPaletteHash(RegistryBlockID var0, int bits, DataPaletteExpandable expander) {
this.registryBlock = var0;
public DataPaletteHash(int bits, DataPaletteExpandable expander) {
this.bits = bits;
this.expander = expander;
this.registryId = new RegistryID(1 << bits);
}
public int getIndex(CompoundTag var0) {
int var1 = this.registryId.getId(var0);
if (var1 == -1) {
var1 = this.registryId.c(var0);
if (var1 >= 1 << this.bits) {
var1 = this.expander.onResize(this.bits + 1, var0);
public int getIndex(CompoundTag block) {
int id = registryId.getId(block);
if (id == -1) {
id = registryId.c(block);
if (id >= 1 << bits) {
id = expander.onResize(bits + 1, block);
}
}
return var1;
return id;
}
public boolean a(Predicate<CompoundTag> var0) {
for (int var1 = 0; var1 < this.b(); ++var1) {
if (var0.test(this.registryId.fromId(var1))) {
public boolean contains(Predicate<CompoundTag> predicate) {
for (int i = 0; i < size(); ++i) {
if (predicate.test(registryId.fromId(i))) {
return true;
}
}
@ -60,61 +56,25 @@ public class DataPaletteHash implements DataPalette {
return false;
}
public CompoundTag getByIndex(int var0) {
return this.registryId.fromId(var0);
public CompoundTag getByIndex(int index) {
return registryId.fromId(index);
}
public void a(PacketDataSerializer var0) {
this.registryId.a();
int var1 = var0.j();
for (int var2 = 0; var2 < var1; ++var2) {
this.registryId.c(this.registryBlock.fromId(var0.j()));
public int size() {
return registryId.size();
}
}
public void replace(ListTag<CompoundTag> palette) {
registryId.clear();
public void b(PacketDataSerializer var0) {
int var1 = this.b();
var0.d(var1);
for (int var2 = 0; var2 < var1; ++var2) {
var0.d(this.registryBlock.getId(this.registryId.fromId(var2)));
}
}
public int a() {
int var0 = PacketDataSerializer.a(this.b());
for (int var1 = 0; var1 < this.b(); ++var1) {
var0 += PacketDataSerializer.a(this.registryBlock.getId(this.registryId.fromId(var1)));
}
return var0;
}
public int b() {
return this.registryId.b();
}
public void replace(ListTag<CompoundTag> var0) {
this.registryId.a();
for (int var1 = 0; var1 < var0.size(); ++var1) {
this.registryId.c(var0.get(var1));
for (int i = 0; i < palette.size(); ++i) {
registryId.c(palette.get(i));
}
}
@Override
public ListTag<CompoundTag> getPalette() {
return null;
public void writePalette(ListTag<CompoundTag> list) {
for (int i = 0; i < size(); ++i) {
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.ListTag;
import net.minecraft.network.PacketDataSerializer;
import java.util.function.Function;
import java.util.function.Predicate;
public class DataPaletteLinear implements DataPalette {
private final RegistryBlockID a;
private final CompoundTag[] b;
private final DataPaletteExpandable c;
private final CompoundTag[] palette;
private final DataPaletteExpandable expander;
private final int e;
private int f;
private int size;
public DataPaletteLinear(RegistryBlockID var0, int var1, DataPaletteExpandable var2) {
this.a = var0;
this.b = (CompoundTag[]) new Object[1 << var1];
this.e = var1;
this.c = var2;
public DataPaletteLinear(int bits, DataPaletteExpandable expander) {
this.palette = new CompoundTag[1 << bits];
this.e = bits;
this.expander = expander;
this.size = 0;
}
public int getIndex(CompoundTag var0) {
int var1;
for (var1 = 0; var1 < this.f; ++var1) {
if (this.b[var1].equals(var0)) {
return var1;
public int getIndex(CompoundTag block) {
int i;
for (i = 0; i < size; ++i) {
if (palette[i].equals(block)) {
return i;
}
}
var1 = this.f;
if (var1 < this.b.length) {
this.b[var1] = var0;
++this.f;
return var1;
i = size;
if (i < palette.length) {
palette[i] = block;
++size;
return i;
} else {
return this.c.onResize(this.e + 1, var0);
return expander.onResize(e + 1, block);
}
}
public boolean a(Predicate<CompoundTag> var0) {
for (int var1 = 0; var1 < this.f; ++var1) {
if (var0.test(this.b[var1])) {
public boolean contains(Predicate<CompoundTag> predicate) {
for (int i = 0; i < this.size; ++i) {
if (predicate.test(palette[i])) {
return true;
}
}
@ -67,58 +64,19 @@ public class DataPaletteLinear implements DataPalette {
return false;
}
public CompoundTag getByIndex(int var0) {
return var0 >= 0 && var0 < this.f ? this.b[var0] : null;
public CompoundTag getByIndex(int index) {
return index >= 0 && index < size ? palette[index] : null;
}
public void a(PacketDataSerializer var0) {
this.f = var0.j();
for (int var1 = 0; var1 < this.f; ++var1) {
this.b[var1] = this.a.fromId(var0.j());
public int size() {
return size;
}
public void replace(ListTag<CompoundTag> palette) {
for (int i = 0; i < palette.size(); ++i) {
this.palette[i] = palette.get(i);
}
public void b(PacketDataSerializer var0) {
var0.d(this.f);
for (int var1 = 0; var1 < this.f; ++var1) {
var0.d(this.a.getId(this.b[var1]));
}
}
public int a() {
int var0 = PacketDataSerializer.a(this.b());
for (int var1 = 0; var1 < this.b(); ++var1) {
var0 += PacketDataSerializer.a(this.a.getId(this.b[var1]));
}
return var0;
}
public int b() {
return this.f;
}
public void replace(ListTag<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;
this.size = palette.size();
}
}

View File

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

View File

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