3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 16:40:10 +01:00

Add UserConnection to item rewriters

Already required for ViaBackwards, later required for ViaVersion as well due to synchronized registry entries in items
Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-21 22:39:13 +02:00
Ursprung 1ed22327f6
Commit a152993ffd
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
37 geänderte Dateien mit 153 neuen und 134 gelöschten Zeilen

Datei anzeigen

@ -22,6 +22,7 @@
*/ */
package com.viaversion.viaversion.api.rewriter; package com.viaversion.viaversion.api.rewriter;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
@ -32,18 +33,22 @@ public interface ItemRewriter<T extends Protocol> extends Rewriter<T> {
/** /**
* Returns the rewritten item, which may or may not be the same given Item instance. * Returns the rewritten item, which may or may not be the same given Item instance.
* *
* @param item item * @param connection user connection
* @param item item
* @return rewritten item * @return rewritten item
*/ */
@Nullable Item handleItemToClient(@Nullable Item item); @Nullable
Item handleItemToClient(UserConnection connection, @Nullable Item item);
/** /**
* Returns the rewritten item, which may or may not be the same given Item instance. * Returns the rewritten item, which may or may not be the same given Item instance.
* *
* @param item item * @param connection user connection
* @param item item
* @return rewritten item * @return rewritten item
*/ */
@Nullable Item handleItemToServer(@Nullable Item item); @Nullable
Item handleItemToServer(UserConnection connection, @Nullable Item item);
/** /**
* Returns the item type of the current protocol. * Returns the item type of the current protocol.

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_10to1_9_3.packets; package com.viaversion.viaversion.protocols.protocol1_10to1_9_3.packets;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4; import com.viaversion.viaversion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
@ -36,7 +37,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
} }
@Override @Override
public Item handleItemToServer(Item item) { public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
boolean newItem = item.identifier() >= 213 && item.identifier() <= 217; boolean newItem = item.identifier() >= 213 && item.identifier() <= 217;
if (newItem) { // Replace server-side unknown items if (newItem) { // Replace server-side unknown items

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_11_1to1_11.packets; package com.viaversion.viaversion.protocols.protocol1_11_1to1_11.packets;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_11_1to1_11.Protocol1_11_1To1_11; import com.viaversion.viaversion.protocols.protocol1_11_1to1_11.Protocol1_11_1To1_11;
@ -36,7 +37,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
} }
@Override @Override
public Item handleItemToServer(Item item) { public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
boolean newItem = item.identifier() == 452; boolean newItem = item.identifier() == 452;
if (newItem) { // Replace server-side unknown items if (newItem) { // Replace server-side unknown items

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.protocols.protocol1_11to1_10.packets; package com.viaversion.viaversion.protocols.protocol1_11to1_10.packets;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
@ -71,13 +72,13 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
} }
@Override @Override
public Item handleItemToClient(Item item) { public Item handleItemToClient(UserConnection connection, Item item) {
EntityIdRewriter.toClientItem(item); EntityIdRewriter.toClientItem(item);
return item; return item;
} }
@Override @Override
public Item handleItemToServer(Item item) { public Item handleItemToServer(UserConnection connection, Item item) {
EntityIdRewriter.toServerItem(item); EntityIdRewriter.toServerItem(item);
if (item == null) return null; if (item == null) return null;
boolean newItem = item.identifier() >= 218 && item.identifier() <= 234; boolean newItem = item.identifier() >= 218 && item.identifier() <= 234;

Datei anzeigen

@ -34,7 +34,7 @@ public class MetadataRewriter1_12To1_11_1 extends EntityRewriter<ClientboundPack
protected void registerRewrites() { protected void registerRewrites() {
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
if (meta.getValue() instanceof Item) { if (meta.getValue() instanceof Item) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(meta.value())); meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
} }
}); });

Datei anzeigen

@ -18,6 +18,7 @@
package com.viaversion.viaversion.protocols.protocol1_12to1_11_1.packets; package com.viaversion.viaversion.protocols.protocol1_12to1_11_1.packets;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
@ -52,12 +53,12 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_8)); // Input Item handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_8)); // Input Item
handleItemToClient(wrapper.passthrough(Type.ITEM1_8)); // Output Item handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_8)); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) { if (secondItem) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_8)); // Second Item handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_8)); // Second Item
} }
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -83,7 +84,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
handler(wrapper -> { handler(wrapper -> {
Item item = wrapper.get(Type.ITEM1_8, 0); Item item = wrapper.get(Type.ITEM1_8, 0);
if (!Via.getConfig().is1_12QuickMoveActionFix()) { if (!Via.getConfig().is1_12QuickMoveActionFix()) {
handleItemToServer(item); handleItemToServer(wrapper.user(), item);
return; return;
} }
byte button = wrapper.get(Type.BYTE, 0); byte button = wrapper.get(Type.BYTE, 0);
@ -100,7 +101,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
} }
// otherwise just pass through so the server sends the PacketPlayOutTransaction packet. // otherwise just pass through so the server sends the PacketPlayOutTransaction packet.
} else { } else {
handleItemToServer(item); handleItemToServer(wrapper.user(), item);
} }
}); });
} }
@ -111,7 +112,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
} }
@Override @Override
public Item handleItemToServer(Item item) { public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
if (item.identifier() == 355) { // Bed rewrite if (item.identifier() == 355) { // Bed rewrite
@ -128,7 +129,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
} }
@Override @Override
public @Nullable Item handleItemToClient(@Nullable Item item) { public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
if (item == null) return null; if (item == null) return null;
if (item.identifier() == 355) { // Bed rewrite if (item.identifier() == 355) { // Bed rewrite
item.setData((short) 14); item.setData((short) 14);

Datei anzeigen

@ -78,7 +78,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
map(Type.BOOLEAN); map(Type.BOOLEAN);
handler(wrapper -> { handler(wrapper -> {
Item item = wrapper.get(Type.ITEM1_13, 0); Item item = wrapper.get(Type.ITEM1_13, 0);
itemRewriter.handleItemToServer(item); itemRewriter.handleItemToServer(wrapper.user(), item);
}); });
handler(wrapper -> { handler(wrapper -> {
int hand = wrapper.read(Type.VAR_INT); int hand = wrapper.read(Type.VAR_INT);

Datei anzeigen

@ -52,14 +52,14 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// Input Item // Input Item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13));
// Output Item // Output Item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) { if (secondItem) {
// Second Item // Second Item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13));
} }
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Type.BOOLEAN); // Trade disabled

Datei anzeigen

@ -531,7 +531,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)); // Title componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)); // Title
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)); // Description componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)); // Description
Item icon = wrapper.read(Type.ITEM1_8); Item icon = wrapper.read(Type.ITEM1_8);
itemRewriter.handleItemToClient(icon); itemRewriter.handleItemToClient(wrapper.user(), icon);
wrapper.write(Type.ITEM1_13, icon); // Translate item to flat item wrapper.write(Type.ITEM1_13, icon); // Translate item to flat item
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags int flags = wrapper.passthrough(Type.INT); // Flags
@ -600,7 +600,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
Item item = wrapper.read(Type.ITEM1_13); Item item = wrapper.read(Type.ITEM1_13);
boolean isSigning = wrapper.read(Type.BOOLEAN); boolean isSigning = wrapper.read(Type.BOOLEAN);
itemRewriter.handleItemToServer(item); itemRewriter.handleItemToServer(wrapper.user(), item);
wrapper.write(Type.STRING, isSigning ? "MC|BSign" : "MC|BEdit"); // Channel wrapper.write(Type.STRING, isSigning ? "MC|BSign" : "MC|BEdit"); // Channel
wrapper.write(Type.ITEM1_8, item); wrapper.write(Type.ITEM1_8, item);

Datei anzeigen

@ -68,7 +68,7 @@ public class ComponentRewriter1_13<C extends ClientboundPacketType> extends Comp
final Item item = new DataItem(); final Item item = new DataItem();
item.setData(damage); item.setData(damage);
item.setTag(itemTag); item.setTag(itemTag);
protocol.getItemRewriter().handleItemToClient(item); protocol.getItemRewriter().handleItemToClient(null, item);
// Serialize again // Serialize again
if (damage != item.data()) { if (damage != item.data()) {

Datei anzeigen

@ -138,7 +138,7 @@ public class ParticleRewriter {
} }
// Transform to new Item // Transform to new Item
Via.getManager().getProtocolManager().getProtocol(Protocol1_13To1_12_2.class).getItemRewriter().handleItemToClient(item); Via.getManager().getProtocolManager().getProtocol(Protocol1_13To1_12_2.class).getItemRewriter().handleItemToClient(null, item);
particle.add(Type.ITEM1_13, item); // Item Slot The item that will be used. particle.add(Type.ITEM1_13, item); // Item Slot The item that will be used.
return particle; return particle;

Datei anzeigen

@ -39,7 +39,7 @@ public class MetadataRewriter1_13To1_12_2 extends EntityRewriter<ClientboundPack
@Override @Override
protected void registerRewrites() { protected void registerRewrites() {
filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId)); filter().mapMetaType(typeId -> Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId));
filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(meta.value()))); filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(event.user(), meta.value())));
filter().metaType(Types1_13.META_TYPES.blockStateType).handler(((event, meta) -> { filter().metaType(Types1_13.META_TYPES.blockStateType).handler(((event, meta) -> {
final int oldId = meta.value(); final int oldId = meta.value();
if (oldId != 0) { if (oldId != 0) {

Datei anzeigen

@ -26,6 +26,7 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
@ -62,7 +63,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
map(Type.SHORT); // 1 - Slot ID map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM1_8, Type.ITEM1_13); // 2 - Slot Value map(Type.ITEM1_8, Type.ITEM1_13); // 2 - Slot Value
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_13, 0))); handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_13, 0)));
} }
}); });
protocol.registerClientbound(ClientboundPackets1_12_1.WINDOW_ITEMS, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_12_1.WINDOW_ITEMS, new PacketHandlers() {
@ -74,7 +75,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
handler(wrapper -> { handler(wrapper -> {
Item[] items = wrapper.get(Type.ITEM1_13_SHORT_ARRAY, 0); Item[] items = wrapper.get(Type.ITEM1_13_SHORT_ARRAY, 0);
for (Item item : items) { for (Item item : items) {
handleItemToClient(item); handleItemToClient(wrapper.user(), item);
} }
}); });
} }
@ -142,18 +143,18 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// Input Item // Input Item
Item input = wrapper.read(Type.ITEM1_8); Item input = wrapper.read(Type.ITEM1_8);
handleItemToClient(input); handleItemToClient(wrapper.user(), input);
wrapper.write(Type.ITEM1_13, input); wrapper.write(Type.ITEM1_13, input);
// Output Item // Output Item
Item output = wrapper.read(Type.ITEM1_8); Item output = wrapper.read(Type.ITEM1_8);
handleItemToClient(output); handleItemToClient(wrapper.user(), output);
wrapper.write(Type.ITEM1_13, output); wrapper.write(Type.ITEM1_13, output);
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) { if (secondItem) {
// Second Item // Second Item
Item second = wrapper.read(Type.ITEM1_8); Item second = wrapper.read(Type.ITEM1_8);
handleItemToClient(second); handleItemToClient(wrapper.user(), second);
wrapper.write(Type.ITEM1_13, second); wrapper.write(Type.ITEM1_13, second);
} }
@ -201,7 +202,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
map(Type.VAR_INT); // 1 - Slot ID map(Type.VAR_INT); // 1 - Slot ID
map(Type.ITEM1_8, Type.ITEM1_13); // 2 - Item map(Type.ITEM1_8, Type.ITEM1_13); // 2 - Item
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_13, 0))); handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_13, 0)));
} }
}); });
@ -216,7 +217,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
map(Type.VAR_INT); // 4 - Mode map(Type.VAR_INT); // 4 - Mode
map(Type.ITEM1_13, Type.ITEM1_8); // 5 - Clicked Item map(Type.ITEM1_13, Type.ITEM1_8); // 5 - Clicked Item
handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_8, 0))); handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
} }
}); });
@ -258,13 +259,13 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
map(Type.SHORT); // 0 - Slot map(Type.SHORT); // 0 - Slot
map(Type.ITEM1_13, Type.ITEM1_8); // 1 - Clicked Item map(Type.ITEM1_13, Type.ITEM1_8); // 1 - Clicked Item
handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_8, 0))); handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
} }
}); });
} }
@Override @Override
public Item handleItemToClient(Item item) { public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
CompoundTag tag = item.tag(); CompoundTag tag = item.tag();
@ -504,7 +505,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
} }
@Override @Override
public Item handleItemToServer(Item item) { public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
Integer rawId = null; Integer rawId = null;

Datei anzeigen

@ -26,6 +26,7 @@ import com.google.common.collect.Sets;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.DataItem; import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -157,14 +158,14 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
int size = wrapper.passthrough(Type.UNSIGNED_BYTE); int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// Input Item // Input Item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
// Output Item // Output Item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) { if (secondItem) {
// Second Item // Second Item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
} }
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -234,7 +235,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
} }
@Override @Override
public Item handleItemToClient(Item item) { public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getNewItemId(item.identifier())); item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getNewItemId(item.identifier()));
@ -256,7 +257,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
} }
@Override @Override
public Item handleItemToServer(Item item) { public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getOldItemId(item.identifier())); item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getOldItemId(item.identifier()));

Datei anzeigen

@ -50,7 +50,7 @@ public class PlayerPackets {
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> { protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> {
Item item = wrapper.passthrough(Type.ITEM1_13_2); Item item = wrapper.passthrough(Type.ITEM1_13_2);
protocol.getItemRewriter().handleItemToServer(item); protocol.getItemRewriter().handleItemToServer(wrapper.user(), item);
if (item == null) return; if (item == null) return;

Datei anzeigen

@ -59,7 +59,7 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
new StatisticsRewriter<>(this).register(ClientboundPackets1_14_4.STATISTICS); new StatisticsRewriter<>(this).register(ClientboundPackets1_14_4.STATISTICS);
registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> itemRewriter.handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> itemRewriter.handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
tagRewriter.register(ClientboundPackets1_14_4.TAGS, RegistryType.ENTITY); tagRewriter.register(ClientboundPackets1_14_4.TAGS, RegistryType.ENTITY);
} }

Datei anzeigen

@ -99,7 +99,7 @@ public final class WorldPackets {
int data = wrapper.passthrough(Type.VAR_INT); int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data)); wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 32) { } else if (id == 32) {
protocol.getItemRewriter().handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
} }
}); });
} }

Datei anzeigen

@ -56,7 +56,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_16, Serve
registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW); registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION); registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.DOUBLE); registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.DOUBLE);
} }

Datei anzeigen

@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
@ -119,7 +120,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
handler(wrapper -> { handler(wrapper -> {
int slot = wrapper.read(Type.VAR_INT); int slot = wrapper.read(Type.VAR_INT);
wrapper.write(Type.BYTE, (byte) slot); wrapper.write(Type.BYTE, (byte) slot);
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
}); });
} }
}); });
@ -134,13 +135,13 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
inventoryTracker.setInventoryOpen(false); inventoryTracker.setInventoryOpen(false);
}); });
protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); protocol.registerServerbound(ServerboundPackets1_16.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.DOUBLE); registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, Type.DOUBLE);
} }
@Override @Override
public Item handleItemToClient(Item item) { public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
CompoundTag tag = item.tag(); CompoundTag tag = item.tag();
@ -169,7 +170,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
} }
@Override @Override
public Item handleItemToServer(Item item) { public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getOldItemId(item.identifier())); item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getOldItemId(item.identifier()));

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_17to1_16_4.packets;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
@ -52,7 +53,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_
registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION); registerCreativeInvAction(ServerboundPackets1_17.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_17.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2))); protocol.registerServerbound(ServerboundPackets1_17.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
protocol.registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketHandlers() { protocol.registerServerbound(ServerboundPackets1_17.CLICK_WINDOW, new PacketHandlers() {
@Override @Override
@ -81,7 +82,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_
item = null; item = null;
} else { } else {
// Use the item sent // Use the item sent
handleItemToServer(item); handleItemToServer(wrapper.user(), item);
} }
wrapper.write(Type.ITEM1_13_2, item); wrapper.write(Type.ITEM1_13_2, item);
@ -126,7 +127,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_
} }
@Override @Override
public Item handleItemToClient(Item item) { public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null; if (item == null) return null;
CompoundTag tag = item.tag(); CompoundTag tag = item.tag();

Datei anzeigen

@ -84,13 +84,13 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
filter().mapMetaType(Types1_18.META_TYPES::byId); filter().mapMetaType(Types1_18.META_TYPES::byId);
filter().metaType(Types1_18.META_TYPES.particleType).handler((event, meta) -> { filter().metaType(Types1_18.META_TYPES.particleType).handler((event, meta) -> {
final Particle particle = (Particle) meta.getValue(); final Particle particle = (Particle) meta.getValue();
if (particle.getId() == 2) { // Barrier if (particle.id() == 2) { // Barrier
particle.setId(3); // Block marker particle.setId(3); // Block marker
particle.add(Type.VAR_INT, 7754); // Barrier state particle.add(Type.VAR_INT, 7754); // Barrier state
} else if (particle.getId() == 3) { // Light block } else if (particle.id() == 3) { // Light block
particle.add(Type.VAR_INT, 7786); // Light block state particle.add(Type.VAR_INT, 7786); // Light block state
} else { } else {
rewriteParticle(particle); rewriteParticle(event.user(), particle);
} }
}); });

Datei anzeigen

@ -86,7 +86,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_17_
int data = wrapper.passthrough(Type.VAR_INT); int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data)); wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) { } else if (mappings.isItemParticle(id)) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
} }
int newId = protocol.getMappingData().getNewParticleId(id); int newId = protocol.getMappingData().getNewParticleId(id);

Datei anzeigen

@ -72,10 +72,10 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
for (int j = 0; j < ingredients; j++) { for (int j = 0; j < ingredients; j++) {
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
for (final Item item : items) { for (final Item item : items) {
handleItemToClient(item); handleItemToClient(wrapper.user(), item);
} }
} }
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
break; break;
} }
case "crafting_shaped": { case "crafting_shaped": {
@ -85,10 +85,10 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
for (int j = 0; j < ingredients; j++) { for (int j = 0; j < ingredients; j++) {
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
for (final Item item : items) { for (final Item item : items) {
handleItemToClient(item); handleItemToClient(wrapper.user(), item);
} }
} }
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
break; break;
} }
case "smelting": case "smelting":
@ -99,9 +99,9 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
wrapper.write(Type.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY); wrapper.write(Type.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY);
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
for (final Item item : items) { for (final Item item : items) {
handleItemToClient(item); handleItemToClient(wrapper.user(), item);
} }
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
wrapper.passthrough(Type.FLOAT); // EXP wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time wrapper.passthrough(Type.VAR_INT); // Cooking time
break; break;

Datei anzeigen

@ -49,7 +49,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
wrapper.passthrough(Type.VAR_INT); // Crafting book category wrapper.passthrough(Type.VAR_INT); // Crafting book category
handleIngredients(wrapper); handleIngredients(wrapper);
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
} }
@ -61,7 +61,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
for (int i = 0; i < ingredients; i++) { for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper); handleIngredient(wrapper);
} }
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
} }
@ -70,7 +70,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
wrapper.passthrough(Type.VAR_INT); // Crafting book category wrapper.passthrough(Type.VAR_INT); // Crafting book category
handleIngredient(wrapper); handleIngredient(wrapper);
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
wrapper.passthrough(Type.FLOAT); // EXP wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time wrapper.passthrough(Type.VAR_INT); // Cooking time

Datei anzeigen

@ -335,7 +335,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
} }
} }
rewriteParticle(particle); rewriteParticle(event.user(), particle);
}); });
registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, null); registerMetaTypeHandler(Types1_19.META_TYPES.itemType, Types1_19.META_TYPES.blockStateType, null);

Datei anzeigen

@ -86,11 +86,11 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_18,
final int size = wrapper.read(Type.UNSIGNED_BYTE); final int size = wrapper.read(Type.UNSIGNED_BYTE);
wrapper.write(Type.VAR_INT, size); wrapper.write(Type.VAR_INT, size);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // First item handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // First item
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Result handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
if (wrapper.read(Type.BOOLEAN)) { if (wrapper.read(Type.BOOLEAN)) {
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
} else { } else {
wrapper.write(Type.ITEM1_13_2, null); wrapper.write(Type.ITEM1_13_2, null);
} }

Datei anzeigen

@ -23,6 +23,7 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.data.entity.EntityTracker; import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
@ -122,10 +123,10 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
handler(wrapper -> { handler(wrapper -> {
final Item[] items = wrapper.read(Type.ITEM1_13_2_ARRAY); final Item[] items = wrapper.read(Type.ITEM1_13_2_ARRAY);
for (final Item item : items) { for (final Item item : items) {
handleItemToClient(item); handleItemToClient(wrapper.user(), item);
} }
wrapper.write(Type.ITEM1_20_2_ARRAY, items); wrapper.write(Type.ITEM1_20_2_ARRAY, items);
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2))); // Carried item wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2))); // Carried item
}); });
} }
}); });
@ -135,7 +136,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
map(Type.UNSIGNED_BYTE); // Window id map(Type.UNSIGNED_BYTE); // Window id
map(Type.VAR_INT); // State id map(Type.VAR_INT); // State id
map(Type.SHORT); // Slot id map(Type.SHORT); // Slot id
handler(wrapper -> wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2)))); handler(wrapper -> wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2))));
} }
}); });
protocol.registerClientbound(ClientboundPackets1_19_4.ADVANCEMENTS, wrapper -> { protocol.registerClientbound(ClientboundPackets1_19_4.ADVANCEMENTS, wrapper -> {
@ -152,7 +153,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
if (wrapper.passthrough(Type.BOOLEAN)) { if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description wrapper.passthrough(Type.COMPONENT); // Description
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2))); // Icon wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2))); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Type.VAR_INT); // Frame type
final int flags = wrapper.passthrough(Type.INT); // Flags final int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) { if ((flags & 1) != 0) {
@ -181,7 +182,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
byte slot; byte slot;
do { do {
slot = wrapper.passthrough(Type.BYTE); slot = wrapper.passthrough(Type.BYTE);
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2))); wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
} while ((slot & 0xFFFFFF80) != 0); } while ((slot & 0xFFFFFF80) != 0);
}); });
} }
@ -200,11 +201,11 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
final int length = wrapper.passthrough(Type.VAR_INT); final int length = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
wrapper.passthrough(Type.SHORT); // Slot wrapper.passthrough(Type.SHORT); // Slot
wrapper.write(Type.ITEM1_13_2, handleItemToServer(wrapper.read(Type.ITEM1_20_2))); wrapper.write(Type.ITEM1_13_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
} }
// Carried item // Carried item
wrapper.write(Type.ITEM1_13_2, handleItemToServer(wrapper.read(Type.ITEM1_20_2))); wrapper.write(Type.ITEM1_13_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
}); });
} }
}); });
@ -212,9 +213,9 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
wrapper.passthrough(Type.VAR_INT); // Container id wrapper.passthrough(Type.VAR_INT); // Container id
final int size = wrapper.passthrough(Type.VAR_INT); final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2))); // Input wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2))); // Input
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2))); // Output wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2))); // Output
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2))); // Second Item wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2))); // Second Item
wrapper.passthrough(Type.BOOLEAN); // Trade disabled wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses wrapper.passthrough(Type.INT); // Number of tools uses
@ -230,7 +231,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
@Override @Override
public void register() { public void register() {
map(Type.SHORT); // 0 - Slot map(Type.SHORT); // 0 - Slot
handler(wrapper -> wrapper.write(Type.ITEM1_13_2, handleItemToServer(wrapper.read(Type.ITEM1_20_2)))); // 1 - Clicked Item handler(wrapper -> wrapper.write(Type.ITEM1_13_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_20_2)))); // 1 - Clicked Item
} }
}); });
protocol.registerClientbound(ClientboundPackets1_19_4.SPAWN_PARTICLE, new PacketHandlers() { protocol.registerClientbound(ClientboundPackets1_19_4.SPAWN_PARTICLE, new PacketHandlers() {
@ -253,7 +254,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
final int data = wrapper.read(Type.VAR_INT); final int data = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data)); wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data));
} else if (mappings.isItemParticle(id)) { } else if (mappings.isItemParticle(id)) {
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.read(Type.ITEM1_13_2))); wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
} }
}); });
} }
@ -267,7 +268,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
handleIngredients(wrapper); handleIngredients(wrapper);
final Item result = wrapper.read(itemType()); final Item result = wrapper.read(itemType());
rewrite(result); rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_20_2, result); wrapper.write(Type.ITEM1_20_2, result);
} }
@ -278,7 +279,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
handleIngredient(wrapper); handleIngredient(wrapper);
final Item result = wrapper.read(itemType()); final Item result = wrapper.read(itemType());
rewrite(result); rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_20_2, result); wrapper.write(Type.ITEM1_20_2, result);
wrapper.passthrough(Type.FLOAT); // EXP wrapper.passthrough(Type.FLOAT); // EXP
@ -295,7 +296,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
} }
final Item result = wrapper.read(itemType()); final Item result = wrapper.read(itemType());
rewrite(result); rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_20_2, result); wrapper.write(Type.ITEM1_20_2, result);
wrapper.passthrough(Type.BOOLEAN); // Show notification wrapper.passthrough(Type.BOOLEAN); // Show notification
@ -307,7 +308,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
handleIngredient(wrapper); handleIngredient(wrapper);
final Item result = wrapper.read(itemType()); final Item result = wrapper.read(itemType());
rewrite(result); rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_20_2, result); wrapper.write(Type.ITEM1_20_2, result);
} }
@ -317,7 +318,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
handleIngredient(wrapper); // Addition handleIngredient(wrapper); // Addition
final Item result = wrapper.read(itemType()); final Item result = wrapper.read(itemType());
rewrite(result); rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_20_2, result); wrapper.write(Type.ITEM1_20_2, result);
} }
@ -328,7 +329,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
handleIngredient(wrapper); // Additions handleIngredient(wrapper); // Additions
final Item result = wrapper.read(itemType()); final Item result = wrapper.read(itemType());
rewrite(result); rewrite(wrapper.user(), result);
wrapper.write(Type.ITEM1_20_2, result); wrapper.write(Type.ITEM1_20_2, result);
} }
@ -337,14 +338,14 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
final Item[] items = wrapper.read(itemArrayType()); final Item[] items = wrapper.read(itemArrayType());
wrapper.write(Type.ITEM1_20_2_ARRAY, items); wrapper.write(Type.ITEM1_20_2_ARRAY, items);
for (final Item item : items) { for (final Item item : items) {
rewrite(item); rewrite(wrapper.user(), item);
} }
} }
}.register(ClientboundPackets1_19_4.DECLARE_RECIPES); }.register(ClientboundPackets1_19_4.DECLARE_RECIPES);
} }
@Override @Override
public @Nullable Item handleItemToClient(@Nullable final Item item) { public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
if (item == null) { if (item == null) {
return null; return null;
} }
@ -353,11 +354,11 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
to1_20_2Effects(item); to1_20_2Effects(item);
} }
return super.handleItemToClient(item); return super.handleItemToClient(connection, item);
} }
@Override @Override
public @Nullable Item handleItemToServer(@Nullable final Item item) { public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) {
if (item == null) { if (item == null) {
return null; return null;
} }
@ -366,7 +367,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
to1_20_1Effects(item); to1_20_1Effects(item);
} }
return super.handleItemToServer(item); return super.handleItemToServer(connection, item);
} }
public static void to1_20_2Effects(final Item item) { public static void to1_20_2Effects(final Item item) {

Datei anzeigen

@ -138,7 +138,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
if (wrapper.passthrough(Type.BOOLEAN)) { if (wrapper.passthrough(Type.BOOLEAN)) {
convertComponent(wrapper); // Title convertComponent(wrapper); // Title
convertComponent(wrapper); // Description convertComponent(wrapper); // Description
itemRewriter.handleItemToClient(wrapper.passthrough(Type.ITEM1_20_2)); // Icon itemRewriter.handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_20_2)); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Type.VAR_INT); // Frame type
final int flags = wrapper.passthrough(Type.INT); final int flags = wrapper.passthrough(Type.INT);
if ((flags & 1) != 0) { if ((flags & 1) != 0) {

Datei anzeigen

@ -23,6 +23,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
@ -110,7 +111,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
for (int i = 0; i < ingredients; i++) { for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper); handleIngredient(wrapper);
} }
rewrite(wrapper.passthrough(itemType())); // Result rewrite(wrapper.user(), wrapper.passthrough(itemType())); // Result
wrapper.passthrough(Type.BOOLEAN); // Show notification wrapper.passthrough(Type.BOOLEAN); // Show notification
} }
}.register(ClientboundPackets1_20_2.DECLARE_RECIPES); }.register(ClientboundPackets1_20_2.DECLARE_RECIPES);
@ -139,7 +140,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
} }
@Override @Override
public @Nullable Item handleItemToClient(@Nullable final Item item) { public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
if (item == null) { if (item == null) {
return null; return null;
} }
@ -149,7 +150,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
updatePages(tag, "pages"); updatePages(tag, "pages");
updatePages(tag, "filtered_pages"); updatePages(tag, "filtered_pages");
} }
return super.handleItemToClient(item); return super.handleItemToClient(connection, item);
} }
private void updatePages(final CompoundTag tag, final String key) { private void updatePages(final CompoundTag tag, final String key) {

Datei anzeigen

@ -126,7 +126,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
} }
} }
rewriteParticle(particle); rewriteParticle(event.user(), particle);
}); });
registerMetaTypeHandler( registerMetaTypeHandler(

Datei anzeigen

@ -39,7 +39,7 @@ public class RecipeRewriter1_20_3<C extends ClientboundPacketType> extends Recip
handleIngredient(wrapper); handleIngredient(wrapper);
} }
final Item item = rewrite(wrapper.read(itemType())); // Result final Item item = rewrite(wrapper.user(), wrapper.read(itemType())); // Result
wrapper.write(mappedItemType(), item); wrapper.write(mappedItemType(), item);
wrapper.passthrough(Type.BOOLEAN); // Show notification wrapper.passthrough(Type.BOOLEAN); // Show notification
} }

Datei anzeigen

@ -23,6 +23,7 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.NumberTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag; import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.minecraft.GameProfile; import com.viaversion.viaversion.api.minecraft.GameProfile;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
@ -110,7 +111,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final int blockStateId = wrapper.read(Type.VAR_INT); final int blockStateId = wrapper.read(Type.VAR_INT);
particle.add(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockStateId)); particle.add(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockStateId));
} else if (mappings.isItemParticle(particleId)) { } else if (mappings.isItemParticle(particleId)) {
final Item item = handleItemToClient(wrapper.read(Type.ITEM1_20_2)); final Item item = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
particle.add(Types1_20_5.ITEM, item); particle.add(Types1_20_5.ITEM, item);
} }
@ -143,9 +144,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
wrapper.passthrough(Type.VAR_INT); // Container id wrapper.passthrough(Type.VAR_INT); // Container id
final int size = wrapper.passthrough(Type.VAR_INT); final int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
final Item input = handleItemToClient(wrapper.read(Type.ITEM1_20_2)); final Item input = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
final Item output = handleItemToClient(wrapper.read(Type.ITEM1_20_2)); final Item output = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
final Item secondItem = handleItemToClient(wrapper.read(Type.ITEM1_20_2)); final Item secondItem = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
wrapper.write(Types1_20_5.ITEM, input); wrapper.write(Types1_20_5.ITEM, input);
wrapper.write(Types1_20_5.ITEM, output); wrapper.write(Types1_20_5.ITEM, output);
wrapper.write(Types1_20_5.ITEM, secondItem); wrapper.write(Types1_20_5.ITEM, secondItem);
@ -177,18 +178,18 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
} }
@Override @Override
public @Nullable Item handleItemToClient(@Nullable final Item item) { public @Nullable Item handleItemToClient(UserConnection connection, @Nullable final Item item) {
if (item == null) return null; if (item == null) return null;
super.handleItemToClient(item); super.handleItemToClient(connection, item);
return toStructuredItem(item); return toStructuredItem(item);
} }
@Override @Override
public @Nullable Item handleItemToServer(@Nullable final Item item) { public @Nullable Item handleItemToServer(UserConnection connection, @Nullable final Item item) {
if (item == null) return null; if (item == null) return null;
super.handleItemToServer(item); super.handleItemToServer(connection, item);
return toOldItem(item); return toOldItem(item);
} }

Datei anzeigen

@ -75,7 +75,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
if (wrapper.passthrough(Type.BOOLEAN)) { if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description wrapper.passthrough(Type.COMPONENT); // Description
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2)); // Icon handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) { if ((flags & 1) != 0) {

Datei anzeigen

@ -224,7 +224,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
filter().handler((event, meta) -> { filter().handler((event, meta) -> {
final MetaType type = meta.metaType(); final MetaType type = meta.metaType();
if (type == itemType) { if (type == itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient(meta.value())); meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
} else if (type == blockStateType) { } else if (type == blockStateType) {
int data = meta.value(); int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
@ -234,7 +234,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} }
} else if (type == particleType) { } else if (type == particleType) {
rewriteParticle(meta.value()); rewriteParticle(event.user(), meta.value());
} }
}); });
} }
@ -589,16 +589,16 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public void rewriteParticle(Particle particle) { public void rewriteParticle(UserConnection connection, Particle particle) {
ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
int id = particle.getId(); int id = particle.id();
if (mappings.isBlockParticle(id)) { if (mappings.isBlockParticle(id)) {
Particle.ParticleData<Integer> data = particle.getArgument(0); Particle.ParticleData<Integer> data = particle.getArgument(0);
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue())); data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
} else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) { } else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) {
Particle.ParticleData<Item> data = particle.getArgument(0); Particle.ParticleData<Item> data = particle.getArgument(0);
Item item = data.getValue(); Item item = data.getValue();
protocol.getItemRewriter().handleItemToClient(item); protocol.getItemRewriter().handleItemToClient(connection, item);
} }
particle.setId(protocol.getMappingData().getNewParticleId(id)); particle.setId(protocol.getMappingData().getNewParticleId(id));
@ -606,7 +606,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
public void rewriteParticle(PacketWrapper wrapper, Type<Particle> from, Type<Particle> to) throws Exception { public void rewriteParticle(PacketWrapper wrapper, Type<Particle> from, Type<Particle> to) throws Exception {
final Particle particle = wrapper.read(from); final Particle particle = wrapper.read(from);
rewriteParticle(particle); rewriteParticle(wrapper.user(), particle);
wrapper.write(to, particle); wrapper.write(to, particle);
} }

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.rewriter; package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.Mappings; import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.minecraft.Particle; import com.viaversion.viaversion.api.minecraft.Particle;
@ -51,7 +52,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
} }
@Override @Override
public @Nullable Item handleItemToClient(@Nullable Item item) { public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable Item item) {
if (item == null) return null; if (item == null) return null;
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) { if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
item.setIdentifier(protocol.getMappingData().getNewItemId(item.identifier())); item.setIdentifier(protocol.getMappingData().getNewItemId(item.identifier()));
@ -60,7 +61,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
} }
@Override @Override
public @Nullable Item handleItemToServer(@Nullable Item item) { public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable Item item) {
if (item == null) return null; if (item == null) return null;
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) { if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
item.setIdentifier(protocol.getMappingData().getOldItemId(item.identifier())); item.setIdentifier(protocol.getMappingData().getOldItemId(item.identifier()));
@ -77,7 +78,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
Item[] items = wrapper.read(itemArrayType); Item[] items = wrapper.read(itemArrayType);
wrapper.write(mappedItemArrayType, items); wrapper.write(mappedItemArrayType, items);
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
items[i] = handleItemToClient(items[i]); items[i] = handleItemToClient(wrapper.user(), items[i]);
} }
}); });
} }
@ -94,7 +95,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
Item[] items = wrapper.read(itemArrayType); Item[] items = wrapper.read(itemArrayType);
wrapper.write(mappedItemArrayType, items); wrapper.write(mappedItemArrayType, items);
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
items[i] = handleItemToClient(items[i]); items[i] = handleItemToClient(wrapper.user(), items[i]);
} }
handleClientboundItem(wrapper); handleClientboundItem(wrapper);
@ -455,7 +456,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
map(Type.INT); // Particle Count map(Type.INT); // Particle Count
handler(wrapper -> { handler(wrapper -> {
final Particle particle = wrapper.read(unmappedParticleType); final Particle particle = wrapper.read(unmappedParticleType);
rewriteParticle(particle); rewriteParticle(wrapper.user(), particle);
wrapper.write(mappedParticleType, particle); wrapper.write(mappedParticleType, particle);
}); });
} }
@ -484,8 +485,8 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
final Particle largeExplosionParticle = wrapper.read(unmappedParticleType); final Particle largeExplosionParticle = wrapper.read(unmappedParticleType);
wrapper.write(mappedParticleType, smallExplosionParticle); wrapper.write(mappedParticleType, smallExplosionParticle);
wrapper.write(mappedParticleType, largeExplosionParticle); wrapper.write(mappedParticleType, largeExplosionParticle);
rewriteParticle(smallExplosionParticle); rewriteParticle(wrapper.user(), smallExplosionParticle);
rewriteParticle(largeExplosionParticle); rewriteParticle(wrapper.user(), largeExplosionParticle);
cSoundRewriter.soundHolderHandler().handle(wrapper); cSoundRewriter.soundHolderHandler().handle(wrapper);
}); });
@ -518,16 +519,16 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
} }
private void handleClientboundItem(final PacketWrapper wrapper) throws Exception { private void handleClientboundItem(final PacketWrapper wrapper) throws Exception {
final Item item = handleItemToClient(wrapper.read(itemType)); final Item item = handleItemToClient(wrapper.user(), wrapper.read(itemType));
wrapper.write(mappedItemType, item); wrapper.write(mappedItemType, item);
} }
private void handleServerboundItem(final PacketWrapper wrapper) throws Exception { private void handleServerboundItem(final PacketWrapper wrapper) throws Exception {
final Item item = handleItemToServer(wrapper.read(mappedItemType)); final Item item = handleItemToServer(wrapper.user(), wrapper.read(mappedItemType));
wrapper.write(itemType, item); wrapper.write(itemType, item);
} }
protected void rewriteParticle(Particle particle) { protected void rewriteParticle(UserConnection connection, Particle particle) {
ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
int id = particle.id(); int id = particle.id();
if (mappings.isBlockParticle(id)) { if (mappings.isBlockParticle(id)) {
@ -535,7 +536,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue())); data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
} else if (mappings.isItemParticle(id)) { } else if (mappings.isItemParticle(id)) {
Particle.ParticleData<Item> data = particle.getArgument(0); Particle.ParticleData<Item> data = particle.getArgument(0);
data.setValue(handleItemToClient(data.getValue())); data.setValue(handleItemToClient(connection, data.getValue()));
} }
particle.setId(protocol.getMappingData().getNewParticleId(id)); particle.setId(protocol.getMappingData().getNewParticleId(id));

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.rewriter; package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
@ -96,21 +97,21 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
handleIngredient(wrapper); handleIngredient(wrapper);
} }
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
} }
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception { public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
handleIngredients(wrapper); handleIngredients(wrapper);
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
} }
public void handleSmelting(PacketWrapper wrapper) throws Exception { public void handleSmelting(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
handleIngredient(wrapper); handleIngredient(wrapper);
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
wrapper.passthrough(Type.FLOAT); // EXP wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time wrapper.passthrough(Type.VAR_INT); // Cooking time
@ -119,14 +120,14 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
public void handleStonecutting(PacketWrapper wrapper) throws Exception { public void handleStonecutting(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.STRING); // Group wrapper.passthrough(Type.STRING); // Group
handleIngredient(wrapper); handleIngredient(wrapper);
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
} }
public void handleSmithing(PacketWrapper wrapper) throws Exception { public void handleSmithing(PacketWrapper wrapper) throws Exception {
handleIngredient(wrapper); // Base handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Addition handleIngredient(wrapper); // Addition
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
} }
@ -138,7 +139,7 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
handleIngredient(wrapper); // Template handleIngredient(wrapper); // Template
handleIngredient(wrapper); // Base handleIngredient(wrapper); // Base
handleIngredient(wrapper); // Additions handleIngredient(wrapper); // Additions
final Item result = rewrite(wrapper.read(itemType())); final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), result); wrapper.write(mappedItemType(), result);
} }
@ -148,9 +149,9 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
handleIngredient(wrapper); // Additions handleIngredient(wrapper); // Additions
} }
protected @Nullable Item rewrite(@Nullable Item item) { protected @Nullable Item rewrite(UserConnection connection, @Nullable Item item) {
if (protocol.getItemRewriter() != null) { if (protocol.getItemRewriter() != null) {
return protocol.getItemRewriter().handleItemToClient(item); return protocol.getItemRewriter().handleItemToClient(connection, item);
} }
return item; return item;
} }
@ -160,7 +161,7 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
wrapper.write(mappedItemArrayType(), items); wrapper.write(mappedItemArrayType(), items);
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
Item item = items[i]; Item item = items[i];
items[i] = rewrite(item); items[i] = rewrite(wrapper.user(), item);
} }
} }

Datei anzeigen

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viaversion.rewriter; package com.viaversion.viaversion.rewriter;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData; import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.data.Mappings; import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.api.data.ParticleMappings; import com.viaversion.viaversion.api.data.ParticleMappings;
@ -44,7 +45,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
} }
@Override @Override
public @Nullable Item handleItemToClient(@Nullable Item item) { public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
if (item == null) { if (item == null) {
return null; return null;
} }
@ -62,7 +63,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
} }
@Override @Override
public @Nullable Item handleItemToServer(@Nullable Item item) { public @Nullable Item handleItemToServer(UserConnection connection, @Nullable Item item) {
if (item == null) { if (item == null) {
return null; return null;
} }