Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 16:12:43 +01:00
Write player rotation on USE_ITEM in 1.21->1.20.5 (#791)
Dieser Commit ist enthalten in:
Ursprung
e662640377
Commit
8e99dddb91
@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.BlockItemPack
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.ComponentRewriter1_21;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter.EntityPacketRewriter1_21;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.PlayerRotationStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
@ -186,6 +187,7 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol<ClientboundPac
|
||||
public void init(final UserConnection user) {
|
||||
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));
|
||||
user.put(new EnchantmentsPaintingsStorage());
|
||||
user.put(new PlayerRotationStorage());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.api.rewriters.StructuredEnchantmentRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.PlayerRotationStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
@ -111,8 +112,10 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.USE_ITEM, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Hand
|
||||
wrapper.passthrough(Types.VAR_INT); // Sequence
|
||||
wrapper.write(Types.FLOAT, 0f); // Y rotation
|
||||
wrapper.write(Types.FLOAT, 0f); // X rotation
|
||||
|
||||
final PlayerRotationStorage rotation = wrapper.user().get(PlayerRotationStorage.class);
|
||||
wrapper.write(Types.FLOAT, rotation.yaw());
|
||||
wrapper.write(Types.FLOAT, rotation.pitch());
|
||||
});
|
||||
|
||||
new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES);
|
||||
|
@ -22,6 +22,7 @@ import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.EnchantmentsPaintingsStorage;
|
||||
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.storage.PlayerRotationStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.Holder;
|
||||
import com.viaversion.viaversion.api.minecraft.PaintingVariant;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||
@ -29,10 +30,12 @@ import com.viaversion.viaversion.api.minecraft.WolfVariant;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
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.version.Types1_20_5;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.Paintings1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
||||
@ -123,6 +126,23 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
|
||||
final String world = wrapper.passthrough(Types.STRING);
|
||||
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> {
|
||||
wrapper.passthrough(Types.DOUBLE); // X
|
||||
wrapper.passthrough(Types.DOUBLE); // Y
|
||||
wrapper.passthrough(Types.DOUBLE); // Z
|
||||
|
||||
storePlayerRotation(wrapper);
|
||||
});
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, this::storePlayerRotation);
|
||||
}
|
||||
|
||||
private void storePlayerRotation(final PacketWrapper wrapper) {
|
||||
final float yaw = wrapper.passthrough(Types.FLOAT);
|
||||
final float pitch = wrapper.passthrough(Types.FLOAT);
|
||||
|
||||
wrapper.user().get(PlayerRotationStorage.class).setRotation(yaw, pitch);
|
||||
}
|
||||
|
||||
private int[] paintingMappingsForEntries(final RegistryEntry[] entries) {
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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_21to1_20_5.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
|
||||
public final class PlayerRotationStorage implements StorableObject {
|
||||
|
||||
private float yaw, pitch;
|
||||
|
||||
public void setRotation(final float yaw, final float pitch) {
|
||||
this.yaw = yaw;
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
public float yaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return pitch;
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren