mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Data Palette stuff for 1.17 mca
This commit is contained in:
parent
23ac209c05
commit
861e11a713
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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.nbt.mca.palettes;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
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 int c;
|
||||
private final long d;
|
||||
private final int e;
|
||||
private final int f;
|
||||
private final int g;
|
||||
private final int h;
|
||||
private final int i;
|
||||
|
||||
public DataBits(int var0, int var1) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
this.b = var2;
|
||||
} else {
|
||||
this.b = new long[var4];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int b(int var0) {
|
||||
long var1 = Integer.toUnsignedLong(this.g);
|
||||
long var3 = Integer.toUnsignedLong(this.h);
|
||||
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;
|
||||
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 int a(int var0) {
|
||||
Validate.inclusiveBetween(0L, (long) (this.e - 1), (long) var0);
|
||||
int var1 = this.b(var0);
|
||||
long var2 = this.b[var1];
|
||||
int var4 = (var0 - var1 * this.f) * this.c;
|
||||
return (int) (var2 >> var4 & this.d);
|
||||
}
|
||||
|
||||
public long[] a() {
|
||||
return this.b;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public int c() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public void a(IntConsumer var0) {
|
||||
int var1 = 0;
|
||||
long[] var3 = this.b;
|
||||
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));
|
||||
var5 >>= this.c;
|
||||
++var1;
|
||||
if (var1 >= this.e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,21 +16,23 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.hunk.io;
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
public class StringHunkIOAdapter extends PaletteHunkIOAdapter<String> {
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@Override
|
||||
public void write(String data, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(DataInputStream din) throws IOException {
|
||||
return din.readUTF();
|
||||
}
|
||||
public interface DataPalette<T> {
|
||||
int a(T var1);
|
||||
|
||||
boolean a(Predicate<T> var1);
|
||||
|
||||
T a(int var1);
|
||||
|
||||
int a();
|
||||
|
||||
int b();
|
||||
|
||||
void a(ListTag<CompoundTag> t);
|
||||
}
|
@ -0,0 +1,230 @@
|
||||
/*
|
||||
* 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.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.util.math.MathHelper;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
import net.minecraft.network.PacketDataSerializer;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class DataPaletteBlock<T> implements DataPaletteExpandable<T> {
|
||||
private static final int d = 4096;
|
||||
public static final int a = 9;
|
||||
public static final int b = 4;
|
||||
private final DataPalette<T> e;
|
||||
private final DataPaletteExpandable<T> f = (var0x, var1x) -> {
|
||||
return 0;
|
||||
};
|
||||
private final RegistryBlockID<T> g;
|
||||
private final Function<CompoundTag, T> h;
|
||||
private final Function<T, CompoundTag> i;
|
||||
private final T j;
|
||||
protected DataBits c;
|
||||
private DataPalette<T> k;
|
||||
private int l;
|
||||
private final Semaphore m = new Semaphore(1);
|
||||
|
||||
public void b() {
|
||||
this.m.release();
|
||||
}
|
||||
|
||||
public DataPaletteBlock(DataPalette<T> var0, RegistryBlockID<T> var1, Function<CompoundTag, T> var2, Function<T, CompoundTag> var3, T var4) {
|
||||
this.e = var0;
|
||||
this.g = var1;
|
||||
this.h = var2;
|
||||
this.i = var3;
|
||||
this.j = var4;
|
||||
this.b(4);
|
||||
}
|
||||
|
||||
private static int b(int var0, int var1, int var2) {
|
||||
return var1 << 8 | var2 << 4 | var0;
|
||||
}
|
||||
|
||||
private void b(int var0) {
|
||||
if (var0 != this.l) {
|
||||
this.l = var0;
|
||||
if (this.l <= 4) {
|
||||
this.l = 4;
|
||||
this.k = new DataPaletteLinear<T>(this.g, this.l, this, this.h);
|
||||
} else if (this.l < 9) {
|
||||
this.k = new DataPaletteHash<T>(this.g, this.l, this, this.h, this.i);
|
||||
} else {
|
||||
this.k = this.e;
|
||||
this.l = MathHelper.e(this.g.a());
|
||||
}
|
||||
|
||||
this.k.a(this.j);
|
||||
this.c = new DataBits(this.l, 4096);
|
||||
}
|
||||
}
|
||||
|
||||
public int onResize(int var0, T var1) {
|
||||
DataBits var2 = this.c;
|
||||
DataPalette<T> var3 = this.k;
|
||||
this.b(var0);
|
||||
|
||||
for (int var4 = 0; var4 < var2.b(); ++var4) {
|
||||
T var5 = var3.a(var2.a(var4));
|
||||
if (var5 != null) {
|
||||
this.setBlockIndex(var4, var5);
|
||||
}
|
||||
}
|
||||
|
||||
return this.k.a(var1);
|
||||
}
|
||||
|
||||
public T setBlock(int var0, int var1, int var2, T var3) {
|
||||
T var6;
|
||||
try {
|
||||
var6 = this.a(b(var0, var1, var2), var3);
|
||||
} finally {
|
||||
this.b();
|
||||
}
|
||||
|
||||
return var6;
|
||||
}
|
||||
|
||||
public T b(int var0, int var1, int var2, T var3) {
|
||||
return this.a(b(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
private T a(int var0, T var1) {
|
||||
int var2 = this.k.a(var1);
|
||||
int var3 = this.c.a(var0, var2);
|
||||
T var4 = this.k.a(var3);
|
||||
return var4 == null ? this.j : var4;
|
||||
}
|
||||
|
||||
public void c(int var0, int var1, int var2, T var3) {
|
||||
try {
|
||||
this.setBlockIndex(b(var0, var1, var2), var3);
|
||||
} finally {
|
||||
this.b();
|
||||
}
|
||||
}
|
||||
|
||||
private void setBlockIndex(int var0, T var1) {
|
||||
int var2 = this.k.a(var1);
|
||||
this.c.b(var0, var2);
|
||||
}
|
||||
|
||||
public T a(int var0, int var1, int var2) {
|
||||
return this.a(b(var0, var1, var2));
|
||||
}
|
||||
|
||||
protected T a(int var0) {
|
||||
T var1 = this.k.a(this.c.a(var0));
|
||||
return var1 == null ? this.j : var1;
|
||||
}
|
||||
|
||||
public void a(ListTag<CompoundTag> var0, long[] var1) {
|
||||
try {
|
||||
int var2 = Math.max(4, MathHelper.e(var0.size()));
|
||||
if (var2 != this.l) {
|
||||
this.b(var2);
|
||||
}
|
||||
|
||||
this.k.a(var0);
|
||||
int var3 = var1.length * 64 / 4096;
|
||||
if (this.k == this.e) {
|
||||
DataPalette<T> var4 = new DataPaletteHash(this.g, var2, this.f, this.h, this.i);
|
||||
var4.a(var0);
|
||||
DataBits var5 = new DataBits(var2, 4096, var1);
|
||||
|
||||
for (int var6 = 0; var6 < 4096; ++var6) {
|
||||
this.c.b(var6, this.e.a(var4.a(var5.a(var6))));
|
||||
}
|
||||
} else if (var3 == this.l) {
|
||||
System.arraycopy(var1, 0, this.c.a(), 0, var1.length);
|
||||
} else {
|
||||
DataBits var4 = new DataBits(var3, 4096, var1);
|
||||
|
||||
for (int var5 = 0; var5 < 4096; ++var5) {
|
||||
this.c.b(var5, var4.a(var5));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
this.b();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void a(CompoundTag var0, String var1, String var2) {
|
||||
try {
|
||||
DataPaletteHash<T> var3 = new DataPaletteHash(this.g, this.l, this.f, this.h, this.i);
|
||||
T var4 = this.j;
|
||||
int var5 = var3.a(this.j);
|
||||
int[] var6 = new int[4096];
|
||||
|
||||
for (int var7 = 0; var7 < 4096; ++var7) {
|
||||
T var8 = this.a(var7);
|
||||
if (var8 != var4) {
|
||||
var4 = var8;
|
||||
var5 = var3.a(var8);
|
||||
}
|
||||
|
||||
var6[var7] = var5;
|
||||
}
|
||||
|
||||
ListTag<CompoundTag> var7 = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
var3.b(var7);
|
||||
var0.put(var1, var7);
|
||||
int var8 = Math.max(4, MathHelper.e(var7.size()));
|
||||
DataBits var9 = new DataBits(var8, 4096);
|
||||
|
||||
for (int var10 = 0; var10 < var6.length; ++var10) {
|
||||
var9.b(var10, var6[var10]);
|
||||
}
|
||||
|
||||
var0.putLongArray(var2, var9.a());
|
||||
} finally {
|
||||
this.b();
|
||||
}
|
||||
}
|
||||
|
||||
public int c() {
|
||||
return 1 + this.k.a() + PacketDataSerializer.a(this.c.b()) + this.c.a().length * 8;
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<T> var0) {
|
||||
return this.k.a(var0);
|
||||
}
|
||||
|
||||
public void a(DataPaletteBlock.a<T> var0) {
|
||||
Int2IntMap var1 = new Int2IntOpenHashMap();
|
||||
this.c.a((var1x) -> {
|
||||
var1.put(var1x, var1.get(var1x) + 1);
|
||||
});
|
||||
var1.int2IntEntrySet().forEach((var1x) -> {
|
||||
var0.accept(this.k.a(var1x.getIntKey()), var1x.getIntValue());
|
||||
});
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface a<T> {
|
||||
void accept(T var1, int var2);
|
||||
}
|
||||
}
|
@ -16,21 +16,8 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.hunk.io;
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BooleanHunkIOAdapter extends PaletteHunkIOAdapter<Boolean> {
|
||||
|
||||
@Override
|
||||
public void write(Boolean data, DataOutputStream dos) throws IOException {
|
||||
dos.writeBoolean(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean read(DataInputStream din) throws IOException {
|
||||
return din.readBoolean();
|
||||
}
|
||||
interface DataPaletteExpandable<T> {
|
||||
int onResize(int var1, T var2);
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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.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<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 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 int a(T var0) {
|
||||
int var1 = this.b.getId(var0);
|
||||
if (var1 == -1) {
|
||||
var1 = this.b.c(var0);
|
||||
if (var1 >= 1 << this.f) {
|
||||
var1 = this.c.onResize(this.f + 1, var0);
|
||||
}
|
||||
}
|
||||
|
||||
return var1;
|
||||
}
|
||||
|
||||
public boolean a(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < this.b(); ++var1) {
|
||||
if (var0.test(this.b.fromId(var1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public T a(int var0) {
|
||||
return this.b.fromId(var0);
|
||||
}
|
||||
|
||||
public void a(PacketDataSerializer var0) {
|
||||
this.b.a();
|
||||
int var1 = var0.j();
|
||||
|
||||
for (int var2 = 0; var2 < var1; ++var2) {
|
||||
this.b.c(this.a.fromId(var0.j()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void b(PacketDataSerializer var0) {
|
||||
int var1 = this.b();
|
||||
var0.d(var1);
|
||||
|
||||
for (int var2 = 0; var2 < var1; ++var2) {
|
||||
var0.d(this.a.getId(this.b.fromId(var2)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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.fromId(var1)));
|
||||
}
|
||||
|
||||
return var0;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.b.b();
|
||||
}
|
||||
|
||||
public void a(ListTag<CompoundTag> var0) {
|
||||
this.b.a();
|
||||
|
||||
for (int var1 = 0; var1 < var0.size(); ++var1) {
|
||||
this.b.c(this.d.apply(var0.get(var1)));
|
||||
}
|
||||
}
|
||||
|
||||
public void b(ListTag<CompoundTag> var0) {
|
||||
for (int var1 = 0; var1 < this.b(); ++var1) {
|
||||
var0.add(this.e.apply(this.b.fromId(var1)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.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<T> implements DataPalette<T> {
|
||||
private final RegistryBlockID<T> a;
|
||||
private final T[] b;
|
||||
private final DataPaletteExpandable<T> c;
|
||||
private final Function<CompoundTag, T> d;
|
||||
private final int e;
|
||||
private int f;
|
||||
|
||||
public DataPaletteLinear(RegistryBlockID<T> var0, int var1, DataPaletteExpandable<T> var2, Function<CompoundTag, T> var3) {
|
||||
this.a = var0;
|
||||
this.b = (T[]) new Object[1 << var1];
|
||||
this.e = var1;
|
||||
this.c = var2;
|
||||
this.d = var3;
|
||||
}
|
||||
|
||||
public int a(T var0) {
|
||||
int var1;
|
||||
for (var1 = 0; var1 < this.f; ++var1) {
|
||||
if (this.b[var1] == var0) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
var1 = this.f;
|
||||
if (var1 < this.b.length) {
|
||||
this.b[var1] = var0;
|
||||
++this.f;
|
||||
return var1;
|
||||
} else {
|
||||
return this.c.onResize(this.e + 1, var0);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean a(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < this.f; ++var1) {
|
||||
if (var0.test(this.b[var1])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public T a(int var0) {
|
||||
return var0 >= 0 && var0 < this.f ? this.b[var0] : 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 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 a(ListTag<CompoundTag> var0) {
|
||||
for (int var1 = 0; var1 < var0.size(); ++var1) {
|
||||
this.b[var1] = this.d.apply(var0.get(var1));
|
||||
}
|
||||
|
||||
this.f = var0.size();
|
||||
}
|
||||
}
|
@ -16,24 +16,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.hunk.io;
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
|
||||
import com.volmit.iris.util.data.B;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
public interface Registry<T> extends Iterable<T> {
|
||||
int getId(T var1);
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class BlockDataHunkIOAdapter extends PaletteHunkIOAdapter<BlockData> {
|
||||
|
||||
@Override
|
||||
public void write(BlockData blockData, DataOutputStream dos) throws IOException {
|
||||
dos.writeUTF(blockData.getAsString(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockData read(DataInputStream din) throws IOException {
|
||||
return B.get(din.readUTF());
|
||||
}
|
||||
T fromId(int var1);
|
||||
}
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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.nbt.mca.palettes;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class RegistryBlockID<T> implements Registry<T> {
|
||||
public static final int a = -1;
|
||||
private int b;
|
||||
private final IdentityHashMap<T, Integer> c;
|
||||
private final List<T> d;
|
||||
|
||||
public RegistryBlockID() {
|
||||
this(512);
|
||||
}
|
||||
|
||||
public RegistryBlockID(int var0) {
|
||||
this.d = Lists.newArrayListWithExpectedSize(var0);
|
||||
this.c = new IdentityHashMap(var0);
|
||||
}
|
||||
|
||||
public void a(T var0, int var1) {
|
||||
this.c.put(var0, var1);
|
||||
|
||||
while (this.d.size() <= var1) {
|
||||
this.d.add(null);
|
||||
}
|
||||
|
||||
this.d.set(var1, var0);
|
||||
if (this.b <= var1) {
|
||||
this.b = var1 + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void b(T var0) {
|
||||
this.a(var0, this.b);
|
||||
}
|
||||
|
||||
public int getId(T var0) {
|
||||
Integer var1 = (Integer) this.c.get(var0);
|
||||
return var1 == null ? -1 : var1;
|
||||
}
|
||||
|
||||
public final T fromId(int var0) {
|
||||
return var0 >= 0 && var0 < this.d.size() ? this.d.get(var0) : null;
|
||||
}
|
||||
|
||||
public Iterator<T> iterator() {
|
||||
return Iterators.filter(this.d.iterator(), Predicates.notNull());
|
||||
}
|
||||
|
||||
public boolean b(int var0) {
|
||||
return this.fromId(var0) != null;
|
||||
}
|
||||
|
||||
public int a() {
|
||||
return this.c.size();
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
/*
|
||||
* 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.nbt.mca.palettes;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.volmit.iris.util.math.MathHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class RegistryID<K> implements Registry<K> {
|
||||
public static final int a = -1;
|
||||
private static final Object b = null;
|
||||
private static final float c = 0.8F;
|
||||
private K[] d;
|
||||
private int[] e;
|
||||
private K[] f;
|
||||
private int g;
|
||||
private int h;
|
||||
|
||||
public RegistryID(int var0) {
|
||||
var0 = (int) ((float) var0 / 0.8F);
|
||||
this.d = (K[]) new Object[var0];
|
||||
this.e = new int[var0];
|
||||
this.f = (K[]) new Object[var0];
|
||||
}
|
||||
|
||||
public int getId(K var0) {
|
||||
return this.c(this.b(var0, this.d(var0)));
|
||||
}
|
||||
|
||||
public K fromId(int var0) {
|
||||
return var0 >= 0 && var0 < this.f.length ? this.f[var0] : null;
|
||||
}
|
||||
|
||||
private int c(int var0) {
|
||||
return var0 == -1 ? -1 : this.e[var0];
|
||||
}
|
||||
|
||||
public boolean b(K var0) {
|
||||
return this.getId(var0) != -1;
|
||||
}
|
||||
|
||||
public boolean b(int var0) {
|
||||
return this.fromId(var0) != null;
|
||||
}
|
||||
|
||||
public int c(K var0) {
|
||||
int var1 = this.c();
|
||||
this.a(var0, var1);
|
||||
return var1;
|
||||
}
|
||||
|
||||
private int c() {
|
||||
while (this.g < this.f.length && this.f[this.g] != null) {
|
||||
++this.g;
|
||||
}
|
||||
|
||||
return this.g;
|
||||
}
|
||||
|
||||
private void d(int var0) {
|
||||
K[] var1 = this.d;
|
||||
int[] var2 = this.e;
|
||||
this.d = (K[]) new Object[var0];
|
||||
this.e = new int[var0];
|
||||
this.f = (K[]) new Object[var0];
|
||||
this.g = 0;
|
||||
this.h = 0;
|
||||
|
||||
for (int var3 = 0; var3 < var1.length; ++var3) {
|
||||
if (var1[var3] != null) {
|
||||
this.a(var1[var3], var2[var3]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void a(K var0, int var1) {
|
||||
int var2 = Math.max(var1, this.h + 1);
|
||||
int var3;
|
||||
if ((float) var2 >= (float) this.d.length * 0.8F) {
|
||||
for (var3 = this.d.length << 1; var3 < var1; var3 <<= 1) {
|
||||
}
|
||||
|
||||
this.d(var3);
|
||||
}
|
||||
|
||||
var3 = this.e(this.d(var0));
|
||||
this.d[var3] = var0;
|
||||
this.e[var3] = var1;
|
||||
this.f[var1] = var0;
|
||||
++this.h;
|
||||
if (var1 == this.g) {
|
||||
++this.g;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int d(K var0) {
|
||||
return (MathHelper.g(System.identityHashCode(var0)) & 2147483647) % this.d.length;
|
||||
}
|
||||
|
||||
private int b(K var0, int var1) {
|
||||
int var2;
|
||||
for (var2 = var1; var2 < this.d.length; ++var2) {
|
||||
if (this.d[var2] == var0) {
|
||||
return var2;
|
||||
}
|
||||
|
||||
if (this.d[var2] == b) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (var2 = 0; var2 < var1; ++var2) {
|
||||
if (this.d[var2] == var0) {
|
||||
return var2;
|
||||
}
|
||||
|
||||
if (this.d[var2] == b) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int e(int var0) {
|
||||
int var1;
|
||||
for (var1 = var0; var1 < this.d.length; ++var1) {
|
||||
if (this.d[var1] == b) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
for (var1 = 0; var1 < var0; ++var1) {
|
||||
if (this.d[var1] == b) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Overflowed :(");
|
||||
}
|
||||
|
||||
public Iterator<K> iterator() {
|
||||
return Iterators.filter(Iterators.forArray(this.f), Predicates.notNull());
|
||||
}
|
||||
|
||||
public void a() {
|
||||
Arrays.fill(this.d, (Object) null);
|
||||
Arrays.fill(this.f, (Object) null);
|
||||
this.g = 0;
|
||||
this.h = 0;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.h;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user