Merge branch 'master' into dev

# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java
This commit is contained in:
Nassim Jahnke 2024-01-29 17:26:49 +01:00
commit da87241549
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
21 changed files with 163 additions and 104 deletions

View File

@ -23,9 +23,11 @@
package com.viaversion.viaversion.api.debug;
import com.google.common.annotations.Beta;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.packet.PacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import java.util.logging.Level;
@Beta
public interface DebugHandler {
@ -102,4 +104,16 @@ public interface DebugHandler {
addPacketTypeToLog(packetType);
}
}
/**
* Logs an error if debug mode is enabled or error suppression is disabled.
*
* @param error error message
* @param t thrown exception
*/
default void error(final String error, final Throwable t) {
if (!Via.getConfig().isSuppressConversionWarnings() || enabled()) {
Via.getPlatform().getLogger().log(Level.SEVERE, error, t);
}
}
}

View File

@ -107,7 +107,8 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
int originalID = packetWrapper.getId();
DebugHandler debugHandler = Via.getManager().debugHandler();
if (debugHandler.enabled() && !debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) {
boolean debug = debugHandler.enabled();
if (debug && !debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) {
logPacket(direction, state, packetWrapper, originalID);
}
@ -115,13 +116,13 @@ public class ProtocolPipelineImpl extends AbstractSimpleProtocol implements Prot
packetWrapper.apply(direction, state, 0, protocolListFor(direction));
super.transform(direction, state, packetWrapper);
if (debugHandler.enabled() && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) {
if (debug && debugHandler.logPostPacketTransform() && debugHandler.shouldLog(packetWrapper, direction)) {
logPacket(direction, state, packetWrapper, originalID);
}
}
private List<Protocol> protocolListFor(final Direction direction) {
return Collections.unmodifiableList(direction == Direction.SERVERBOUND ? protocolList : reversedProtocolList);
return direction == Direction.SERVERBOUND ? protocolList : reversedProtocolList;
}
private void logPacket(Direction direction, State state, PacketWrapper packetWrapper, int originalID) {

View File

@ -27,12 +27,12 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_10To1_9_3_4> {
public InventoryPackets(Protocol1_10To1_9_3_4 protocol) {
super(protocol, null, null);
super(protocol, Type.ITEM1_8, null);
}
@Override
public void registerPackets() {
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);
}
@Override

View File

@ -27,12 +27,12 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11_1To1_11> {
public InventoryPackets(Protocol1_11_1To1_11 protocol) {
super(protocol, null, null);
super(protocol, Type.ITEM1_8, null);
}
@Override
public void registerPackets() {
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);
}
@Override

View File

@ -29,14 +29,14 @@ import com.viaversion.viaversion.rewriter.ItemRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_9_3, Protocol1_11To1_10> {
public InventoryPackets(Protocol1_11To1_10 protocol) {
super(protocol, null, null);
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT);
// Plugin message Packet -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() {
@ -66,8 +66,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
}
});
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerClickWindow(ServerboundPackets1_9_3.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION);
}
@Override

View File

@ -31,16 +31,16 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, ServerboundPackets1_12, Protocol1_12To1_11_1> {
public InventoryPackets(Protocol1_12To1_11_1 protocol) {
super(protocol, null, null);
super(protocol, Type.ITEM1_8, Type.ITEM1_8_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT, Type.ITEM1_8);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS, Type.ITEM1_8_SHORT_ARRAY);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT, Type.ITEM1_8);
registerSetSlot(ClientboundPackets1_9_3.SET_SLOT);
registerWindowItems(ClientboundPackets1_9_3.WINDOW_ITEMS);
registerEntityEquipment(ClientboundPackets1_9_3.ENTITY_EQUIPMENT);
// Plugin message Packet -> Trading
// Plugin message -> Trading
protocol.registerClientbound(ClientboundPackets1_9_3.PLUGIN_MESSAGE, new PacketHandlers() {
@Override
public void register() {
@ -107,8 +107,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
}
);
// Creative Inventory Action
registerCreativeInvAction(ServerboundPackets1_12.CREATIVE_INVENTORY_ACTION, Type.ITEM1_8);
registerCreativeInvAction(ServerboundPackets1_12.CREATIVE_INVENTORY_ACTION);
}
@Override

View File

@ -30,14 +30,14 @@ import com.viaversion.viaversion.util.Key;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_13, Protocol1_13_1To1_13> {
public InventoryPackets(Protocol1_13_1To1_13 protocol) {
super(protocol, Type.ITEM1_13, Type.ITEM1_13_ARRAY);
super(protocol, Type.ITEM1_13, Type.ITEM1_13_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.ITEM1_13);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.ITEM1_13_SHORT_ARRAY);
registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.ITEM1_13);
registerSetSlot(ClientboundPackets1_13.SET_SLOT);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS);
registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS);
registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketHandlers() {
@ -71,7 +71,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
}
});
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.ITEM1_13);
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT);
RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter<ClientboundPackets1_13>(protocol) {
@Override
@ -94,9 +94,9 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
}
});
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW, Type.ITEM1_13);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13);
registerClickWindow(ServerboundPackets1_13.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_13.CREATIVE_INVENTORY_ACTION);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.ITEM1_13, Type.FLOAT);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLOAT);
}
}

View File

@ -60,13 +60,13 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
};
public InventoryPackets(Protocol1_14To1_13_2 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_13.COOLDOWN);
registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_13.ADVANCEMENTS);
protocol.registerClientbound(ClientboundPackets1_13.OPEN_WINDOW, null, wrapper -> {
Short windowId = wrapper.read(Type.UNSIGNED_BYTE);
@ -136,8 +136,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
}
});
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerSetSlot(ClientboundPackets1_13.SET_SLOT, Type.ITEM1_13_2);
registerWindowItems(ClientboundPackets1_13.WINDOW_ITEMS);
registerSetSlot(ClientboundPackets1_13.SET_SLOT);
protocol.registerClientbound(ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketHandlers() {
@Override
@ -190,7 +190,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
}
});
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT, Type.ITEM1_13_2);
registerEntityEquipment(ClientboundPackets1_13.ENTITY_EQUIPMENT);
RecipeRewriter<ClientboundPackets1_13> recipeRewriter = new RecipeRewriter<>(protocol);
protocol.registerClientbound(ClientboundPackets1_13.DECLARE_RECIPES, wrapper -> {
@ -212,7 +212,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
});
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW);
protocol.registerServerbound(ServerboundPackets1_14.SELECT_TRADE, wrapper -> {
// Selecting trade now moves the items, we need to resync the inventory
@ -229,9 +229,9 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
resyncPacket.scheduleSendToServer(Protocol1_14To1_13_2.class);
});
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.FLOAT);
registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, Type.FLOAT);
}
@Override

View File

@ -27,21 +27,21 @@ import com.viaversion.viaversion.rewriter.RecipeRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_14_4, ServerboundPackets1_14, Protocol1_15To1_14_4> {
public InventoryPackets(Protocol1_15To1_14_4 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_14_4.COOLDOWN);
registerWindowItems(ClientboundPackets1_14_4.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerWindowItems(ClientboundPackets1_14_4.WINDOW_ITEMS);
registerTradeList(ClientboundPackets1_14_4.TRADE_LIST);
registerSetSlot(ClientboundPackets1_14_4.SET_SLOT, Type.ITEM1_13_2);
registerEntityEquipment(ClientboundPackets1_14_4.ENTITY_EQUIPMENT, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_14_4.ADVANCEMENTS, Type.ITEM1_13_2);
registerSetSlot(ClientboundPackets1_14_4.SET_SLOT);
registerEntityEquipment(ClientboundPackets1_14_4.ENTITY_EQUIPMENT);
registerAdvancements(ClientboundPackets1_14_4.ADVANCEMENTS);
new RecipeRewriter<>(protocol).register(ClientboundPackets1_14_4.DECLARE_RECIPES);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION);
}
}

View File

@ -27,17 +27,17 @@ import com.viaversion.viaversion.rewriter.RecipeRewriter;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_16, ServerboundPackets1_16_2, Protocol1_16_2To1_16_1> {
public InventoryPackets(Protocol1_16_2To1_16_1 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_16.COOLDOWN);
registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS);
registerTradeList(ClientboundPackets1_16.TRADE_LIST);
registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.ITEM1_13_2);
registerSetSlot(ClientboundPackets1_16.SET_SLOT);
registerEntityEquipmentArray(ClientboundPackets1_16.ENTITY_EQUIPMENT);
registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS);
protocol.registerClientbound(ClientboundPackets1_16.UNLOCK_RECIPES, wrapper -> {
wrapper.passthrough(Type.VAR_INT);
@ -54,10 +54,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_16, Serve
new RecipeRewriter<>(protocol).register(ClientboundPackets1_16.DECLARE_RECIPES);
registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE);
registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.DOUBLE);
}
}

View File

@ -43,7 +43,7 @@ import java.util.UUID;
public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, ServerboundPackets1_16, Protocol1_16To1_15_2> {
public InventoryPackets(Protocol1_16To1_15_2 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}
@Override
@ -107,10 +107,10 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
});
registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS);
registerTradeList(ClientboundPackets1_15.TRADE_LIST);
registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.ITEM1_13_2);
registerSetSlot(ClientboundPackets1_15.SET_SLOT);
registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS);
protocol.registerClientbound(ClientboundPackets1_15.ENTITY_EQUIPMENT, new PacketHandlers() {
@Override
@ -127,8 +127,8 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
new RecipeRewriter<>(protocol).register(ClientboundPackets1_15.DECLARE_RECIPES);
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_16.CLOSE_WINDOW, wrapper -> {
InventoryTracker1_16 inventoryTracker = wrapper.user().get(InventoryTracker1_16.class);
@ -137,7 +137,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE);
registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.DOUBLE);
}
@Override

View File

@ -36,22 +36,22 @@ import com.viaversion.viaversion.rewriter.RecipeRewriter;
public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_2, ServerboundPackets1_17, Protocol1_17To1_16_4> {
public InventoryPackets(Protocol1_17To1_16_4 protocol) {
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY);
super(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_SHORT_ARRAY);
}
@Override
public void registerPackets() {
registerSetCooldown(ClientboundPackets1_16_2.COOLDOWN);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS, Type.ITEM1_13_2_SHORT_ARRAY);
registerWindowItems(ClientboundPackets1_16_2.WINDOW_ITEMS);
registerTradeList(ClientboundPackets1_16_2.TRADE_LIST);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS, Type.ITEM1_13_2);
registerSetSlot(ClientboundPackets1_16_2.SET_SLOT);
registerAdvancements(ClientboundPackets1_16_2.ADVANCEMENTS);
registerEntityEquipmentArray(ClientboundPackets1_16_2.ENTITY_EQUIPMENT);
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.ITEM1_13_2, Type.DOUBLE);
registerSpawnParticle(ClientboundPackets1_16_2.SPAWN_PARTICLE, Type.DOUBLE);
new RecipeRewriter<>(protocol).register(ClientboundPackets1_16_2.DECLARE_RECIPES);
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_17.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));

View File

@ -38,7 +38,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_17_
registerWindowItems1_17_1(ClientboundPackets1_17_1.WINDOW_ITEMS);
registerTradeList(ClientboundPackets1_17_1.TRADE_LIST);
registerSetSlot1_17_1(ClientboundPackets1_17_1.SET_SLOT);
registerAdvancements(ClientboundPackets1_17_1.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_17_1.ADVANCEMENTS);
registerEntityEquipmentArray(ClientboundPackets1_17_1.ENTITY_EQUIPMENT);
protocol.registerClientbound(ClientboundPackets1_17_1.EFFECT, new PacketHandlers() {
@ -100,6 +100,6 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_17_
new RecipeRewriter<>(protocol).register(ClientboundPackets1_17_1.DECLARE_RECIPES);
registerClickWindow1_17_1(ServerboundPackets1_17.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION);
}
}

View File

@ -50,11 +50,11 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
registerSetCooldown(ClientboundPackets1_19_1.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_19_1.WINDOW_ITEMS);
registerSetSlot1_17_1(ClientboundPackets1_19_1.SET_SLOT);
registerAdvancements(ClientboundPackets1_19_1.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_19_1.ADVANCEMENTS);
registerEntityEquipmentArray(ClientboundPackets1_19_1.ENTITY_EQUIPMENT);
registerClickWindow1_17_1(ServerboundPackets1_19_3.CLICK_WINDOW);
registerTradeList1_19(ClientboundPackets1_19_1.TRADE_LIST);
registerCreativeInvAction(ServerboundPackets1_19_3.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_19_3.CREATIVE_INVENTORY_ACTION);
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_19_1.WINDOW_PROPERTY);
registerSpawnParticle1_19(ClientboundPackets1_19_1.SPAWN_PARTICLE);

View File

@ -86,12 +86,12 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
registerSetCooldown(ClientboundPackets1_19_3.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_19_3.WINDOW_ITEMS);
registerSetSlot1_17_1(ClientboundPackets1_19_3.SET_SLOT);
registerAdvancements(ClientboundPackets1_19_3.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_19_3.ADVANCEMENTS);
registerEntityEquipmentArray(ClientboundPackets1_19_3.ENTITY_EQUIPMENT);
registerTradeList1_19(ClientboundPackets1_19_3.TRADE_LIST);
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_19_3.WINDOW_PROPERTY);
registerSpawnParticle1_19(ClientboundPackets1_19_3.SPAWN_PARTICLE);
registerCreativeInvAction(ServerboundPackets1_19_4.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_19_4.CREATIVE_INVENTORY_ACTION);
registerClickWindow1_17_1(ServerboundPackets1_19_4.CLICK_WINDOW);
new RecipeRewriter1_19_3<ClientboundPackets1_19_3>(protocol) {

View File

@ -41,7 +41,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_18,
registerSetCooldown(ClientboundPackets1_18.COOLDOWN);
registerWindowItems1_17_1(ClientboundPackets1_18.WINDOW_ITEMS);
registerSetSlot1_17_1(ClientboundPackets1_18.SET_SLOT);
registerAdvancements(ClientboundPackets1_18.ADVANCEMENTS, Type.ITEM1_13_2);
registerAdvancements(ClientboundPackets1_18.ADVANCEMENTS);
registerEntityEquipmentArray(ClientboundPackets1_18.ENTITY_EQUIPMENT);
protocol.registerClientbound(ClientboundPackets1_18.SPAWN_PARTICLE, new PacketHandlers() {
@Override
@ -74,7 +74,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_18,
});
registerClickWindow1_17_1(ServerboundPackets1_19.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_19.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_19.CREATIVE_INVENTORY_ACTION);
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_18.WINDOW_PROPERTY);

View File

@ -17,8 +17,15 @@
*/
package com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
@ -32,7 +39,9 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.Serverb
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ServerboundPackets1_20_3;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.ItemRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Key;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<ClientboundPacket1_20_2, ServerboundPacket1_20_3, Protocol1_20_3To1_20_2> {
@ -127,4 +136,39 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
wrapper.write(Type.OPTIONAL_FLOAT, null); // Sound range
});
}
@Override
public @Nullable Item handleItemToClient(@Nullable final Item item) {
if (item == null) {
return null;
}
final CompoundTag tag = item.tag();
if (tag != null) {
updatePages(tag, "pages");
updatePages(tag, "filtered_pages");
}
return super.handleItemToClient(item);
}
private void updatePages(final CompoundTag tag, final String key) {
if (!(tag.get(key) instanceof ListTag)) {
return;
}
final ListTag pages = tag.get(key);
for (final Tag pageTag : pages) {
if (!(pageTag instanceof StringTag)) {
continue;
}
final StringTag stringTag = (StringTag) pageTag;
try {
final JsonElement updatedComponent = ComponentUtil.convertJson(stringTag.getValue(), ComponentUtil.SerializerVersion.V1_19_4, ComponentUtil.SerializerVersion.V1_20_3);
stringTag.setValue(updatedComponent.toString());
} catch (final Exception e) {
Via.getManager().debugHandler().error("Error during book conversion", e);
}
}
}
}

View File

@ -57,7 +57,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
registerEntityEquipmentArray(ClientboundPackets1_19_4.ENTITY_EQUIPMENT);
registerClickWindow1_17_1(ServerboundPackets1_19_4.CLICK_WINDOW);
registerTradeList1_19(ClientboundPackets1_19_4.TRADE_LIST);
registerCreativeInvAction(ServerboundPackets1_19_4.CREATIVE_INVENTORY_ACTION, Type.ITEM1_13_2);
registerCreativeInvAction(ServerboundPackets1_19_4.CREATIVE_INVENTORY_ACTION);
registerWindowPropertyEnchantmentHandler(ClientboundPackets1_19_4.WINDOW_PROPERTY);
registerSpawnParticle1_19(ClientboundPackets1_19_4.SPAWN_PARTICLE);

View File

@ -84,7 +84,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
/**
* Returns a meta filter builder.
* <p>
* Calling {@link MetaFilter.Builder#register()} will automatically register the filter on this rewriter.
* Calling {@link com.viaversion.viaversion.rewriter.meta.MetaFilter.Builder#register()} will automatically register the filter on this rewriter.
*
* @return meta filter builder
*/
@ -94,7 +94,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
/**
* Registers a metadata filter.
* Note that {@link MetaFilter.Builder#register()} already calls this method.
* Note that {@link com.viaversion.viaversion.rewriter.meta.MetaFilter.Builder#register()} already calls this method.
*
* @param filter filter to register
* @throws IllegalArgumentException if the filter is already registered

View File

@ -35,11 +35,6 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
private final Type<Item> itemType;
private final Type<Item[]> itemArrayType;
@Deprecated/*(forRemoval = true)*/
protected ItemRewriter(T protocol) {
this(protocol, Type.ITEM1_13_2, Type.ITEM1_13_2_ARRAY);
}
public ItemRewriter(T protocol, Type<Item> itemType, Type<Item[]> itemArrayType) {
super(protocol);
this.itemType = itemType;
@ -66,13 +61,13 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
return item;
}
public void registerWindowItems(C packetType, Type<Item[]> type) {
public void registerWindowItems(C packetType) {
protocol.registerClientbound(packetType, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // Window id
map(type); // Items
handler(itemArrayToClientHandler(type));
map(itemArrayType); // Items
handler(itemArrayToClientHandler(itemArrayType));
}
});
}
@ -114,14 +109,14 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
});
}
public void registerSetSlot(C packetType, Type<Item> type) {
public void registerSetSlot(C packetType) {
protocol.registerClientbound(packetType, new PacketHandlers() {
@Override
public void register() {
map(Type.UNSIGNED_BYTE); // Window id
map(Type.SHORT); // Slot id
map(type); // Item
handler(itemToClientHandler(type));
map(itemType); // Item
handler(itemToClientHandler(itemType));
}
});
}
@ -140,15 +135,15 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
}
// Sub 1.16
public void registerEntityEquipment(C packetType, Type<Item> type) {
public void registerEntityEquipment(C packetType) {
protocol.registerClientbound(packetType, new PacketHandlers() {
@Override
public void register() {
map(Type.VAR_INT); // 0 - Entity ID
map(Type.VAR_INT); // 1 - Slot ID
map(type); // 2 - Item
map(itemType); // 2 - Item
handler(itemToClientHandler(type));
handler(itemToClientHandler(itemType));
}
});
}
@ -173,21 +168,17 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
}
public void registerCreativeInvAction(S packetType) {
registerCreativeInvAction(packetType, itemType);
}
public void registerCreativeInvAction(S packetType, Type<Item> type) {
protocol.registerServerbound(packetType, new PacketHandlers() {
@Override
public void register() {
map(Type.SHORT); // 0 - Slot
map(type); // 1 - Clicked Item
handler(itemToServerHandler(type));
map(itemType); // 1 - Clicked Item
handler(itemToServerHandler(itemType));
}
});
}
public void registerClickWindow(S packetType, Type<Item> type) {
public void registerClickWindow(S packetType) {
protocol.registerServerbound(packetType, new PacketHandlers() {
@Override
public void register() {
@ -196,9 +187,9 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
map(Type.BYTE); // 2 - Button
map(Type.SHORT); // 3 - Action number
map(Type.VAR_INT); // 4 - Mode
map(type); // 5 - Clicked Item
map(itemType); // 5 - Clicked Item
handler(itemToServerHandler(type));
handler(itemToServerHandler(itemType));
}
});
}
@ -304,7 +295,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
});
}
public void registerAdvancements(C packetType, Type<Item> type) {
public void registerAdvancements(C packetType) {
protocol.registerClientbound(packetType, wrapper -> {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
@ -319,7 +310,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
handleItemToClient(wrapper.passthrough(type)); // Icon
handleItemToClient(wrapper.passthrough(itemType)); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) {
@ -405,7 +396,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
}
// Not the very best place for this, but has to stay here until *everything* is abstracted
public void registerSpawnParticle(C packetType, Type<Item> itemType, Type<?> coordType) {
public void registerSpawnParticle(C packetType, Type<?> coordType) {
protocol.registerClientbound(packetType, new PacketHandlers() {
@Override
public void register() {
@ -552,4 +543,11 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
particle.setId(protocol.getMappingData().getNewParticleId(id));
}
public Type<Item> getItemType() {
return itemType;
}
public Type<Item[]> getItemArrayType() {
return itemArrayType;
}
}

View File

@ -77,11 +77,14 @@ public final class ComponentUtil {
}
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
final ATextComponent component = from.jsonSerializer.deserialize(element);
if (element == null) {
return null;
}
return element != null ? convert(from, to, from.jsonSerializer.deserialize(element)) : null;
}
public static @Nullable JsonElement convertJson(@Nullable final String json, final SerializerVersion from, final SerializerVersion to) {
return json != null ? convert(from, to, from.jsonSerializer.deserialize(json)) : null;
}
private static JsonElement convert(final SerializerVersion from, final SerializerVersion to, final ATextComponent component) {
if (from.ordinal() >= SerializerVersion.V1_16.ordinal() && to.ordinal() < SerializerVersion.V1_16.ordinal()) {
// Convert hover event to legacy format
final Style style = component.getStyle();