From a68eac7cd2f1ba64702f4ad08c695683503ea8a3 Mon Sep 17 00:00:00 2001 From: KennyTV <28825609+KennyTV@users.noreply.github.com> Date: Wed, 27 Nov 2019 12:56:20 +0100 Subject: [PATCH] Add set cooldown register in ItemRewriter --- .../ViaVersion/api/rewriters/ItemRewriter.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java index cf9b76b2d..8314c03a1 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/ItemRewriter.java @@ -85,6 +85,18 @@ public class ItemRewriter { }); } + public void registerSetCooldown(int oldPacketId, int newPacketId, ItemIdRewriteFunction itemIDRewriteFunction) { + protocol.registerOutgoing(State.PLAY, oldPacketId, newPacketId, new PacketRemapper() { + @Override + public void registerMap() { + handler(wrapper -> { + int itemId = wrapper.read(Type.VAR_INT); + wrapper.write(Type.VAR_INT, itemIDRewriteFunction.rewrite(itemId)); + }); + } + }); + } + // Only sent to the client public PacketHandler itemArrayHandler(Type type) { return wrapper -> { @@ -108,4 +120,10 @@ public class ItemRewriter { void rewrite(Item item); } + + @FunctionalInterface + public interface ItemIdRewriteFunction { + + int rewrite(int itemId); + } }