From 22508f6ab7298b3425520ec0c2862f22b4f0fba1 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Thu, 4 Jul 2024 08:58:42 +0200 Subject: [PATCH] Add setting to send bedrock at y 0 Closes #670 --- .../viabackwards/ViaBackwardsConfig.java | 7 +++ .../viabackwards/api/ViaBackwardsConfig.java | 7 +++ .../rewriter/BlockItemPacketRewriter1_17.java | 45 +++++++++++++++---- .../resources/assets/viabackwards/config.yml | 3 ++ 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java b/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java index 09164f90..71aed29f 100644 --- a/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java +++ b/common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java @@ -34,6 +34,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback private boolean alwaysShowOriginalMobName; private boolean fix1_13FormattedInventoryTitles; private boolean handlePingsAsInvAcknowledgements; + private boolean bedrockAtY0; private boolean suppressEmulationWarnings; public ViaBackwardsConfig(File configFile, Logger logger) { @@ -53,6 +54,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback fix1_13FormattedInventoryTitles = getBoolean("fix-formatted-inventory-titles", true); alwaysShowOriginalMobName = getBoolean("always-show-original-mob-name", true); handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false); + bedrockAtY0 = getBoolean("bedrock-at-y-0", false); suppressEmulationWarnings = getBoolean("suppress-emulation-warnings", false); } @@ -86,6 +88,11 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback return handlePingsAsInvAcknowledgements || Boolean.getBoolean("com.viaversion.handlePingsAsInvAcknowledgements"); } + @Override + public boolean bedrockAtY0() { + return bedrockAtY0; + } + @Override public boolean suppressEmulationWarnings() { return suppressEmulationWarnings; diff --git a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java index c06cb555..37554f57 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java @@ -64,6 +64,13 @@ public interface ViaBackwardsConfig extends Config { */ boolean handlePingsAsInvAcknowledgements(); + /** + * Adds bedrock at y=0 for sub 1.17 clients. + * + * @return true if enabled + */ + boolean bedrockAtY0(); + /** * Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+). * diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java index a2d85615..bf75a32c 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/v1_17to1_16_4/rewriter/BlockItemPacketRewriter1_17.java @@ -17,6 +17,10 @@ */ package com.viaversion.viabackwards.protocol.v1_17to1_16_4.rewriter; +import com.viaversion.nbt.tag.CompoundTag; +import com.viaversion.nbt.tag.LongArrayTag; +import com.viaversion.nbt.tag.NumberTag; +import com.viaversion.nbt.tag.Tag; import com.viaversion.viabackwards.ViaBackwards; import com.viaversion.viabackwards.api.rewriters.BackwardsItemRewriter; import com.viaversion.viabackwards.api.rewriters.MapColorRewriter; @@ -28,16 +32,14 @@ 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.chunks.DataPalette; +import com.viaversion.viaversion.api.minecraft.chunks.PaletteType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_16_2; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_17; -import com.viaversion.nbt.tag.CompoundTag; -import com.viaversion.nbt.tag.LongArrayTag; -import com.viaversion.nbt.tag.NumberTag; -import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ClientboundPackets1_16_2; import com.viaversion.viaversion.protocols.v1_16_1to1_16_2.packet.ServerboundPackets1_16_2; import com.viaversion.viaversion.protocols.v1_16_4to1_17.packet.ClientboundPackets1_17; @@ -53,6 +55,8 @@ import java.util.List; public final class BlockItemPacketRewriter1_17 extends BackwardsItemRewriter { + private static final int BEDROCK_BLOCK_STATE = 33; + public BlockItemPacketRewriter1_17(Protocol1_17To1_16_4 protocol) { super(protocol, Types.ITEM1_13_2, Types.ITEM1_13_2_SHORT_ARRAY); } @@ -295,7 +299,11 @@ public final class BlockItemPacketRewriter1_17 extends BackwardsItemRewriter { NumberTag tag = compound.getNumberTag("y"); - return tag != null && (tag.asInt() < 0 || tag.asInt() > 255); + if (tag == null) { + return false; + } + + final int y = tag.asInt(); + return y < 0 || y > 255 || (ViaBackwards.getConfig().bedrockAtY0() && y == 0); }); }); protocol.registerClientbound(ClientboundPackets1_17.BLOCK_ENTITY_DATA, wrapper -> { int y = wrapper.passthrough(Types.BLOCK_POSITION1_14).y(); - if (y < 0 || y > 255) { + if (y < 0 || y > 255 || (ViaBackwards.getConfig().bedrockAtY0() && y == 0)) { wrapper.cancel(); } }); @@ -369,7 +396,7 @@ public final class BlockItemPacketRewriter1_17 extends BackwardsItemRewriter { int y = wrapper.passthrough(Types.BLOCK_POSITION1_14).y(); - if (y < 0 || y > 255) { + if (y < 0 || y > 255 || (ViaBackwards.getConfig().bedrockAtY0() && y == 0)) { wrapper.cancel(); } }); diff --git a/common/src/main/resources/assets/viabackwards/config.yml b/common/src/main/resources/assets/viabackwards/config.yml index ccd3f80e..5d481cf6 100644 --- a/common/src/main/resources/assets/viabackwards/config.yml +++ b/common/src/main/resources/assets/viabackwards/config.yml @@ -21,5 +21,8 @@ fix-formatted-inventory-titles: true # This only takes effect for ids in the short range. Useful for anticheat compatibility. handle-pings-as-inv-acknowledgements: false # +# Adds bedrock blocks at y=0 for sub 1.17 clients. This may allow for weird interactions due to sending fake blocks. +bedrock-at-y-0: false +# # Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+). suppress-emulation-warnings: false \ No newline at end of file