Add option to fix wrong block placement rotation in 1.20.5->1.21 (#4166)

This commit is contained in:
EnZaXD 2024-10-06 15:19:05 +02:00 committed by GitHub
parent 9df1704357
commit 9674c617ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 5 deletions

View File

@ -471,4 +471,11 @@ public interface ViaVersionConfig extends Config {
* @return true if enabled
*/
boolean hideScoreboardNumbers();
/**
* Fixes 1.21+ clients on 1.20.5 servers placing water/lava buckets at the wrong location when moving fast.
*
* @return true if enabled
*/
boolean fix1_21PlacementRotation();
}

View File

@ -25,14 +25,14 @@ import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocol.BlockedProtocolVersionsImpl;
import com.viaversion.viaversion.util.Config;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ObjectSet;
import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class AbstractViaConfig extends Config implements ViaVersionConfig {
@ -95,6 +95,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private boolean handleInvalidItemCount;
private boolean cancelBlockSounds;
private boolean hideScoreboardNumbers;
private boolean fix1_21PlacementRotation;
protected AbstractViaConfig(final File configFile, final Logger logger) {
super(configFile, logger);
@ -163,6 +164,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
handleInvalidItemCount = getBoolean("handle-invalid-item-count", false);
cancelBlockSounds = getBoolean("cancel-block-sounds", true);
hideScoreboardNumbers = getBoolean("hide-scoreboard-numbers", false);
fix1_21PlacementRotation = getBoolean("fix-1_21-placement-rotation", false);
}
private BlockedProtocolVersions loadBlockedProtocolVersions() {
@ -549,4 +551,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
public boolean hideScoreboardNumbers() {
return hideScoreboardNumbers;
}
@Override
public boolean fix1_21PlacementRotation() {
return fix1_21PlacementRotation;
}
}

View File

@ -19,12 +19,14 @@ package com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_20_5;
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_21;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
@ -105,8 +107,22 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter<Cl
protocol.registerServerbound(ServerboundPackets1_20_5.USE_ITEM, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Hand
wrapper.passthrough(Types.VAR_INT); // Sequence
wrapper.read(Types.FLOAT); // Y rotation
wrapper.read(Types.FLOAT); // X rotation
final float yaw = wrapper.read(Types.FLOAT); // Y rotation
final float pitch = wrapper.read(Types.FLOAT); // X rotation
if (!Via.getConfig().fix1_21PlacementRotation()) {
return;
}
// Not correct but *enough* for vanilla/normal servers to have block placement synchronized
final PacketWrapper playerRotation = wrapper.create(ServerboundPackets1_20_5.MOVE_PLAYER_ROT);
playerRotation.write(Types.FLOAT, yaw);
playerRotation.write(Types.FLOAT, pitch);
playerRotation.write(Types.BOOLEAN, true); // On Ground
playerRotation.sendToServer(Protocol1_20_5To1_21.class);
wrapper.sendToServer(Protocol1_20_5To1_21.class);
wrapper.cancel();
});
new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_20_5.UPDATE_RECIPES);

View File

@ -167,6 +167,9 @@ handle-invalid-item-count: false
# Hides scoreboard numbers for 1.20.3+ clients on older server versions.
hide-scoreboard-numbers: false
#
# Fixes 1.21+ clients on 1.20.5 servers placing water/lava buckets at the wrong location when moving fast, NOTE: This may cause issues with anti-cheat plugins.
fix-1_21-placement-rotation: false
#
#----------------------------------------------------------#
# 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS #
#----------------------------------------------------------#
@ -211,4 +214,4 @@ chunk-border-fix: false
# Allows 1.9+ left-handedness (main hand) on 1.8 servers
left-handed-handling: true
# Tries to cancel block break/place sounds sent by 1.8 servers to 1.9+ clients to prevent them from playing twice
cancel-block-sounds: true
cancel-block-sounds: true