mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2024-12-22 16:48:25 +01:00
Rename storage classes and move init into ViaFabricPlusProtocol
This commit is contained in:
parent
a6327fb588
commit
73d21aaf2c
@ -63,7 +63,7 @@ public class ClientsideFixes {
|
||||
private static final Map<String, Consumer<RegistryByteBuf>> PENDING_EXECUTION_TASKS = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* This identifier is an internal identifier that is used to identify packets that are sent by ViaFabricPlus
|
||||
* This identifier is an internal identifier used to identify packets that are sent by ViaFabricPlus
|
||||
*/
|
||||
public static final String PACKET_SYNC_IDENTIFIER = UUID.randomUUID() + ":" + UUID.randomUUID();
|
||||
|
||||
|
@ -19,19 +19,14 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.fixes.viaversion;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public class JoinGameDataTracker extends StoredObject {
|
||||
public class BedrockJoinGameTracker implements StorableObject {
|
||||
|
||||
private long seed;
|
||||
private String levelId;
|
||||
private long enchantmentSeed;
|
||||
|
||||
public JoinGameDataTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public long getSeed() {
|
||||
return seed;
|
||||
}
|
@ -19,17 +19,12 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.fixes.viaversion;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public class TeleportTracker extends StoredObject {
|
||||
public class TeleportTracker1_7_6_10 implements StorableObject {
|
||||
|
||||
private Boolean onGround = null;
|
||||
|
||||
public TeleportTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public Boolean getPending() {
|
||||
return onGround;
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.fixes.viaversion;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@ -29,12 +30,14 @@ import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import net.minecraft.network.packet.BrandCustomPayload;
|
||||
import net.minecraft.network.packet.CustomPayload;
|
||||
import net.minecraft.network.packet.s2c.custom.DebugGameTestAddMarkerCustomPayload;
|
||||
import net.minecraft.network.packet.s2c.custom.DebugGameTestClearCustomPayload;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -71,15 +74,18 @@ public class ViaFabricPlusProtocol extends AbstractSimpleProtocol {
|
||||
|
||||
final ProtocolVersion version = wrapper.user().getProtocolInfo().serverProtocolVersion();
|
||||
if (!payloadDiff.containsKey(channel) || version.olderThan(payloadDiff.get(channel).getLeft())) {
|
||||
// Technically it's wrong to just drop all payloads, but ViaVersion doesn't translate them and the server can't detect if
|
||||
// we handled the payload or not, so dropping them is easier than adding a bunch of useless translations for payloads
|
||||
// which doesn't do anything on the client anyway.
|
||||
// Technically, it's wrong to just drop all payloads.
|
||||
// However, ViaVersion doesn't translate them and the server can't detect if
|
||||
// we handled the payload or not,
|
||||
// so dropping them is easier
|
||||
// than adding a bunch of useless translations for payloads
|
||||
// which don't do anything on the client anyway.
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (version.olderThanOrEqualTo(ProtocolVersion.v1_20)) {
|
||||
// Skip remaining bytes after reading the payload and cancel if the payload fails to read
|
||||
// Skip all remaining bytes after reading the payload and cancel if the payload fails to read
|
||||
final PacketReader reader = payloadDiff.get(channel).getRight();
|
||||
try {
|
||||
reader.read(wrapper);
|
||||
@ -91,6 +97,25 @@ public class ViaFabricPlusProtocol extends AbstractSimpleProtocol {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(UserConnection connection) {
|
||||
super.init(connection);
|
||||
|
||||
final ProtocolVersion serverVersion = connection.getChannel().attr(ProtocolTranslator.TARGET_VERSION_ATTRIBUTE_KEY).get();
|
||||
|
||||
// Add storages we need for different fixes here
|
||||
if (serverVersion.equals(BedrockProtocolVersion.bedrockLatest)) {
|
||||
connection.put(new BedrockJoinGameTracker());
|
||||
} else {
|
||||
if (serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_14_4)) {
|
||||
connection.put(new WolfHealthTracker1_14_4());
|
||||
}
|
||||
if (serverVersion.olderThanOrEqualTo(ProtocolVersion.v1_7_6)) {
|
||||
connection.put(new TeleportTracker1_7_6_10());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void registerMapping(final CustomPayload.Id<?> id, final ProtocolVersion version, final PacketReader reader) {
|
||||
payloadDiff.put(id.id().toString(), new Pair<>(version, reader));
|
||||
}
|
||||
|
@ -19,19 +19,14 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.fixes.viaversion;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2FloatOpenHashMap;
|
||||
|
||||
public class WolfHealthTracker extends StoredObject {
|
||||
public class WolfHealthTracker1_14_4 implements StorableObject {
|
||||
|
||||
private final Int2FloatMap healthDataMap = new Int2FloatOpenHashMap();
|
||||
|
||||
public WolfHealthTracker(UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public float getWolfHealth(final int entityId, final float fallback) {
|
||||
return this.healthDataMap.getOrDefault(entityId, fallback);
|
||||
}
|
||||
@ -40,12 +35,4 @@ public class WolfHealthTracker extends StoredObject {
|
||||
this.healthDataMap.put(entityId, wolfHealth);
|
||||
}
|
||||
|
||||
public static WolfHealthTracker get(final UserConnection userConnection) {
|
||||
var tracker = userConnection.get(WolfHealthTracker.class);
|
||||
if (tracker == null) {
|
||||
userConnection.put(tracker = new WolfHealthTracker(userConnection));
|
||||
}
|
||||
return tracker;
|
||||
}
|
||||
|
||||
}
|
@ -21,7 +21,7 @@ package de.florianmichael.viafabricplus.injection.mixin.base.integration;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.JoinGameDataTracker;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.BedrockJoinGameTracker;
|
||||
import de.florianmichael.viafabricplus.injection.ViaFabricPlusMixinPlugin;
|
||||
import de.florianmichael.viafabricplus.injection.access.IChunkTracker;
|
||||
import de.florianmichael.viafabricplus.injection.access.IRakSessionCodec;
|
||||
@ -94,7 +94,7 @@ public abstract class MixinDebugHud {
|
||||
}
|
||||
|
||||
// Bedrock
|
||||
final JoinGameDataTracker joinGameDataTracker = userConnection.get(JoinGameDataTracker.class);
|
||||
final BedrockJoinGameTracker joinGameDataTracker = userConnection.get(BedrockJoinGameTracker.class);
|
||||
if (joinGameDataTracker != null) {
|
||||
final ServerAuthMovementMode movementMode = userConnection.get(GameSessionStorage.class).getMovementMode();
|
||||
information.add("Bedrock Level: " + joinGameDataTracker.getLevelId() + ", Enchantment Seed: " + joinGameDataTracker.getEnchantmentSeed() + ", Movement: " + movementMode.name());
|
||||
|
@ -20,7 +20,7 @@
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.entity;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.WolfHealthTracker;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.WolfHealthTracker1_14_4;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import net.minecraft.component.DataComponentTypes;
|
||||
import net.minecraft.component.type.FoodComponent;
|
||||
@ -102,7 +102,8 @@ public abstract class MixinWolfEntity extends TameableEntity implements Angerabl
|
||||
|
||||
@Unique
|
||||
private float viaFabricPlus$getWolfHealth() {
|
||||
return WolfHealthTracker.get(ProtocolTranslator.getPlayNetworkUserConnection()).getWolfHealth(this.getId(), this.getHealth());
|
||||
return ProtocolTranslator.getPlayNetworkUserConnection().get(WolfHealthTracker1_14_4.class).
|
||||
getWolfHealth(this.getId(), this.getHealth());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,13 +19,12 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.vialegacy;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ClientboundPackets1_8;
|
||||
import com.viaversion.viaversion.protocols.v1_8to1_9.packet.ServerboundPackets1_8;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.TeleportTracker;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.TeleportTracker1_7_6_10;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_7_2_5tor1_7_6_10.packet.ClientboundPackets1_7_2;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_7_2_5tor1_7_6_10.packet.ServerboundPackets1_7_2;
|
||||
import net.raphimc.vialegacy.protocol.release.r1_7_6_10tor1_8.Protocolr1_7_6_10Tor1_8;
|
||||
@ -49,7 +48,7 @@ public abstract class MixinProtocolr1_7_6_10Tor1_8 extends AbstractProtocol<Clie
|
||||
map(Types.FLOAT); // pitch
|
||||
handler(wrapper -> {
|
||||
final boolean onGround = wrapper.read(Types.BOOLEAN); // On Ground
|
||||
final TeleportTracker teleportTracker = wrapper.user().get(TeleportTracker.class);
|
||||
final TeleportTracker1_7_6_10 teleportTracker = wrapper.user().get(TeleportTracker1_7_6_10.class);
|
||||
if (teleportTracker != null) {
|
||||
teleportTracker.setPending(onGround);
|
||||
}
|
||||
@ -69,7 +68,7 @@ public abstract class MixinProtocolr1_7_6_10Tor1_8 extends AbstractProtocol<Clie
|
||||
map(Types.FLOAT); // pitch
|
||||
map(Types.BOOLEAN); // onGround
|
||||
handler(wrapper -> {
|
||||
final TeleportTracker teleportTracker = wrapper.user().get(TeleportTracker.class);
|
||||
final TeleportTracker1_7_6_10 teleportTracker = wrapper.user().get(TeleportTracker1_7_6_10.class);
|
||||
if (teleportTracker != null) {
|
||||
Boolean pendingTeleport = teleportTracker.getPending();
|
||||
if (pendingTeleport != null) {
|
||||
@ -82,9 +81,4 @@ public abstract class MixinProtocolr1_7_6_10Tor1_8 extends AbstractProtocol<Clie
|
||||
}, true);
|
||||
}
|
||||
|
||||
@Inject(method = "init", at = @At("RETURN"))
|
||||
private void initPipeline(UserConnection userConnection, CallbackInfo ci) {
|
||||
userConnection.put(new TeleportTracker(userConnection));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import com.viaversion.viaversion.protocols.v1_14_4to1_15.Protocol1_14_4To1_15;
|
||||
import com.viaversion.viaversion.protocols.v1_14_4to1_15.rewriter.EntityPacketRewriter1_15;
|
||||
import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.rewriter.entitydata.EntityDataFilter;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.WolfHealthTracker;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.WolfHealthTracker1_14_4;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@ -37,11 +37,11 @@ public abstract class MixinEntityPacketRewriter1_15 extends EntityRewriter<Clien
|
||||
}
|
||||
|
||||
@Redirect(method = "registerRewrites", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/rewriter/entitydata/EntityDataFilter$Builder;removeIndex(I)V"))
|
||||
private void trackHealth(EntityDataFilter.Builder instance, int index) {
|
||||
instance.handler((event, meta) -> { // Basically removeIndex, but we need to track the actual health value
|
||||
private void removeAndTrackHealth(EntityDataFilter.Builder instance, int index) {
|
||||
instance.handler((event, meta) -> {
|
||||
final int metaIndex = event.index();
|
||||
if (metaIndex == index) {
|
||||
WolfHealthTracker.get(event.user()).setWolfHealth(event.entityId(), meta.value());
|
||||
event.user().get(WolfHealthTracker1_14_4.class).setWolfHealth(event.entityId(), meta.value());
|
||||
event.cancel();
|
||||
} else if (metaIndex > index) {
|
||||
event.setIndex(metaIndex - 1);
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
|
||||
* Copyright (C) 2023-2024 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 de.florianmichael.viafabricplus.injection.mixin.viabedrock;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.JoinGameDataTracker;
|
||||
import net.raphimc.viabedrock.protocol.BedrockProtocol;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(value = BedrockProtocol.class, remap = false)
|
||||
public abstract class MixinBedrockProtocol {
|
||||
|
||||
@Inject(method = "init", at = @At("RETURN"))
|
||||
private void hookStorages(UserConnection user, CallbackInfo ci) {
|
||||
user.put(new JoinGameDataTracker(user));
|
||||
}
|
||||
|
||||
}
|
@ -21,7 +21,7 @@ package de.florianmichael.viafabricplus.injection.mixin.viabedrock;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.JoinGameDataTracker;
|
||||
import de.florianmichael.viafabricplus.fixes.viaversion.BedrockJoinGameTracker;
|
||||
import net.raphimc.viabedrock.protocol.packet.JoinPackets;
|
||||
import net.raphimc.viabedrock.protocol.types.primitive.LongLEType;
|
||||
import net.raphimc.viabedrock.protocol.types.primitive.StringType;
|
||||
@ -36,21 +36,21 @@ public abstract class MixinJoinPackets {
|
||||
@Redirect(method = "lambda$register$8", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 5))
|
||||
private static Object trackWorldSeed(PacketWrapper instance, Type<LongLEType> tType) {
|
||||
final Object seed = instance.read(tType);
|
||||
instance.user().get(JoinGameDataTracker.class).setSeed((long) seed);
|
||||
instance.user().get(BedrockJoinGameTracker.class).setSeed((long) seed);
|
||||
return seed;
|
||||
}
|
||||
|
||||
@Redirect(method = "lambda$register$8", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 56))
|
||||
private static Object trackLevelId(PacketWrapper instance, Type<StringType> tType) {
|
||||
final Object levelId = instance.read(tType);
|
||||
instance.user().get(JoinGameDataTracker.class).setLevelId((String) levelId);
|
||||
instance.user().get(BedrockJoinGameTracker.class).setLevelId((String) levelId);
|
||||
return levelId;
|
||||
}
|
||||
|
||||
@Redirect(method = "lambda$register$8", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/packet/PacketWrapper;read(Lcom/viaversion/viaversion/api/type/Type;)Ljava/lang/Object;", ordinal = 64))
|
||||
private static Object trackEnchantmentSeed(PacketWrapper instance, Type<VarIntType> tType) {
|
||||
final Object enchantmentSeed = instance.read(tType);
|
||||
instance.user().get(JoinGameDataTracker.class).setEnchantmentSeed((Integer) enchantmentSeed);
|
||||
instance.user().get(BedrockJoinGameTracker.class).setEnchantmentSeed((Integer) enchantmentSeed);
|
||||
return enchantmentSeed;
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,6 @@
|
||||
"fixes.viaversion.MixinWorldPacketRewriter1_16_2",
|
||||
"fixes.viaversion.MixinWorldPacketRewriter1_17",
|
||||
"fixes.viaversion.MixinWorldPacketRewriter1_19",
|
||||
"viabedrock.MixinBedrockProtocol",
|
||||
"viabedrock.MixinJoinPackets",
|
||||
"vialegacy.MixinExtensionProtocolMetadataStorage",
|
||||
"vialegacy.MixinViaLegacyConfig"
|
||||
|
Loading…
Reference in New Issue
Block a user