mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
No generics in the palette.
This commit is contained in:
parent
2683c2433b
commit
1dce68212f
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.function;
|
||||
|
||||
public interface NastySupplier<T> {
|
||||
T get() throws Throwable;
|
||||
}
|
@ -23,12 +23,12 @@ import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface DataPalette<T> {
|
||||
int getIndex(T var1);
|
||||
public interface DataPalette {
|
||||
int getIndex(CompoundTag var1);
|
||||
|
||||
boolean a(Predicate<T> var1);
|
||||
boolean a(Predicate<CompoundTag> var1);
|
||||
|
||||
T getByIndex(int var1);
|
||||
CompoundTag getByIndex(int var1);
|
||||
|
||||
int a();
|
||||
|
||||
|
@ -24,67 +24,50 @@ import com.volmit.iris.util.math.MathHelper;
|
||||
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.network.PacketDataSerializer;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Getter
|
||||
public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
||||
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<T> globalPalette;
|
||||
private final DataPaletteExpandable<T> f = (var0x, var1x) -> 0;
|
||||
private final RegistryBlockID<T> stolenRegistry;
|
||||
private final Function<CompoundTag, T> h;
|
||||
private final Function<T, CompoundTag> i;
|
||||
private final T defAir;
|
||||
private static final AtomicCache<RegistryBlockID<CompoundTag>> reg = new AtomicCache<>();
|
||||
private static final AtomicCache<DataPaletteGlobal<CompoundTag>> global = new AtomicCache<>();
|
||||
private final DataPalette globalPalette;
|
||||
private final DataPaletteExpandable f = (var0x, var1x) -> 0;
|
||||
private final RegistryBlockID stolenRegistry;
|
||||
private final CompoundTag defAir;
|
||||
private static final AtomicCache<RegistryBlockID> reg = new AtomicCache<>();
|
||||
private static final AtomicCache<DataPaletteGlobal> global = new AtomicCache<>();
|
||||
private static final CompoundTag air = NBTWorld.getCompound(Material.AIR.createBlockData());
|
||||
protected DataBits dataBits;
|
||||
private DataPalette<T> currentPalette;
|
||||
private DataPalette currentPalette;
|
||||
private int bits = 0;
|
||||
|
||||
public DataPaletteBlock() {
|
||||
this((DataPalette<T>) global.aquire(() ->
|
||||
new DataPaletteGlobal<>(reg.aquire(() -> {
|
||||
try {
|
||||
return INMS.get().computeBlockIDRegistry();
|
||||
} catch (NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}), air)
|
||||
), (RegistryBlockID<T>) reg.aquire(() -> {
|
||||
try {
|
||||
return INMS.get().computeBlockIDRegistry();
|
||||
} catch (NoSuchFieldException ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}), (i) -> (T) i, (i) -> (CompoundTag) i, (T) air);
|
||||
this(global(), registry(), air);
|
||||
}
|
||||
|
||||
public DataPaletteBlock(DataPalette<T> var0,
|
||||
RegistryBlockID<T> var1,
|
||||
Function<CompoundTag, T> var2,
|
||||
Function<T, CompoundTag> var3,
|
||||
T var4) {
|
||||
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) {
|
||||
this.globalPalette = var0;
|
||||
this.stolenRegistry = var1;
|
||||
this.h = var2;
|
||||
this.i = var3;
|
||||
this.defAir = var4;
|
||||
this.defAir = airType;
|
||||
this.changeBitsTo(4);
|
||||
}
|
||||
|
||||
@ -97,9 +80,9 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
||||
this.bits = newbits;
|
||||
if (this.bits <= LINEAR_BITS) {
|
||||
this.bits = LINEAR_BITS;
|
||||
this.currentPalette = new DataPaletteLinear<T>(this.stolenRegistry, this.bits, this, this.h);
|
||||
this.currentPalette = new DataPaletteLinear(this.stolenRegistry, this.bits, this);
|
||||
} else if (this.bits < HASH_BITS) {
|
||||
this.currentPalette = new DataPaletteHash<T>(this.stolenRegistry, this.bits, this, this.h, this.i);
|
||||
this.currentPalette = new DataPaletteHash(this.stolenRegistry, this.bits, this);
|
||||
} else {
|
||||
this.currentPalette = this.globalPalette;
|
||||
this.bits = MathHelper.e(this.stolenRegistry.size());
|
||||
@ -110,52 +93,52 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public int onResize(int var0, T var1) {
|
||||
public int onResize(int newBits, CompoundTag newData) {
|
||||
DataBits var2 = this.dataBits;
|
||||
DataPalette<T> var3 = this.currentPalette;
|
||||
this.changeBitsTo(var0);
|
||||
DataPalette var3 = this.currentPalette;
|
||||
this.changeBitsTo(newBits);
|
||||
|
||||
for (int var4 = 0; var4 < var2.b(); ++var4) {
|
||||
T var5 = var3.getByIndex(var2.getIndexFromPos(var4));
|
||||
CompoundTag var5 = var3.getByIndex(var2.getIndexFromPos(var4));
|
||||
if (var5 != null) {
|
||||
this.setBlockIndex(var4, var5);
|
||||
}
|
||||
}
|
||||
|
||||
return this.currentPalette.getIndex(var1);
|
||||
return this.currentPalette.getIndex(newData);
|
||||
}
|
||||
|
||||
public T setBlock(int var0, int var1, int var2, T var3) {
|
||||
public CompoundTag setBlock(int var0, int var1, int var2, CompoundTag var3) {
|
||||
return this.a(blockIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
private T a(int var0, T var1) {
|
||||
private CompoundTag a(int var0, CompoundTag var1) {
|
||||
int var2 = this.currentPalette.getIndex(var1);
|
||||
int var3 = this.dataBits.a(var0, var2);
|
||||
T var4 = this.currentPalette.getByIndex(var3);
|
||||
CompoundTag var4 = this.currentPalette.getByIndex(var3);
|
||||
return var4 == null ? this.defAir : var4;
|
||||
}
|
||||
|
||||
public void c(int var0, int var1, int var2, T var3) {
|
||||
public void c(int var0, int var1, int var2, CompoundTag var3) {
|
||||
this.setBlockIndex(blockIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
private void setBlockIndex(int var0, T var1) {
|
||||
private void setBlockIndex(int var0, CompoundTag var1) {
|
||||
int var2 = this.currentPalette.getIndex(var1);
|
||||
this.dataBits.b(var0, var2);
|
||||
}
|
||||
|
||||
public T getBlock(int var0, int var1, int var2) {
|
||||
public CompoundTag getBlock(int var0, int var1, int var2) {
|
||||
return this.getByIndex(blockIndex(var0, var1, var2));
|
||||
}
|
||||
|
||||
protected T getByIndex(int var0) {
|
||||
protected CompoundTag getByIndex(int var0) {
|
||||
if(this.currentPalette == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
T data = this.currentPalette.getByIndex(this.dataBits.getIndexFromPos(var0));
|
||||
CompoundTag data = this.currentPalette.getByIndex(this.dataBits.getIndexFromPos(var0));
|
||||
return data == null ? this.defAir : data;
|
||||
}
|
||||
|
||||
@ -168,7 +151,7 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
||||
this.currentPalette.replace(palettedata);
|
||||
int dblen = databits.length * 64 / 4096;
|
||||
if (this.currentPalette == this.globalPalette) {
|
||||
DataPalette<T> hashPalette = new DataPaletteHash<T>(this.stolenRegistry, readBits, this.f, this.h, this.i);
|
||||
DataPalette hashPalette = new DataPaletteHash(this.stolenRegistry, readBits, this.f);
|
||||
hashPalette.replace(palettedata);
|
||||
DataBits var5 = new DataBits(readBits, 4096, databits);
|
||||
|
||||
@ -187,13 +170,13 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
||||
}
|
||||
|
||||
public void save(CompoundTag to, String paletteName, String blockStatesName) {
|
||||
DataPaletteHash<T> hashpal = new DataPaletteHash<T>(this.stolenRegistry, bits, this.f, this.h, this.i);
|
||||
T cursor = this.defAir;
|
||||
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) {
|
||||
T entry = this.getByIndex(var7);
|
||||
CompoundTag entry = this.getByIndex(var7);
|
||||
if (!entry.equals(cursor)) {
|
||||
cursor = entry;
|
||||
palIndex = hashpal.getIndex(entry);
|
||||
@ -213,24 +196,25 @@ public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<T> var0) {
|
||||
public boolean contains(Predicate<CompoundTag> var0) {
|
||||
return this.currentPalette.a(var0);
|
||||
}
|
||||
|
||||
public void a(DataPaletteBlock.a<T> 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()));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface a<T> {
|
||||
public interface PaletteConsumer<T> {
|
||||
void accept(T var1, int var2);
|
||||
}
|
||||
}
|
@ -18,6 +18,8 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
interface DataPaletteExpandable<T> {
|
||||
int onResize(int var1, T var2);
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
interface DataPaletteExpandable {
|
||||
int onResize(int newBits, CompoundTag newData);
|
||||
}
|
||||
|
@ -20,30 +20,29 @@ 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;
|
||||
|
||||
public class DataPaletteGlobal<T> implements DataPalette<T> {
|
||||
private final RegistryBlockID<T> a;
|
||||
private final T b;
|
||||
@RequiredArgsConstructor
|
||||
public class DataPaletteGlobal implements DataPalette {
|
||||
@Getter
|
||||
private final RegistryBlockID registry;
|
||||
private final CompoundTag air;
|
||||
|
||||
public DataPaletteGlobal(RegistryBlockID<T> var0, T var1) {
|
||||
this.a = var0;
|
||||
this.b = var1;
|
||||
}
|
||||
|
||||
public int getIndex(T var0) {
|
||||
int var1 = this.a.getId(var0);
|
||||
public int getIndex(CompoundTag var0) {
|
||||
int var1 = this.registry.getId(var0);
|
||||
return var1 == -1 ? 0 : var1;
|
||||
}
|
||||
|
||||
public boolean a(Predicate<T> var0) {
|
||||
public boolean a(Predicate<CompoundTag> var0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public T getByIndex(int var0) {
|
||||
T var1 = this.a.fromId(var0);
|
||||
return var1 == null ? this.b : var1;
|
||||
public CompoundTag getByIndex(int var0) {
|
||||
CompoundTag var1 = this.registry.fromId(var0);
|
||||
return var1 == null ? this.air : var1;
|
||||
}
|
||||
|
||||
public static int aa(int i) {
|
||||
@ -61,7 +60,7 @@ public class DataPaletteGlobal<T> implements DataPalette<T> {
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.a.size();
|
||||
return this.registry.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -18,47 +18,41 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import net.minecraft.network.PacketDataSerializer;
|
||||
import net.minecraft.world.level.chunk.ChunkSection;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DataPaletteHash<T> implements DataPalette<T> {
|
||||
private final RegistryBlockID<T> a;
|
||||
private final RegistryID<T> b;
|
||||
private final DataPaletteExpandable<T> c;
|
||||
private final Function<CompoundTag, T> d;
|
||||
private final Function<T, CompoundTag> e;
|
||||
private final int f;
|
||||
public class DataPaletteHash implements DataPalette {
|
||||
private final RegistryBlockID registryBlock;
|
||||
private final RegistryID registryId;
|
||||
private final DataPaletteExpandable expander;
|
||||
private final int bits;
|
||||
|
||||
public DataPaletteHash(RegistryBlockID<T> var0, int var1, DataPaletteExpandable<T> var2, Function<CompoundTag, T> var3, Function<T, CompoundTag> var4) {
|
||||
this.a = var0;
|
||||
this.f = var1;
|
||||
this.c = var2;
|
||||
this.d = var3;
|
||||
this.e = var4;
|
||||
this.b = new RegistryID<T>(1 << var1);
|
||||
public DataPaletteHash(RegistryBlockID var0, int bits, DataPaletteExpandable expander) {
|
||||
this.registryBlock = var0;
|
||||
this.bits = bits;
|
||||
this.expander = expander;
|
||||
this.registryId = new RegistryID(1 << bits);
|
||||
}
|
||||
|
||||
public int getIndex(T var0) {
|
||||
int var1 = this.b.getId(var0);
|
||||
public int getIndex(CompoundTag var0) {
|
||||
int var1 = this.registryId.getId(var0);
|
||||
if (var1 == -1) {
|
||||
var1 = this.b.c(var0);
|
||||
if (var1 >= 1 << this.f) {
|
||||
var1 = this.c.onResize(this.f + 1, var0);
|
||||
var1 = this.registryId.c(var0);
|
||||
if (var1 >= 1 << this.bits) {
|
||||
var1 = this.expander.onResize(this.bits + 1, var0);
|
||||
}
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
|
||||
public boolean a(Predicate<T> var0) {
|
||||
public boolean a(Predicate<CompoundTag> var0) {
|
||||
for (int var1 = 0; var1 < this.b(); ++var1) {
|
||||
if (var0.test(this.b.fromId(var1))) {
|
||||
if (var0.test(this.registryId.fromId(var1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -66,16 +60,16 @@ public class DataPaletteHash<T> implements DataPalette<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public T getByIndex(int var0) {
|
||||
return this.b.fromId(var0);
|
||||
public CompoundTag getByIndex(int var0) {
|
||||
return this.registryId.fromId(var0);
|
||||
}
|
||||
|
||||
public void a(PacketDataSerializer var0) {
|
||||
this.b.a();
|
||||
this.registryId.a();
|
||||
int var1 = var0.j();
|
||||
|
||||
for (int var2 = 0; var2 < var1; ++var2) {
|
||||
this.b.c(this.a.fromId(var0.j()));
|
||||
this.registryId.c(this.registryBlock.fromId(var0.j()));
|
||||
}
|
||||
|
||||
}
|
||||
@ -85,7 +79,7 @@ public class DataPaletteHash<T> implements DataPalette<T> {
|
||||
var0.d(var1);
|
||||
|
||||
for (int var2 = 0; var2 < var1; ++var2) {
|
||||
var0.d(this.a.getId(this.b.fromId(var2)));
|
||||
var0.d(this.registryBlock.getId(this.registryId.fromId(var2)));
|
||||
}
|
||||
|
||||
}
|
||||
@ -94,21 +88,21 @@ public class DataPaletteHash<T> implements DataPalette<T> {
|
||||
int var0 = PacketDataSerializer.a(this.b());
|
||||
|
||||
for (int var1 = 0; var1 < this.b(); ++var1) {
|
||||
var0 += PacketDataSerializer.a(this.a.getId(this.b.fromId(var1)));
|
||||
var0 += PacketDataSerializer.a(this.registryBlock.getId(this.registryId.fromId(var1)));
|
||||
}
|
||||
|
||||
return var0;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.b.b();
|
||||
return this.registryId.b();
|
||||
}
|
||||
|
||||
public void replace(ListTag<CompoundTag> var0) {
|
||||
this.b.a();
|
||||
this.registryId.a();
|
||||
|
||||
for (int var1 = 0; var1 < var0.size(); ++var1) {
|
||||
this.b.c(this.d.apply(var0.get(var1)));
|
||||
this.registryId.c(var0.get(var1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -119,7 +113,7 @@ public class DataPaletteHash<T> implements DataPalette<T> {
|
||||
|
||||
public void writePalette(ListTag<CompoundTag> var0) {
|
||||
for (int var1 = 0; var1 < this.b(); ++var1) {
|
||||
var0.add((CompoundTag) this.b.fromId(var1));
|
||||
var0.add((CompoundTag) this.registryId.fromId(var1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,23 +25,21 @@ import net.minecraft.network.PacketDataSerializer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DataPaletteLinear<T> implements DataPalette<T> {
|
||||
private final RegistryBlockID<T> a;
|
||||
private final T[] b;
|
||||
private final DataPaletteExpandable<T> c;
|
||||
private final Function<CompoundTag, T> d;
|
||||
public class DataPaletteLinear implements DataPalette {
|
||||
private final RegistryBlockID a;
|
||||
private final CompoundTag[] b;
|
||||
private final DataPaletteExpandable c;
|
||||
private final int e;
|
||||
private int f;
|
||||
|
||||
public DataPaletteLinear(RegistryBlockID<T> var0, int var1, DataPaletteExpandable<T> var2, Function<CompoundTag, T> var3) {
|
||||
public DataPaletteLinear(RegistryBlockID var0, int var1, DataPaletteExpandable var2) {
|
||||
this.a = var0;
|
||||
this.b = (T[]) new Object[1 << var1];
|
||||
this.b = (CompoundTag[]) new Object[1 << var1];
|
||||
this.e = var1;
|
||||
this.c = var2;
|
||||
this.d = var3;
|
||||
}
|
||||
|
||||
public int getIndex(T var0) {
|
||||
public int getIndex(CompoundTag var0) {
|
||||
int var1;
|
||||
for (var1 = 0; var1 < this.f; ++var1) {
|
||||
if (this.b[var1].equals(var0)) {
|
||||
@ -59,7 +57,7 @@ public class DataPaletteLinear<T> implements DataPalette<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean a(Predicate<T> var0) {
|
||||
public boolean a(Predicate<CompoundTag> var0) {
|
||||
for (int var1 = 0; var1 < this.f; ++var1) {
|
||||
if (var0.test(this.b[var1])) {
|
||||
return true;
|
||||
@ -69,7 +67,7 @@ public class DataPaletteLinear<T> implements DataPalette<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public T getByIndex(int var0) {
|
||||
public CompoundTag getByIndex(int var0) {
|
||||
return var0 >= 0 && var0 < this.f ? this.b[var0] : null;
|
||||
}
|
||||
|
||||
@ -107,7 +105,7 @@ public class DataPaletteLinear<T> implements DataPalette<T> {
|
||||
|
||||
public void replace(ListTag<CompoundTag> var0) {
|
||||
for (int var1 = 0; var1 < var0.size(); ++var1) {
|
||||
this.b[var1] = this.d.apply(var0.get(var1));
|
||||
this.b[var1] = var0.get(var1);
|
||||
}
|
||||
|
||||
this.f = var0.size();
|
||||
@ -116,9 +114,9 @@ public class DataPaletteLinear<T> implements DataPalette<T> {
|
||||
@Override
|
||||
public ListTag<CompoundTag> getPalette() {
|
||||
ListTag<CompoundTag> c = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
for(T i : b)
|
||||
for(CompoundTag i : b)
|
||||
{
|
||||
c.add((CompoundTag) i);
|
||||
c.add(i);
|
||||
}
|
||||
|
||||
return c;
|
||||
|
@ -18,8 +18,10 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
public interface Registry<T> extends Iterable<T> {
|
||||
int getId(T var1);
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
T fromId(int var1);
|
||||
public interface Registry extends Iterable<CompoundTag> {
|
||||
int getId(CompoundTag var1);
|
||||
|
||||
CompoundTag fromId(int var1);
|
||||
}
|
@ -21,20 +21,18 @@ 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class RegistryBlockID<T> implements Registry<T> {
|
||||
public class RegistryBlockID implements Registry {
|
||||
public static final int a = -1;
|
||||
private int b;
|
||||
private final HashMap<T, Integer> indexMap;
|
||||
private final List<T> indexes;
|
||||
private final Map<CompoundTag, Integer> indexMap;
|
||||
private final List<CompoundTag> indexes;
|
||||
|
||||
public RegistryBlockID(IdentityHashMap<T, Integer> c, List<T> d, int b) {
|
||||
this.indexMap = new HashMap<>(c);
|
||||
public RegistryBlockID(Map<CompoundTag, Integer> c, List<CompoundTag> d, int b) {
|
||||
this.indexMap = c;
|
||||
this.indexes = d;
|
||||
this.b = b;
|
||||
}
|
||||
@ -48,16 +46,16 @@ public class RegistryBlockID<T> implements Registry<T> {
|
||||
this.indexMap = new HashMap<>(var0);
|
||||
}
|
||||
|
||||
public int getId(T var0) {
|
||||
public int getId(CompoundTag var0) {
|
||||
Integer var1 = this.indexMap.get(var0);
|
||||
return var1 == null ? -1 : var1;
|
||||
}
|
||||
|
||||
public final T fromId(int var0) {
|
||||
public final CompoundTag fromId(int var0) {
|
||||
return var0 >= 0 && var0 < this.indexes.size() ? this.indexes.get(var0) : null;
|
||||
}
|
||||
|
||||
public Iterator<T> iterator() {
|
||||
public Iterator<CompoundTag> iterator() {
|
||||
return Iterators.filter(this.indexes.iterator(), Predicates.notNull());
|
||||
}
|
||||
|
||||
|
@ -21,32 +21,33 @@ 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;
|
||||
|
||||
public class RegistryID<K> implements Registry<K> {
|
||||
public class RegistryID implements Registry {
|
||||
public static final int a = -1;
|
||||
private static final Object b = null;
|
||||
private static final float c = 0.8F;
|
||||
private K[] d;
|
||||
private CompoundTag[] d;
|
||||
private int[] e;
|
||||
private K[] f;
|
||||
private CompoundTag[] f;
|
||||
private int g;
|
||||
private int h;
|
||||
|
||||
public RegistryID(int var0) {
|
||||
var0 = (int) ((float) var0 / 0.8F);
|
||||
this.d = (K[]) new Object[var0];
|
||||
this.d = (CompoundTag[]) new Object[var0];
|
||||
this.e = new int[var0];
|
||||
this.f = (K[]) new Object[var0];
|
||||
this.f = (CompoundTag[]) new Object[var0];
|
||||
}
|
||||
|
||||
public int getId(K var0) {
|
||||
public int getId(CompoundTag var0) {
|
||||
return this.c(this.b(var0, this.d(var0)));
|
||||
}
|
||||
|
||||
public K fromId(int var0) {
|
||||
public CompoundTag fromId(int var0) {
|
||||
return var0 >= 0 && var0 < this.f.length ? this.f[var0] : null;
|
||||
}
|
||||
|
||||
@ -54,7 +55,7 @@ public class RegistryID<K> implements Registry<K> {
|
||||
return var0 == -1 ? -1 : this.e[var0];
|
||||
}
|
||||
|
||||
public boolean b(K var0) {
|
||||
public boolean b(CompoundTag var0) {
|
||||
return this.getId(var0) != -1;
|
||||
}
|
||||
|
||||
@ -62,7 +63,7 @@ public class RegistryID<K> implements Registry<K> {
|
||||
return this.fromId(var0) != null;
|
||||
}
|
||||
|
||||
public int c(K var0) {
|
||||
public int c(CompoundTag var0) {
|
||||
int var1 = this.c();
|
||||
this.a(var0, var1);
|
||||
return var1;
|
||||
@ -77,11 +78,11 @@ public class RegistryID<K> implements Registry<K> {
|
||||
}
|
||||
|
||||
private void d(int var0) {
|
||||
K[] var1 = this.d;
|
||||
CompoundTag[] var1 = this.d;
|
||||
int[] var2 = this.e;
|
||||
this.d = (K[]) new Object[var0];
|
||||
this.d = (CompoundTag[]) new Object[var0];
|
||||
this.e = new int[var0];
|
||||
this.f = (K[]) new Object[var0];
|
||||
this.f = (CompoundTag[]) new Object[var0];
|
||||
this.g = 0;
|
||||
this.h = 0;
|
||||
|
||||
@ -93,7 +94,7 @@ public class RegistryID<K> implements Registry<K> {
|
||||
|
||||
}
|
||||
|
||||
public void a(K var0, int var1) {
|
||||
public void a(CompoundTag var0, int var1) {
|
||||
int var2 = Math.max(var1, this.h + 1);
|
||||
int var3;
|
||||
if ((float) var2 >= (float) this.d.length * 0.8F) {
|
||||
@ -114,11 +115,11 @@ public class RegistryID<K> implements Registry<K> {
|
||||
|
||||
}
|
||||
|
||||
private int d(K var0) {
|
||||
private int d(CompoundTag var0) {
|
||||
return (MathHelper.g(System.identityHashCode(var0)) & 2147483647) % this.d.length;
|
||||
}
|
||||
|
||||
private int b(K var0, int var1) {
|
||||
private int b(CompoundTag var0, int var1) {
|
||||
int var2;
|
||||
for (var2 = var1; var2 < this.d.length; ++var2) {
|
||||
if (this.d[var2] == var0) {
|
||||
@ -160,7 +161,7 @@ public class RegistryID<K> implements Registry<K> {
|
||||
throw new RuntimeException("Overflowed :(");
|
||||
}
|
||||
|
||||
public Iterator<K> iterator() {
|
||||
public Iterator<CompoundTag> iterator() {
|
||||
return Iterators.filter(Iterators.forArray(this.f), Predicates.notNull());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user