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) {
|
public void addMapping(T var0, int var1) {
|
||||||
this.tToId.put(var0, Integer.valueOf(var1));
|
this.tToId.put(var0, Integer.valueOf(var1));
|
||||||
while (this.idToT.size() <= var1)
|
while (this.idToT.size() <= var1)
|
||||||
|
{
|
||||||
this.idToT.add(null);
|
this.idToT.add(null);
|
||||||
|
}
|
||||||
this.idToT.set(var1, var0);
|
this.idToT.set(var1, var0);
|
||||||
if (this.nextId <= var1)
|
if (this.nextId <= var1)
|
||||||
this.nextId = var1 + 1;
|
this.nextId = var1 + 1;
|
||||||
@ -67,7 +69,9 @@ public class IdMapper<T> implements IdMap<T> {
|
|||||||
|
|
||||||
public final T byId(int var0) {
|
public final T byId(int var0) {
|
||||||
if (var0 >= 0 && var0 < this.idToT.size())
|
if (var0 >= 0 && var0 < this.idToT.size())
|
||||||
|
{
|
||||||
return this.idToT.get(var0);
|
return this.idToT.get(var0);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,37 +19,34 @@
|
|||||||
package com.volmit.iris.util.data.palette;
|
package com.volmit.iris.util.data.palette;
|
||||||
|
|
||||||
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 java.util.function.Function;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class LinearPalette<T> implements Palette<T> {
|
public class LinearPalette<T> implements Palette<T> {
|
||||||
private final IdMapper<T> registry;
|
|
||||||
|
|
||||||
private final T[] values;
|
private final T[] values;
|
||||||
|
|
||||||
private final PaletteResize<T> resizeHandler;
|
private final PaletteResize<T> resizeHandler;
|
||||||
|
|
||||||
private final Function<CompoundTag, T> reader;
|
|
||||||
|
|
||||||
private final int bits;
|
private final int bits;
|
||||||
|
|
||||||
private int size;
|
private int size;
|
||||||
|
|
||||||
public LinearPalette(IdMapper<T> var0, int var1, PaletteResize<T> var2, Function<CompoundTag, T> var3) {
|
public LinearPalette(int var1, PaletteResize<T> var2) {
|
||||||
this.registry = var0;
|
|
||||||
this.values = (T[]) new Object[1 << var1];
|
this.values = (T[]) new Object[1 << var1];
|
||||||
this.bits = var1;
|
this.bits = var1;
|
||||||
this.resizeHandler = var2;
|
this.resizeHandler = var2;
|
||||||
this.reader = var3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int idFor(T var0) {
|
public int idFor(T var0) {
|
||||||
int var1;
|
int var1;
|
||||||
for (var1 = 0; var1 < this.size; var1++) {
|
for (var1 = 0; var1 < this.size; var1++) {
|
||||||
if (this.values[var1] == var0)
|
if(this.values[var1] == null && var0 == null)
|
||||||
|
{
|
||||||
return var1;
|
return var1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.values[var1].equals(var0))
|
||||||
|
{
|
||||||
|
return var1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var1 = this.size;
|
var1 = this.size;
|
||||||
if (var1 < this.values.length) {
|
if (var1 < this.values.length) {
|
||||||
@ -78,9 +75,22 @@ public class LinearPalette<T> implements Palette<T> {
|
|||||||
return this.size;
|
return this.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(ListTag var0) {
|
@Override
|
||||||
for (int var1 = 0; var1 < var0.size(); var1++)
|
public void read(List<T> fromList) {
|
||||||
this.values[var1] = this.reader.apply((CompoundTag) var0.get(var1));
|
for (int i = 0; i < fromList.size(); i++)
|
||||||
this.size = var0.size();
|
{
|
||||||
|
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