mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-27 20:46:23 +01:00
Small code cleanup (#4213)
This commit is contained in:
parent
82ff0bae49
commit
3858a83972
@ -22,12 +22,12 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.BlockEntityProvider;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class FlowerPotHandler implements BlockEntityProvider.BlockEntityHandler {
|
||||
// Object -> string (id without namespace) or byte (numeric id)
|
||||
private static final Map<Pair<?, Byte>, Integer> flowers = new ConcurrentHashMap<>();
|
||||
private static final Map<Pair<?, Byte>, Integer> flowers = new HashMap<>();
|
||||
|
||||
static {
|
||||
register("air", (byte) 0, (byte) 0, 5265);
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.viaversion.viaversion.protocols.v1_17_1to1_18.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.ChunkPosition;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@ -30,27 +31,27 @@ public final class ChunkLightStorage implements StorableObject {
|
||||
private final Set<Long> loadedChunks = new HashSet<>();
|
||||
|
||||
public void storeLight(final int x, final int z, final ChunkLight chunkLight) {
|
||||
lightPackets.put(getChunkSectionIndex(x, z), chunkLight);
|
||||
lightPackets.put(ChunkPosition.chunkKey(x, z), chunkLight);
|
||||
}
|
||||
|
||||
public @Nullable ChunkLight removeLight(final int x, final int z) {
|
||||
return lightPackets.remove(getChunkSectionIndex(x, z));
|
||||
return lightPackets.remove(ChunkPosition.chunkKey(x, z));
|
||||
}
|
||||
|
||||
public @Nullable ChunkLight getLight(final int x, final int z) {
|
||||
return lightPackets.get(getChunkSectionIndex(x, z));
|
||||
return lightPackets.get(ChunkPosition.chunkKey(x, z));
|
||||
}
|
||||
|
||||
public boolean addLoadedChunk(final int x, final int z) {
|
||||
return loadedChunks.add(getChunkSectionIndex(x, z));
|
||||
return loadedChunks.add(ChunkPosition.chunkKey(x, z));
|
||||
}
|
||||
|
||||
public boolean isLoaded(final int x, final int z) {
|
||||
return loadedChunks.contains(getChunkSectionIndex(x, z));
|
||||
return loadedChunks.contains(ChunkPosition.chunkKey(x, z));
|
||||
}
|
||||
|
||||
public void clear(final int x, final int z) {
|
||||
final long index = getChunkSectionIndex(x, z);
|
||||
final long index = ChunkPosition.chunkKey(x, z);
|
||||
lightPackets.remove(index);
|
||||
loadedChunks.remove(index);
|
||||
}
|
||||
@ -60,10 +61,6 @@ public final class ChunkLightStorage implements StorableObject {
|
||||
lightPackets.clear();
|
||||
}
|
||||
|
||||
private long getChunkSectionIndex(final int x, final int z) {
|
||||
return ((x & 0x3FFFFFFL) << 38) | (z & 0x3FFFFFFL);
|
||||
}
|
||||
|
||||
public record ChunkLight(boolean trustEdges, long[] skyLightMask, long[] blockLightMask,
|
||||
long[] emptySkyLightMask, long[] emptyBlockLightMask,
|
||||
byte[][] skyLight, byte[][] blockLight) {
|
||||
|
@ -21,8 +21,8 @@ import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.minecraft.ChunkPosition;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
@ -133,7 +133,7 @@ public class WorldPacketRewriter1_9 {
|
||||
ClientWorld1_9 clientWorld = wrapper.user().getClientWorld(Protocol1_8To1_9.class);
|
||||
Chunk chunk = wrapper.read(ChunkType1_8.forEnvironment(clientWorld.getEnvironment()));
|
||||
|
||||
long chunkHash = ClientWorld1_9.toLong(chunk.getX(), chunk.getZ());
|
||||
long chunkHash = ChunkPosition.chunkKey(chunk.getX(), chunk.getZ());
|
||||
|
||||
// Check if the chunk should be handled as an unload packet
|
||||
if (chunk.isFullChunk() && chunk.getBitmask() == 0) {
|
||||
@ -152,7 +152,7 @@ public class WorldPacketRewriter1_9 {
|
||||
for (BlockFace face : BlockFace.HORIZONTAL) {
|
||||
int chunkX = chunk.getX() + face.modX();
|
||||
int chunkZ = chunk.getZ() + face.modZ();
|
||||
if (!clientWorld.getLoadedChunks().contains(ClientWorld1_9.toLong(chunkX, chunkZ))) {
|
||||
if (!clientWorld.getLoadedChunks().contains(ChunkPosition.chunkKey(chunkX, chunkZ))) {
|
||||
PacketWrapper unloadChunk = wrapper.create(ClientboundPackets1_9.FORGET_LEVEL_CHUNK);
|
||||
unloadChunk.write(Types.INT, chunkX);
|
||||
unloadChunk.write(Types.INT, chunkZ);
|
||||
@ -171,7 +171,7 @@ public class WorldPacketRewriter1_9 {
|
||||
for (BlockFace face : BlockFace.HORIZONTAL) {
|
||||
int chunkX = chunk.getX() + face.modX();
|
||||
int chunkZ = chunk.getZ() + face.modZ();
|
||||
if (!clientWorld.getLoadedChunks().contains(ClientWorld1_9.toLong(chunkX, chunkZ))) {
|
||||
if (!clientWorld.getLoadedChunks().contains(ChunkPosition.chunkKey(chunkX, chunkZ))) {
|
||||
PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.LEVEL_CHUNK);
|
||||
Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>());
|
||||
emptyChunk.write(chunkType, c);
|
||||
@ -194,14 +194,14 @@ public class WorldPacketRewriter1_9 {
|
||||
chunkData.write(chunkType, chunk);
|
||||
chunkData.send(Protocol1_8To1_9.class);
|
||||
|
||||
clientWorld.getLoadedChunks().add(ClientWorld1_9.toLong(chunk.getX(), chunk.getZ()));
|
||||
clientWorld.getLoadedChunks().add(ChunkPosition.chunkKey(chunk.getX(), chunk.getZ()));
|
||||
|
||||
// Send empty chunks surrounding the loaded chunk to force 1.9+ clients to render the new chunk
|
||||
if (Via.getConfig().isChunkBorderFix()) {
|
||||
for (BlockFace face : BlockFace.HORIZONTAL) {
|
||||
int chunkX = chunk.getX() + face.modX();
|
||||
int chunkZ = chunk.getZ() + face.modZ();
|
||||
if (!clientWorld.getLoadedChunks().contains(ClientWorld1_9.toLong(chunkX, chunkZ))) {
|
||||
if (!clientWorld.getLoadedChunks().contains(ChunkPosition.chunkKey(chunkX, chunkZ))) {
|
||||
PacketWrapper emptyChunk = wrapper.create(ClientboundPackets1_9.LEVEL_CHUNK);
|
||||
Chunk c = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], new int[256], new ArrayList<>());
|
||||
emptyChunk.write(chunkType, c);
|
||||
|
@ -17,16 +17,13 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.v1_8to1_9.storage;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ClientWorld1_9 extends ClientWorld {
|
||||
private final Set<Long> loadedChunks = Sets.newConcurrentHashSet();
|
||||
|
||||
public static long toLong(int msw, int lsw) {
|
||||
return ((long) msw << 32) + lsw + 2147483648L;
|
||||
}
|
||||
private final Set<Long> loadedChunks = new HashSet<>();
|
||||
|
||||
public Set<Long> getLoadedChunks() {
|
||||
return loadedChunks;
|
||||
|
@ -22,12 +22,12 @@ import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class CommandBlockStorage implements StorableObject {
|
||||
private final Map<Pair<Integer, Integer>, Map<BlockPosition, CompoundTag>> storedCommandBlocks = new ConcurrentHashMap<>();
|
||||
private final Map<Pair<Integer, Integer>, Map<BlockPosition, CompoundTag>> storedCommandBlocks = new HashMap<>();
|
||||
private boolean permissions;
|
||||
|
||||
public void unloadChunk(int x, int z) {
|
||||
@ -39,7 +39,7 @@ public class CommandBlockStorage implements StorableObject {
|
||||
Pair<Integer, Integer> chunkPos = getChunkCoords(position);
|
||||
|
||||
if (!storedCommandBlocks.containsKey(chunkPos)) {
|
||||
storedCommandBlocks.put(chunkPos, new ConcurrentHashMap<>());
|
||||
storedCommandBlocks.put(chunkPos, new HashMap<>());
|
||||
}
|
||||
|
||||
Map<BlockPosition, CompoundTag> blocks = storedCommandBlocks.get(chunkPos);
|
||||
|
Loading…
Reference in New Issue
Block a user