mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Hashmap palettes for custom data
This commit is contained in:
parent
600bf94044
commit
5f3dcac8e1
@ -21,29 +21,19 @@ package com.volmit.iris.util.data.palette;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class HashMapPalette<T> implements Palette<T> {
|
||||
private final IdMapper<T> registry;
|
||||
|
||||
private final CrudeIncrementalIntIdentityHashBiMap<T> values;
|
||||
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
private final Function<T, CompoundTag> writer;
|
||||
|
||||
private final int bits;
|
||||
|
||||
public HashMapPalette(IdMapper<T> var0, int var1, PaletteResize<T> var2, Function<CompoundTag, T> var3, Function<T, CompoundTag> var4) {
|
||||
this.registry = var0;
|
||||
public HashMapPalette(int var1, PaletteResize<T> var2) {
|
||||
this.bits = var1;
|
||||
this.resizeHandler = var2;
|
||||
this.reader = var3;
|
||||
this.writer = var4;
|
||||
this.values = new CrudeIncrementalIntIdentityHashBiMap(1 << var1);
|
||||
this.values = new CrudeIncrementalIntIdentityHashBiMap<>(1 << var1);
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
@ -51,8 +41,10 @@ public class HashMapPalette<T> implements Palette<T> {
|
||||
if (var1 == -1) {
|
||||
var1 = this.values.add(var0);
|
||||
if (var1 >= 1 << this.bits)
|
||||
{
|
||||
var1 = this.resizeHandler.onResize(this.bits + 1, var0);
|
||||
}
|
||||
}
|
||||
return var1;
|
||||
}
|
||||
|
||||
@ -72,14 +64,13 @@ public class HashMapPalette<T> implements Palette<T> {
|
||||
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)));
|
||||
@Override
|
||||
public void read(List<T> data) {
|
||||
data.forEach(values::add);
|
||||
}
|
||||
|
||||
public void write(ListTag var0) {
|
||||
for (int var1 = 0; var1 < getSize(); var1++)
|
||||
var0.add(this.writer.apply(this.values.byId(var1)));
|
||||
@Override
|
||||
public void write(List<T> toList) {
|
||||
this.values.iterator().forEachRemaining(toList::add);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user