mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-18 16:17:45 +01:00
parent
29a7b01937
commit
87d05ae487
@ -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.OpenScreenStorage;
|
||||
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;
|
||||
@ -76,7 +77,6 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol<ClientboundPac
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_21.AWARD_STATS);
|
||||
|
||||
translatableRewriter.registerOpenScreen(ClientboundPackets1_21.OPEN_SCREEN);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_ACTION_BAR_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_TITLE_TEXT);
|
||||
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_SUBTITLE_TEXT);
|
||||
@ -187,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 OpenScreenStorage());
|
||||
user.put(new PlayerRotationStorage());
|
||||
}
|
||||
|
||||
@ -224,4 +225,4 @@ public final class Protocol1_21To1_20_5 extends BackwardsProtocol<ClientboundPac
|
||||
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,6 @@
|
||||
package com.viaversion.viabackwards.protocol.v1_21to1_20_5.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.ByteTag;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
|
||||
@ -27,6 +25,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.OpenScreenStorage;
|
||||
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;
|
||||
@ -85,10 +84,25 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe
|
||||
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
|
||||
registerExplosion(ClientboundPackets1_21.EXPLODE, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.OPEN_SCREEN, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Id
|
||||
|
||||
// Tracking the type actually matters now with crafters also using container data above index 3
|
||||
final int menuType = wrapper.passthrough(Types.VAR_INT);
|
||||
wrapper.user().get(OpenScreenStorage.class).setMenuType(menuType);
|
||||
|
||||
protocol.getComponentRewriter().passthroughAndProcess(wrapper);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21.CONTAINER_SET_DATA, wrapper -> {
|
||||
wrapper.passthrough(Types.UNSIGNED_BYTE); // Container id
|
||||
final short property = wrapper.passthrough(Types.SHORT);
|
||||
if (property >= 4 && property <= 6) { // Enchantment hints
|
||||
final OpenScreenStorage openScreenStorage = wrapper.user().get(OpenScreenStorage.class);
|
||||
if (openScreenStorage.menuType() != 13) { // Enchantment table
|
||||
return;
|
||||
}
|
||||
|
||||
final short enchantmentId = wrapper.read(Types.SHORT);
|
||||
final EnchantmentsPaintingsStorage storage = wrapper.user().get(EnchantmentsPaintingsStorage.class);
|
||||
final String key = storage.enchantments().idToKey(enchantmentId);
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 OpenScreenStorage implements StorableObject {
|
||||
|
||||
private int menuType = -1;
|
||||
|
||||
public int menuType() {
|
||||
return menuType;
|
||||
}
|
||||
|
||||
public void setMenuType(final int menuType) {
|
||||
this.menuType = menuType;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user