mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
NBTSpecific palettes
This commit is contained in:
parent
92f72b45d5
commit
c7638a6485
@ -18,8 +18,8 @@
|
||||
|
||||
package com.volmit.iris.core.nms;
|
||||
|
||||
import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -65,9 +65,9 @@ public interface INMSBinding {
|
||||
|
||||
int getBiomeId(Biome biome);
|
||||
|
||||
BiomeContainer newBiomeContainer(int min, int max, int[] data);
|
||||
MCABiomeContainer newBiomeContainer(int min, int max, int[] data);
|
||||
|
||||
BiomeContainer newBiomeContainer(int min, int max);
|
||||
MCABiomeContainer newBiomeContainer(int min, int max);
|
||||
|
||||
default World createWorld(WorldCreator c) {
|
||||
return c.createWorld();
|
||||
@ -81,5 +81,5 @@ public interface INMSBinding {
|
||||
return false;
|
||||
}
|
||||
|
||||
PaletteAccess createPalette();
|
||||
MCAPaletteAccess createPalette();
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ 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.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.ChunkBiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.GlobalPalette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.IdMap;
|
||||
import com.volmit.iris.util.nbt.mca.palette.IdMapper;
|
||||
import com.volmit.iris.util.nbt.mca.palette.Palette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PalettedContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.WrappedPalettedContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAChunkBiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAGlobalPalette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAIdMap;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAIdMapper;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPalette;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPalettedContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAWrappedPalettedContainer;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.core.IRegistry;
|
||||
@ -82,9 +82,9 @@ 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 final AtomicCache<IdMap<BiomeBase>> biomeMapCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMapper<IBlockData>> registryCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAPalette<IBlockData>> globalCache = new AtomicCache<>();
|
||||
private final AtomicCache<MCAIdMap<BiomeBase>> biomeMapCache = new AtomicCache<>();
|
||||
private Field biomeStorageCache = null;
|
||||
|
||||
public boolean supportsDataPacks() {
|
||||
@ -92,8 +92,8 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteAccess createPalette() {
|
||||
IdMapper<IBlockData> registry = registryCache.aquireNasty(() -> {
|
||||
public MCAPaletteAccess createPalette() {
|
||||
MCAIdMapper<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");
|
||||
@ -104,14 +104,14 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
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);
|
||||
return new MCAIdMapper<>(c, d, b);
|
||||
});
|
||||
Palette<IBlockData> global = globalCache.aquireNasty(() -> new GlobalPalette<>(registry, ((CraftBlockData) AIR).getState()));
|
||||
PalettedContainer<IBlockData> container = new PalettedContainer<>(global, registry,
|
||||
MCAPalette<IBlockData> global = globalCache.aquireNasty(() -> new MCAGlobalPalette<>(registry, ((CraftBlockData) AIR).getState()));
|
||||
MCAPalettedContainer<IBlockData> container = new MCAPalettedContainer<>(global, registry,
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState(),
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
((CraftBlockData) AIR).getState());
|
||||
return new WrappedPalettedContainer<>(container,
|
||||
return new MCAWrappedPalettedContainer<>(container,
|
||||
i -> NBTWorld.getCompound(CraftBlockData.fromData(i)),
|
||||
i -> ((CraftBlockData) NBTWorld.getBlockData(i)).getState());
|
||||
}
|
||||
@ -399,8 +399,8 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
return biome.ordinal();
|
||||
}
|
||||
|
||||
private IdMap<BiomeBase> getBiomeMapping() {
|
||||
return biomeMapCache.aquire(() -> new IdMap<>() {
|
||||
private MCAIdMap<BiomeBase> getBiomeMapping() {
|
||||
return biomeMapCache.aquire(() -> new MCAIdMap<>() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<BiomeBase> iterator() {
|
||||
@ -420,20 +420,20 @@ public class NMSBinding17_1 implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max) {
|
||||
ChunkBiomeContainer<BiomeBase> base = new ChunkBiomeContainer<>(getBiomeMapping(), min, max);
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max) {
|
||||
MCAChunkBiomeContainer<BiomeBase> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max, int[] data) {
|
||||
ChunkBiomeContainer<BiomeBase> base = new ChunkBiomeContainer<>(getBiomeMapping(), min, max, data);
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max, int[] data) {
|
||||
MCAChunkBiomeContainer<BiomeBase> base = new MCAChunkBiomeContainer<>(getBiomeMapping(), min, max, data);
|
||||
return getBiomeContainerInterface(getBiomeMapping(), base);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private BiomeContainer getBiomeContainerInterface(IdMap<BiomeBase> biomeMapping, ChunkBiomeContainer<BiomeBase> base) {
|
||||
return new BiomeContainer() {
|
||||
private MCABiomeContainer getBiomeContainerInterface(MCAIdMap<BiomeBase> biomeMapping, MCAChunkBiomeContainer<BiomeBase> base) {
|
||||
return new MCABiomeContainer() {
|
||||
@Override
|
||||
public int[] getData() {
|
||||
return base.writeBiomes();
|
||||
|
@ -20,8 +20,8 @@ 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.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
@ -137,14 +137,14 @@ public class NMSBinding1X implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max) {
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max) {
|
||||
Iris.error("Cannot use the custom biome data! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeContainer newBiomeContainer(int min, int max, int[] v) {
|
||||
public MCABiomeContainer newBiomeContainer(int min, int max, int[] v) {
|
||||
Iris.error("Cannot use the custom biome data! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
|
||||
return null;
|
||||
@ -161,7 +161,7 @@ public class NMSBinding1X implements INMSBinding {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaletteAccess createPalette() {
|
||||
public MCAPaletteAccess createPalette() {
|
||||
Iris.error("Cannot use the global data palette! Iris is incapable of using MCA generation on this version of minecraft!");
|
||||
return null;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.nbt.io.NBTDeserializer;
|
||||
import com.volmit.iris.util.nbt.io.NBTSerializer;
|
||||
import com.volmit.iris.util.nbt.io.NamedTag;
|
||||
import com.volmit.iris.util.nbt.mca.palette.BiomeContainer;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCABiomeContainer;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
@ -46,7 +46,7 @@ public class Chunk {
|
||||
private int dataVersion;
|
||||
private long lastUpdate;
|
||||
private long inhabitedTime;
|
||||
private BiomeContainer biomes;
|
||||
private MCABiomeContainer biomes;
|
||||
private CompoundTag heightMaps;
|
||||
private CompoundTag carvingMasks;
|
||||
private ListTag<CompoundTag> entities;
|
||||
|
@ -19,7 +19,7 @@
|
||||
package com.volmit.iris.util.nbt.mca;
|
||||
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.util.nbt.mca.palette.PaletteAccess;
|
||||
import com.volmit.iris.util.nbt.mca.palette.MCAPaletteAccess;
|
||||
import com.volmit.iris.util.nbt.tag.ByteArrayTag;
|
||||
import com.volmit.iris.util.nbt.tag.CompoundTag;
|
||||
import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
@ -27,7 +27,7 @@ import com.volmit.iris.util.nbt.tag.ListTag;
|
||||
|
||||
public class Section {
|
||||
private CompoundTag data;
|
||||
private PaletteAccess palette;
|
||||
private MCAPaletteAccess palette;
|
||||
private byte[] blockLight;
|
||||
private byte[] skyLight;
|
||||
private int dataVersion;
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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 interface MCABiomeContainer {
|
||||
int[] getData();
|
||||
|
||||
void setBiome(int x, int y, int z, int id);
|
||||
|
||||
int getBiome(int x, int y, int z);
|
||||
}
|
@ -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 MCABitStorage {
|
||||
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 MCABitStorage(int bits, int length) {
|
||||
this(bits, length, null);
|
||||
}
|
||||
|
||||
public MCABitStorage(int bits, int length, long[] data) {
|
||||
Validate.inclusiveBetween(1L, 32L, bits);
|
||||
this.size = length;
|
||||
this.bits = bits;
|
||||
this.mask = (1L << bits) - 1L;
|
||||
this.valuesPerLong = (char) (64 / bits);
|
||||
int var3 = 3 * (this.valuesPerLong - 1);
|
||||
this.divideMul = MAGIC[var3 + 0];
|
||||
this.divideAdd = MAGIC[var3 + 1];
|
||||
this.divideShift = MAGIC[var3 + 2];
|
||||
int var4 = (length + this.valuesPerLong - 1) / this.valuesPerLong;
|
||||
if (data != null) {
|
||||
if (data.length != var4)
|
||||
throw new RuntimeException("NO!");
|
||||
this.data = data;
|
||||
} 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 org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class MCAChunkBiomeContainer<T> {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final int WIDTH_BITS = MCAMth.ceillog2(16) - 2;
|
||||
private static final int HORIZONTAL_MASK = (1 << WIDTH_BITS) - 1;
|
||||
private static final int PACKED_X_LENGTH = 1 + MCAMth.log2(MCAMth.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 MCAIdMap<T> biomeRegistry;
|
||||
|
||||
private final T[] biomes;
|
||||
|
||||
private final int quartMinY;
|
||||
|
||||
private final int quartHeight;
|
||||
|
||||
protected MCAChunkBiomeContainer(MCAIdMap<T> registry, int minHeight, int maxHeight, T[] abiomebase) {
|
||||
this.biomeRegistry = registry;
|
||||
this.biomes = abiomebase;
|
||||
this.quartMinY = MCAQuartPos.fromBlock(minHeight);
|
||||
this.quartHeight = MCAQuartPos.fromBlock(maxHeight) - 1;
|
||||
}
|
||||
|
||||
public MCAChunkBiomeContainer(MCAIdMap<T> registry, int min, int max) {
|
||||
this(registry, min, max, new int[(1 << WIDTH_BITS + WIDTH_BITS) * ceilDiv(max - min, 4)]);
|
||||
}
|
||||
|
||||
public MCAChunkBiomeContainer(MCAIdMap<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] = 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 = MCAMth.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 = MCAMth.clamp(j - this.quartMinY, 0, this.quartHeight);
|
||||
int j1 = k & HORIZONTAL_MASK;
|
||||
this.biomes[i1 << WIDTH_BITS + WIDTH_BITS | j1 << WIDTH_BITS | l] = biome;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface MCACountConsumer<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 MCACrudeIncrementalIntIdentityHashBiMap<K> implements MCAIdMap<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 MCACrudeIncrementalIntIdentityHashBiMap(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 (MCAMth.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(Iterators.forArray((Object[]) this.byId), Predicates.notNull());
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Arrays.fill(this.keys, null);
|
||||
Arrays.fill(this.byId, null);
|
||||
this.nextId = 0;
|
||||
this.size = 0;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return this.size;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 MCAGlobalPalette<T> implements MCAPalette<T> {
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
public MCAGlobalPalette(MCAIdMapper<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 = 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 MCAHashMapPalette<T> implements MCAPalette<T> {
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final MCACrudeIncrementalIntIdentityHashBiMap<T> values;
|
||||
|
||||
private final MCAPaletteResize<T> resizeHandler;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
private final Function<T, CompoundTag> writer;
|
||||
|
||||
private final int bits;
|
||||
|
||||
public MCAHashMapPalette(MCAIdMapper<T> var0, int var1, MCAPaletteResize<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 MCACrudeIncrementalIntIdentityHashBiMap(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(this.values.byId(var1)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public T valueFor(int var0) {
|
||||
return 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(this.values.byId(var1)));
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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 interface MCAIdMap<T> extends Iterable<T> {
|
||||
int getId(T paramT);
|
||||
|
||||
T byId(int paramInt);
|
||||
}
|
@ -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.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 MCAIdMapper<T> implements MCAIdMap<T> {
|
||||
public static final int DEFAULT = -1;
|
||||
private final IdentityHashMap<T, Integer> tToId;
|
||||
private final List<T> idToT;
|
||||
private int nextId;
|
||||
|
||||
public MCAIdMapper(IdentityHashMap<T, Integer> tToId, List<T> idToT, int nextId) {
|
||||
this.tToId = tToId;
|
||||
this.idToT = idToT;
|
||||
this.nextId = nextId;
|
||||
}
|
||||
|
||||
public MCAIdMapper() {
|
||||
this(512);
|
||||
}
|
||||
|
||||
public MCAIdMapper(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 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 MCALinearPalette<T> implements MCAPalette<T> {
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final T[] values;
|
||||
|
||||
private final MCAPaletteResize<T> resizeHandler;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
private final int bits;
|
||||
|
||||
private int size;
|
||||
|
||||
public MCALinearPalette(MCAIdMapper<T> var0, int var1, MCAPaletteResize<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();
|
||||
}
|
||||
}
|
712
src/main/java/com/volmit/iris/util/nbt/mca/palette/MCAMth.java
Normal file
712
src/main/java/com/volmit/iris/util/nbt/mca/palette/MCAMth.java
Normal file
@ -0,0 +1,712 @@
|
||||
/*
|
||||
* 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 MCAMth {
|
||||
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 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;
|
||||
private static final float SIN_SCALE = 10430.378F;
|
||||
|
||||
private static final float[] SIN;
|
||||
private static final Random RANDOM = new Random();
|
||||
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;
|
||||
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 {
|
||||
SIN = 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);
|
||||
});
|
||||
}
|
||||
|
||||
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 <T> T make(Supplier<T> var0) {
|
||||
return var0.get();
|
||||
}
|
||||
|
||||
public static <T> T make(T var0, Consumer<T> var1) {
|
||||
var1.accept(var0);
|
||||
return var0;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 interface MCAPalette<T> {
|
||||
int idFor(T paramT);
|
||||
|
||||
boolean maybeHas(Predicate<T> paramPredicate);
|
||||
|
||||
T valueFor(int paramInt);
|
||||
|
||||
int getSize();
|
||||
|
||||
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 MCAPaletteAccess {
|
||||
void setBlock(int x, int y, int z, CompoundTag data);
|
||||
|
||||
CompoundTag getBlock(int x, int y, int z);
|
||||
|
||||
void writeToSection(CompoundTag tag);
|
||||
|
||||
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 MCAPaletteResize<T> {
|
||||
int onResize(int paramInt, T paramT);
|
||||
}
|
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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 MCAPalettedContainer<T> implements MCAPaletteResize<T> {
|
||||
public static final int GLOBAL_PALETTE_BITS = 9;
|
||||
public static final int MIN_PALETTE_SIZE = 4;
|
||||
private static final int SIZE = 4096;
|
||||
private final MCAPalette<T> globalPalette;
|
||||
|
||||
private final MCAPaletteResize<T> dummyPaletteResize = (var0, var1) -> 0;
|
||||
|
||||
private final MCAIdMapper<T> registry;
|
||||
|
||||
private final Function<CompoundTag, T> reader;
|
||||
|
||||
private final Function<T, CompoundTag> writer;
|
||||
|
||||
private final T defaultValue;
|
||||
|
||||
protected MCABitStorage storage;
|
||||
|
||||
private MCAPalette<T> palette;
|
||||
|
||||
private int bits;
|
||||
|
||||
public MCAPalettedContainer(MCAPalette<T> var0, MCAIdMapper<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 MCALinearPalette<>(this.registry, this.bits, this, this.reader);
|
||||
} else if (this.bits < 9) {
|
||||
this.palette = new MCAHashMapPalette<>(this.registry, this.bits, this, this.reader, this.writer);
|
||||
} else {
|
||||
this.palette = this.globalPalette;
|
||||
this.bits = MCAMth.ceillog2(this.registry.size());
|
||||
}
|
||||
this.palette.idFor(this.defaultValue);
|
||||
this.storage = new MCABitStorage(this.bits, 4096);
|
||||
}
|
||||
|
||||
public int onResize(int var0, T var1) {
|
||||
MCABitStorage var2 = this.storage;
|
||||
MCAPalette<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, MCAMth.ceillog2(var0.size()));
|
||||
if (var2 != this.bits)
|
||||
setBits(var2);
|
||||
this.palette.read(var0);
|
||||
int var3 = var1.length * 64 / 4096;
|
||||
if (this.palette == this.globalPalette) {
|
||||
MCAPalette<T> var4 = new MCAHashMapPalette<>(this.registry, var2, this.dummyPaletteResize, this.reader, this.writer);
|
||||
var4.read(var0);
|
||||
MCABitStorage var5 = new MCABitStorage(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 {
|
||||
MCABitStorage var4 = new MCABitStorage(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) {
|
||||
MCAHashMapPalette<T> var3 = new MCAHashMapPalette<>(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, MCAMth.ceillog2(paletteList.size()));
|
||||
MCABitStorage var9 = new MCABitStorage(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(MCACountConsumer<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 MCAQuartPos {
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MCAWrappedPalettedContainer<T> implements MCAPaletteAccess {
|
||||
private final MCAPalettedContainer<T> container;
|
||||
private final Function<T, CompoundTag> reader;
|
||||
private final Function<CompoundTag, T> writer;
|
||||
|
||||
public void setBlock(int x, int y, int z, CompoundTag data) {
|
||||
container.set(x, y, z, writer.apply(data));
|
||||
}
|
||||
|
||||
public CompoundTag getBlock(int x, int y, int z) {
|
||||
return reader.apply(container.get(x, y, z));
|
||||
}
|
||||
|
||||
public void writeToSection(CompoundTag tag) {
|
||||
container.write(tag, "Palette", "BlockStates");
|
||||
}
|
||||
|
||||
public void readFromSection(CompoundTag tag) {
|
||||
container.read(tag.getListTag("Palette"), tag.getLongArrayTag("BlockStates").getValue());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user