Remove unused
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-09-07 16:01:39 +02:00
Ursprung b8fa0aa640
Commit 35c4443996
4 geänderte Dateien mit 3 neuen und 296 gelöschten Zeilen

Datei anzeigen

@ -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<Biome>[] palette;
private final Object2ByteMap<ResourceKey<Biome>> 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<Biome>[] palette, Object2ByteMap<ResourceKey<Biome>> paletteReverse) {
private BiomeBuffer(Position2ByteMap map, ResourceKey<Biome>[] 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<Biome>[] palette = new ResourceKey[255];
Object2ByteMap<ResourceKey<Biome>> paletteReverse = new Object2ByteOpenHashMap<>();
for (int i = 0; i < paletteSize; i++) {
ResourceKey<Biome> 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<ResourceKey<Biome>> consumer) {
this.map.forEachEntry((x, y, z, v) -> {
if (v != 0) consumer.accept(x, y, z, this.palette[(v & 0xFF) - 1]);
});
}
public ResourceKey<Biome> 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> 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> biome) {
this.map.put(quartX, quartY, quartZ, (byte) this.getPaletteIndex(biome));
}
}

Datei anzeigen

@ -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<PalettedContainer<BlockState>> values) {
this.values = values;
}
public void save(FriendlyByteBuf friendlyByteBuf) {
for (Long2ObjectMap.Entry<PalettedContainer<BlockState>> entry : this.entrySet()) {
friendlyByteBuf.writeLong(entry.getLongKey());
entry.getValue().write(friendlyByteBuf);
Short2ObjectMap<CompressedBlockEntity> blockEntities = this.blockEntities.get(entry.getLongKey());
if (blockEntities != null) {
friendlyByteBuf.writeVarInt(blockEntities.size());
for (Short2ObjectMap.Entry<CompressedBlockEntity> 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<CompressedBlockEntity> 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<CompressedBlockEntity> 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<CompressedBlockEntity> 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<Long2ObjectMap.Entry<PalettedContainer<BlockState>>> entrySet() {
return this.values.long2ObjectEntrySet();
}
public PalettedContainer<BlockState> 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<BlockState> getOrCreateSectionForCoord(int x, int y, int z) {
long id = BlockPos.asLong(x >> 4, y >> 4, z >> 4);
return this.getOrCreateSection(id);
}
public PalettedContainer<BlockState> getOrCreateSection(long id) {
private PalettedContainer<BlockState> 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,

Datei anzeigen

@ -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<byte[]> defaultFunction;
private final Long2ObjectMap<byte[]> 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<byte[]> 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<byte[]> 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;
}
}

Datei anzeigen

@ -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<Integer> blockStateMapper(Player player) {
return id -> id;
}
}