From 35c4443996d44dc21036711eb878b17d542f58be Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 7 Sep 2023 16:01:39 +0200 Subject: [PATCH] Remove unused --- .../moulberry/axiom/buffer/BiomeBuffer.java | 56 +------- .../moulberry/axiom/buffer/BlockBuffer.java | 108 +--------------- .../axiom/buffer/Position2ByteMap.java | 121 ------------------ .../axiom/integration/ViaVersionDummy.java | 14 -- 4 files changed, 3 insertions(+), 296 deletions(-) delete mode 100644 src/main/java/com/moulberry/axiom/integration/ViaVersionDummy.java diff --git a/src/main/java/com/moulberry/axiom/buffer/BiomeBuffer.java b/src/main/java/com/moulberry/axiom/buffer/BiomeBuffer.java index bf14541..c68cda4 100644 --- a/src/main/java/com/moulberry/axiom/buffer/BiomeBuffer.java +++ b/src/main/java/com/moulberry/axiom/buffer/BiomeBuffer.java @@ -1,7 +1,5 @@ package com.moulberry.axiom.buffer; -import it.unimi.dsi.fastutil.objects.Object2ByteMap; -import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap; import net.minecraft.core.registries.Registries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; @@ -11,78 +9,28 @@ public class BiomeBuffer { private final Position2ByteMap map; private final ResourceKey[] palette; - private final Object2ByteMap> paletteReverse; - private int paletteSize = 0; - public BiomeBuffer() { - this.map = new Position2ByteMap(); - this.palette = new ResourceKey[255]; - this.paletteReverse = new Object2ByteOpenHashMap<>(); - } - - private BiomeBuffer(Position2ByteMap map, ResourceKey[] palette, Object2ByteMap> paletteReverse) { + private BiomeBuffer(Position2ByteMap map, ResourceKey[] palette) { this.map = map; this.palette = palette; - this.paletteReverse = paletteReverse; - this.paletteSize = this.paletteReverse.size(); - } - - public void save(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeByte(this.paletteSize); - for (int i = 0; i < this.paletteSize; i++) { - friendlyByteBuf.writeResourceKey(this.palette[i]); - } - this.map.save(friendlyByteBuf); } public static BiomeBuffer load(FriendlyByteBuf friendlyByteBuf) { int paletteSize = friendlyByteBuf.readByte(); ResourceKey[] palette = new ResourceKey[255]; - Object2ByteMap> paletteReverse = new Object2ByteOpenHashMap<>(); for (int i = 0; i < paletteSize; i++) { ResourceKey key = friendlyByteBuf.readResourceKey(Registries.BIOME); palette[i] = key; - paletteReverse.put(key, (byte)(i+1)); } Position2ByteMap map = Position2ByteMap.load(friendlyByteBuf); - return new BiomeBuffer(map, palette, paletteReverse); + return new BiomeBuffer(map, palette); } - public void clear() { - this.map.clear(); - } - public void forEachEntry(PositionConsumer> consumer) { this.map.forEachEntry((x, y, z, v) -> { if (v != 0) consumer.accept(x, y, z, this.palette[(v & 0xFF) - 1]); }); } - public ResourceKey get(int quartX, int quartY, int quartZ) { - int index = this.map.get(quartX, quartY, quartZ) & 0xFF; - if (index == 0) return null; - return this.palette[index - 1]; - } - - private int getPaletteIndex(ResourceKey biome) { - int index = this.paletteReverse.getOrDefault(biome, (byte) 0) & 0xFF; - if (index != 0) return index; - - index = this.paletteSize; - if (index >= this.palette.length) { - throw new UnsupportedOperationException("Too many biomes! :("); - } - - this.palette[index] = biome; - this.paletteReverse.put(biome, (byte)(index + 1)); - - this.paletteSize += 1; - return index + 1; - } - - public void set(int quartX, int quartY, int quartZ, ResourceKey biome) { - this.map.put(quartX, quartY, quartZ, (byte) this.getPaletteIndex(biome)); - } - } diff --git a/src/main/java/com/moulberry/axiom/buffer/BlockBuffer.java b/src/main/java/com/moulberry/axiom/buffer/BlockBuffer.java index 6cc39bb..7d948a9 100644 --- a/src/main/java/com/moulberry/axiom/buffer/BlockBuffer.java +++ b/src/main/java/com/moulberry/axiom/buffer/BlockBuffer.java @@ -1,13 +1,11 @@ package com.moulberry.axiom.buffer; import com.moulberry.axiom.AxiomConstants; -import com.moulberry.axiom.AxiomPaper; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectSet; import it.unimi.dsi.fastutil.shorts.Short2ObjectMap; import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap; -import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; @@ -29,30 +27,6 @@ public class BlockBuffer { this.values = new Long2ObjectOpenHashMap<>(); } - public BlockBuffer(Long2ObjectMap> values) { - this.values = values; - } - - public void save(FriendlyByteBuf friendlyByteBuf) { - for (Long2ObjectMap.Entry> entry : this.entrySet()) { - friendlyByteBuf.writeLong(entry.getLongKey()); - entry.getValue().write(friendlyByteBuf); - - Short2ObjectMap blockEntities = this.blockEntities.get(entry.getLongKey()); - if (blockEntities != null) { - friendlyByteBuf.writeVarInt(blockEntities.size()); - for (Short2ObjectMap.Entry entry2 : blockEntities.short2ObjectEntrySet()) { - friendlyByteBuf.writeShort(entry2.getShortKey()); - entry2.getValue().write(friendlyByteBuf); - } - } else { - friendlyByteBuf.writeVarInt(0); - } - } - - friendlyByteBuf.writeLong(AxiomConstants.MIN_POSITION_LONG); - } - public static BlockBuffer load(FriendlyByteBuf friendlyByteBuf) { BlockBuffer buffer = new BlockBuffer(); @@ -78,96 +52,16 @@ public class BlockBuffer { return buffer; } - public void clear() { - this.last = null; - this.lastId = AxiomConstants.MIN_POSITION_LONG; - this.values.clear(); - } - - public void putBlockEntity(int x, int y, int z, CompressedBlockEntity blockEntity) { - long cpos = BlockPos.asLong(x >> 4, y >> 4, z >> 4); - Short2ObjectMap chunkMap = this.blockEntities.computeIfAbsent(cpos, k -> new Short2ObjectOpenHashMap<>()); - - int key = (x & 0xF) | ((y & 0xF) << 4) | ((z & 0xF) << 8); - chunkMap.put((short)key, blockEntity); - } - - @Nullable - public CompressedBlockEntity getBlockEntity(int x, int y, int z) { - long cpos = BlockPos.asLong(x >> 4, y >> 4, z >> 4); - Short2ObjectMap chunkMap = this.blockEntities.get(cpos); - - if (chunkMap == null) return null; - - int key = (x & 0xF) | ((y & 0xF) << 4) | ((z & 0xF) << 8); - return chunkMap.get((short)key); - } - @Nullable public Short2ObjectMap getBlockEntityChunkMap(long cpos) { return this.blockEntities.get(cpos); } - public BlockState get(int x, int y, int z) { - var container = this.getSectionForCoord(x, y, z); - if (container == null) { - return null; - } - - var state = container.get(x & 0xF, y & 0xF, z & 0xF); - if (state == EMPTY_STATE) { - return null; - } else { - return state; - } - } - - public void set(int x, int y, int z, BlockState state) { - var container = this.getOrCreateSectionForCoord(x, y, z); - var old = container.getAndSet(x & 0xF, y & 0xF, z & 0xF, state); - } - - public void set(int cx, int cy, int cz, int lx, int ly, int lz, BlockState state) { - var container = this.getOrCreateSection(BlockPos.asLong(cx, cy, cz)); - var old = container.getAndSet(lx, ly, lz, state); - } - - public BlockState remove(int x, int y, int z) { - var container = this.getSectionForCoord(x, y, z); - if (container == null) { - return null; - } - - var state = container.get(x & 0xF, y & 0xF, z & 0xF); - if (state == EMPTY_STATE) { - return null; - } else { - container.set(x & 0xF, y & 0xF, z & 0xF, EMPTY_STATE); - return state; - } - } - public ObjectSet>> entrySet() { return this.values.long2ObjectEntrySet(); } - public PalettedContainer getSectionForCoord(int x, int y, int z) { - long id = BlockPos.asLong(x >> 4, y >> 4, z >> 4); - - if (id != this.lastId) { - this.lastId = id; - this.last = this.values.get(id); - } - - return this.last; - } - - public PalettedContainer getOrCreateSectionForCoord(int x, int y, int z) { - long id = BlockPos.asLong(x >> 4, y >> 4, z >> 4); - return this.getOrCreateSection(id); - } - - public PalettedContainer getOrCreateSection(long id) { + private PalettedContainer getOrCreateSection(long id) { if (this.last == null || id != this.lastId) { this.lastId = id; this.last = this.values.computeIfAbsent(id, k -> new PalettedContainer<>(Block.BLOCK_STATE_REGISTRY, diff --git a/src/main/java/com/moulberry/axiom/buffer/Position2ByteMap.java b/src/main/java/com/moulberry/axiom/buffer/Position2ByteMap.java index b57e307..dfaf5bc 100644 --- a/src/main/java/com/moulberry/axiom/buffer/Position2ByteMap.java +++ b/src/main/java/com/moulberry/axiom/buffer/Position2ByteMap.java @@ -6,9 +6,6 @@ import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.core.BlockPos; import net.minecraft.network.FriendlyByteBuf; -import java.util.Arrays; -import java.util.function.LongFunction; - public class Position2ByteMap { @FunctionalInterface @@ -17,37 +14,10 @@ public class Position2ByteMap { } private final byte defaultValue; - private final LongFunction defaultFunction; private final Long2ObjectMap map = new Long2ObjectOpenHashMap<>(); - private long lastChunkPos = AxiomConstants.MIN_POSITION_LONG; - private byte[] lastChunk = null; - - public Position2ByteMap() { - this((byte) 0); - } - public Position2ByteMap(byte defaultValue) { this.defaultValue = defaultValue; - - if (defaultValue == 0) { - this.defaultFunction = k -> new byte[16*16*16]; - } else { - this.defaultFunction = k -> { - byte[] array = new byte[16*16*16]; - Arrays.fill(array, defaultValue); - return array; - }; - } - } - - public void save(FriendlyByteBuf friendlyByteBuf) { - friendlyByteBuf.writeByte(this.defaultValue); - for (Long2ObjectMap.Entry entry : this.map.long2ObjectEntrySet()) { - friendlyByteBuf.writeLong(entry.getLongKey()); - friendlyByteBuf.writeBytes(entry.getValue()); - } - friendlyByteBuf.writeLong(AxiomConstants.MIN_POSITION_LONG); } public static Position2ByteMap load(FriendlyByteBuf friendlyByteBuf) { @@ -65,69 +35,6 @@ public class Position2ByteMap { return map; } - public void clear() { - this.map.clear(); - this.lastChunkPos = AxiomConstants.MIN_POSITION_LONG; - this.lastChunk = null; - } - - public byte get(int x, int y, int z) { - int xC = x >> 4; - int yC = y >> 4; - int zC = z >> 4; - - byte[] array = this.getChunk(xC, yC, zC); - if (array == null) return this.defaultValue; - - return array[(x&15) + (y&15)*16 + (z&15)*16*16]; - } - - public void put(int x, int y, int z, byte v) { - int xC = x >> 4; - int yC = y >> 4; - int zC = z >> 4; - - byte[] array = this.getOrCreateChunk(xC, yC, zC); - array[(x&15) + (y&15)*16 + (z&15)*16*16] = v; - } - - public byte add(int x, int y, int z, byte v) { - if (v == 0) return this.get(x, y, z); - - int xC = x >> 4; - int yC = y >> 4; - int zC = z >> 4; - - byte[] array = this.getOrCreateChunk(xC, yC, zC); - return array[(x&15) + (y&15)*16 + (z&15)*16*16] += v; - } - - - public byte binaryAnd(int x, int y, int z, byte v) { - int xC = x >> 4; - int yC = y >> 4; - int zC = z >> 4; - - byte[] array = this.getOrCreateChunk(xC, yC, zC); - return array[(x&15) + (y&15)*16 + (z&15)*16*16] &= v; - } - - public boolean min(int x, int y, int z, byte v) { - int xC = x >> 4; - int yC = y >> 4; - int zC = z >> 4; - - byte[] array = this.getOrCreateChunk(xC, yC, zC); - int index = (x&15) + (y&15)*16 + (z&15)*16*16; - - if (v < array[index]) { - array[index] = v; - return true; - } else { - return false; - } - } - public void forEachEntry(EntryConsumer consumer) { for (Long2ObjectMap.Entry entry : this.map.long2ObjectEntrySet()) { int cx = BlockPos.getX(entry.getLongKey()) * 16; @@ -148,32 +55,4 @@ public class Position2ByteMap { } } - public byte[] getChunk(int xC, int yC, int zC) { - return this.getChunk(BlockPos.asLong(xC, yC, zC)); - } - - public byte[] getChunk(long pos) { - if (this.lastChunkPos != pos) { - byte[] chunk = this.map.get(pos); - this.lastChunkPos = pos; - this.lastChunk = chunk; - } - - return this.lastChunk; - } - - public byte[] getOrCreateChunk(int xC, int yC, int zC) { - return this.getOrCreateChunk(BlockPos.asLong(xC, yC, zC)); - } - - public byte[] getOrCreateChunk(long pos) { - if (this.lastChunk == null || this.lastChunkPos != pos) { - byte[] chunk = this.map.computeIfAbsent(pos, this.defaultFunction); - this.lastChunkPos = pos; - this.lastChunk = chunk; - } - - return this.lastChunk; - } - } diff --git a/src/main/java/com/moulberry/axiom/integration/ViaVersionDummy.java b/src/main/java/com/moulberry/axiom/integration/ViaVersionDummy.java deleted file mode 100644 index cd8c822..0000000 --- a/src/main/java/com/moulberry/axiom/integration/ViaVersionDummy.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.moulberry.axiom.integration; - -import org.bukkit.entity.Player; - -import java.util.function.IntFunction; - -public class ViaVersionDummy implements VersionTranslator { - - @Override - public IntFunction blockStateMapper(Player player) { - return id -> id; - } - -}