Skip to content

Commit

Permalink
Merge branch 'master' into fix/backup-new-data
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv authored Nov 17, 2024
2 parents a07fcc3 + 07e2848 commit c7a6d0c
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
private boolean handlePingsAsInvAcknowledgements;
private boolean bedrockAtY0;
private boolean sculkShriekersToCryingObsidian;
private boolean mapDarknessEffect;
private boolean suppressEmulationWarnings;

public ViaBackwardsConfig(File configFile, Logger logger) {
Expand All @@ -57,6 +58,7 @@ private void loadFields() {
handlePingsAsInvAcknowledgements = getBoolean("handle-pings-as-inv-acknowledgements", false);
bedrockAtY0 = getBoolean("bedrock-at-y-0", false);
sculkShriekersToCryingObsidian = getBoolean("sculk-shriekers-to-crying-obsidian", false);
mapDarknessEffect = getBoolean("map-darkness-effect", true);
suppressEmulationWarnings = getBoolean("suppress-emulation-warnings", false);
}

Expand Down Expand Up @@ -100,6 +102,11 @@ public boolean sculkShriekerToCryingObsidian() {
return sculkShriekersToCryingObsidian;
}

@Override
public boolean mapDarknessEffect() {
return mapDarknessEffect;
}

@Override
public boolean suppressEmulationWarnings() {
return suppressEmulationWarnings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public interface ViaBackwardsConfig extends Config {
*/
boolean sculkShriekerToCryingObsidian();

/**
* Maps the darkness effect to blindness for 1.18.2 clients on 1.19+ servers.
*
* @return true if enabled
*/
boolean mapDarknessEffect();

/**
* Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

public interface ViaBackwardsPlatform {

String MINIMUM_VV_VERSION = "5.1.1";
String MINIMUM_VV_VERSION = "5.1.2";

/**
* Initialize ViaBackwards.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ protected PacketHandler getTrackerHandler() {
}

protected PacketHandler getTrackerHandler(EntityType entityType) {
return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(Types.VAR_INT, 0), entityType);
return wrapper -> tracker(wrapper.user()).addEntity(wrapper.get(Types.VAR_INT, 0), entityType);
}

protected PacketHandler getPlayerTrackerHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,18 @@ public void register() {
positionAndLook.send(Protocol1_13To1_12_2.class);
});

if (ViaBackwards.getConfig().isFix1_13FacePlayer()) {
PacketHandler movementRemapper = wrapper -> {
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
wrapper.user().get(PlayerPositionStorage1_13.class).setPosition(x, y, z);
};
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS, movementRemapper); // Player Position
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS_ROT, movementRemapper); // Player Position And Look (serverbound)
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_VEHICLE, movementRemapper); // Vehicle Move (serverbound)
}
PacketHandler movementRemapper = wrapper -> {
if (!ViaBackwards.getConfig().isFix1_13FacePlayer()) {
return;
}
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
wrapper.user().get(PlayerPositionStorage1_13.class).setPosition(x, y, z);
};
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS, movementRemapper); // Player Position
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS_ROT, movementRemapper); // Player Position And Look (serverbound)
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_VEHICLE, movementRemapper); // Vehicle Move (serverbound)
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public void register() {
wrapper.write(Types.STRING, newChannel);

if (newChannel.equals("minecraft:register") || newChannel.equals("minecraft:unregister")) {
String[] channels = new String(wrapper.read(Types.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
String[] channels = new String(wrapper.read(Types.SERVERBOUND_CUSTOM_PAYLOAD_DATA), StandardCharsets.UTF_8).split("\0");
List<String> rewrittenChannels = new ArrayList<>();
for (String s : channels) {
String rewritten = ItemPacketRewriter1_13.getNewPluginChannelId(s);
Expand All @@ -480,7 +480,7 @@ public void register() {
}
}
if (!rewrittenChannels.isEmpty()) {
wrapper.write(Types.REMAINING_BYTES, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
wrapper.write(Types.SERVERBOUND_CUSTOM_PAYLOAD_DATA, Joiner.on('\0').join(rewrittenChannels).getBytes(StandardCharsets.UTF_8));
} else {
wrapper.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,18 @@
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.rewriter.CommandRewriter1_19;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.rewriter.EntityPacketRewriter1_19;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.DimensionRegistryStorage;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.EntityTracker1_19;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.NonceStorage;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.RegistryType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
import com.viaversion.viaversion.api.minecraft.signature.SignableCommandArgumentsProvider;
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
Expand Down Expand Up @@ -364,7 +363,7 @@ public void register() {
@Override
public void init(final UserConnection user) {
user.put(new DimensionRegistryStorage());
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_19.PLAYER));
addEntityTracker(user, new EntityTracker1_19(user));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.NumberTag;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.Protocol1_19To1_18_2;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.DimensionRegistryStorage;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.EntityTracker1_19;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.LastDeathPosition;
import com.viaversion.viabackwards.protocol.v1_19to1_18_2.storage.StoredPainting;
import com.viaversion.viaversion.api.data.ParticleMappings;
Expand Down Expand Up @@ -111,6 +113,50 @@ public void register() {
handler(wrapper -> {
// Remove factor data
wrapper.read(Types.OPTIONAL_NAMED_COMPOUND_TAG);

if (!ViaBackwards.getConfig().mapDarknessEffect()) {
return;
}

final EntityTracker1_19 tracker = tracker(wrapper.user());

final int entityId = wrapper.get(Types.VAR_INT, 0);
final int effectId = wrapper.get(Types.VAR_INT, 1);
if (effectId == 33) { // Newly added darkness, rewrite to blindness
tracker.getAffectedByDarkness().add(entityId);
wrapper.set(Types.VAR_INT, 1, 15);
} else if (effectId == 15) { // Track actual blindness effect for removal later
tracker.getAffectedByBlindness().add(entityId);
}
});
}
});

protocol.registerClientbound(ClientboundPackets1_19.REMOVE_MOB_EFFECT, new PacketHandlers() {
@Override
protected void register() {
map(Types.VAR_INT); // Entity id
map(Types.VAR_INT); // Effect id
handler(wrapper -> {
if (!ViaBackwards.getConfig().mapDarknessEffect()) {
return;
}

final int entityId = wrapper.get(Types.VAR_INT, 0);
final int effectId = wrapper.get(Types.VAR_INT, 1);

final EntityTracker1_19 tracker = tracker(wrapper.user());
if (effectId == 33) { // Remove darkness and the fake blindness effect if the client doesn't have actual blindness
tracker.getAffectedByDarkness().rem(entityId);
if (!tracker.getAffectedByBlindness().contains(entityId)) {
wrapper.set(Types.VAR_INT, 1, 15);
}
} else if (effectId == 15) { // Remove blindness and cancel if the client has darkness (will be removed by darkness removal)
tracker.getAffectedByBlindness().rem(entityId);
if (tracker.getAffectedByDarkness().contains(entityId)) {
wrapper.cancel();
}
}
});
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 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.v1_19to1_18_2.storage;

import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_19;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.libs.fastutil.ints.IntArrayList;
import com.viaversion.viaversion.libs.fastutil.ints.IntList;

public final class EntityTracker1_19 extends EntityTrackerBase {

private final IntList affectedByBlindness = new IntArrayList();
private final IntList affectedByDarkness = new IntArrayList();

public EntityTracker1_19(final UserConnection connection) {
super(connection, EntityTypes1_19.PLAYER);
}

@Override
public void removeEntity(final int id) {
super.removeEntity(id);
this.affectedByBlindness.rem(id);
this.affectedByDarkness.rem(id);
}

public IntList getAffectedByBlindness() {
return affectedByBlindness;
}

public IntList getAffectedByDarkness() {
return affectedByDarkness;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ protected void registerPackets() {
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS);
new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES);

translatableRewriter.registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.Limit;
import com.viaversion.viaversion.util.Unit;

import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.downgradeItemData;
Expand Down Expand Up @@ -101,8 +102,19 @@ public void registerPackets() {
wrapper.write(Types.UNSIGNED_BYTE, (short) -1); // Player inventory
wrapper.write(Types.VAR_INT, wrapper.user().get(InventoryStateIdStorage.class).stateId()); // State id; re-use the last known one
wrapper.write(Types.SHORT, (short) -1); // Cursor
final Item item = wrapper.passthrough(Types1_21_2.ITEM);
handleItemToClient(wrapper.user(), item);
passthroughClientboundItem(wrapper);
});

protocol.registerClientbound(ClientboundPackets1_21_2.OPEN_SCREEN, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Id

final int containerType = wrapper.passthrough(Types.VAR_INT);
if (containerType == 21) {
// Track smithing table to remove new data
wrapper.user().get(InventoryStateIdStorage.class).setSmithingTableOpen(true);
}

protocol.getComponentRewriter().passthroughAndProcess(wrapper);
});

protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, wrapper -> {
Expand All @@ -127,18 +139,31 @@ public void registerPackets() {
wrapper.passthrough(Types.SHORT); // Slot id
passthroughClientboundItem(wrapper);
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, wrapper -> {
updateContainerId(wrapper);

if (wrapper.user().get(InventoryStateIdStorage.class).smithingTableOpen()) {
// Cancel new data for smithing table
wrapper.cancel();
}
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_CLOSE, wrapper -> {
updateContainerId(wrapper);
wrapper.user().get(InventoryStateIdStorage.class).setSmithingTableOpen(false);
});
protocol.registerClientbound(ClientboundPackets1_21_2.SET_HELD_SLOT, ClientboundPackets1_21.SET_CARRIED_ITEM);
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_CLOSE, this::updateContainerId);
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, this::updateContainerId);
protocol.registerClientbound(ClientboundPackets1_21_2.HORSE_SCREEN_OPEN, this::updateContainerId);
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, this::updateContainerIdServerbound);
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, wrapper -> {
updateContainerIdServerbound(wrapper);
wrapper.user().get(InventoryStateIdStorage.class).setSmithingTableOpen(false);
});
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLICK, wrapper -> {
updateContainerIdServerbound(wrapper);
wrapper.passthrough(Types.VAR_INT); // State id
wrapper.passthrough(Types.SHORT); // Slot
wrapper.passthrough(Types.BYTE); // Button
wrapper.passthrough(Types.VAR_INT); // Mode
final int length = wrapper.passthrough(Types.VAR_INT);
final int length = Limit.max(wrapper.passthrough(Types.VAR_INT), 128);
for (int i = 0; i < length; i++) {
wrapper.passthrough(Types.SHORT); // Slot
passthroughServerboundItem(wrapper);
Expand All @@ -162,6 +187,7 @@ public void registerPackets() {
wrapper.write(Types.VAR_INT, 0); // 0 state id
final int slot = wrapper.read(Types.VAR_INT);
wrapper.write(Types.SHORT, (short) slot);
passthroughClientboundItem(wrapper);
});

protocol.registerClientbound(ClientboundPackets1_21_2.EXPLODE, wrapper -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ public void register() {

// New one
if (actions.get(6)) {
actions.clear(6);
wrapper.read(Types.VAR_INT); // List order
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public final class InventoryStateIdStorage implements StorableObject {

private boolean smithingTableOpen;
private int stateId = -1;

public int stateId() {
Expand All @@ -30,4 +31,12 @@ public int stateId() {
public void setStateId(final int stateId) {
this.stateId = stateId;
}

public boolean smithingTableOpen() {
return smithingTableOpen;
}

public void setSmithingTableOpen(final boolean smithingTableOpen) {
this.smithingTableOpen = smithingTableOpen;
}
}
5 changes: 4 additions & 1 deletion common/src/main/resources/assets/viabackwards/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ bedrock-at-y-0: false
# If disabled, the client will see them as end portal frames.
sculk-shriekers-to-crying-obsidian: true
#
# Maps the darkness effect to blindness for 1.18.2 clients on 1.19+ servers.
map-darkness-effect: true
#
# Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
suppress-emulation-warnings: false
suppress-emulation-warnings: false
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ metadata.format.version = "1.1"
[versions]

# ViaVersion
viaver = "5.1.1-SNAPSHOT"
viaver = "5.1.2-SNAPSHOT"

# Common provided
netty = "4.0.20.Final"
Expand All @@ -16,7 +16,7 @@ checkerQual = "3.39.0"
paper = "1.16.5-R0.1-SNAPSHOT"
velocity = "3.1.1"
fabricLoader = "0.11.6"
viaProxy = "3.3.5-SNAPSHOT"
viaProxy = "3.3.5"

[libraries]

Expand Down
Loading

0 comments on commit c7a6d0c

Please sign in to comment.