Start working on 24w09a

This commit is contained in:
Nassim Jahnke 2024-02-29 12:26:23 +01:00
parent 8f417b6caa
commit 05b1a6bacd
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
12 changed files with 154 additions and 18 deletions

View File

@ -41,6 +41,10 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
super(protocol, itemType, itemArrayType, true);
}
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType, true);
}
@Override
public @Nullable Item handleItemToClient(@Nullable Item item) {
if (item == null) {

View File

@ -35,12 +35,16 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
protected final String nbtTagName;
protected final boolean jsonNameFormat;
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
super(protocol, itemType, itemArrayType);
this.jsonNameFormat = jsonNameFormat;
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType, boolean jsonFormat) {
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
this.jsonNameFormat = jsonFormat;
nbtTagName = "VB|" + protocol.getClass().getSimpleName();
}
protected ItemRewriterBase(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, boolean jsonNameFormat) {
this(protocol, itemType, itemArrayType, itemType, itemArrayType, jsonNameFormat);
}
@Override
public @Nullable Item handleItemToServer(@Nullable Item item) {
if (item == null) return null;

View File

@ -0,0 +1,79 @@
/*
* 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.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.MappedItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
import com.viaversion.viaversion.api.type.Type;
import org.checkerframework.checker.nullness.qual.Nullable;
public class StructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriter<C, S, T> {
public StructuredItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
super(protocol, itemType, itemArrayType);
}
public StructuredItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType, Type<Item> mappedItemType, Type<Item[]> mappedItemArrayType) {
super(protocol, itemType, itemArrayType, mappedItemType, mappedItemArrayType);
}
@Override
public @Nullable Item handleItemToClient(@Nullable Item item) {
if (item == null) {
return null;
}
// TODO Translatable rewriter on name and lore
MappedItem data = protocol.getMappingData() != null ? protocol.getMappingData().getMappedItem(item.identifier()) : null;
if (data == null) {
// Just rewrite the id
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
item.setIdentifier(protocol.getMappingData().getNewItemId(item.identifier()));
}
}
// TODO Save original id, set remapped id
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
item.setIdentifier(protocol.getMappingData().getNewItemId(item.identifier()));
}
// TODO custom model data and custom name
return item;
}
@Override
public @Nullable Item handleItemToServer(@Nullable Item item) {
if (item == null) return null;
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
item.setIdentifier(protocol.getMappingData().getOldItemId(item.identifier()));
}
// TODO restore original id and display
return item;
}
@Override
protected void restoreDisplayTag(final Item item) {
// TODO
}
}

View File

@ -61,7 +61,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM1_8); // 2 - Slot Value
handler(itemToClientHandler(Type.ITEM1_8));
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0)));
// Handle Llama
handler(wrapper -> {
@ -147,7 +147,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
map(Type.VAR_INT); // 4 - Mode
map(Type.ITEM1_8); // 5 - Clicked Item
handler(itemToServerHandler(Type.ITEM1_8));
handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_8, 0)));
// Llama slot
handler(wrapper -> {

View File

@ -267,7 +267,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.SHORT);
map(Type.ITEM1_13, Type.ITEM1_8);
handler(itemToClientHandler(Type.ITEM1_8));
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0)));
}
});
@ -437,7 +437,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.VAR_INT);
map(Type.ITEM1_13, Type.ITEM1_8);
handler(itemToClientHandler(Type.ITEM1_8));
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0)));
}
});
@ -465,7 +465,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.SHORT);
map(Type.ITEM1_8, Type.ITEM1_13);
handler(itemToServerHandler(Type.ITEM1_13));
handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0)));
}
});
@ -479,7 +479,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.VAR_INT);
map(Type.ITEM1_8, Type.ITEM1_13);
handler(itemToServerHandler(Type.ITEM1_13));
handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0)));
}
});
}

View File

@ -228,7 +228,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
map(Type.VAR_INT); // 1 - Slot ID
map(Type.ITEM1_13_2); // 2 - Item
handler(itemToClientHandler(Type.ITEM1_13_2));
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_13_2, 0)));
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);

View File

@ -57,6 +57,8 @@ import com.viaversion.viaversion.util.ComponentUtil;
import java.util.BitSet;
import java.util.UUID;
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol<ClientboundPacket1_20_3, ClientboundPacket1_20_2, ServerboundPacket1_20_3, ServerboundPacket1_20_2> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings("1.20.3", "1.20.2", Protocol1_20_3To1_20_2.class);

View File

@ -57,6 +57,8 @@ import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
public final class Protocol1_20_3To1_20_5 extends BackwardsProtocol<ClientboundPacket1_20_5, ClientboundPacket1_20_3, ServerboundPacket1_20_5, ServerboundPacket1_20_3> {
public static final BackwardsMappings MAPPINGS = new BackwardsMappings();

View File

@ -18,8 +18,10 @@
package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter;
import com.viaversion.viabackwards.api.rewriters.ItemRewriter;
import com.viaversion.viabackwards.api.rewriters.StructuredItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.api.type.types.version.Types1_20_3;
@ -31,11 +33,12 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.Clientb
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_5, ServerboundPacket1_20_3, Protocol1_20_3To1_20_5> {
public final class BlockItemPacketRewriter1_20_5 extends StructuredItemRewriter<ClientboundPacket1_20_5, ServerboundPacket1_20_3, Protocol1_20_3To1_20_5> {
public BlockItemPacketRewriter1_20_5(final Protocol1_20_3To1_20_5 protocol) {
super(protocol, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY);
super(protocol, Types1_20_5.ITEM, Types1_20_5.ITEM_ARRAY, Type.ITEM1_20_2, Type.ITEM1_20_2_ARRAY);
}
@Override
@ -72,7 +75,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
// Move it to the beginning, move out arguments here
final Particle particle = wrapper.read(Types1_20_5.PARTICLE);
rewriteParticle(particle);
wrapper.set(Type.VAR_INT, 0, particle.getId());
wrapper.set(Type.VAR_INT, 0, particle.id());
for (final Particle.ParticleData<?> argument : particle.getArguments()) {
argument.write(wrapper);
}
@ -113,9 +116,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
wrapper.passthrough(Type.VAR_INT); // Container id
final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Input
handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Output
handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Second Item
final Item input = handleItemToClient(wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, input);
final Item output = handleItemToClient(wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, output);
final Item secondItem = handleItemToClient(wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, secondItem);
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses
@ -128,7 +135,27 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
});
final RecipeRewriter1_20_3<ClientboundPacket1_20_5> recipeRewriter = new RecipeRewriter1_20_3<>(protocol);
final RecipeRewriter1_20_3<ClientboundPacket1_20_5> recipeRewriter = new RecipeRewriter1_20_3<ClientboundPacket1_20_5>(protocol) {
@Override
protected Type<Item> itemType() {
return Types1_20_5.ITEM;
}
@Override
protected Type<Item[]> itemArrayType() {
return Types1_20_5.ITEM_ARRAY;
}
@Override
protected Type<Item> mappedItemType() {
return Type.ITEM1_20_2;
}
@Override
protected Type<Item[]> mappedItemArrayType() {
return Type.ITEM1_20_2_ARRAY;
}
};
protocol.registerClientbound(ClientboundPackets1_20_5.DECLARE_RECIPES, wrapper -> {
final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
@ -142,4 +169,21 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
});
}
@Override
public @Nullable Item handleItemToClient(@Nullable final Item item) {
if (item == null) return null;
super.handleItemToClient(item);
return com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.BlockItemPacketRewriter1_20_5.toOldItem(item);
}
@Override
public @Nullable Item handleItemToServer(@Nullable final Item item) {
if (item == null) return null;
// Convert to structured item first
final Item structuredItem = com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.rewriter.BlockItemPacketRewriter1_20_5.toStructuredItem(item);
return super.handleItemToServer(structuredItem);
}
}

View File

@ -144,6 +144,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
map(Type.BOOLEAN); // Debug
map(Type.BOOLEAN); // Flat
map(Type.OPTIONAL_GLOBAL_POSITION); // Last death location
map(Type.VAR_INT); // Portal cooldown
handler(wrapper -> {
// Moved to server data
final boolean enforcesSecureChat = wrapper.read(Type.BOOLEAN);

View File

@ -3,7 +3,7 @@ metadata.format.version = "1.1"
[versions]
# ViaVersion
viaver = "4.10.0-24w07a-SNAPSHOT"
viaver = "4.10.0-24w09a-SNAPSHOT"
# Common provided
netty = "4.0.20.Final"