mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Linear palettes for custom data
This commit is contained in:
parent
5f3dcac8e1
commit
f21306a19d
@ -50,7 +50,9 @@ public class IdMapper<T> implements IdMap<T> {
|
||||
public void addMapping(T var0, int var1) {
|
||||
this.tToId.put(var0, Integer.valueOf(var1));
|
||||
while (this.idToT.size() <= var1)
|
||||
{
|
||||
this.idToT.add(null);
|
||||
}
|
||||
this.idToT.set(var1, var0);
|
||||
if (this.nextId <= var1)
|
||||
this.nextId = var1 + 1;
|
||||
@ -67,7 +69,9 @@ public class IdMapper<T> implements IdMap<T> {
|
||||
|
||||
public final T byId(int var0) {
|
||||
if (var0 >= 0 && var0 < this.idToT.size())
|
||||
{
|
||||
return this.idToT.get(var0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -19,38 +19,35 @@
|
||||
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.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class LinearPalette<T> implements Palette<T> {
|
||||
private final IdMapper<T> registry;
|
||||
|
||||
private final T[] values;
|
||||
|
||||
private final PaletteResize<T> resizeHandler;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
private final int bits;
|
||||
|
||||
private int size;
|
||||
|
||||
public LinearPalette(IdMapper<T> var0, int var1, PaletteResize<T> var2, Function<CompoundTag, T> var3) {
|
||||
this.registry = var0;
|
||||
public LinearPalette(int var1, PaletteResize<T> var2) {
|
||||
this.values = (T[]) new Object[1 << var1];
|
||||
this.bits = var1;
|
||||
this.resizeHandler = var2;
|
||||
this.reader = var3;
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
int var1;
|
||||
for (var1 = 0; var1 < this.size; var1++) {
|
||||
if (this.values[var1] == var0)
|
||||
if(this.values[var1] == null && var0 == null)
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
|
||||
if (this.values[var1].equals(var0))
|
||||
{
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
var1 = this.size;
|
||||
if (var1 < this.values.length) {
|
||||
this.values[var1] = var0;
|
||||
@ -78,9 +75,22 @@ public class LinearPalette<T> implements Palette<T> {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public void read(ListTag var0) {
|
||||
for (int var1 = 0; var1 < var0.size(); var1++)
|
||||
this.values[var1] = this.reader.apply((CompoundTag) var0.get(var1));
|
||||
this.size = var0.size();
|
||||
@Override
|
||||
public void read(List<T> fromList) {
|
||||
for (int i = 0; i < fromList.size(); i++)
|
||||
{
|
||||
this.values[i] = fromList.get(i);
|
||||
}
|
||||
|
||||
this.size = fromList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(List<T> toList) {
|
||||
for (int i = 0; i < this.size; i++)
|
||||
{
|
||||
T v = values[i];
|
||||
toList.add(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user