From 088f654159e91be7c0582606e36d463effaf773a Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 4 Feb 2023 19:42:26 +0100 Subject: [PATCH] Remove some deprecated api usage, small cleanup --- .../com/viaversion/viaversion/api/ViaAPI.java | 4 +- .../viaversion/viaversion/api/ViaManager.java | 1 - .../viaversion/api/data/Mappings.java | 2 +- .../api/minecraft/BlockChangeRecord.java | 4 +- .../viaversion/api/minecraft/BlockFace.java | 6 +- .../viaversion/api/minecraft/Position.java | 2 +- .../api/protocol/AbstractProtocol.java | 1 + .../viaversion/api/type/types/Particle.java | 1 - .../types/version/ChunkSectionType1_13.java | 21 +++--- .../types/version/ChunkSectionType1_16.java | 21 +++--- .../types/version/ChunkSectionType1_9.java | 20 +++--- .../protocol1_9to1_8/BlockListener.java | 2 +- .../BukkitInventoryUpdateTask.java | 2 +- .../providers/BungeeVersionProvider.java | 4 +- .../viaversion/dump/DumpTemplate.java | 3 - .../Protocol1_10To1_9_3_4.java | 3 +- .../packets/WorldPackets.java | 13 +++- .../packets/InventoryPackets.java | 4 +- .../packets/WorldPackets.java | 4 +- .../AbstractStempConnectionHandler.java | 3 +- .../blockconnections/ConnectionData.java | 4 +- .../packets/InventoryPackets.java | 3 +- .../packets/WorldPackets.java | 4 +- .../storage/BlockConnectionStorage.java | 71 +++++++++++-------- .../storage/BlockStorage.java | 1 - .../packets/InventoryPackets.java | 9 +-- .../packets/PlayerPackets.java | 5 +- .../packets/EntityPackets.java | 2 +- .../packets/WorldPackets.java | 15 ++-- .../packets/WorldPackets.java | 14 ++-- .../packets/WorldPackets.java | 14 ++-- .../Protocol1_17To1_16_4.java | 2 +- .../packets/EntityPackets.java | 2 +- .../packets/WorldPackets.java | 19 +++-- .../types/Chunk1_18Type.java | 1 - .../Protocol1_19_1To1_19.java | 1 - .../Protocol1_9_1_2To1_9_3_4.java | 2 +- .../Protocol1_9_3To1_9_1_2.java | 2 +- .../types/Chunk1_9_1_2Type.java | 2 +- .../protocol1_9to1_8/Protocol1_9To1_8.java | 25 +++++-- .../packets/EntityPackets.java | 2 +- .../packets/InventoryPackets.java | 2 +- .../packets/WorldPackets.java | 9 +-- .../storage/EntityTracker1_9.java | 2 +- .../viaversion/update/UpdateUtil.java | 2 - .../viaversion/viaversion/util/Config.java | 2 - 46 files changed, 194 insertions(+), 144 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java index 1ad93ef7d..517e617aa 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaAPI.java @@ -136,7 +136,7 @@ public interface ViaAPI { * Returns the supported protocol versions. * This method removes any blocked protocol versions. * - * @return a list of protocol versions + * @return a sorted set of protocol versions * @see #getFullSupportedVersions() for a full list */ SortedSet getSupportedVersions(); @@ -144,7 +144,7 @@ public interface ViaAPI { /** * Returns the supported protocol versions, including blocked protocols. * - * @return a list of protocol versions + * @return a sorted set of protocol versions */ SortedSet getFullSupportedVersions(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java b/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java index 8efdaa20e..f1a663cc1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java +++ b/api/src/main/java/com/viaversion/viaversion/api/ViaManager.java @@ -89,7 +89,6 @@ public interface ViaManager { * * @return true if enabled */ - @Deprecated default boolean isDebug() { return debugHandler().enabled(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java index f3887cc05..9930be7a8 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/Mappings.java @@ -85,7 +85,7 @@ public interface Mappings { int mappedSize(); static Builder builder(final MappingsSupplier supplier) { - return new Builder(supplier); + return new Builder<>(supplier); } @FunctionalInterface diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockChangeRecord.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockChangeRecord.java index 5461aaf62..f23ba688c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockChangeRecord.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockChangeRecord.java @@ -54,10 +54,10 @@ public interface BlockChangeRecord { short getY(int chunkSectionY); /** + * Returns the absolute y coordinate - only works for sub 1.16 protocols. + * * @return absolute y coordinate - * @deprecated 1.16+ stores the relative y coordinate */ - @Deprecated default short getY() { return getY(-1); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java index 17a948d5b..1c81d6378 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockFace.java @@ -22,7 +22,7 @@ */ package com.viaversion.viaversion.api.minecraft; -import java.util.HashMap; +import java.util.EnumMap; import java.util.Map; public enum BlockFace { @@ -33,9 +33,9 @@ public enum BlockFace { TOP((byte) 0, (byte) 1, (byte) 0, EnumAxis.Y), BOTTOM((byte) 0, (byte) -1, (byte) 0, EnumAxis.Y); - public static final BlockFace[] HORIZONTAL = new BlockFace[]{NORTH, SOUTH, EAST, WEST}; + public static final BlockFace[] HORIZONTAL = {NORTH, SOUTH, EAST, WEST}; - private static final Map opposites = new HashMap<>(); + private static final Map opposites = new EnumMap<>(BlockFace.class); static { opposites.put(BlockFace.NORTH, BlockFace.SOUTH); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java index 6a0e874db..3b82c125a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/Position.java @@ -33,7 +33,7 @@ public class Position { this.z = z; } - @Deprecated/*(forRemoval=true)*/ + // @Deprecated/*(forRemoval=true)*/ Just leave this unchecked public Position(int x, short y, int z) { this(x, (int) y, z); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java index 1841375c8..2dfe2743f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/AbstractProtocol.java @@ -314,6 +314,7 @@ public abstract class AbstractProtocol { public ChunkSection read(ByteBuf buffer) throws Exception { // Reaad bits per block int bitsPerBlock = buffer.readUnsignedByte(); - int originalBitsPerBlock = bitsPerBlock; - if (bitsPerBlock > 8) { bitsPerBlock = GLOBAL_PALETTE; } else if (bitsPerBlock < 4) { @@ -52,8 +52,9 @@ public class ChunkSectionType1_13 extends Type { if (bitsPerBlock != GLOBAL_PALETTE) { int paletteLength = Type.VAR_INT.readPrimitive(buffer); chunkSection = new ChunkSectionImpl(true, paletteLength); + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); for (int i = 0; i < paletteLength; i++) { - chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer)); + blockPalette.addId(Type.VAR_INT.readPrimitive(buffer)); } } else { chunkSection = new ChunkSectionImpl(true); @@ -64,8 +65,9 @@ public class ChunkSectionType1_13 extends Type { if (blockData.length > 0) { int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0); if (blockData.length == expectedLength) { + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData, - bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex); + bitsPerBlock == GLOBAL_PALETTE ? blockPalette::setIdAt : blockPalette::setPaletteIndexAt); } } @@ -75,7 +77,8 @@ public class ChunkSectionType1_13 extends Type { @Override public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception { int bitsPerBlock = 4; - while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) { + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); + while (blockPalette.size() > 1 << bitsPerBlock) { bitsPerBlock += 1; } @@ -87,14 +90,14 @@ public class ChunkSectionType1_13 extends Type { // Write palette if (bitsPerBlock != GLOBAL_PALETTE) { - Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize()); - for (int i = 0; i < chunkSection.getPaletteSize(); i++) { - Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteEntry(i)); + Type.VAR_INT.writePrimitive(buffer, blockPalette.size()); + for (int i = 0; i < blockPalette.size(); i++) { + Type.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i)); } } long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE, - bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex); + bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt); Type.LONG_ARRAY_PRIMITIVE.write(buffer, data); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_16.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_16.java index 6d778daf3..c78a6d5ed 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_16.java @@ -24,6 +24,8 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.util.CompactArrayUtil; import io.netty.buffer.ByteBuf; @@ -39,8 +41,6 @@ public class ChunkSectionType1_16 extends Type { public ChunkSection read(ByteBuf buffer) throws Exception { // Reaad bits per block int bitsPerBlock = buffer.readUnsignedByte(); - int originalBitsPerBlock = bitsPerBlock; - if (bitsPerBlock > 8) { bitsPerBlock = GLOBAL_PALETTE; } else if (bitsPerBlock < 4) { @@ -52,8 +52,9 @@ public class ChunkSectionType1_16 extends Type { if (bitsPerBlock != GLOBAL_PALETTE) { int paletteLength = Type.VAR_INT.readPrimitive(buffer); chunkSection = new ChunkSectionImpl(false, paletteLength); + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); for (int i = 0; i < paletteLength; i++) { - chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer)); + blockPalette.addId(Type.VAR_INT.readPrimitive(buffer)); } } else { chunkSection = new ChunkSectionImpl(false); @@ -65,8 +66,9 @@ public class ChunkSectionType1_16 extends Type { char valuesPerLong = (char) (64 / bitsPerBlock); int expectedLength = (ChunkSection.SIZE + valuesPerLong - 1) / valuesPerLong; if (blockData.length == expectedLength) { + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE, blockData, - bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex); + bitsPerBlock == GLOBAL_PALETTE ? blockPalette::setIdAt : blockPalette::setPaletteIndexAt); } } @@ -76,7 +78,8 @@ public class ChunkSectionType1_16 extends Type { @Override public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception { int bitsPerBlock = 4; - while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) { + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); + while (blockPalette.size() > 1 << bitsPerBlock) { bitsPerBlock += 1; } @@ -88,14 +91,14 @@ public class ChunkSectionType1_16 extends Type { // Write palette if (bitsPerBlock != GLOBAL_PALETTE) { - Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize()); - for (int i = 0; i < chunkSection.getPaletteSize(); i++) { - Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteEntry(i)); + Type.VAR_INT.writePrimitive(buffer, blockPalette.size()); + for (int i = 0; i < blockPalette.size(); i++) { + Type.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i)); } } long[] data = CompactArrayUtil.createCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE, - bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex); + bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt); Type.LONG_ARRAY_PRIMITIVE.write(buffer, data); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_9.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_9.java index 72d2718ae..3799bdfcb 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_9.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/ChunkSectionType1_9.java @@ -24,6 +24,8 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSectionImpl; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.util.CompactArrayUtil; import io.netty.buffer.ByteBuf; @@ -39,7 +41,6 @@ public class ChunkSectionType1_9 extends Type { public ChunkSection read(ByteBuf buffer) throws Exception { // Reaad bits per block int bitsPerBlock = buffer.readUnsignedByte(); - int originalBitsPerBlock = bitsPerBlock; if (bitsPerBlock < 4) { bitsPerBlock = 4; } @@ -50,9 +51,10 @@ public class ChunkSectionType1_9 extends Type { // Read palette int paletteLength = Type.VAR_INT.readPrimitive(buffer); ChunkSection chunkSection = bitsPerBlock != GLOBAL_PALETTE ? new ChunkSectionImpl(true, paletteLength) : new ChunkSectionImpl(true); + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); for (int i = 0; i < paletteLength; i++) { if (bitsPerBlock != GLOBAL_PALETTE) { - chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer)); + blockPalette.addId(Type.VAR_INT.readPrimitive(buffer)); } else { Type.VAR_INT.readPrimitive(buffer); } @@ -64,8 +66,7 @@ public class ChunkSectionType1_9 extends Type { int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0); if (blockData.length == expectedLength) { CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData, - bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock - : chunkSection::setPaletteIndex); + bitsPerBlock == GLOBAL_PALETTE ? blockPalette::setIdAt : blockPalette::setPaletteIndexAt); } } @@ -75,7 +76,8 @@ public class ChunkSectionType1_9 extends Type { @Override public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception { int bitsPerBlock = 4; - while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) { + DataPalette blockPalette = chunkSection.palette(PaletteType.BLOCKS); + while (blockPalette.size() > 1 << bitsPerBlock) { bitsPerBlock += 1; } @@ -87,16 +89,16 @@ public class ChunkSectionType1_9 extends Type { // Write palette if (bitsPerBlock != GLOBAL_PALETTE) { - Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize()); - for (int i = 0; i < chunkSection.getPaletteSize(); i++) { - Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteEntry(i)); + Type.VAR_INT.writePrimitive(buffer, blockPalette.size()); + for (int i = 0; i < blockPalette.size(); i++) { + Type.VAR_INT.writePrimitive(buffer, blockPalette.idByIndex(i)); } } else { Type.VAR_INT.writePrimitive(buffer, 0); } long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE, - bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex); + bitsPerBlock == GLOBAL_PALETTE ? blockPalette::idAt : blockPalette::paletteIndexAt); Type.LONG_ARRAY_PRIMITIVE.write(buffer, data); } } diff --git a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/BlockListener.java b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/BlockListener.java index dd420011d..d3392519b 100644 --- a/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/BlockListener.java +++ b/bukkit-legacy/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_9to1_8/BlockListener.java @@ -38,7 +38,7 @@ public class BlockListener extends ViaBukkitListener { if (isOnPipe(e.getPlayer())) { Block b = e.getBlockPlaced(); EntityTracker1_9 tracker = getUserConnection(e.getPlayer()).getEntityTracker(Protocol1_9To1_8.class); - tracker.addBlockInteraction(new Position(b.getX(), (short) b.getY(), b.getZ())); + tracker.addBlockInteraction(new Position(b.getX(), b.getY(), b.getZ())); } } } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java index 2e21c16bd..3b717ddb5 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/tasks/protocol1_12to1_11_1/BukkitInventoryUpdateTask.java @@ -36,7 +36,7 @@ public class BukkitInventoryUpdateTask implements Runnable { public BukkitInventoryUpdateTask(BukkitInventoryQuickMoveProvider provider, UUID uuid) { this.provider = provider; this.uuid = uuid; - this.items = Collections.synchronizedList(new ArrayList()); + this.items = Collections.synchronizedList(new ArrayList<>()); } public void addItem(short windowId, short slotId, short actionId) { diff --git a/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java b/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java index eb99a0208..7748760ce 100644 --- a/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java +++ b/bungee/src/main/java/com/viaversion/viaversion/bungee/providers/BungeeVersionProvider.java @@ -80,9 +80,7 @@ public class BungeeVersionProvider extends BaseVersionProvider { try { list = ReflectionUtil.getStatic(ref, "SUPPORTED_VERSION_IDS", List.class); return list.get(0); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } // Fallback diff --git a/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java b/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java index 29701f7d1..368de4e50 100644 --- a/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java +++ b/common/src/main/java/com/viaversion/viaversion/dump/DumpTemplate.java @@ -18,9 +18,6 @@ package com.viaversion.viaversion.dump; import com.google.gson.JsonObject; -import org.checkerframework.checker.nullness.qual.Nullable; - -import java.util.Collection; import java.util.Map; public class DumpTemplate { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java index 0acce2b28..a69c26583 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_10to1_9_3/Protocol1_10To1_9_3_4.java @@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; @@ -201,7 +202,7 @@ public class Protocol1_10To1_9_3_4 extends AbstractProtocol blockId = new HashSet<>(); - private final Map stemps = new HashMap<>(); + private final Map stemps = new EnumMap<>(BlockFace.class); protected AbstractStempConnectionHandler(String baseStateId) { this.baseStateId = ConnectionData.getId(baseStateId); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index bdbcf8849..0d5044d43 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -218,7 +218,7 @@ public class ConnectionData { blockConnectionData = new Int2ObjectOpenHashMap<>(1146, .99F); JsonObject mappingBlockConnections = MappingDataLoader.loadData("blockConnections.json"); for (Entry entry : mappingBlockConnections.entrySet()) { - int id = keyToId.get(entry.getKey()); + int id = keyToId.getInt(entry.getKey()); BlockData blockData = new BlockData(); for (Entry type : entry.getValue().getAsJsonObject().entrySet()) { String name = type.getKey(); @@ -242,7 +242,7 @@ public class ConnectionData { JsonObject blockData = MappingDataLoader.loadData("blockData.json"); JsonArray occluding = blockData.getAsJsonArray("occluding"); for (JsonElement jsonElement : occluding) { - occludingStates.add(keyToId.get(jsonElement.getAsString()).intValue()); + occludingStates.add(keyToId.getInt(jsonElement.getAsString())); } List initActions = new ArrayList<>(); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java index 3940cd0f3..90b3a39af 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/InventoryPackets.java @@ -35,6 +35,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter; +import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.BlockIdData; @@ -113,7 +114,7 @@ public class InventoryPackets extends ItemRewriter> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId); + chunk.getSections()[y >> 4].palette(PaletteType.BLOCKS).setIdAt(x & 0xF, y & 0xF, z & 0xF, newId); } final Tag idTag = tag.get("id"); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java index 574bc2636..ea21d8f62 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockConnectionStorage.java @@ -19,23 +19,21 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.storage; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.StorableObject; -import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.NibbleArray; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets; -import com.viaversion.viaversion.util.Pair; - import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import org.checkerframework.checker.nullness.qual.Nullable; public class BlockConnectionStorage implements StorableObject { private static final short[] REVERSE_BLOCK_MAPPINGS = new short[8582]; private static Constructor fastUtilLongObjectHashMap; - private final Map> blockStorage = createLongObjectMap(); + private final Map blockStorage = createLongObjectMap(); static { try { @@ -61,10 +59,10 @@ public class BlockConnectionStorage implements StorableObject { blockState = mapping; long pair = getChunkSectionIndex(x, y, z); - Pair map = getChunkSection(pair, (blockState & 0xF) != 0); + SectionData map = getChunkSection(pair, (blockState & 0xF) != 0); int blockIndex = encodeBlockPos(x, y, z); - map.key()[blockIndex] = (byte) (blockState >> 4); - NibbleArray nibbleArray = map.value(); + map.blockIds()[blockIndex] = (byte) (blockState >> 4); + NibbleArray nibbleArray = map.nibbleArray(); if (nibbleArray != null) { nibbleArray.set(blockIndex, blockState); } @@ -72,22 +70,22 @@ public class BlockConnectionStorage implements StorableObject { public int get(int x, int y, int z) { long pair = getChunkSectionIndex(x, y, z); - Pair map = blockStorage.get(pair); + SectionData map = blockStorage.get(pair); if (map == null) return 0; short blockPosition = encodeBlockPos(x, y, z); - NibbleArray nibbleArray = map.value(); + NibbleArray nibbleArray = map.nibbleArray(); return WorldPackets.toNewId( - ((map.key()[blockPosition] & 0xFF) << 4) + ((map.blockIds()[blockPosition] & 0xFF) << 4) | (nibbleArray == null ? 0 : nibbleArray.get(blockPosition)) ); } public void remove(int x, int y, int z) { long pair = getChunkSectionIndex(x, y, z); - Pair map = blockStorage.get(pair); + SectionData map = blockStorage.get(pair); if (map == null) return; int blockIndex = encodeBlockPos(x, y, z); - NibbleArray nibbleArray = map.value(); + NibbleArray nibbleArray = map.nibbleArray(); if (nibbleArray != null) { nibbleArray.set(blockIndex, 0); boolean allZero = true; @@ -97,10 +95,10 @@ public class BlockConnectionStorage implements StorableObject { break; } } - if (allZero) map.setValue(null); + if (allZero) map.setNibbleArray(null); } - map.key()[blockIndex] = 0; - for (short entry : map.key()) { + map.blockIds()[blockIndex] = 0; + for (short entry : map.blockIds()) { if (entry != 0) return; } blockStorage.remove(pair); @@ -111,7 +109,7 @@ public class BlockConnectionStorage implements StorableObject { } public void unloadChunk(int x, int z) { - for (int y = 0; y < 16; y ++) { + for (int y = 0; y < 16; y++) { unloadSection(x, y, z); } } @@ -120,14 +118,14 @@ public class BlockConnectionStorage implements StorableObject { blockStorage.remove(getChunkSectionIndex(x << 4, y << 4, z << 4)); } - private Pair getChunkSection(long index, boolean requireNibbleArray) { - Pair map = blockStorage.get(index); + private SectionData getChunkSection(long index, boolean requireNibbleArray) { + SectionData map = blockStorage.get(index); if (map == null) { - map = new Pair<>(new byte[4096], null); + map = new SectionData(new byte[4096]); blockStorage.put(index, map); } - if (map.value() == null && requireNibbleArray) { - map.setValue(new NibbleArray(4096)); + if (map.nibbleArray() == null && requireNibbleArray) { + map.setNibbleArray(new NibbleArray(4096)); } return map; } @@ -136,18 +134,10 @@ public class BlockConnectionStorage implements StorableObject { return (((x >> 4) & 0x3FFFFFFL) << 38) | (((y >> 4) & 0xFFFL) << 26) | ((z >> 4) & 0x3FFFFFFL); } - private long getChunkSectionIndex(Position position) { - return getChunkSectionIndex(position.x(), position.y(), position.z()); - } - private short encodeBlockPos(int x, int y, int z) { return (short) (((y & 0xF) << 8) | ((x & 0xF) << 4) | (z & 0xF)); } - private short encodeBlockPos(Position pos) { - return encodeBlockPos(pos.x(), pos.y(), pos.z()); - } - private Map createLongObjectMap() { if (fastUtilLongObjectHashMap != null) { try { @@ -158,4 +148,25 @@ public class BlockConnectionStorage implements StorableObject { } return new HashMap<>(); } -} + + private static final class SectionData { + private final byte[] blockIds; + private NibbleArray nibbleArray; + + private SectionData(byte[] blockIds) { + this.blockIds = blockIds; + } + + public byte[] blockIds() { + return blockIds; + } + + public @Nullable NibbleArray nibbleArray() { + return nibbleArray; + } + + public void setNibbleArray(@Nullable NibbleArray nibbleArray) { + this.nibbleArray = nibbleArray; + } + } +} \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java index c88101094..371be0aee 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/storage/BlockStorage.java @@ -24,7 +24,6 @@ import it.unimi.dsi.fastutil.ints.IntSet; import space.vectrix.flare.SyncMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; // TODO Fix memory leak lolz (only a smol one tho) public class BlockStorage implements StorableObject { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java index 53e34a1c6..ee48b9f50 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/packets/InventoryPackets.java @@ -35,6 +35,7 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.data.RecipeRewriter1_13_2; +import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage.EntityTracker1_14; @@ -81,13 +82,13 @@ public class InventoryPackets extends ItemRewriter rewriter) throws Exception { // Meta is no longer included in the spawn packets, but sent separately List metadata = wrapper.read(Types1_14.METADATA_LIST); if (metadata.isEmpty()) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java index bb90ee498..3f91f72b3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/packets/WorldPackets.java @@ -19,6 +19,8 @@ package com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; @@ -72,11 +74,14 @@ public class WorldPackets { for (int s = 0; s < chunk.getSections().length; s++) { ChunkSection section = chunk.getSections()[s]; - if (section == null) continue; - for (int i = 0; i < section.getPaletteSize(); i++) { - int old = section.getPaletteEntry(i); - int newId = protocol.getMappingData().getNewBlockStateId(old); - section.setPaletteEntry(i, newId); + if (section == null) { + continue; + } + + DataPalette palette = section.palette(PaletteType.BLOCKS); + for (int i = 0; i < palette.size(); i++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i)); + palette.setIdByIndex(i, mappedBlockStateId); } } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java index 120744d8d..e70cc3825 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/packets/WorldPackets.java @@ -21,6 +21,8 @@ import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_16_2; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; @@ -53,10 +55,14 @@ public class WorldPackets { for (int s = 0; s < chunk.getSections().length; s++) { ChunkSection section = chunk.getSections()[s]; - if (section == null) continue; - for (int i = 0; i < section.getPaletteSize(); i++) { - int old = section.getPaletteEntry(i); - section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old)); + if (section == null) { + continue; + } + + DataPalette palette = section.palette(PaletteType.BLOCKS); + for (int i = 0; i < palette.size(); i++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i)); + palette.setIdByIndex(i, mappedBlockStateId); } } }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java index 81b8b30a0..a8dbd0711 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/WorldPackets.java @@ -26,6 +26,8 @@ import com.google.gson.JsonElement; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; +import com.viaversion.viaversion.api.minecraft.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.UUIDIntArrayType; @@ -69,10 +71,14 @@ public class WorldPackets { for (int s = 0; s < chunk.getSections().length; s++) { ChunkSection section = chunk.getSections()[s]; - if (section == null) continue; - for (int i = 0; i < section.getPaletteSize(); i++) { - int old = section.getPaletteEntry(i); - section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(old)); + if (section == null) { + continue; + } + + DataPalette palette = section.palette(PaletteType.BLOCKS); + for (int i = 0; i < palette.size(); i++) { + int mappedBlockStateId = protocol.getMappingData().getNewBlockStateId(palette.idByIndex(i)); + palette.setIdByIndex(i, mappedBlockStateId); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java index fee7c3d24..0938915fc 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/Protocol1_17To1_16_4.java @@ -160,7 +160,7 @@ public final class Protocol1_17To1_16_4 extends AbstractProtocol { } } - return new BaseChunk(chunkX, chunkZ, groundUp, false, primaryBitmask, sections, biomeData, new ArrayList()); + return new BaseChunk(chunkX, chunkZ, groundUp, false, primaryBitmask, sections, biomeData, new ArrayList<>()); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java index 159c3ea8d..eb7ed6e7e 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/Protocol1_9To1_8.java @@ -28,15 +28,28 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; -import com.viaversion.viaversion.api.rewriter.EntityRewriter; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9to1_8.metadata.MetadataRewriter1_9To1_8; -import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.*; -import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.*; -import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.*; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.EntityPackets; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.InventoryPackets; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.PlayerPackets; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.SpawnPackets; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.packets.WorldPackets; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.BossBarProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CommandBlockProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.EntityIdProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.HandItemProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlockStorage; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTracker; +import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker; import com.viaversion.viaversion.util.GsonUtil; public class Protocol1_9To1_8 extends AbstractProtocol { @@ -46,7 +59,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol>>(15.9, ImmutableList.of( // Neutralize modifiers + properties.put("generic.attackSpeed", new Pair<>(15.9, ImmutableList.of( // Neutralize modifiers new Triple<>(UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3"), 0.0, (byte) 0), // Tool and weapon modifier new Triple<>(UUID.fromString("AF8B6E3F-3328-4C0A-AA36-5BA2BB9DBEF3"), 0.0, (byte) 2), // Dig speed new Triple<>(UUID.fromString("55FCED67-E92A-486E-9800-B47F202C4386"), 0.0, (byte) 2) // Dig slow down diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/InventoryPackets.java index b313cf209..d8e7327df 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/InventoryPackets.java @@ -34,7 +34,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTra public class InventoryPackets { - public static void register(Protocol protocol) { + public static void register(Protocol1_9To1_8 protocol) { protocol.registerClientbound(ClientboundPackets1_8.WINDOW_PROPERTY, new PacketRemapper() { @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java index b666e08ce..319a6005c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/packets/WorldPackets.java @@ -27,12 +27,12 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.Item; -import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.protocols.protocol1_8.ClientboundPackets1_8; +import com.viaversion.viaversion.protocols.protocol1_8.ServerboundPackets1_8; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.types.Chunk1_9_1_2Type; import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9; @@ -46,13 +46,11 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9; import com.viaversion.viaversion.protocols.protocol1_9to1_8.types.Chunk1_8Type; import com.viaversion.viaversion.protocols.protocol1_9to1_8.types.ChunkBulk1_8Type; -import org.checkerframework.checker.nullness.qual.Nullable; - import java.util.ArrayList; import java.util.Optional; public class WorldPackets { - public static void register(Protocol protocol) { + public static void register(Protocol1_9To1_8 protocol) { protocol.registerClientbound(ClientboundPackets1_8.UPDATE_SIGN, new PacketRemapper() { @Override public void registerMap() { @@ -320,8 +318,7 @@ public class WorldPackets { int hand = wrapper.read(Type.VAR_INT); // Wipe the input buffer wrapper.clearInputBuffer(); - // First set this packet ID to Block placement - wrapper.setId(0x08); + wrapper.setPacketType(ServerboundPackets1_8.PLAYER_BLOCK_PLACEMENT); wrapper.write(Type.POSITION, new Position(-1, (short) -1, -1)); wrapper.write(Type.UNSIGNED_BYTE, (short) 255); // Write item in hand diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java index 2af6af23d..9078bb702 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_9to1_8/storage/EntityTracker1_9.java @@ -152,7 +152,7 @@ public class EntityTracker1_9 extends EntityTrackerBase { } public boolean interactedBlockRecently(int x, int y, int z) { - return blockInteractions.contains(new Position(x, (short) y, z)); + return blockInteractions.contains(new Position(x, y, z)); } public void addBlockInteraction(Position p) { diff --git a/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java b/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java index 2480016a4..a7be76127 100644 --- a/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/update/UpdateUtil.java @@ -111,8 +111,6 @@ public class UpdateUtil { return null; } return statistics.get("name").getAsString(); - } catch (MalformedURLException e) { - return null; } catch (IOException e) { return null; } diff --git a/common/src/main/java/com/viaversion/viaversion/util/Config.java b/common/src/main/java/com/viaversion/viaversion/util/Config.java index 8e1454ef3..784b7e532 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/Config.java +++ b/common/src/main/java/com/viaversion/viaversion/util/Config.java @@ -83,8 +83,6 @@ public abstract class Config implements ConfigurationProvider { if (location.exists()) { try (FileInputStream input = new FileInputStream(location)) { config = (Map) YAML.get().load(input); - } catch (FileNotFoundException e) { - e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }