Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c75e5bd6a7 | ||
|
|
30a3a4fb89 | ||
|
|
9fe9cd3a8a | ||
|
|
12926980e2 | ||
|
|
31787b5e5b | ||
|
|
eda8abf55c | ||
|
|
2b955894d3 | ||
|
|
539c4e696a | ||
|
|
aa35ace816 | ||
|
|
8ea7686b2c |
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ plugins {
|
||||
|
||||
allprojects {
|
||||
group = "com.viaversion"
|
||||
version = "4.2.0"
|
||||
version = "4.2.1"
|
||||
description = "Allow older clients to join newer server versions."
|
||||
}
|
||||
|
||||
|
||||
+42
-1
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
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.protocol.Protocol;
|
||||
@@ -58,6 +60,45 @@ public class WorldPackets1_13_1 {
|
||||
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
|
||||
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
|
||||
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
|
||||
blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001);
|
||||
protocol.registerClientbound(ClientboundPackets1_13.EFFECT, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // Effect Id
|
||||
map(Type.POSITION); // Location
|
||||
map(Type.INT); // Data
|
||||
handler(wrapper -> {
|
||||
int id = wrapper.get(Type.INT, 0);
|
||||
int data = wrapper.get(Type.INT, 1);
|
||||
if (id == 1010) { // Play record
|
||||
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(data));
|
||||
} else if (id == 2001) { // Block break + block break sound
|
||||
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (id == 2000) { // Smoke
|
||||
switch (data) {
|
||||
case 0: // Down
|
||||
case 1: // Up
|
||||
Position pos = wrapper.get(Type.POSITION, 0);
|
||||
BlockFace relative = data == 0 ? BlockFace.BOTTOM : BlockFace.TOP;
|
||||
wrapper.set(Type.POSITION, 0, pos.getRelative(relative)); // Y Offset
|
||||
wrapper.set(Type.INT, 1, 4); // Self
|
||||
break;
|
||||
case 2: // North
|
||||
wrapper.set(Type.INT, 1, 1); // North
|
||||
break;
|
||||
case 3: // South
|
||||
wrapper.set(Type.INT, 1, 7); // South
|
||||
break;
|
||||
case 4: // West
|
||||
wrapper.set(Type.INT, 1, 3); // West
|
||||
break;
|
||||
case 5: // East
|
||||
wrapper.set(Type.INT, 1, 5); // East
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
+25
-9
@@ -17,16 +17,19 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.packets;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage.BiomeStorage;
|
||||
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.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.UUIDIntArrayType;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
@@ -170,15 +173,28 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
}
|
||||
|
||||
if (chunk.isBiomeData()) {
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int biome = chunk.getBiomeData()[i];
|
||||
switch (biome) {
|
||||
case 170: // new nether biomes
|
||||
case 171:
|
||||
case 172:
|
||||
case 173:
|
||||
chunk.getBiomeData()[i] = 8;
|
||||
break;
|
||||
if (wrapper.user().getProtocolInfo().getServerProtocolVersion() >= ProtocolVersion.v1_16_2.getVersion()) {
|
||||
BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class);
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int biome = chunk.getBiomeData()[i];
|
||||
int legacyBiome = biomeStorage.legacyBiome(biome);
|
||||
if (legacyBiome == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Biome sent that does not exist in the biome registry: " + biome);
|
||||
legacyBiome = 1;
|
||||
}
|
||||
chunk.getBiomeData()[i] = legacyBiome;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 1024; i++) {
|
||||
int biome = chunk.getBiomeData()[i];
|
||||
switch (biome) {
|
||||
case 170: // new nether biomes
|
||||
case 171:
|
||||
case 172:
|
||||
case 173:
|
||||
chunk.getBiomeData()[i] = 8;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -24,6 +24,7 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data.CommandRewriter1_16_2;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.BlockItemPackets1_16_2;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets.EntityPackets1_16_2;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage.BiomeStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
|
||||
@@ -136,6 +137,7 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
user.put(new BiomeStorage());
|
||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, Entity1_16_2Types.PLAYER));
|
||||
}
|
||||
|
||||
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data;
|
||||
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.data.VBMappingDataLoader;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.objects.Object2IntOpenHashMap;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class BiomeMappings {
|
||||
|
||||
private static final Object2IntMap<String> MODERN_TO_LEGACY_ID = new Object2IntOpenHashMap<>();
|
||||
private static final Object2IntMap<String> LEGACY_BIOMES = new Object2IntOpenHashMap<>();
|
||||
|
||||
static {
|
||||
LEGACY_BIOMES.defaultReturnValue(-1);
|
||||
MODERN_TO_LEGACY_ID.defaultReturnValue(-1);
|
||||
|
||||
add(0, "ocean");
|
||||
add(1, "plains");
|
||||
add(2, "desert");
|
||||
add(3, "mountains");
|
||||
add(4, "forest");
|
||||
add(5, "taiga");
|
||||
add(6, "swamp");
|
||||
add(7, "river");
|
||||
add(8, "nether");
|
||||
add(9, "the_end");
|
||||
add(10, "frozen_ocean");
|
||||
add(11, "frozen_river");
|
||||
add(12, "snowy_tundra");
|
||||
add(13, "snowy_mountains");
|
||||
add(14, "mushroom_fields");
|
||||
add(15, "mushroom_field_shore");
|
||||
add(16, "beach");
|
||||
add(17, "desert_hills");
|
||||
add(18, "wooded_hills");
|
||||
add(19, "taiga_hills");
|
||||
add(20, "mountain_edge");
|
||||
add(21, "jungle");
|
||||
add(22, "jungle_hills");
|
||||
add(23, "jungle_edge");
|
||||
add(24, "deep_ocean");
|
||||
add(25, "stone_shore");
|
||||
add(26, "snowy_beach");
|
||||
add(27, "birch_forest");
|
||||
add(28, "birch_forest_hills");
|
||||
add(29, "dark_forest");
|
||||
add(30, "snowy_taiga");
|
||||
add(31, "snowy_taiga_hills");
|
||||
add(32, "giant_tree_taiga");
|
||||
add(33, "giant_tree_taiga_hills");
|
||||
add(34, "wooded_mountains");
|
||||
add(35, "savanna");
|
||||
add(36, "savanna_plateau");
|
||||
add(37, "badlands");
|
||||
add(38, "wooded_badlands_plateau");
|
||||
add(39, "badlands_plateau");
|
||||
add(40, "small_end_islands");
|
||||
add(41, "end_midlands");
|
||||
add(42, "end_highlands");
|
||||
add(43, "end_barrens");
|
||||
add(44, "warm_ocean");
|
||||
add(45, "lukewarm_ocean");
|
||||
add(46, "cold_ocean");
|
||||
add(47, "deep_warm_ocean");
|
||||
add(48, "deep_lukewarm_ocean");
|
||||
add(49, "deep_cold_ocean");
|
||||
add(50, "deep_frozen_ocean");
|
||||
add(127, "the_void");
|
||||
add(129, "sunflower_plains");
|
||||
add(130, "desert_lakes");
|
||||
add(131, "gravelly_mountains");
|
||||
add(132, "flower_forest");
|
||||
add(133, "taiga_mountains");
|
||||
add(134, "swamp_hills");
|
||||
add(140, "ice_spikes");
|
||||
add(149, "modified_jungle");
|
||||
add(151, "modified_jungle_edge");
|
||||
add(155, "tall_birch_forest");
|
||||
add(156, "tall_birch_hills");
|
||||
add(157, "dark_forest_hills");
|
||||
add(158, "snowy_taiga_mountains");
|
||||
add(160, "giant_spruce_taiga");
|
||||
add(161, "giant_spruce_taiga_hills");
|
||||
add(162, "modified_gravelly_mountains");
|
||||
add(163, "shattered_savanna");
|
||||
add(164, "shattered_savanna_plateau");
|
||||
add(165, "eroded_badlands");
|
||||
add(166, "modified_wooded_badlands_plateau");
|
||||
add(167, "modified_badlands_plateau");
|
||||
add(168, "bamboo_jungle");
|
||||
add(169, "bamboo_jungle_hills");
|
||||
|
||||
// Include the legacy biomes themselves
|
||||
for (final Object2IntMap.Entry<String> entry : LEGACY_BIOMES.object2IntEntrySet()) {
|
||||
MODERN_TO_LEGACY_ID.put("minecraft:" + entry.getKey(), entry.getIntValue());
|
||||
}
|
||||
|
||||
final JsonObject mappings = VBMappingDataLoader.loadFromDataDir("biome-mappings.json");
|
||||
for (final Map.Entry<String, JsonElement> entry : mappings.entrySet()) {
|
||||
final int legacyBiome = LEGACY_BIOMES.getInt(entry.getValue().getAsString());
|
||||
if (legacyBiome == -1) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Unknown legacy biome: " + entry.getValue().getAsString());
|
||||
continue;
|
||||
}
|
||||
|
||||
MODERN_TO_LEGACY_ID.put(entry.getKey(), legacyBiome);
|
||||
}
|
||||
}
|
||||
|
||||
private static void add(final int id, final String biome) {
|
||||
LEGACY_BIOMES.put(biome, id);
|
||||
}
|
||||
|
||||
public static int toLegacyBiome(String biome) {
|
||||
if (biome.indexOf(':') == -1) {
|
||||
biome = "minecraft:" + biome;
|
||||
}
|
||||
final int legacyBiome = MODERN_TO_LEGACY_ID.getInt(biome);
|
||||
if (legacyBiome == -1) {
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
ViaBackwards.getPlatform().getLogger().warning("Biome with id " + biome + " has no legacy biome mapping (custom datapack?)");
|
||||
}
|
||||
return 1; // Plains
|
||||
}
|
||||
return legacyBiome;
|
||||
}
|
||||
}
|
||||
+27
-2
@@ -18,16 +18,22 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.packets;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.viaversion.viabackwards.ViaBackwards;
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage.BiomeStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.EntityPackets;
|
||||
|
||||
@@ -36,6 +42,7 @@ import java.util.Set;
|
||||
public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2> {
|
||||
|
||||
private final Set<String> oldDimensions = Sets.newHashSet("minecraft:overworld", "minecraft:the_nether", "minecraft:the_end");
|
||||
private boolean warned;
|
||||
|
||||
public EntityPackets1_16_2(Protocol1_16_1To1_16_2 protocol) {
|
||||
super(protocol);
|
||||
@@ -66,8 +73,25 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
|
||||
map(Type.BYTE); // Previous Gamemode
|
||||
map(Type.STRING_ARRAY); // World List
|
||||
handler(wrapper -> {
|
||||
CompoundTag registry = wrapper.read(Type.NBT);
|
||||
if (wrapper.user().getProtocolInfo().getProtocolVersion() <= ProtocolVersion.v1_15_2.getVersion()) {
|
||||
// Store biomes for <1.16 client handling
|
||||
CompoundTag biomeRegistry = registry.get("minecraft:worldgen/biome");
|
||||
ListTag biomes = biomeRegistry.get("value");
|
||||
BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class);
|
||||
biomeStorage.clear();
|
||||
for (Tag biome : biomes) {
|
||||
CompoundTag biomeCompound = (CompoundTag) biome;
|
||||
StringTag name = biomeCompound.get("name");
|
||||
NumberTag id = biomeCompound.get("id");
|
||||
biomeStorage.addBiome(name.getValue(), id.asInt());
|
||||
}
|
||||
} else if (!warned) {
|
||||
warned = true;
|
||||
ViaBackwards.getPlatform().getLogger().warning("1.16 and 1.16.1 clients are only partially supported and may have wrong biomes displayed.");
|
||||
}
|
||||
|
||||
// Just screw the registry and write the defaults for 1.16 and 1.16.1 clients
|
||||
wrapper.read(Type.NBT);
|
||||
wrapper.write(Type.NBT, EntityPackets.DIMENSIONS_TAG);
|
||||
|
||||
CompoundTag dimensionData = wrapper.read(Type.NBT);
|
||||
@@ -98,7 +122,8 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
|
||||
private String getDimensionFromData(CompoundTag dimensionData) {
|
||||
// This may technically break other custom dimension settings for 1.16/1.16.1 clients, so those cases are considered semi "unsupported" here
|
||||
StringTag effectsLocation = dimensionData.get("effects");
|
||||
return effectsLocation != null && oldDimensions.contains(effectsLocation.getValue()) ? effectsLocation.getValue() : "minecraft:overworld";
|
||||
return effectsLocation != null && oldDimensions.contains(effectsLocation.getValue()) ?
|
||||
effectsLocation.getValue() : "minecraft:overworld";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage;
|
||||
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.data.BiomeMappings;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntMap;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.Int2IntOpenHashMap;
|
||||
|
||||
public final class BiomeStorage implements StorableObject {
|
||||
|
||||
private final Int2IntMap modernToLegacyBiomes = new Int2IntOpenHashMap();
|
||||
|
||||
public BiomeStorage() {
|
||||
modernToLegacyBiomes.defaultReturnValue(-1);
|
||||
}
|
||||
|
||||
public void addBiome(final String biome, final int id) {
|
||||
modernToLegacyBiomes.put(id, BiomeMappings.toLegacyBiome(biome));
|
||||
}
|
||||
|
||||
public int legacyBiome(final int biome) {
|
||||
return modernToLegacyBiomes.get(biome);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
modernToLegacyBiomes.clear();
|
||||
}
|
||||
}
|
||||
+2
@@ -25,6 +25,7 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.BlockItemPackets1_17;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.packets.EntityPackets1_17;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PingRequests;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PlayerLastCursorItem;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.api.minecraft.TagData;
|
||||
@@ -249,6 +250,7 @@ public final class Protocol1_16_4To1_17 extends BackwardsProtocol<ClientboundPac
|
||||
public void init(UserConnection user) {
|
||||
addEntityTracker(user, new EntityTrackerBase(user, Entity1_17Types.PLAYER));
|
||||
user.put(new PingRequests());
|
||||
user.put(new PlayerLastCursorItem());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+79
-9
@@ -23,15 +23,18 @@ import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.Protocol1_16_4To1_17;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.data.MapColorRewrites;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PingRequests;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PlayerLastCursorItem;
|
||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.LongArrayTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.NumberTag;
|
||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
|
||||
@@ -63,7 +66,6 @@ public final class BlockItemPackets1_17 extends ItemRewriter<Protocol1_16_4To1_1
|
||||
|
||||
registerSetCooldown(ClientboundPackets1_17.COOLDOWN);
|
||||
registerWindowItems(ClientboundPackets1_17.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
|
||||
registerSetSlot(ClientboundPackets1_17.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerEntityEquipmentArray(ClientboundPackets1_17.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
|
||||
registerTradeList(ClientboundPackets1_17.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
|
||||
registerAdvancements(ClientboundPackets1_17.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
|
||||
@@ -81,24 +83,87 @@ public final class BlockItemPackets1_17 extends ItemRewriter<Protocol1_16_4To1_1
|
||||
}
|
||||
});
|
||||
|
||||
//TODO This will cause desync issues for players under certain circumstances, but mostly works:tm:
|
||||
// TODO Since the carried and modified items are typically set incorrectly, the server sends unnecessary
|
||||
// set slot packets after practically every window click, since it thinks the client and server
|
||||
// inventories are desynchronized. Ideally, we want to store a replica of each container state, and update
|
||||
// it appropriately for both serverbound and clientbound window packets, then fill in the carried
|
||||
// and modified items array as appropriate here. That would be a ton of work and replicated vanilla code,
|
||||
// and the hack below mitigates the worst side effects of this issue, which is an incorrect carried item
|
||||
// sent to the client when a right/left click drag is started. It works, at least for now...
|
||||
protocol.registerServerbound(ServerboundPackets1_16_2.CLICK_WINDOW, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.UNSIGNED_BYTE); // Window Id
|
||||
map(Type.SHORT); // Slot
|
||||
map(Type.BYTE); // Button
|
||||
map(Type.SHORT, Type.NOTHING); // Action id - removed
|
||||
map(Type.VAR_INT); // Mode
|
||||
map(Type.UNSIGNED_BYTE);
|
||||
handler(wrapper -> {
|
||||
short slot = wrapper.passthrough(Type.SHORT); // Slot
|
||||
byte button = wrapper.passthrough(Type.BYTE); // Button
|
||||
wrapper.read(Type.SHORT); // Action id - removed
|
||||
int mode = wrapper.passthrough(Type.VAR_INT); // Mode
|
||||
Item clicked = handleItemToServer(wrapper.read(Type.FLAT_VAR_INT_ITEM)); // Clicked item
|
||||
|
||||
// The 1.17 client would check the entire inventory for changes before -> after a click and send the changed slots here
|
||||
wrapper.write(Type.VAR_INT, 0); // Empty array of slot+item
|
||||
|
||||
// Expected is the carried item after clicking, old clients send the clicked one (*mostly* being the same)
|
||||
handleItemToServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
|
||||
PlayerLastCursorItem state = wrapper.user().get(PlayerLastCursorItem.class);
|
||||
if (mode == 0 && button == 0 && clicked != null) {
|
||||
// Left click PICKUP
|
||||
// Carried item will (usually) be the entire clicked stack
|
||||
state.setLastCursorItem(clicked);
|
||||
} else if (mode == 0 && button == 1 && clicked != null) {
|
||||
// Right click PICKUP
|
||||
// Carried item will (usually) be half of the clicked stack (rounding up)
|
||||
// if the clicked slot is empty, otherwise it will (usually) be the whole clicked stack
|
||||
if (state.isSet()) {
|
||||
state.setLastCursorItem(clicked);
|
||||
} else {
|
||||
state.setLastCursorItem(clicked, (clicked.amount() + 1) / 2);
|
||||
}
|
||||
} else if (mode == 5 && slot == -999 && (button == 0 || button == 4)) {
|
||||
// Start drag (left or right click)
|
||||
// Preserve guessed carried item and forward to server
|
||||
// This mostly fixes the click and drag ghost item issue
|
||||
|
||||
// no-op
|
||||
} else {
|
||||
// Carried item unknown (TODO)
|
||||
state.setLastCursorItem(null);
|
||||
}
|
||||
|
||||
Item carried = state.getLastCursorItem();
|
||||
if (carried == null) {
|
||||
// Expected is the carried item after clicking, old clients send the clicked one (*mostly* being the same)
|
||||
wrapper.write(Type.FLAT_VAR_INT_ITEM, clicked);
|
||||
} else {
|
||||
wrapper.write(Type.FLAT_VAR_INT_ITEM, carried);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_17.SET_SLOT, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
short windowId = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
short slot = wrapper.passthrough(Type.SHORT);
|
||||
|
||||
Item carried = wrapper.read(Type.FLAT_VAR_INT_ITEM);
|
||||
if (carried != null && windowId == -1 && slot == -1) {
|
||||
// This is related to the hack to fix click and drag ghost items above.
|
||||
// After a completed drag, we have no idea how many items remain on the cursor,
|
||||
// and vanilla logic replication would be required to calculate the value.
|
||||
// When the click drag complete packet is sent, we will send an incorrect
|
||||
// carried item, and the server will helpfully send this packet allowing us
|
||||
// to update the internal state. This is necessary for fixing multiple sequential
|
||||
// click drag actions without intermittent pickup actions.
|
||||
wrapper.user().get(PlayerLastCursorItem.class).setLastCursorItem(carried);
|
||||
}
|
||||
|
||||
wrapper.write(Type.FLAT_VAR_INT_ITEM, handleItemToClient(carried));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_16_2.WINDOW_CONFIRMATION, null, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
@@ -305,6 +370,11 @@ public final class BlockItemPackets1_17 extends ItemRewriter<Protocol1_16_4To1_1
|
||||
section.setPaletteEntry(j, protocol.getMappingData().getNewBlockStateId(old));
|
||||
}
|
||||
}
|
||||
|
||||
chunk.getBlockEntities().removeIf(compound -> {
|
||||
NumberTag tag = compound.get("y");
|
||||
return tag != null && (tag.asInt() < 0 || tag.asInt() > 255);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
|
||||
* Copyright (C) 2016-2022 ViaVersion and contributors
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.item.DataItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
|
||||
public class PlayerLastCursorItem implements StorableObject {
|
||||
private Item lastCursorItem;
|
||||
|
||||
public Item getLastCursorItem() {
|
||||
return copyItem(lastCursorItem);
|
||||
}
|
||||
|
||||
public void setLastCursorItem(Item item) {
|
||||
this.lastCursorItem = copyItem(item);
|
||||
}
|
||||
|
||||
public void setLastCursorItem(Item item, int amount) {
|
||||
this.lastCursorItem = copyItem(item);
|
||||
this.lastCursorItem.setAmount(amount);
|
||||
}
|
||||
|
||||
public boolean isSet() {
|
||||
return lastCursorItem != null;
|
||||
}
|
||||
|
||||
private static Item copyItem(Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
Item copy = new DataItem(item);
|
||||
copy.setTag(copy.tag() == null ? null : copy.tag().clone());
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+44
@@ -26,6 +26,7 @@ import com.viaversion.viabackwards.protocol.protocol1_17_1to1_18.packets.EntityP
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types;
|
||||
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.data.entity.EntityTrackerBase;
|
||||
@@ -88,6 +89,49 @@ public final class Protocol1_17_1To1_18 extends BackwardsProtocol<ClientboundPac
|
||||
create(Type.BOOLEAN, true); // Allow listing in server list preview
|
||||
}
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_18.SCOREBOARD_OBJECTIVE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING); // Name
|
||||
handler(cutName(0, 16));
|
||||
}
|
||||
});
|
||||
registerClientbound(ClientboundPackets1_18.DISPLAY_SCOREBOARD, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.BYTE); // Slot
|
||||
map(Type.STRING); // Name
|
||||
handler(cutName(0, 16));
|
||||
}
|
||||
});
|
||||
registerClientbound(ClientboundPackets1_18.TEAMS, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING); // Name
|
||||
handler(cutName(0, 16));
|
||||
}
|
||||
});
|
||||
registerClientbound(ClientboundPackets1_18.UPDATE_SCORE, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING); // Owner
|
||||
map(Type.VAR_INT); // Method
|
||||
map(Type.STRING); // Name
|
||||
handler(cutName(0, 40));
|
||||
handler(cutName(1, 16));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private PacketHandler cutName(final int index, final int maxLength) {
|
||||
// May in some case cause clashes or bad ordering, but nothing we can do about that
|
||||
return wrapper -> {
|
||||
final String s = wrapper.get(Type.STRING, index);
|
||||
if (s.length() > maxLength) {
|
||||
wrapper.set(Type.STRING, index, s.substring(0, maxLength));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+12
-1
@@ -18,6 +18,7 @@
|
||||
package com.viaversion.viabackwards.protocol.protocol1_17to1_17_1;
|
||||
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_16_4to1_17.storage.PlayerLastCursorItem;
|
||||
import com.viaversion.viabackwards.protocol.protocol1_17to1_17_1.storage.InventoryStateIds;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
@@ -91,7 +92,17 @@ public final class Protocol1_17To1_17_1 extends BackwardsProtocol<ClientboundPac
|
||||
wrapper.write(Type.FLAT_VAR_INT_ITEM_ARRAY, wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT));
|
||||
|
||||
// Carried item - should work without adding it to the array above
|
||||
wrapper.read(Type.FLAT_VAR_INT_ITEM);
|
||||
Item carried = wrapper.read(Type.FLAT_VAR_INT_ITEM);
|
||||
|
||||
PlayerLastCursorItem lastCursorItem = wrapper.user().get(PlayerLastCursorItem.class);
|
||||
if (lastCursorItem != null) {
|
||||
// For click drag ghost item fix -- since the state ID is always wrong,
|
||||
// the server always resends the entire window contents after a drag action,
|
||||
// which is useful since we need to update the carried item in preparation
|
||||
// for a subsequent drag
|
||||
|
||||
lastCursorItem.setLastCursorItem(carried);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"minecraft:nether_wastes": "nether",
|
||||
"minecraft:soul_sand_valley": "nether",
|
||||
"minecraft:crimson_forest": "nether",
|
||||
"minecraft:warped_forest": "nether",
|
||||
"minecraft:basalt_deltas": "nether",
|
||||
"minecraft:dripstone_caves": "mountains",
|
||||
"minecraft:lush_caves": "mountains",
|
||||
"minecraft:meadow": "plains",
|
||||
"minecraft:grove": "snowy_mountains",
|
||||
"minecraft:snowy_slopes": "snowy_mountains",
|
||||
"minecraft:frozen_peaks": "snowy_mountains",
|
||||
"minecraft:jagged_peaks": "mountains",
|
||||
"minecraft:stony_peaks": "mountains",
|
||||
"minecraft:windswept_hills": "mountains",
|
||||
"minecraft:snowy_plains": "snowy_tundra",
|
||||
"minecraft:sparse_jungle": "jungle_edge",
|
||||
"minecraft:stony_shore": "stone_shore",
|
||||
"minecraft:old_growth_pine_taiga": "giant_spruce_taiga",
|
||||
"minecraft:windswept_forest": "forest",
|
||||
"minecraft:wooded_badlands": "wooded_badlands_plateau",
|
||||
"minecraft:windswept_gravelly_hills": "gravelly_mountains",
|
||||
"minecraft:old_growth_birch_forest": "tall_birch_forest",
|
||||
"minecraft:old_growth_spruce_taiga": "giant_spruce_taiga",
|
||||
"minecraft:windswept_savanna": "shattered_savanna"
|
||||
}
|
||||
@@ -3,7 +3,7 @@ metadata.format.version = "1.1"
|
||||
[versions]
|
||||
|
||||
# ViaVersion
|
||||
viaver = "4.2.0-1.18.2-pre1-SNAPSHOT"
|
||||
viaver = "4.2.1"
|
||||
|
||||
# Common provided
|
||||
netty = "4.0.20.Final"
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
@@ -1,5 +1,4 @@
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
enableFeaturePreview("VERSION_CATALOGS")
|
||||
|
||||
rootProject.name = "viabackwards-parent"
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SpongePlugin implements ViaBackwardsPlatform {
|
||||
@Listener
|
||||
public void constructPlugin(ConstructPluginEvent event) {
|
||||
// Init!
|
||||
Via.getManager().addEnableListener(() -> this.init(configPath.resolve("config.yml").toFile()));
|
||||
Via.getManager().addEnableListener(() -> this.init(getDataFolder()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,7 +53,7 @@ public class VelocityPlugin implements ViaBackwardsPlatform {
|
||||
public void onProxyStart(ProxyInitializeEvent e) {
|
||||
// Setup Logger
|
||||
this.logger = new LoggerWrapper(loggerSlf4j);
|
||||
Via.getManager().addEnableListener(() -> this.init(configPath.resolve("config.yml").toFile()));
|
||||
Via.getManager().addEnableListener(() -> this.init(getDataFolder()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user