mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Merge remote-tracking branch 'upstream/master' into DecreeCommands
This commit is contained in:
commit
151c384313
@ -129,7 +129,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
private void testmca() {
|
||||
try
|
||||
{
|
||||
int forceBits = 6;
|
||||
int forceBits = 5;
|
||||
int possibilities = (int) (Math.pow(2, forceBits) - 1);
|
||||
KList<BlockData> bp = new KList<>();
|
||||
Set<BlockData> bf = new KSet<>();
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -76,5 +76,5 @@ public interface INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException;
|
||||
PaletteAccess createPalette();
|
||||
}
|
||||
|
@ -20,10 +20,11 @@ package com.volmit.iris.core.nms.v17_1;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.nbt.io.NBTUtil;
|
||||
import com.volmit.iris.util.nbt.mca.NBTWorld;
|
||||
import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID;
|
||||
import com.volmit.iris.util.nbt.mca.palette.*;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.IRegistry;
|
||||
@ -38,7 +39,6 @@ import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.TileEntity;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.BiomeStorage;
|
||||
@ -46,6 +46,7 @@ import net.minecraft.world.level.chunk.Chunk;
|
||||
import net.minecraft.world.level.chunk.ChunkSection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Biome;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
@ -59,14 +60,15 @@ import org.bukkit.generator.ChunkGenerator;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class NMSBinding17_1 implements INMSBinding {
|
||||
private final BlockData AIR = Material.AIR.createBlockData();
|
||||
private final KMap<Biome, Object> baseBiomeCache = new KMap<>();
|
||||
private final AtomicCache<IdMapper<IBlockData>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<Palette<IBlockData>> globalCache = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
public boolean supportsDataPacks() {
|
||||
@ -74,21 +76,28 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException {
|
||||
Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c");
|
||||
Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d");
|
||||
cf.setAccessible(true);
|
||||
df.setAccessible(true);
|
||||
net.minecraft.core.RegistryBlockID<IBlockData> blockData = Block.p;
|
||||
IdentityHashMap<IBlockData, Integer> c = (IdentityHashMap<IBlockData, Integer>) cf.get(blockData);
|
||||
List<IBlockData> d = (List<IBlockData>) df.get(blockData);
|
||||
List<CompoundTag> realTags = new ArrayList<>();
|
||||
HashMap<CompoundTag, Integer> realMap = new HashMap<>(512);
|
||||
d.forEach((i) -> realTags.add(NBTWorld.getCompound(CraftBlockData.fromData(i))));
|
||||
c.forEach((k,v) -> realMap.put(NBTWorld.getCompound(CraftBlockData.fromData(k)), v));
|
||||
RegistryBlockID registry = new RegistryBlockID(realMap, realTags);
|
||||
Iris.info("INMS: Stole Global Palette: " + realTags.size() + " Tags, " + realMap.size() + " Mapped");
|
||||
return registry;
|
||||
public PaletteAccess createPalette() {
|
||||
IdMapper<IBlockData> registry = registryCache.aquireNasty(() -> {
|
||||
Field cf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("c");
|
||||
Field df = net.minecraft.core.RegistryBlockID.class.getDeclaredField("d");
|
||||
Field bf = net.minecraft.core.RegistryBlockID.class.getDeclaredField("b");
|
||||
cf.setAccessible(true);
|
||||
df.setAccessible(true);
|
||||
bf.setAccessible(true);
|
||||
net.minecraft.core.RegistryBlockID<IBlockData> blockData = Block.p;
|
||||
int b = bf.getInt(blockData);
|
||||
IdentityHashMap<IBlockData, Integer> c = (IdentityHashMap<IBlockData, Integer>) cf.get(blockData);
|
||||
List<IBlockData> d = (List<IBlockData>) df.get(blockData);
|
||||
return new IdMapper<>(c, d, b);
|
||||
});
|
||||
Palette<IBlockData> global = globalCache.aquireNasty(() -> new GlobalPalette<>(registry, ((CraftBlockData)AIR).getState()));
|
||||
PalettedContainer<IBlockData> container = new PalettedContainer<>(global, registry,
|
||||
i -> ((CraftBlockData)NBTWorld.getBlockData(i)).getState(),
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
((CraftBlockData) AIR).getState());
|
||||
return new WrappedPalettedContainer<>(container,
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
i -> ((CraftBlockData)NBTWorld.getBlockData(i)).getState());
|
||||
}
|
||||
|
||||
private Object getBiomeStorage(ChunkGenerator.BiomeGrid g) {
|
||||
|
@ -20,7 +20,7 @@ package com.volmit.iris.core.nms.v1X;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.nms.INMSBinding;
|
||||
import com.volmit.iris.util.nbt.mca.palettes.RegistryBlockID;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -146,7 +146,7 @@ public class NMSBinding1X implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegistryBlockID computeBlockIDRegistry() throws NoSuchFieldException, IllegalAccessException {
|
||||
public PaletteAccess createPalette() {
|
||||
Iris.error("Cannot use the global data palette! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
return null;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
package com.volmit.iris.engine.data.cache;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.util.function.NastySupplier;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
@ -50,6 +51,21 @@ public class AtomicCache<T> {
|
||||
}
|
||||
}
|
||||
|
||||
public T aquireNasty(NastySupplier<T> t)
|
||||
{
|
||||
return aquire(() -> {
|
||||
try
|
||||
{
|
||||
return t.get();
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public T aquire(Supplier<T> t) {
|
||||
if (this.t.get() != null) {
|
||||
return this.t.get();
|
||||
|
@ -25,6 +25,7 @@ import com.volmit.iris.util.nbt.io.NBTSerializer;
|
||||
import com.volmit.iris.util.nbt.io.NamedTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.Tag;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
@ -33,15 +34,10 @@ import java.util.concurrent.atomic.AtomicReferenceArray;
|
||||
import static com.volmit.iris.util.nbt.mca.LoadFlags.*;
|
||||
|
||||
public class Chunk {
|
||||
|
||||
public static final int DEFAULT_DATA_VERSION = 1628;
|
||||
|
||||
public static final int DEFAULT_DATA_VERSION = 2730;
|
||||
private boolean partial;
|
||||
|
||||
private int lastMCAUpdate;
|
||||
|
||||
private CompoundTag data;
|
||||
|
||||
private int dataVersion;
|
||||
private long lastUpdate;
|
||||
private long inhabitedTime;
|
||||
@ -72,6 +68,7 @@ public class Chunk {
|
||||
public Chunk(CompoundTag data) {
|
||||
this.data = data;
|
||||
initReferences(ALL_DATA);
|
||||
setStatus("full");
|
||||
}
|
||||
|
||||
private void initReferences(long loadFlags) {
|
||||
@ -163,6 +160,7 @@ public class Chunk {
|
||||
try (BufferedOutputStream nbtOut = new BufferedOutputStream(CompressionType.ZLIB.compress(baos))) {
|
||||
new NBTSerializer(false).toStream(new NamedTag(null, updateHandle(xPos, zPos)), nbtOut);
|
||||
}
|
||||
|
||||
byte[] rawData = baos.toByteArray();
|
||||
raf.writeInt(rawData.length + 1); // including the byte to store the compression type
|
||||
raf.writeByte(CompressionType.ZLIB.getID());
|
||||
@ -648,11 +646,18 @@ public class Chunk {
|
||||
Chunk c = new Chunk(0);
|
||||
c.dataVersion = DEFAULT_DATA_VERSION;
|
||||
c.data = new CompoundTag();
|
||||
c.data.put("Level", new CompoundTag());
|
||||
c.status = "mobs_spawned";
|
||||
c.data.put("Level", defaultLevel());
|
||||
c.status = "full";
|
||||
return c;
|
||||
}
|
||||
|
||||
private static CompoundTag defaultLevel() {
|
||||
CompoundTag level = new CompoundTag();
|
||||
level.putString("Status", "full");
|
||||
level.putString("Generator", "Iris Headless " + Iris.instance.getDescription().getVersion());
|
||||
return level;
|
||||
}
|
||||
|
||||
public CompoundTag updateHandle(int xPos, int zPos) {
|
||||
data.putInt("DataVersion", dataVersion);
|
||||
CompoundTag level = data.getCompoundTag("Level");
|
||||
|
@ -18,16 +18,16 @@
|
||||
|
||||
package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.util.nbt.mca.palettes.DataPaletteBlock;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import com.volmit.iris.util.nbt.tag.LongArrayTag;
|
||||
|
||||
|
||||
public class Section {
|
||||
private CompoundTag data;
|
||||
private DataPaletteBlock palette;
|
||||
private PaletteAccess palette;
|
||||
private byte[] blockLight;
|
||||
private byte[] skyLight;
|
||||
private int dataVersion;
|
||||
@ -43,9 +43,8 @@ public class Section {
|
||||
if (rawPalette == null) {
|
||||
return;
|
||||
}
|
||||
palette = new DataPaletteBlock();
|
||||
LongArrayTag blockStates = sectionRoot.getLongArrayTag("BlockStates");
|
||||
palette.load((ListTag<CompoundTag>) rawPalette, blockStates.getValue());
|
||||
palette = INMS.get().createPalette();
|
||||
palette.readFromSection(sectionRoot);
|
||||
ByteArrayTag blockLight = sectionRoot.getByteArrayTag("BlockLight");
|
||||
ByteArrayTag skyLight = sectionRoot.getByteArrayTag("SkyLight");
|
||||
this.blockLight = blockLight != null ? blockLight.getValue() : null;
|
||||
@ -151,8 +150,8 @@ public class Section {
|
||||
*/
|
||||
public static Section newSection() {
|
||||
Section s = new Section();
|
||||
s.palette = new DataPaletteBlock();
|
||||
s.data = new CompoundTag();
|
||||
s.palette = INMS.get().createPalette();
|
||||
return s;
|
||||
}
|
||||
|
||||
@ -170,7 +169,7 @@ public class Section {
|
||||
if (palette != null) {
|
||||
synchronized (palette)
|
||||
{
|
||||
palette.save(data, "Palette", "BlockStates");
|
||||
palette.writeToSection(data);
|
||||
}
|
||||
}
|
||||
if (blockLight != null) {
|
||||
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
public class BitStorage {
|
||||
private static final int[] MAGIC = new int[] {
|
||||
-1, -1, 0, Integer.MIN_VALUE, 0, 0, 1431655765, 1431655765, 0, Integer.MIN_VALUE,
|
||||
0, 1, 858993459, 858993459, 0, 715827882, 715827882, 0, 613566756, 613566756,
|
||||
0, Integer.MIN_VALUE, 0, 2, 477218588, 477218588, 0, 429496729, 429496729, 0,
|
||||
390451572, 390451572, 0, 357913941, 357913941, 0, 330382099, 330382099, 0, 306783378,
|
||||
306783378, 0, 286331153, 286331153, 0, Integer.MIN_VALUE, 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, Integer.MIN_VALUE, 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, Integer.MIN_VALUE,
|
||||
0, 5 };
|
||||
|
||||
private final long[] data;
|
||||
|
||||
private final int bits;
|
||||
|
||||
private final long mask;
|
||||
|
||||
private final int size;
|
||||
|
||||
private final int valuesPerLong;
|
||||
|
||||
private final int divideMul;
|
||||
|
||||
private final int divideAdd;
|
||||
|
||||
private final int divideShift;
|
||||
|
||||
public BitStorage(int var0, int var1) {
|
||||
this(var0, var1, null);
|
||||
}
|
||||
|
||||
public BitStorage(int var0, int var1, long[] var2) {
|
||||
Validate.inclusiveBetween(1L, 32L, var0);
|
||||
this.size = var1;
|
||||
this.bits = var0;
|
||||
this.mask = (1L << var0) - 1L;
|
||||
this.valuesPerLong = (char)(64 / var0);
|
||||
int var3 = 3 * (this.valuesPerLong - 1);
|
||||
this.divideMul = MAGIC[var3 + 0];
|
||||
this.divideAdd = MAGIC[var3 + 1];
|
||||
this.divideShift = MAGIC[var3 + 2];
|
||||
int var4 = (var1 + this.valuesPerLong - 1) / this.valuesPerLong;
|
||||
if (var2 != null) {
|
||||
if (var2.length != var4)
|
||||
throw new RuntimeException("NO!");
|
||||
this.data = var2;
|
||||
} else {
|
||||
this.data = new long[var4];
|
||||
}
|
||||
}
|
||||
|
||||
private int cellIndex(int var0) {
|
||||
long var1 = Integer.toUnsignedLong(this.divideMul);
|
||||
long var3 = Integer.toUnsignedLong(this.divideAdd);
|
||||
return (int)(var0 * var1 + var3 >> 32L >> this.divideShift);
|
||||
}
|
||||
|
||||
public int getAndSet(int var0, int var1) {
|
||||
Validate.inclusiveBetween(0L, (this.size - 1), var0);
|
||||
Validate.inclusiveBetween(0L, this.mask, var1);
|
||||
int var2 = cellIndex(var0);
|
||||
long var3 = this.data[var2];
|
||||
int var5 = (var0 - var2 * this.valuesPerLong) * this.bits;
|
||||
int var6 = (int)(var3 >> var5 & this.mask);
|
||||
this.data[var2] = var3 & (this.mask << var5 ^ 0xFFFFFFFFFFFFFFFFL) | (var1 & this.mask) << var5;
|
||||
return var6;
|
||||
}
|
||||
|
||||
public void set(int var0, int var1) {
|
||||
Validate.inclusiveBetween(0L, (this.size - 1), var0);
|
||||
Validate.inclusiveBetween(0L, this.mask, var1);
|
||||
int var2 = cellIndex(var0);
|
||||
long var3 = this.data[var2];
|
||||
int var5 = (var0 - var2 * this.valuesPerLong) * this.bits;
|
||||
this.data[var2] = var3 & (this.mask << var5 ^ 0xFFFFFFFFFFFFFFFFL) | (var1 & this.mask) << var5;
|
||||
}
|
||||
|
||||
public int get(int var0) {
|
||||
Validate.inclusiveBetween(0L, (this.size - 1), var0);
|
||||
int var1 = cellIndex(var0);
|
||||
long var2 = this.data[var1];
|
||||
int var4 = (var0 - var1 * this.valuesPerLong) * this.bits;
|
||||
return (int)(var2 >> var4 & this.mask);
|
||||
}
|
||||
|
||||
public long[] getRaw() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public int getBits() {
|
||||
return this.bits;
|
||||
}
|
||||
|
||||
public void getAll(IntConsumer var0) {
|
||||
int var1 = 0;
|
||||
for (long var5 : this.data) {
|
||||
for (int var7 = 0; var7 < this.valuesPerLong; var7++) {
|
||||
var0.accept((int)(var5 & this.mask));
|
||||
var5 >>= this.bits;
|
||||
if (++var1 >= this.size)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
import net.minecraft.world.level.LevelHeightAccessor;
|
||||
import net.minecraft.world.level.biome.BiomeBase;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.block.Biome;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ChunkBiomeContainer<T> {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final int WIDTH_BITS = Mth.ceillog2(16) - 2;
|
||||
private static final int HORIZONTAL_MASK = (1 << WIDTH_BITS) - 1;
|
||||
private static final int PACKED_X_LENGTH = 1 + Mth.log2(Mth.smallestEncompassingPowerOfTwo(30000000));
|
||||
private static final int PACKED_Z_LENGTH = PACKED_X_LENGTH;
|
||||
public static final int PACKED_Y_LENGTH = 64 - PACKED_X_LENGTH - PACKED_Z_LENGTH;
|
||||
public static final int MAX_SIZE = 1 << WIDTH_BITS + WIDTH_BITS + PACKED_Y_LENGTH - 2;
|
||||
|
||||
public final IdMap<T> biomeRegistry;
|
||||
|
||||
private final T[] biomes;
|
||||
|
||||
private final int quartMinY;
|
||||
|
||||
private final int quartHeight;
|
||||
|
||||
protected ChunkBiomeContainer(IdMap<T> registry, int minHeight, int maxHeight, T[] abiomebase) {
|
||||
this.biomeRegistry = registry;
|
||||
this.biomes = abiomebase;
|
||||
this.quartMinY = QuartPos.fromBlock(minHeight);
|
||||
this.quartHeight = QuartPos.fromBlock(maxHeight) - 1;
|
||||
}
|
||||
|
||||
public ChunkBiomeContainer(IdMap<T> registry, int minHeight, int maxHeight, int[] aint) {
|
||||
this(registry, minHeight, maxHeight, (T[])new Object[aint.length]);
|
||||
int i = -1;
|
||||
for (int j = 0; j < this.biomes.length; j++) {
|
||||
int k = aint[j];
|
||||
T biomebase = registry.byId(k);
|
||||
if (biomebase == null) {
|
||||
if (i == -1)
|
||||
i = j;
|
||||
this.biomes[j] = (T)registry.byId(0);
|
||||
} else {
|
||||
this.biomes[j] = biomebase;
|
||||
}
|
||||
}
|
||||
if (i != -1)
|
||||
LOGGER.warn("Invalid biome data received, starting from {}: {}", Integer.valueOf(i), Arrays.toString(aint));
|
||||
}
|
||||
|
||||
private static int ceilDiv(int i, int j) {
|
||||
return (i + j - 1) / j;
|
||||
}
|
||||
|
||||
public int[] writeBiomes() {
|
||||
int[] aint = new int[this.biomes.length];
|
||||
for (int i = 0; i < this.biomes.length; i++)
|
||||
aint[i] = this.biomeRegistry.getId(this.biomes[i]);
|
||||
return aint;
|
||||
}
|
||||
|
||||
public T getBiome(int i, int j, int k) {
|
||||
int l = i & HORIZONTAL_MASK;
|
||||
int i1 = Mth.clamp(j - this.quartMinY, 0, this.quartHeight);
|
||||
int j1 = k & HORIZONTAL_MASK;
|
||||
return this.biomes[i1 << WIDTH_BITS + WIDTH_BITS | j1 << WIDTH_BITS | l];
|
||||
}
|
||||
|
||||
public void setBiome(int i, int j, int k, T biome) {
|
||||
int l = i & HORIZONTAL_MASK;
|
||||
int i1 = Mth.clamp(j - this.quartMinY, 0, this.quartHeight);
|
||||
int j1 = k & HORIZONTAL_MASK;
|
||||
this.biomes[i1 << WIDTH_BITS + WIDTH_BITS | j1 << WIDTH_BITS | l] = biome;
|
||||
}
|
||||
}
|
@ -16,12 +16,9 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
public interface Registry extends Iterable<CompoundTag> {
|
||||
int getId(CompoundTag block);
|
||||
|
||||
CompoundTag fromId(int id);
|
||||
@FunctionalInterface
|
||||
public interface CountConsumer<T> {
|
||||
void accept(T paramT, int paramInt);
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterators;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class CrudeIncrementalIntIdentityHashBiMap<K> implements IdMap<K> {
|
||||
public static final int NOT_FOUND = -1;
|
||||
|
||||
private static final Object EMPTY_SLOT = null;
|
||||
|
||||
private static final float LOADFACTOR = 0.8F;
|
||||
|
||||
private K[] keys;
|
||||
|
||||
private int[] values;
|
||||
|
||||
private K[] byId;
|
||||
|
||||
private int nextId;
|
||||
|
||||
private int size;
|
||||
|
||||
public CrudeIncrementalIntIdentityHashBiMap(int var0) {
|
||||
var0 = (int)(var0 / 0.8F);
|
||||
this.keys = (K[])new Object[var0];
|
||||
this.values = new int[var0];
|
||||
this.byId = (K[])new Object[var0];
|
||||
}
|
||||
|
||||
public int getId(K var0) {
|
||||
return getValue(indexOf(var0, hash(var0)));
|
||||
}
|
||||
|
||||
|
||||
public K byId(int var0) {
|
||||
if (var0 < 0 || var0 >= this.byId.length)
|
||||
return null;
|
||||
return this.byId[var0];
|
||||
}
|
||||
|
||||
private int getValue(int var0) {
|
||||
if (var0 == -1)
|
||||
return -1;
|
||||
return this.values[var0];
|
||||
}
|
||||
|
||||
public boolean contains(K var0) {
|
||||
return (getId(var0) != -1);
|
||||
}
|
||||
|
||||
public boolean contains(int var0) {
|
||||
return (byId(var0) != null);
|
||||
}
|
||||
|
||||
public int add(K var0) {
|
||||
int var1 = nextId();
|
||||
addMapping(var0, var1);
|
||||
return var1;
|
||||
}
|
||||
|
||||
private int nextId() {
|
||||
while (this.nextId < this.byId.length && this.byId[this.nextId] != null)
|
||||
this.nextId++;
|
||||
return this.nextId;
|
||||
}
|
||||
|
||||
private void grow(int var0) {
|
||||
K[] var1 = this.keys;
|
||||
int[] var2 = this.values;
|
||||
this.keys = (K[])new Object[var0];
|
||||
this.values = new int[var0];
|
||||
this.byId = (K[])new Object[var0];
|
||||
this.nextId = 0;
|
||||
this.size = 0;
|
||||
for (int var3 = 0; var3 < var1.length; var3++) {
|
||||
if (var1[var3] != null)
|
||||
addMapping(var1[var3], var2[var3]);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMapping(K var0, int var1) {
|
||||
int var2 = Math.max(var1, this.size + 1);
|
||||
if (var2 >= this.keys.length * 0.8F) {
|
||||
int i = this.keys.length << 1;
|
||||
while (i < var1)
|
||||
i <<= 1;
|
||||
grow(i);
|
||||
}
|
||||
int var3 = findEmpty(hash(var0));
|
||||
this.keys[var3] = var0;
|
||||
this.values[var3] = var1;
|
||||
this.byId[var1] = var0;
|
||||
this.size++;
|
||||
if (var1 == this.nextId)
|
||||
this.nextId++;
|
||||
}
|
||||
|
||||
private int hash( K var0) {
|
||||
return (Mth.murmurHash3Mixer(System.identityHashCode(var0)) & Integer.MAX_VALUE) % this.keys.length;
|
||||
}
|
||||
|
||||
private int indexOf( K var0, int var1) {
|
||||
int var2;
|
||||
for (var2 = var1; var2 < this.keys.length; var2++) {
|
||||
if (this.keys[var2] == var0)
|
||||
return var2;
|
||||
if (this.keys[var2] == EMPTY_SLOT)
|
||||
return -1;
|
||||
}
|
||||
for (var2 = 0; var2 < var1; var2++) {
|
||||
if (this.keys[var2] == var0)
|
||||
return var2;
|
||||
if (this.keys[var2] == EMPTY_SLOT)
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int findEmpty(int var0) {
|
||||
int var1;
|
||||
for (var1 = var0; var1 < this.keys.length; var1++) {
|
||||
if (this.keys[var1] == EMPTY_SLOT)
|
||||
return var1;
|
||||
}
|
||||
for (var1 = 0; var1 < var0; var1++) {
|
||||
if (this.keys[var1] == EMPTY_SLOT)
|
||||
return var1;
|
||||
}
|
||||
throw new RuntimeException("Overflowed :(");
|
||||
}
|
||||
|
||||
public Iterator<K> iterator() {
|
||||
return (Iterator<K>) Iterators.filter((Iterator)Iterators.forArray((Object[])this.byId), Predicates.notNull());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Arrays.fill((Object[])this.keys, (Object)null);
|
||||
Arrays.fill((Object[])this.byId, (Object)null);
|
||||
this.nextId = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.size;
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class GlobalPalette<T> implements Palette<T> {
|
||||
private final IdMapper<T> registry;
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
public GlobalPalette(IdMapper<T> var0, T var1) {
|
||||
this.registry = var0;
|
||||
this.defaultValue = var1;
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
int var1 = this.registry.getId(var0);
|
||||
return (var1 == -1) ? 0 : var1;
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
T var1 = (T)this.registry.byId(var0);
|
||||
return (var1 == null) ? this.defaultValue : var1;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return this.registry.size();
|
||||
}
|
||||
|
||||
public void read(ListTag var0) {}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.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.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;
|
||||
this.bits = var1;
|
||||
this.resizeHandler = var2;
|
||||
this.reader = var3;
|
||||
this.writer = var4;
|
||||
this.values = new CrudeIncrementalIntIdentityHashBiMap(1 << var1);
|
||||
}
|
||||
|
||||
public int idFor(T var0) {
|
||||
int var1 = this.values.getId(var0);
|
||||
if (var1 == -1) {
|
||||
var1 = this.values.add(var0);
|
||||
if (var1 >= 1 << this.bits)
|
||||
var1 = this.resizeHandler.onResize(this.bits + 1, var0);
|
||||
}
|
||||
return var1;
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < getSize(); var1++) {
|
||||
if (var0.test((T)this.values.byId(var1)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
return (T)this.values.byId(var0);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
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)));
|
||||
}
|
||||
|
||||
public void write(ListTag var0) {
|
||||
for (int var1 = 0; var1 < getSize(); var1++)
|
||||
var0.add(this.writer.apply((T)this.values.byId(var1)));
|
||||
}
|
||||
}
|
@ -16,10 +16,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
public interface IdMap<T> extends Iterable<T> {
|
||||
int getId(T paramT);
|
||||
|
||||
interface DataPaletteExpandable {
|
||||
int onResize(int newBits, CompoundTag newData);
|
||||
T byId(int paramInt);
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
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 IdMapper<T> implements IdMap<T> {
|
||||
public static final int DEFAULT = -1;
|
||||
|
||||
private int nextId;
|
||||
|
||||
private final IdentityHashMap<T, Integer> tToId;
|
||||
|
||||
private final List<T> idToT;
|
||||
|
||||
public IdMapper(IdentityHashMap<T, Integer> tToId, List<T> idToT, int nextId) {
|
||||
this.tToId = tToId;
|
||||
this.idToT = idToT;
|
||||
this.nextId = nextId;
|
||||
}
|
||||
|
||||
public IdMapper() {
|
||||
this(512);
|
||||
}
|
||||
|
||||
public IdMapper(int var0) {
|
||||
this.idToT = Lists.newArrayListWithExpectedSize(var0);
|
||||
this.tToId = new IdentityHashMap<>(var0);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void add(T var0) {
|
||||
addMapping(var0, this.nextId);
|
||||
}
|
||||
|
||||
public int getId(T var0) {
|
||||
Integer var1 = this.tToId.get(var0);
|
||||
return (var1 == null) ? -1 : var1.intValue();
|
||||
}
|
||||
|
||||
public final T byId(int var0) {
|
||||
if (var0 >= 0 && var0 < this.idToT.size())
|
||||
return this.idToT.get(var0);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator<T> iterator() {
|
||||
return (Iterator<T>) Iterators.filter(this.idToT.iterator(), Predicates.notNull());
|
||||
}
|
||||
|
||||
public boolean contains(int var0) {
|
||||
return (byId(var0) != null);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.tToId.size();
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* 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.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.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;
|
||||
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)
|
||||
return var1;
|
||||
}
|
||||
var1 = this.size;
|
||||
if (var1 < this.values.length) {
|
||||
this.values[var1] = var0;
|
||||
this.size++;
|
||||
return var1;
|
||||
}
|
||||
return this.resizeHandler.onResize(this.bits + 1, var0);
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
for (int var1 = 0; var1 < this.size; var1++) {
|
||||
if (var0.test(this.values[var1]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
if (var0 >= 0 && var0 < this.size)
|
||||
return this.values[var0];
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
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();
|
||||
}
|
||||
}
|
733
src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java
Normal file
733
src/main/java/com/volmit/iris/util/nbt/mca/palette/Mth.java
Normal file
@ -0,0 +1,733 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class Mth {
|
||||
private static final int BIG_ENOUGH_INT = 1024;
|
||||
|
||||
private static final float BIG_ENOUGH_FLOAT = 1024.0F;
|
||||
|
||||
private static final long UUID_VERSION = 61440L;
|
||||
|
||||
private static final long UUID_VERSION_TYPE_4 = 16384L;
|
||||
|
||||
private static final long UUID_VARIANT = -4611686018427387904L;
|
||||
|
||||
private static final long UUID_VARIANT_2 = -9223372036854775808L;
|
||||
|
||||
public static final float PI = 3.1415927F;
|
||||
|
||||
public static final float HALF_PI = 1.5707964F;
|
||||
|
||||
public static final float TWO_PI = 6.2831855F;
|
||||
|
||||
public static final float DEG_TO_RAD = 0.017453292F;
|
||||
|
||||
public static final float RAD_TO_DEG = 57.295776F;
|
||||
|
||||
public static final float EPSILON = 1.0E-5F;
|
||||
|
||||
public static final float SQRT_OF_TWO = sqrt(2.0F);
|
||||
|
||||
private static final float SIN_SCALE = 10430.378F;
|
||||
|
||||
private static final float[] SIN;
|
||||
|
||||
static {
|
||||
SIN = (float[])make(new float[65536], var0 -> {
|
||||
for (int var1 = 0; var1 < var0.length; var1++)
|
||||
var0[var1] = (float)Math.sin(var1 * Math.PI * 2.0D / 65536.0D);
|
||||
});
|
||||
}
|
||||
|
||||
public static <T> T make(Supplier<T> var0) {
|
||||
return var0.get();
|
||||
}
|
||||
|
||||
public static <T> T make(T var0, Consumer<T> var1) {
|
||||
var1.accept(var0);
|
||||
return var0;
|
||||
}
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
public static float sin(float var0) {
|
||||
return SIN[(int)(var0 * 10430.378F) & 0xFFFF];
|
||||
}
|
||||
|
||||
public static float cos(float var0) {
|
||||
return SIN[(int)(var0 * 10430.378F + 16384.0F) & 0xFFFF];
|
||||
}
|
||||
|
||||
public static float sqrt(float var0) {
|
||||
return (float)Math.sqrt(var0);
|
||||
}
|
||||
|
||||
public static int floor(float var0) {
|
||||
int var1 = (int)var0;
|
||||
return (var0 < var1) ? (var1 - 1) : var1;
|
||||
}
|
||||
|
||||
public static int fastFloor(double var0) {
|
||||
return (int)(var0 + 1024.0D) - 1024;
|
||||
}
|
||||
|
||||
public static int floor(double var0) {
|
||||
int var2 = (int)var0;
|
||||
return (var0 < var2) ? (var2 - 1) : var2;
|
||||
}
|
||||
|
||||
public static long lfloor(double var0) {
|
||||
long var2 = (long)var0;
|
||||
return (var0 < var2) ? (var2 - 1L) : var2;
|
||||
}
|
||||
|
||||
public static int absFloor(double var0) {
|
||||
return (int)((var0 >= 0.0D) ? var0 : (-var0 + 1.0D));
|
||||
}
|
||||
|
||||
public static float abs(float var0) {
|
||||
return Math.abs(var0);
|
||||
}
|
||||
|
||||
public static int abs(int var0) {
|
||||
return Math.abs(var0);
|
||||
}
|
||||
|
||||
public static int ceil(float var0) {
|
||||
int var1 = (int)var0;
|
||||
return (var0 > var1) ? (var1 + 1) : var1;
|
||||
}
|
||||
|
||||
public static int ceil(double var0) {
|
||||
int var2 = (int)var0;
|
||||
return (var0 > var2) ? (var2 + 1) : var2;
|
||||
}
|
||||
|
||||
public static byte clamp(byte var0, byte var1, byte var2) {
|
||||
if (var0 < var1)
|
||||
return var1;
|
||||
if (var0 > var2)
|
||||
return var2;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int clamp(int var0, int var1, int var2) {
|
||||
if (var0 < var1)
|
||||
return var1;
|
||||
if (var0 > var2)
|
||||
return var2;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static long clamp(long var0, long var2, long var4) {
|
||||
if (var0 < var2)
|
||||
return var2;
|
||||
if (var0 > var4)
|
||||
return var4;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float clamp(float var0, float var1, float var2) {
|
||||
if (var0 < var1)
|
||||
return var1;
|
||||
if (var0 > var2)
|
||||
return var2;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double clamp(double var0, double var2, double var4) {
|
||||
if (var0 < var2)
|
||||
return var2;
|
||||
if (var0 > var4)
|
||||
return var4;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double clampedLerp(double var0, double var2, double var4) {
|
||||
if (var4 < 0.0D)
|
||||
return var0;
|
||||
if (var4 > 1.0D)
|
||||
return var2;
|
||||
return lerp(var4, var0, var2);
|
||||
}
|
||||
|
||||
public static float clampedLerp(float var0, float var1, float var2) {
|
||||
if (var2 < 0.0F)
|
||||
return var0;
|
||||
if (var2 > 1.0F)
|
||||
return var1;
|
||||
return lerp(var2, var0, var1);
|
||||
}
|
||||
|
||||
public static double absMax(double var0, double var2) {
|
||||
if (var0 < 0.0D)
|
||||
var0 = -var0;
|
||||
if (var2 < 0.0D)
|
||||
var2 = -var2;
|
||||
return (var0 > var2) ? var0 : var2;
|
||||
}
|
||||
|
||||
public static int intFloorDiv(int var0, int var1) {
|
||||
return Math.floorDiv(var0, var1);
|
||||
}
|
||||
|
||||
public static int nextInt(Random var0, int var1, int var2) {
|
||||
if (var1 >= var2)
|
||||
return var1;
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
|
||||
public static float nextFloat(Random var0, float var1, float var2) {
|
||||
if (var1 >= var2)
|
||||
return var1;
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double nextDouble(Random var0, double var1, double var3) {
|
||||
if (var1 >= var3)
|
||||
return var1;
|
||||
return var0.nextDouble() * (var3 - var1) + var1;
|
||||
}
|
||||
|
||||
public static double average(long[] var0) {
|
||||
long var1 = 0L;
|
||||
for (long var6 : var0)
|
||||
var1 += var6;
|
||||
return var1 / var0.length;
|
||||
}
|
||||
|
||||
public static boolean equal(float var0, float var1) {
|
||||
return (Math.abs(var1 - var0) < 1.0E-5F);
|
||||
}
|
||||
|
||||
public static boolean equal(double var0, double var2) {
|
||||
return (Math.abs(var2 - var0) < 9.999999747378752E-6D);
|
||||
}
|
||||
|
||||
public static int positiveModulo(int var0, int var1) {
|
||||
return Math.floorMod(var0, var1);
|
||||
}
|
||||
|
||||
public static float positiveModulo(float var0, float var1) {
|
||||
return (var0 % var1 + var1) % var1;
|
||||
}
|
||||
|
||||
public static double positiveModulo(double var0, double var2) {
|
||||
return (var0 % var2 + var2) % var2;
|
||||
}
|
||||
|
||||
public static int wrapDegrees(int var0) {
|
||||
int var1 = var0 % 360;
|
||||
if (var1 >= 180)
|
||||
var1 -= 360;
|
||||
if (var1 < -180)
|
||||
var1 += 360;
|
||||
return var1;
|
||||
}
|
||||
|
||||
public static float wrapDegrees(float var0) {
|
||||
float var1 = var0 % 360.0F;
|
||||
if (var1 >= 180.0F)
|
||||
var1 -= 360.0F;
|
||||
if (var1 < -180.0F)
|
||||
var1 += 360.0F;
|
||||
return var1;
|
||||
}
|
||||
|
||||
public static double wrapDegrees(double var0) {
|
||||
double var2 = var0 % 360.0D;
|
||||
if (var2 >= 180.0D)
|
||||
var2 -= 360.0D;
|
||||
if (var2 < -180.0D)
|
||||
var2 += 360.0D;
|
||||
return var2;
|
||||
}
|
||||
|
||||
public static float degreesDifference(float var0, float var1) {
|
||||
return wrapDegrees(var1 - var0);
|
||||
}
|
||||
|
||||
public static float degreesDifferenceAbs(float var0, float var1) {
|
||||
return abs(degreesDifference(var0, var1));
|
||||
}
|
||||
|
||||
public static float rotateIfNecessary(float var0, float var1, float var2) {
|
||||
float var3 = degreesDifference(var0, var1);
|
||||
float var4 = clamp(var3, -var2, var2);
|
||||
return var1 - var4;
|
||||
}
|
||||
|
||||
public static float approach(float var0, float var1, float var2) {
|
||||
var2 = abs(var2);
|
||||
if (var0 < var1)
|
||||
return clamp(var0 + var2, var0, var1);
|
||||
return clamp(var0 - var2, var1, var0);
|
||||
}
|
||||
|
||||
public static float approachDegrees(float var0, float var1, float var2) {
|
||||
float var3 = degreesDifference(var0, var1);
|
||||
return approach(var0, var0 + var3, var2);
|
||||
}
|
||||
|
||||
public static int getInt(String var0, int var1) {
|
||||
return Integer.valueOf(var0, var1);
|
||||
}
|
||||
|
||||
public static int getInt(String var0, int var1, int var2) {
|
||||
return Math.max(var2, getInt(var0, var1));
|
||||
}
|
||||
|
||||
public static double getDouble(String var0, double var1) {
|
||||
try {
|
||||
return Double.parseDouble(var0);
|
||||
} catch (Throwable var3) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
public static double getDouble(String var0, double var1, double var3) {
|
||||
return Math.max(var3, getDouble(var0, var1));
|
||||
}
|
||||
|
||||
public static int smallestEncompassingPowerOfTwo(int var0) {
|
||||
int var1 = var0 - 1;
|
||||
var1 |= var1 >> 1;
|
||||
var1 |= var1 >> 2;
|
||||
var1 |= var1 >> 4;
|
||||
var1 |= var1 >> 8;
|
||||
var1 |= var1 >> 16;
|
||||
return var1 + 1;
|
||||
}
|
||||
|
||||
public static boolean isPowerOfTwo(int var0) {
|
||||
return (var0 != 0 && (var0 & var0 - 1) == 0);
|
||||
}
|
||||
|
||||
private static final int[] MULTIPLY_DE_BRUIJN_BIT_POSITION = new int[] {
|
||||
0, 1, 28, 2, 29, 14, 24, 3, 30, 22,
|
||||
20, 15, 25, 17, 4, 8, 31, 27, 13, 23,
|
||||
21, 19, 16, 7, 26, 12, 18, 6, 11, 5,
|
||||
10, 9 };
|
||||
|
||||
private static final double ONE_SIXTH = 0.16666666666666666D;
|
||||
|
||||
private static final int FRAC_EXP = 8;
|
||||
|
||||
private static final int LUT_SIZE = 257;
|
||||
|
||||
public static int ceillog2(int var0) {
|
||||
var0 = isPowerOfTwo(var0) ? var0 : smallestEncompassingPowerOfTwo(var0);
|
||||
return MULTIPLY_DE_BRUIJN_BIT_POSITION[(int)(var0 * 125613361L >> 27L) & 0x1F];
|
||||
}
|
||||
|
||||
public static int log2(int var0) {
|
||||
return ceillog2(var0) - (isPowerOfTwo(var0) ? 0 : 1);
|
||||
}
|
||||
|
||||
public static int color(float var0, float var1, float var2) {
|
||||
return color(floor(var0 * 255.0F), floor(var1 * 255.0F), floor(var2 * 255.0F));
|
||||
}
|
||||
|
||||
public static int color(int var0, int var1, int var2) {
|
||||
int var3 = var0;
|
||||
var3 = (var3 << 8) + var1;
|
||||
var3 = (var3 << 8) + var2;
|
||||
return var3;
|
||||
}
|
||||
|
||||
public static int colorMultiply(int var0, int var1) {
|
||||
int var2 = (var0 & 0xFF0000) >> 16;
|
||||
int var3 = (var1 & 0xFF0000) >> 16;
|
||||
int var4 = (var0 & 0xFF00) >> 8;
|
||||
int var5 = (var1 & 0xFF00) >> 8;
|
||||
int var6 = (var0 & 0xFF) >> 0;
|
||||
int var7 = (var1 & 0xFF) >> 0;
|
||||
int var8 = (int)(var2 * var3 / 255.0F);
|
||||
int var9 = (int)(var4 * var5 / 255.0F);
|
||||
int var10 = (int)(var6 * var7 / 255.0F);
|
||||
return var0 & 0xFF000000 | var8 << 16 | var9 << 8 | var10;
|
||||
}
|
||||
|
||||
public static int colorMultiply(int var0, float var1, float var2, float var3) {
|
||||
int var4 = (var0 & 0xFF0000) >> 16;
|
||||
int var5 = (var0 & 0xFF00) >> 8;
|
||||
int var6 = (var0 & 0xFF) >> 0;
|
||||
int var7 = (int)(var4 * var1);
|
||||
int var8 = (int)(var5 * var2);
|
||||
int var9 = (int)(var6 * var3);
|
||||
return var0 & 0xFF000000 | var7 << 16 | var8 << 8 | var9;
|
||||
}
|
||||
|
||||
public static float frac(float var0) {
|
||||
return var0 - floor(var0);
|
||||
}
|
||||
|
||||
public static double frac(double var0) {
|
||||
return var0 - lfloor(var0);
|
||||
}
|
||||
|
||||
public static long getSeed(int var0, int var1, int var2) {
|
||||
long var3 = (var0 * 3129871) ^ var2 * 116129781L ^ var1;
|
||||
var3 = var3 * var3 * 42317861L + var3 * 11L;
|
||||
return var3 >> 16L;
|
||||
}
|
||||
|
||||
public static UUID createInsecureUUID(Random var0) {
|
||||
long var1 = var0.nextLong() & 0xFFFFFFFFFFFF0FFFL | 0x4000L;
|
||||
long var3 = var0.nextLong() & 0x3FFFFFFFFFFFFFFFL | Long.MIN_VALUE;
|
||||
return new UUID(var1, var3);
|
||||
}
|
||||
|
||||
public static UUID createInsecureUUID() {
|
||||
return createInsecureUUID(RANDOM);
|
||||
}
|
||||
|
||||
public static double inverseLerp(double var0, double var2, double var4) {
|
||||
return (var0 - var2) / (var4 - var2);
|
||||
}
|
||||
|
||||
public static double atan2(double var0, double var2) {
|
||||
double var4 = var2 * var2 + var0 * var0;
|
||||
if (Double.isNaN(var4))
|
||||
return Double.NaN;
|
||||
boolean var6 = (var0 < 0.0D);
|
||||
if (var6)
|
||||
var0 = -var0;
|
||||
boolean var7 = (var2 < 0.0D);
|
||||
if (var7)
|
||||
var2 = -var2;
|
||||
boolean var8 = (var0 > var2);
|
||||
if (var8) {
|
||||
double d = var2;
|
||||
var2 = var0;
|
||||
var0 = d;
|
||||
}
|
||||
double var9 = fastInvSqrt(var4);
|
||||
var2 *= var9;
|
||||
var0 *= var9;
|
||||
double var11 = FRAC_BIAS + var0;
|
||||
int var13 = (int)Double.doubleToRawLongBits(var11);
|
||||
double var14 = ASIN_TAB[var13];
|
||||
double var16 = COS_TAB[var13];
|
||||
double var18 = var11 - FRAC_BIAS;
|
||||
double var20 = var0 * var16 - var2 * var18;
|
||||
double var22 = (6.0D + var20 * var20) * var20 * 0.16666666666666666D;
|
||||
double var24 = var14 + var22;
|
||||
if (var8)
|
||||
var24 = 1.5707963267948966D - var24;
|
||||
if (var7)
|
||||
var24 = Math.PI - var24;
|
||||
if (var6)
|
||||
var24 = -var24;
|
||||
return var24;
|
||||
}
|
||||
|
||||
public static float fastInvSqrt(float var0) {
|
||||
float var1 = 0.5F * var0;
|
||||
int var2 = Float.floatToIntBits(var0);
|
||||
var2 = 1597463007 - (var2 >> 1);
|
||||
var0 = Float.intBitsToFloat(var2);
|
||||
var0 *= 1.5F - var1 * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double fastInvSqrt(double var0) {
|
||||
double var2 = 0.5D * var0;
|
||||
long var4 = Double.doubleToRawLongBits(var0);
|
||||
var4 = 6910469410427058090L - (var4 >> 1L);
|
||||
var0 = Double.longBitsToDouble(var4);
|
||||
var0 *= 1.5D - var2 * var0 * var0;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static float fastInvCubeRoot(float var0) {
|
||||
int var1 = Float.floatToIntBits(var0);
|
||||
var1 = 1419967116 - var1 / 3;
|
||||
float var2 = Float.intBitsToFloat(var1);
|
||||
var2 = 0.6666667F * var2 + 1.0F / 3.0F * var2 * var2 * var0;
|
||||
var2 = 0.6666667F * var2 + 1.0F / 3.0F * var2 * var2 * var0;
|
||||
return var2;
|
||||
}
|
||||
|
||||
private static final double FRAC_BIAS = Double.longBitsToDouble(4805340802404319232L);
|
||||
|
||||
private static final double[] ASIN_TAB = new double[257];
|
||||
|
||||
private static final double[] COS_TAB = new double[257];
|
||||
|
||||
static {
|
||||
for (int var0 = 0; var0 < 257; var0++) {
|
||||
double var1 = var0 / 256.0D;
|
||||
double var3 = Math.asin(var1);
|
||||
COS_TAB[var0] = Math.cos(var3);
|
||||
ASIN_TAB[var0] = var3;
|
||||
}
|
||||
}
|
||||
|
||||
public static int hsvToRgb(float var0, float var1, float var2) {
|
||||
float var8, var9, var10;
|
||||
int var11, var12, var13, var3 = (int)(var0 * 6.0F) % 6;
|
||||
float var4 = var0 * 6.0F - var3;
|
||||
float var5 = var2 * (1.0F - var1);
|
||||
float var6 = var2 * (1.0F - var4 * var1);
|
||||
float var7 = var2 * (1.0F - (1.0F - var4) * var1);
|
||||
switch (var3) {
|
||||
case 0:
|
||||
var8 = var2;
|
||||
var9 = var7;
|
||||
var10 = var5;
|
||||
var11 = clamp((int)(var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int)(var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int)(var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 1:
|
||||
var8 = var6;
|
||||
var9 = var2;
|
||||
var10 = var5;
|
||||
var11 = clamp((int)(var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int)(var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int)(var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 2:
|
||||
var8 = var5;
|
||||
var9 = var2;
|
||||
var10 = var7;
|
||||
var11 = clamp((int)(var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int)(var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int)(var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 3:
|
||||
var8 = var5;
|
||||
var9 = var6;
|
||||
var10 = var2;
|
||||
var11 = clamp((int)(var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int)(var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int)(var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 4:
|
||||
var8 = var7;
|
||||
var9 = var5;
|
||||
var10 = var2;
|
||||
var11 = clamp((int)(var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int)(var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int)(var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
case 5:
|
||||
var8 = var2;
|
||||
var9 = var5;
|
||||
var10 = var6;
|
||||
var11 = clamp((int)(var8 * 255.0F), 0, 255);
|
||||
var12 = clamp((int)(var9 * 255.0F), 0, 255);
|
||||
var13 = clamp((int)(var10 * 255.0F), 0, 255);
|
||||
return var11 << 16 | var12 << 8 | var13;
|
||||
}
|
||||
throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + var0 + ", " + var1 + ", " + var2);
|
||||
}
|
||||
|
||||
public static int murmurHash3Mixer(int var0) {
|
||||
var0 ^= var0 >>> 16;
|
||||
var0 *= -2048144789;
|
||||
var0 ^= var0 >>> 13;
|
||||
var0 *= -1028477387;
|
||||
var0 ^= var0 >>> 16;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static long murmurHash3Mixer(long var0) {
|
||||
var0 ^= var0 >>> 33L;
|
||||
var0 *= -49064778989728563L;
|
||||
var0 ^= var0 >>> 33L;
|
||||
var0 *= -4265267296055464877L;
|
||||
var0 ^= var0 >>> 33L;
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static double[] cumulativeSum(double... var0) {
|
||||
float var1 = 0.0F;
|
||||
for (double var5 : var0)
|
||||
var1 = (float)(var1 + var5);
|
||||
int var2;
|
||||
for (var2 = 0; var2 < var0.length; var2++)
|
||||
var0[var2] = var0[var2] / var1;
|
||||
for (var2 = 0; var2 < var0.length; var2++)
|
||||
var0[var2] = ((var2 == 0) ? 0.0D : var0[var2 - 1]) + var0[var2];
|
||||
return var0;
|
||||
}
|
||||
|
||||
public static int getRandomForDistributionIntegral(Random var0, double[] var1) {
|
||||
double var2 = var0.nextDouble();
|
||||
for (int var4 = 0; var4 < var1.length; var4++) {
|
||||
if (var2 < var1[var4])
|
||||
return var4;
|
||||
}
|
||||
return var1.length;
|
||||
}
|
||||
|
||||
public static double[] binNormalDistribution(double var0, double var2, double var4, int var6, int var7) {
|
||||
double[] var8 = new double[var7 - var6 + 1];
|
||||
int var9 = 0;
|
||||
for (int var10 = var6; var10 <= var7; var10++) {
|
||||
var8[var9] = Math.max(0.0D, var0 *
|
||||
|
||||
StrictMath.exp(-(var10 - var4) * (var10 - var4) / 2.0D * var2 * var2));
|
||||
var9++;
|
||||
}
|
||||
return var8;
|
||||
}
|
||||
|
||||
public static double[] binBiModalNormalDistribution(double var0, double var2, double var4, double var6, double var8, double var10, int var12, int var13) {
|
||||
double[] var14 = new double[var13 - var12 + 1];
|
||||
int var15 = 0;
|
||||
for (int var16 = var12; var16 <= var13; var16++) {
|
||||
var14[var15] = Math.max(0.0D, var0 *
|
||||
|
||||
StrictMath.exp(-(var16 - var4) * (var16 - var4) / 2.0D * var2 * var2) + var6 *
|
||||
StrictMath.exp(-(var16 - var10) * (var16 - var10) / 2.0D * var8 * var8));
|
||||
var15++;
|
||||
}
|
||||
return var14;
|
||||
}
|
||||
|
||||
public static double[] binLogDistribution(double var0, double var2, int var4, int var5) {
|
||||
double[] var6 = new double[var5 - var4 + 1];
|
||||
int var7 = 0;
|
||||
for (int var8 = var4; var8 <= var5; var8++) {
|
||||
var6[var7] = Math.max(var0 * StrictMath.log(var8) + var2, 0.0D);
|
||||
var7++;
|
||||
}
|
||||
return var6;
|
||||
}
|
||||
|
||||
public static float lerp(float var0, float var1, float var2) {
|
||||
return var1 + var0 * (var2 - var1);
|
||||
}
|
||||
|
||||
public static double lerp(double var0, double var2, double var4) {
|
||||
return var2 + var0 * (var4 - var2);
|
||||
}
|
||||
|
||||
public static double lerp2(double var0, double var2, double var4, double var6, double var8, double var10) {
|
||||
return lerp(var2,
|
||||
|
||||
lerp(var0, var4, var6),
|
||||
lerp(var0, var8, var10));
|
||||
}
|
||||
|
||||
public static double lerp3(double var0, double var2, double var4, double var6, double var8, double var10, double var12, double var14, double var16, double var18, double var20) {
|
||||
return lerp(var4,
|
||||
|
||||
lerp2(var0, var2, var6, var8, var10, var12),
|
||||
lerp2(var0, var2, var14, var16, var18, var20));
|
||||
}
|
||||
|
||||
public static double smoothstep(double var0) {
|
||||
return var0 * var0 * var0 * (var0 * (var0 * 6.0D - 15.0D) + 10.0D);
|
||||
}
|
||||
|
||||
public static double smoothstepDerivative(double var0) {
|
||||
return 30.0D * var0 * var0 * (var0 - 1.0D) * (var0 - 1.0D);
|
||||
}
|
||||
|
||||
public static int sign(double var0) {
|
||||
if (var0 == 0.0D)
|
||||
return 0;
|
||||
return (var0 > 0.0D) ? 1 : -1;
|
||||
}
|
||||
|
||||
public static float rotLerp(float var0, float var1, float var2) {
|
||||
return var1 + var0 * wrapDegrees(var2 - var1);
|
||||
}
|
||||
|
||||
public static float diffuseLight(float var0, float var1, float var2) {
|
||||
return Math.min(var0 * var0 * 0.6F + var1 * var1 * (3.0F + var1) / 4.0F + var2 * var2 * 0.8F, 1.0F);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float rotlerp(float var0, float var1, float var2) {
|
||||
float var3 = var1 - var0;
|
||||
while (var3 < -180.0F)
|
||||
var3 += 360.0F;
|
||||
while (var3 >= 180.0F)
|
||||
var3 -= 360.0F;
|
||||
return var0 + var2 * var3;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static float rotWrap(double var0) {
|
||||
while (var0 >= 180.0D)
|
||||
var0 -= 360.0D;
|
||||
while (var0 < -180.0D)
|
||||
var0 += 360.0D;
|
||||
return (float)var0;
|
||||
}
|
||||
|
||||
public static float triangleWave(float var0, float var1) {
|
||||
return (Math.abs(var0 % var1 - var1 * 0.5F) - var1 * 0.25F) / var1 * 0.25F;
|
||||
}
|
||||
|
||||
public static float square(float var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static double square(double var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static int square(int var0) {
|
||||
return var0 * var0;
|
||||
}
|
||||
|
||||
public static double clampedMap(double var0, double var2, double var4, double var6, double var8) {
|
||||
return clampedLerp(var6, var8, inverseLerp(var0, var2, var4));
|
||||
}
|
||||
|
||||
public static double map(double var0, double var2, double var4, double var6, double var8) {
|
||||
return lerp(inverseLerp(var0, var2, var4), var6, var8);
|
||||
}
|
||||
|
||||
public static double wobble(double var0) {
|
||||
return var0 + (2.0D * (new Random(floor(var0 * 3000.0D))).nextDouble() - 1.0D) * 1.0E-7D / 2.0D;
|
||||
}
|
||||
|
||||
public static int roundToward(int var0, int var1) {
|
||||
return (var0 + var1 - 1) / var1 * var1;
|
||||
}
|
||||
|
||||
public static int randomBetweenInclusive(Random var0, int var1, int var2) {
|
||||
return var0.nextInt(var2 - var1 + 1) + var1;
|
||||
}
|
||||
|
||||
public static float randomBetween(Random var0, float var1, float var2) {
|
||||
return var0.nextFloat() * (var2 - var1) + var1;
|
||||
}
|
||||
|
||||
public static float normal(Random var0, float var1, float var2) {
|
||||
return var1 + (float)var0.nextGaussian() * var2;
|
||||
}
|
||||
|
||||
public static double length(int var0, double var1, int var3) {
|
||||
return Math.sqrt((var0 * var0) + var1 * var1 + (var3 * var3));
|
||||
}
|
||||
}
|
@ -16,21 +16,20 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public interface DataPalette {
|
||||
int getIndex(CompoundTag block);
|
||||
public interface Palette<T> {
|
||||
int idFor(T paramT);
|
||||
|
||||
boolean contains(Predicate<CompoundTag> predicate);
|
||||
boolean maybeHas(Predicate<T> paramPredicate);
|
||||
|
||||
CompoundTag getByIndex(int index);
|
||||
T valueFor(int paramInt);
|
||||
|
||||
int size();
|
||||
int getSize();
|
||||
|
||||
void replace(ListTag<CompoundTag> palette);
|
||||
void read(ListTag paramListTag);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
public interface PaletteAccess {
|
||||
public void setBlock(int x, int y, int z, CompoundTag data);
|
||||
|
||||
public CompoundTag getBlock(int x, int y, int z);
|
||||
|
||||
public void writeToSection(CompoundTag tag);
|
||||
|
||||
public void readFromSection(CompoundTag tag);
|
||||
}
|
@ -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.nbt.mca.palette;
|
||||
|
||||
interface PaletteResize<T> {
|
||||
int onResize(int paramInt, T paramT);
|
||||
}
|
@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class PalettedContainer<T> implements PaletteResize<T> {
|
||||
private static final int SIZE = 4096;
|
||||
|
||||
public static final int GLOBAL_PALETTE_BITS = 9;
|
||||
|
||||
public static final int MIN_PALETTE_SIZE = 4;
|
||||
|
||||
private final Palette<T> globalPalette;
|
||||
|
||||
private final PaletteResize<T> dummyPaletteResize = (var0, var1) -> 0;
|
||||
|
||||
private final IdMapper<T> registry;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
private final Function<T, CompoundTag> writer;
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
protected BitStorage storage;
|
||||
|
||||
private Palette<T> palette;
|
||||
|
||||
private int bits;
|
||||
|
||||
public PalettedContainer(Palette<T> var0, IdMapper<T> var1, Function<CompoundTag, T> var2, Function<T, CompoundTag> var3, T var4) {
|
||||
this.globalPalette = var0;
|
||||
this.registry = var1;
|
||||
this.reader = var2;
|
||||
this.writer = var3;
|
||||
this.defaultValue = var4;
|
||||
setBits(4);
|
||||
}
|
||||
|
||||
private static int getIndex(int var0, int var1, int var2) {
|
||||
return var1 << 8 | var2 << 4 | var0;
|
||||
}
|
||||
|
||||
private void setBits(int var0) {
|
||||
if (var0 == this.bits)
|
||||
return;
|
||||
this.bits = var0;
|
||||
if (this.bits <= 4) {
|
||||
this.bits = 4;
|
||||
this.palette = new LinearPalette<>(this.registry, this.bits, this, this.reader);
|
||||
} else if (this.bits < 9) {
|
||||
this.palette = new HashMapPalette<>(this.registry, this.bits, this, this.reader, this.writer);
|
||||
} else {
|
||||
this.palette = this.globalPalette;
|
||||
this.bits = Mth.ceillog2(this.registry.size());
|
||||
}
|
||||
this.palette.idFor(this.defaultValue);
|
||||
this.storage = new BitStorage(this.bits, 4096);
|
||||
}
|
||||
|
||||
public int onResize(int var0, T var1) {
|
||||
BitStorage var2 = this.storage;
|
||||
Palette<T> var3 = this.palette;
|
||||
setBits(var0);
|
||||
for (int var4 = 0; var4 < var2.getSize(); var4++) {
|
||||
T var5 = var3.valueFor(var2.get(var4));
|
||||
if (var5 != null)
|
||||
set(var4, var5);
|
||||
}
|
||||
return this.palette.idFor(var1);
|
||||
}
|
||||
|
||||
public T getAndSet(int var0, int var1, int var2, T var3) {
|
||||
return getAndSet(getIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
public T getAndSetUnchecked(int var0, int var1, int var2, T var3) {
|
||||
return getAndSet(getIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
private T getAndSet(int var0, T var1) {
|
||||
int var2 = this.palette.idFor(var1);
|
||||
int var3 = this.storage.getAndSet(var0, var2);
|
||||
T var4 = this.palette.valueFor(var3);
|
||||
return (var4 == null) ? this.defaultValue : var4;
|
||||
}
|
||||
|
||||
public void set(int var0, int var1, int var2, T var3) {
|
||||
set(getIndex(var0, var1, var2), var3);
|
||||
}
|
||||
|
||||
private void set(int var0, T var1) {
|
||||
int var2 = this.palette.idFor(var1);
|
||||
this.storage.set(var0, var2);
|
||||
}
|
||||
|
||||
public T get(int var0, int var1, int var2) {
|
||||
return get(getIndex(var0, var1, var2));
|
||||
}
|
||||
|
||||
protected T get(int var0) {
|
||||
T var1 = this.palette.valueFor(this.storage.get(var0));
|
||||
return (var1 == null) ? this.defaultValue : var1;
|
||||
}
|
||||
|
||||
public void read(ListTag var0, long[] var1) {
|
||||
int var2 = Math.max(4, Mth.ceillog2(var0.size()));
|
||||
if (var2 != this.bits)
|
||||
setBits(var2);
|
||||
this.palette.read(var0);
|
||||
int var3 = var1.length * 64 / 4096;
|
||||
if (this.palette == this.globalPalette) {
|
||||
Palette<T> var4 = new HashMapPalette<>(this.registry, var2, this.dummyPaletteResize, this.reader, this.writer);
|
||||
var4.read(var0);
|
||||
BitStorage var5 = new BitStorage(var2, 4096, var1);
|
||||
for (int var6 = 0; var6 < 4096; var6++)
|
||||
this.storage.set(var6, this.globalPalette.idFor(var4.valueFor(var5.get(var6))));
|
||||
} else if (var3 == this.bits) {
|
||||
System.arraycopy(var1, 0, this.storage.getRaw(), 0, var1.length);
|
||||
} else {
|
||||
BitStorage var4 = new BitStorage(var3, 4096, var1);
|
||||
for (int var5 = 0; var5 < 4096; var5++)
|
||||
this.storage.set(var5, var4.get(var5));
|
||||
}
|
||||
}
|
||||
|
||||
public void write(CompoundTag var0, String var1, String var2) {
|
||||
HashMapPalette<T> var3 = new HashMapPalette<>(this.registry, this.bits, this.dummyPaletteResize, this.reader, this.writer);
|
||||
T var4 = this.defaultValue;
|
||||
int var5 = var3.idFor(this.defaultValue);
|
||||
int[] var6 = new int[4096];
|
||||
for (int i = 0; i < 4096; i++) {
|
||||
T t = get(i);
|
||||
if (t != var4) {
|
||||
var4 = t;
|
||||
var5 = var3.idFor(t);
|
||||
}
|
||||
var6[i] = var5;
|
||||
}
|
||||
ListTag<CompoundTag> paletteList = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
var3.write(paletteList);
|
||||
var0.put(var1, paletteList);
|
||||
int var8 = Math.max(4, Mth.ceillog2(paletteList.size()));
|
||||
BitStorage var9 = new BitStorage(var8, 4096);
|
||||
for (int var10 = 0; var10 < var6.length; var10++)
|
||||
{
|
||||
var9.set(var10, var6[var10]);
|
||||
}
|
||||
var0.putLongArray(var2, var9.getRaw());
|
||||
}
|
||||
|
||||
public boolean maybeHas(Predicate<T> var0) {
|
||||
return this.palette.maybeHas(var0);
|
||||
}
|
||||
|
||||
public void count(CountConsumer<T> var0) {
|
||||
Int2IntOpenHashMap int2IntOpenHashMap = new Int2IntOpenHashMap();
|
||||
this.storage.getAll(var1 -> int2IntOpenHashMap.put(var1, int2IntOpenHashMap.get(var1) + 1));
|
||||
int2IntOpenHashMap.int2IntEntrySet().forEach(var1 -> var0.accept(this.palette.valueFor(var1.getIntKey()), var1.getIntValue()));
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.palette;
|
||||
|
||||
public final class QuartPos {
|
||||
public static final int BITS = 2;
|
||||
|
||||
public static final int SIZE = 4;
|
||||
|
||||
private static final int SECTION_TO_QUARTS_BITS = 2;
|
||||
|
||||
public static int fromBlock(int var0) {
|
||||
return var0 >> 2;
|
||||
}
|
||||
|
||||
public static int toBlock(int var0) {
|
||||
return var0 << 2;
|
||||
}
|
||||
|
||||
public static int fromSection(int var0) {
|
||||
return var0 << 2;
|
||||
}
|
||||
|
||||
public static int toSection(int var0) {
|
||||
return var0 >> 2;
|
||||
}
|
||||
}
|
@ -16,41 +16,36 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.volmit.iris.util.nbt.mca.palettes;
|
||||
package com.volmit.iris.util.nbt.mca.palette;
|
||||
|
||||
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;
|
||||
import java.util.function.Function;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class DataPaletteGlobal implements DataPalette {
|
||||
@Getter
|
||||
private final RegistryBlockID registry;
|
||||
private final CompoundTag air;
|
||||
public class WrappedPalettedContainer<T> implements PaletteAccess {
|
||||
private final PalettedContainer<T> container;
|
||||
private final Function<T, CompoundTag> reader;
|
||||
private final Function<CompoundTag, T> writer;
|
||||
|
||||
public int getIndex(CompoundTag block) {
|
||||
int id = this.registry.getId(block);
|
||||
return id == -1 ? 0 : id;
|
||||
public void setBlock(int x, int y, int z, CompoundTag data)
|
||||
{
|
||||
container.set(x,y,z,writer.apply(data));
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> predicate) {
|
||||
return true;
|
||||
public CompoundTag getBlock(int x, int y, int z)
|
||||
{
|
||||
return reader.apply(container.get(x,y,z));
|
||||
}
|
||||
|
||||
public CompoundTag getByIndex(int index) {
|
||||
CompoundTag block = registry.fromId(index);
|
||||
return block == null ? air : block;
|
||||
public void writeToSection(CompoundTag tag)
|
||||
{
|
||||
container.write(tag, "Palette", "BlockStates");
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return registry.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void replace(ListTag<CompoundTag> palette) {
|
||||
throw new UnsupportedOperationException("Cannot replace the global palette!");
|
||||
public void readFromSection(CompoundTag tag)
|
||||
{
|
||||
container.read(tag.getListTag("Palette"), tag.getLongArrayTag("BlockStates").getValue());
|
||||
}
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
* 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[] data;
|
||||
private final int c;
|
||||
private final long paletteSize;
|
||||
private final int blockSize;
|
||||
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 bitsPerBlock, int var1, long[] data) {
|
||||
Validate.inclusiveBetween(1L, 32L, (long) bitsPerBlock);
|
||||
this.blockSize = var1;
|
||||
this.c = bitsPerBlock;
|
||||
this.paletteSize = (1L << bitsPerBlock) - 1L;
|
||||
this.f = (char) (64 / bitsPerBlock);
|
||||
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 (data != null) {
|
||||
if (data.length != var4) {
|
||||
throw new RuntimeException("Invalid length given for storage, got: " + data.length + " but expected: " + var4);
|
||||
}
|
||||
|
||||
this.data = data;
|
||||
} else {
|
||||
this.data = 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 setBlockResulting(int blockIndex, int paletteIndex) {
|
||||
Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex);
|
||||
Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex);
|
||||
int var2 = this.b(blockIndex);
|
||||
long var3 = this.data[var2];
|
||||
int var5 = (blockIndex - var2 * this.f) * this.c;
|
||||
int var6 = (int) (var3 >> var5 & this.paletteSize);
|
||||
this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5;
|
||||
return var6;
|
||||
}
|
||||
|
||||
public void setBlock(int blockIndex, int paletteIndex) {
|
||||
Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) blockIndex);
|
||||
Validate.inclusiveBetween(0L, this.paletteSize, (long) paletteIndex);
|
||||
int var2 = this.b(blockIndex);
|
||||
long var3 = this.data[var2];
|
||||
int var5 = (blockIndex - var2 * this.f) * this.c;
|
||||
this.data[var2] = var3 & ~(this.paletteSize << var5) | ((long) paletteIndex & this.paletteSize) << var5;
|
||||
}
|
||||
|
||||
public int getIndexFromPos(int var0) {
|
||||
Validate.inclusiveBetween(0L, (long) (this.blockSize - 1), (long) var0);
|
||||
int var1 = this.b(var0);
|
||||
long var2 = this.data[var1];
|
||||
int var4 = (var0 - var1 * this.f) * this.c;
|
||||
return (int) (var2 >> var4 & this.paletteSize);
|
||||
}
|
||||
|
||||
public long[] getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
public int b() {
|
||||
return this.blockSize;
|
||||
}
|
||||
|
||||
public int getBitsPerBlock() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public void a(IntConsumer var0) {
|
||||
int var1 = 0;
|
||||
long[] var3 = this.data;
|
||||
int var4 = var3.length;
|
||||
for (long l : var3) {
|
||||
long var5 = l;
|
||||
for (int j = 0; j < this.f; ++j) {
|
||||
var0.accept((int) (var5 & this.paletteSize));
|
||||
var5 >>= this.c;
|
||||
++var1;
|
||||
if (var1 >= this.blockSize) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,225 +0,0 @@
|
||||
/*
|
||||
* 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.Iris;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.engine.data.cache.AtomicCache;
|
||||
import com.volmit.iris.util.math.MathHelper;
|
||||
import com.volmit.iris.util.nbt.io.SNBTSerializer;
|
||||
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.world.level.chunk.ChunkSection;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Getter
|
||||
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 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 currentPalette;
|
||||
private int bits = 0;
|
||||
|
||||
public DataPaletteBlock() {
|
||||
this(global(), registry(), air);
|
||||
}
|
||||
|
||||
public DataPaletteBlock(DataPalette var0,
|
||||
RegistryBlockID var1,
|
||||
CompoundTag airType) {
|
||||
this.globalPalette = var0;
|
||||
this.stolenRegistry = var1;
|
||||
this.defAir = airType;
|
||||
this.changeBitsTo(4);
|
||||
}
|
||||
|
||||
private static RegistryBlockID registry()
|
||||
{
|
||||
return ((DataPaletteGlobal) global()).getRegistry();
|
||||
}
|
||||
|
||||
private static DataPalette global() {
|
||||
return global.aquire(() -> new DataPaletteGlobal(J.attemptResult(() -> INMS.get().computeBlockIDRegistry()), air));
|
||||
}
|
||||
|
||||
|
||||
private static int blockIndex(int x, int y, int z) {
|
||||
return y << 8 | z << 4 | x;
|
||||
}
|
||||
|
||||
private void changeBitsTo(int newbits) {
|
||||
if (newbits != bits) {
|
||||
bits = newbits;
|
||||
if (bits <= LINEAR_BITS) {
|
||||
bits = LINEAR_BITS;
|
||||
currentPalette = new DataPaletteLinear(bits, this);
|
||||
} else if (bits < HASH_BITS) {
|
||||
currentPalette = new DataPaletteHash(bits, this);
|
||||
} else {
|
||||
currentPalette = globalPalette;
|
||||
bits = MathHelper.e(stolenRegistry.size());
|
||||
}
|
||||
|
||||
currentPalette.getIndex(defAir);
|
||||
dataBits = new DataBits(bits, 4096);
|
||||
}
|
||||
}
|
||||
|
||||
public int onResize(int newBits, CompoundTag newData) {
|
||||
DataBits oldBits = dataBits;
|
||||
DataPalette oldPalette = currentPalette;
|
||||
changeBitsTo(newBits);
|
||||
|
||||
for (int i = 0; i < oldBits.b(); ++i) {
|
||||
CompoundTag block = oldPalette.getByIndex(oldBits.getIndexFromPos(i));
|
||||
if (block != null) {
|
||||
setBlockIndex(i, block);
|
||||
}
|
||||
}
|
||||
|
||||
return currentPalette.getIndex(newData);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CompoundTag setBlockAndReturn(int x, int y, int z, CompoundTag block) {
|
||||
return setBlockIndexAndReturn(blockIndex(x, y, z), block);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private CompoundTag setBlockIndexAndReturn(int index, CompoundTag block) {
|
||||
int paletteIndex = currentPalette.getIndex(block);
|
||||
int res = dataBits.setBlockResulting(index, paletteIndex);
|
||||
CompoundTag testBlock = currentPalette.getByIndex(res);
|
||||
return testBlock == null ? defAir : testBlock;
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, CompoundTag block) {
|
||||
setBlockIndex(blockIndex(x, y, z), block);
|
||||
}
|
||||
|
||||
private void setBlockIndex(int blockIndex, CompoundTag block) {
|
||||
int paletteIndex = currentPalette.getIndex(block);
|
||||
dataBits.setBlock(blockIndex, paletteIndex);
|
||||
}
|
||||
|
||||
public CompoundTag getBlock(int x, int y, int z) {
|
||||
return getByIndex(blockIndex(x, y, z));
|
||||
}
|
||||
|
||||
protected CompoundTag getByIndex(int index) {
|
||||
if(currentPalette == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
CompoundTag data = currentPalette.getByIndex(dataBits.getIndexFromPos(index));
|
||||
return data == null ? defAir : data;
|
||||
}
|
||||
|
||||
public void load(ListTag<CompoundTag> palettedata, long[] databits) {
|
||||
int readBits = Math.max(4, MathHelper.e(palettedata.size()));
|
||||
if (readBits != bits) {
|
||||
changeBitsTo(readBits);
|
||||
}
|
||||
|
||||
currentPalette.replace(palettedata);
|
||||
int dblen = databits.length * 64 / 4096;
|
||||
if (currentPalette == globalPalette) {
|
||||
DataPalette hashPalette = new DataPaletteHash(readBits, f);
|
||||
hashPalette.replace(palettedata);
|
||||
DataBits var5 = new DataBits(readBits, 4096, databits);
|
||||
|
||||
for (int i = 0; i < 4096; ++i) {
|
||||
dataBits.setBlock(i, globalPalette.getIndex(hashPalette.getByIndex(var5.getIndexFromPos(i))));
|
||||
}
|
||||
} else if (dblen == bits) {
|
||||
System.arraycopy(databits, 0, dataBits.getData(), 0, databits.length);
|
||||
} else {
|
||||
DataBits var4 = new DataBits(dblen, 4096, databits);
|
||||
|
||||
for (int i = 0; i < 4096; ++i) {
|
||||
dataBits.setBlock(i, var4.getIndexFromPos(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save(CompoundTag to, String paletteName, String blockStatesName) {
|
||||
DataPaletteHash hashpal = new DataPaletteHash(bits, f);
|
||||
CompoundTag cursor = defAir;
|
||||
int palIndex = hashpal.getIndex(defAir);
|
||||
int[] paletteIndex = new int[4096];
|
||||
int i;
|
||||
for (i = 0; i < 4096; ++i) {
|
||||
CompoundTag entry = getByIndex(i);
|
||||
if (!entry.equals(cursor)) {
|
||||
cursor = entry;
|
||||
palIndex = hashpal.getIndex(entry);
|
||||
}
|
||||
|
||||
paletteIndex[i] = palIndex;
|
||||
}
|
||||
|
||||
ListTag<CompoundTag> npalette = (ListTag<CompoundTag>) ListTag.createUnchecked(CompoundTag.class);
|
||||
hashpal.writePalette(npalette);
|
||||
to.put(paletteName, npalette);
|
||||
int bits = Math.max(4, MathHelper.e(npalette.size()));
|
||||
DataBits writeBits = new DataBits(bits, 4096);
|
||||
|
||||
for (i = 0; i < paletteIndex.length; ++i) {
|
||||
writeBits.setBlock(i, paletteIndex[i]);
|
||||
}
|
||||
|
||||
to.putLongArray(blockStatesName, writeBits.getData());
|
||||
to.putString("DEBUG_PALETTE_MODE", currentPalette.getClass().getSimpleName());
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> var0) {
|
||||
return currentPalette.contains(var0);
|
||||
}
|
||||
|
||||
public void a(PaletteConsumer<CompoundTag> var0) {
|
||||
Int2IntMap var1 = new Int2IntOpenHashMap();
|
||||
dataBits.a((var1x) -> var1.put(var1x, var1.get(var1x) + 1));
|
||||
var1.int2IntEntrySet().forEach((var1x) -> var0.accept(currentPalette.getByIndex(var1x.getIntKey()), var1x.getIntValue()));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PaletteConsumer<T> {
|
||||
void accept(T var1, int var2);
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.function.Predicate;
|
||||
|
||||
public class DataPaletteHash implements DataPalette {
|
||||
private final RegistryID registryId;
|
||||
private final DataPaletteExpandable expander;
|
||||
private final int bits;
|
||||
|
||||
public DataPaletteHash(int bits, DataPaletteExpandable expander) {
|
||||
this.bits = bits;
|
||||
this.expander = expander;
|
||||
this.registryId = new RegistryID(1 << bits);
|
||||
}
|
||||
|
||||
public int getIndex(CompoundTag block) {
|
||||
int id = registryId.getId(block);
|
||||
if (id == -1) {
|
||||
id = registryId.c(block);
|
||||
if (id >= 1 << bits) {
|
||||
id = expander.onResize(bits + 1, block);
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> predicate) {
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
if (predicate.test(registryId.fromId(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public CompoundTag getByIndex(int index) {
|
||||
return registryId.fromId(index);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return registryId.size();
|
||||
}
|
||||
|
||||
public void replace(ListTag<CompoundTag> palette) {
|
||||
registryId.clear();
|
||||
|
||||
for (int i = 0; i < palette.size(); ++i) {
|
||||
registryId.c(palette.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void writePalette(ListTag<CompoundTag> list) {
|
||||
for (int i = 0; i < size(); ++i) {
|
||||
list.add(registryId.fromId(i));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.function.Predicate;
|
||||
|
||||
public class DataPaletteLinear implements DataPalette {
|
||||
private final CompoundTag[] palette;
|
||||
private final DataPaletteExpandable expander;
|
||||
private final int e;
|
||||
private int size;
|
||||
|
||||
public DataPaletteLinear(int bits, DataPaletteExpandable expander) {
|
||||
this.palette = new CompoundTag[1 << bits];
|
||||
this.e = bits;
|
||||
this.expander = expander;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public int getIndex(CompoundTag block) {
|
||||
int i;
|
||||
for (i = 0; i < size; ++i) {
|
||||
if (palette[i].equals(block)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
i = size;
|
||||
if (i < palette.length) {
|
||||
palette[i] = block;
|
||||
++size;
|
||||
return i;
|
||||
} else {
|
||||
return expander.onResize(e + 1, block);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(Predicate<CompoundTag> predicate) {
|
||||
for (int i = 0; i < this.size; ++i) {
|
||||
if (predicate.test(palette[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public CompoundTag getByIndex(int index) {
|
||||
return index >= 0 && index < size ? palette[index] : null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void replace(ListTag<CompoundTag> palette) {
|
||||
for (int i = 0; i < palette.size(); ++i) {
|
||||
this.palette[i] = palette.get(i);
|
||||
}
|
||||
|
||||
this.size = palette.size();
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
/*
|
||||
* 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.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class RegistryBlockID implements Registry {
|
||||
private final Map<CompoundTag, Integer> indexMap;
|
||||
private final List<CompoundTag> indexes;
|
||||
|
||||
public RegistryBlockID(Map<CompoundTag, Integer> c, List<CompoundTag> d) {
|
||||
this.indexMap = c;
|
||||
this.indexes = d;
|
||||
}
|
||||
|
||||
public RegistryBlockID() {
|
||||
this(512);
|
||||
}
|
||||
|
||||
public RegistryBlockID(int var0) {
|
||||
this.indexes = Lists.newArrayListWithExpectedSize(var0);
|
||||
this.indexMap = new HashMap<>(var0);
|
||||
}
|
||||
|
||||
public int getId(CompoundTag block) {
|
||||
Integer var1 = this.indexMap.get(block);
|
||||
return var1 == null ? -1 : var1;
|
||||
}
|
||||
|
||||
public final CompoundTag fromId(int id) {
|
||||
return id >= 0 && id < this.indexes.size() ? this.indexes.get(id) : null;
|
||||
}
|
||||
|
||||
public Iterator<CompoundTag> iterator() {
|
||||
return Iterators.filter(this.indexes.iterator(), Objects::nonNull);
|
||||
}
|
||||
|
||||
public boolean hasIndex(int var0) {
|
||||
return this.fromId(var0) != null;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.indexMap.size();
|
||||
}
|
||||
}
|
@ -1,176 +0,0 @@
|
||||
/*
|
||||
* 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.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;
|
||||
import java.util.Objects;
|
||||
|
||||
public class RegistryID implements Registry {
|
||||
public static final int a = -1;
|
||||
private static final CompoundTag b = null;
|
||||
private static final float c = 0.8F;
|
||||
private CompoundTag[] d;
|
||||
private int[] e;
|
||||
private CompoundTag[] f;
|
||||
private int g;
|
||||
private int size;
|
||||
|
||||
public RegistryID(int var0) {
|
||||
var0 = (int) ((float) var0 / 0.8F);
|
||||
this.d = new CompoundTag[var0];
|
||||
this.f = new CompoundTag[var0];
|
||||
this.e = new int[var0];
|
||||
}
|
||||
|
||||
public int getId(CompoundTag block) {
|
||||
return this.c(this.b(block, this.d(block)));
|
||||
}
|
||||
|
||||
public CompoundTag fromId(int id) {
|
||||
return id >= 0 && id < this.f.length ? this.f[id] : null;
|
||||
}
|
||||
|
||||
private int c(int var0) {
|
||||
return var0 == -1 ? -1 : this.e[var0];
|
||||
}
|
||||
|
||||
public boolean b(CompoundTag var0) {
|
||||
return this.getId(var0) != -1;
|
||||
}
|
||||
|
||||
public boolean b(int var0) {
|
||||
return this.fromId(var0) != null;
|
||||
}
|
||||
|
||||
public int c(CompoundTag 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) {
|
||||
CompoundTag[] var1 = this.d;
|
||||
int[] var2 = this.e;
|
||||
this.d = new CompoundTag[var0];
|
||||
this.e = new int[var0];
|
||||
this.f = new CompoundTag[var0];
|
||||
this.g = 0;
|
||||
this.size = 0;
|
||||
|
||||
for (int var3 = 0; var3 < var1.length; ++var3) {
|
||||
if (var1[var3] != null) {
|
||||
this.a(var1[var3], var2[var3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void a(CompoundTag var0, int var1) {
|
||||
int var2 = Math.max(var1, this.size + 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.size;
|
||||
if (var1 == this.g) {
|
||||
++this.g;
|
||||
}
|
||||
}
|
||||
|
||||
private int d(CompoundTag block) {
|
||||
return (MathHelper.g(System.identityHashCode(block)) & 2147483647) % this.d.length;
|
||||
}
|
||||
|
||||
private int b(CompoundTag block, int var1) {
|
||||
int var2;
|
||||
for (var2 = var1; var2 < this.d.length; ++var2) {
|
||||
if (this.d[var2] == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this.d[var2].equals(block)) {
|
||||
return var2;
|
||||
}
|
||||
}
|
||||
|
||||
for (var2 = 0; var2 < var1; ++var2) {
|
||||
if (this.d[var2] == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (this.d[var2].equals(block)) {
|
||||
return var2;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int e(int var0) {
|
||||
int var1;
|
||||
for (var1 = var0; var1 < this.d.length; ++var1) {
|
||||
if (this.d[var1] == null) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
for (var1 = 0; var1 < var0; ++var1) {
|
||||
if (this.d[var1] == null) {
|
||||
return var1;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Overflowed :(");
|
||||
}
|
||||
|
||||
public Iterator<CompoundTag> iterator() {
|
||||
return Iterators.filter(Iterators.forArray(this.f), Objects::nonNull);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Arrays.fill(this.d, null);
|
||||
Arrays.fill(this.f, null);
|
||||
this.g = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.size;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user