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:
Ursprung
1ed22327f6
Commit
a152993ffd
@ -22,6 +22,7 @@
|
||||
*/
|
||||
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.protocol.Protocol;
|
||||
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.
|
||||
*
|
||||
* @param item item
|
||||
* @param connection user connection
|
||||
* @param item 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.
|
||||
*
|
||||
* @param item item
|
||||
* @param connection user connection
|
||||
* @param item 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.
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
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.type.Type;
|
||||
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
|
||||
public Item handleItemToServer(Item item) {
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
boolean newItem = item.identifier() >= 213 && item.identifier() <= 217;
|
||||
if (newItem) { // Replace server-side unknown items
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
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.type.Type;
|
||||
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
|
||||
public Item handleItemToServer(Item item) {
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
boolean newItem = item.identifier() == 452;
|
||||
if (newItem) { // Replace server-side unknown items
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
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.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
@ -71,13 +72,13 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(Item item) {
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
EntityIdRewriter.toClientItem(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(Item item) {
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
EntityIdRewriter.toServerItem(item);
|
||||
if (item == null) return null;
|
||||
boolean newItem = item.identifier() >= 218 && item.identifier() <= 234;
|
||||
|
@ -34,7 +34,7 @@ public class MetadataRewriter1_12To1_11_1 extends EntityRewriter<ClientboundPack
|
||||
protected void registerRewrites() {
|
||||
filter().handler((event, meta) -> {
|
||||
if (meta.getValue() instanceof Item) {
|
||||
meta.setValue(protocol.getItemRewriter().handleItemToClient(meta.value()));
|
||||
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.viaversion.viaversion.protocols.protocol1_12to1_11_1.packets;
|
||||
|
||||
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.protocol.remapper.PacketHandlers;
|
||||
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);
|
||||
for (int i = 0; i < size; i++) {
|
||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_8)); // Input Item
|
||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_8)); // Output Item
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_8)); // Input Item
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_8)); // Output Item
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
|
||||
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
|
||||
@ -83,7 +84,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
|
||||
handler(wrapper -> {
|
||||
Item item = wrapper.get(Type.ITEM1_8, 0);
|
||||
if (!Via.getConfig().is1_12QuickMoveActionFix()) {
|
||||
handleItemToServer(item);
|
||||
handleItemToServer(wrapper.user(), item);
|
||||
return;
|
||||
}
|
||||
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.
|
||||
} else {
|
||||
handleItemToServer(item);
|
||||
handleItemToServer(wrapper.user(), item);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -111,7 +112,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(Item item) {
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
if (item.identifier() == 355) { // Bed rewrite
|
||||
@ -128,7 +129,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_9_3, Serv
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(@Nullable Item item) {
|
||||
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
if (item.identifier() == 355) { // Bed rewrite
|
||||
item.setData((short) 14);
|
||||
|
@ -78,7 +78,7 @@ public class Protocol1_13_1To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
map(Type.BOOLEAN);
|
||||
handler(wrapper -> {
|
||||
Item item = wrapper.get(Type.ITEM1_13, 0);
|
||||
itemRewriter.handleItemToServer(item);
|
||||
itemRewriter.handleItemToServer(wrapper.user(), item);
|
||||
});
|
||||
handler(wrapper -> {
|
||||
int hand = wrapper.read(Type.VAR_INT);
|
||||
|
@ -52,14 +52,14 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||
for (int i = 0; i < size; i++) {
|
||||
// Input Item
|
||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_13));
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13));
|
||||
// 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
|
||||
if (secondItem) {
|
||||
// Second Item
|
||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_13));
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13));
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||
|
@ -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)); // Description
|
||||
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.passthrough(Type.VAR_INT); // Frame type
|
||||
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);
|
||||
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.ITEM1_8, item);
|
||||
|
@ -68,7 +68,7 @@ public class ComponentRewriter1_13<C extends ClientboundPacketType> extends Comp
|
||||
final Item item = new DataItem();
|
||||
item.setData(damage);
|
||||
item.setTag(itemTag);
|
||||
protocol.getItemRewriter().handleItemToClient(item);
|
||||
protocol.getItemRewriter().handleItemToClient(null, item);
|
||||
|
||||
// Serialize again
|
||||
if (damage != item.data()) {
|
||||
|
@ -138,7 +138,7 @@ public class ParticleRewriter {
|
||||
}
|
||||
|
||||
// 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.
|
||||
return particle;
|
||||
|
@ -39,7 +39,7 @@ public class MetadataRewriter1_13To1_12_2 extends EntityRewriter<ClientboundPack
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
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) -> {
|
||||
final int oldId = meta.value();
|
||||
if (oldId != 0) {
|
||||
|
@ -26,6 +26,7 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.primitives.Ints;
|
||||
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.protocol.remapper.PacketHandlers;
|
||||
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.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() {
|
||||
@ -74,7 +75,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
||||
handler(wrapper -> {
|
||||
Item[] items = wrapper.get(Type.ITEM1_13_SHORT_ARRAY, 0);
|
||||
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++) {
|
||||
// Input Item
|
||||
Item input = wrapper.read(Type.ITEM1_8);
|
||||
handleItemToClient(input);
|
||||
handleItemToClient(wrapper.user(), input);
|
||||
wrapper.write(Type.ITEM1_13, input);
|
||||
// Output Item
|
||||
Item output = wrapper.read(Type.ITEM1_8);
|
||||
handleItemToClient(output);
|
||||
handleItemToClient(wrapper.user(), output);
|
||||
wrapper.write(Type.ITEM1_13, output);
|
||||
|
||||
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
|
||||
if (secondItem) {
|
||||
// Second Item
|
||||
Item second = wrapper.read(Type.ITEM1_8);
|
||||
handleItemToClient(second);
|
||||
handleItemToClient(wrapper.user(), 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.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.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.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
|
||||
public Item handleItemToClient(Item item) {
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
CompoundTag tag = item.tag();
|
||||
|
||||
@ -504,7 +505,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_12_1, Ser
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(Item item) {
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
Integer rawId = null;
|
||||
|
@ -26,6 +26,7 @@ import com.google.common.collect.Sets;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
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.Item;
|
||||
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);
|
||||
for (int i = 0; i < size; i++) {
|
||||
// Input Item
|
||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
|
||||
// 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
|
||||
if (secondItem) {
|
||||
// Second Item
|
||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
|
||||
}
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
|
||||
@ -234,7 +235,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(Item item) {
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getNewItemId(item.identifier()));
|
||||
|
||||
@ -256,7 +257,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(Item item) {
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
item.setIdentifier(Protocol1_14To1_13_2.MAPPINGS.getOldItemId(item.identifier()));
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class PlayerPackets {
|
||||
|
||||
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> {
|
||||
Item item = wrapper.passthrough(Type.ITEM1_13_2);
|
||||
protocol.getItemRewriter().handleItemToServer(item);
|
||||
protocol.getItemRewriter().handleItemToServer(wrapper.user(), item);
|
||||
|
||||
if (item == null) return;
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class Protocol1_15To1_14_4 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public final class WorldPackets {
|
||||
int data = wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
|
||||
} else if (id == 32) {
|
||||
protocol.getItemRewriter().handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
|
||||
protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_16, Serve
|
||||
|
||||
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)));
|
||||
protocol.registerServerbound(ServerboundPackets1_16_2.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
|
||||
|
||||
registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, Type.DOUBLE);
|
||||
}
|
||||
|
@ -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.NumberTag;
|
||||
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.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
@ -119,7 +120,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
|
||||
handler(wrapper -> {
|
||||
int slot = wrapper.read(Type.VAR_INT);
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(Item item) {
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
@ -169,7 +170,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToServer(Item item) {
|
||||
public Item handleItemToServer(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
item.setIdentifier(Protocol1_16To1_15_2.MAPPINGS.getOldItemId(item.identifier()));
|
||||
|
@ -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.IntTag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
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);
|
||||
|
||||
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() {
|
||||
@Override
|
||||
@ -81,7 +82,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_
|
||||
item = null;
|
||||
} else {
|
||||
// Use the item sent
|
||||
handleItemToServer(item);
|
||||
handleItemToServer(wrapper.user(), item);
|
||||
}
|
||||
|
||||
wrapper.write(Type.ITEM1_13_2, item);
|
||||
@ -126,7 +127,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_16_
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(Item item) {
|
||||
public Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
CompoundTag tag = item.tag();
|
||||
|
@ -84,13 +84,13 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
|
||||
filter().mapMetaType(Types1_18.META_TYPES::byId);
|
||||
filter().metaType(Types1_18.META_TYPES.particleType).handler((event, meta) -> {
|
||||
final Particle particle = (Particle) meta.getValue();
|
||||
if (particle.getId() == 2) { // Barrier
|
||||
if (particle.id() == 2) { // Barrier
|
||||
particle.setId(3); // Block marker
|
||||
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
|
||||
} else {
|
||||
rewriteParticle(particle);
|
||||
rewriteParticle(event.user(), particle);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -86,7 +86,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_17_
|
||||
int data = wrapper.passthrough(Type.VAR_INT);
|
||||
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
|
||||
} 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);
|
||||
|
@ -72,10 +72,10 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
||||
for (int j = 0; j < ingredients; j++) {
|
||||
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
|
||||
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;
|
||||
}
|
||||
case "crafting_shaped": {
|
||||
@ -85,10 +85,10 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
||||
for (int j = 0; j < ingredients; j++) {
|
||||
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
|
||||
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;
|
||||
}
|
||||
case "smelting":
|
||||
@ -99,9 +99,9 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
||||
wrapper.write(Type.VAR_INT, MISC_CRAFTING_BOOK_CATEGORY);
|
||||
final Item[] items = wrapper.passthrough(Type.ITEM1_13_2_ARRAY); // Ingredients
|
||||
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.VAR_INT); // Cooking time
|
||||
break;
|
||||
|
@ -49,7 +49,7 @@ public class RecipeRewriter1_19_3<C extends ClientboundPacketType> extends Recip
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
wrapper.passthrough(Type.VAR_INT); // Crafting book category
|
||||
handleIngredients(wrapper);
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
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++) {
|
||||
handleIngredient(wrapper);
|
||||
}
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
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.VAR_INT); // Crafting book category
|
||||
handleIngredient(wrapper);
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), result);
|
||||
wrapper.passthrough(Type.FLOAT); // EXP
|
||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||
|
@ -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);
|
||||
|
@ -86,11 +86,11 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_18,
|
||||
final int size = wrapper.read(Type.UNSIGNED_BYTE);
|
||||
wrapper.write(Type.VAR_INT, size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
handleItemToClient(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)); // First item
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
|
||||
|
||||
if (wrapper.read(Type.BOOLEAN)) {
|
||||
handleItemToClient(wrapper.passthrough(Type.ITEM1_13_2));
|
||||
handleItemToClient(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2));
|
||||
} else {
|
||||
wrapper.write(Type.ITEM1_13_2, null);
|
||||
}
|
||||
|
@ -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.StringTag;
|
||||
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.entity.EntityTracker;
|
||||
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
||||
@ -122,10 +123,10 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
handler(wrapper -> {
|
||||
final Item[] items = wrapper.read(Type.ITEM1_13_2_ARRAY);
|
||||
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, 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.VAR_INT); // State 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 -> {
|
||||
@ -152,7 +153,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||
wrapper.passthrough(Type.COMPONENT); // Title
|
||||
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
|
||||
final int flags = wrapper.passthrough(Type.INT); // Flags
|
||||
if ((flags & 1) != 0) {
|
||||
@ -181,7 +182,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
byte slot;
|
||||
do {
|
||||
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);
|
||||
});
|
||||
}
|
||||
@ -200,11 +201,11 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
final int length = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < length; i++) {
|
||||
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
|
||||
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
|
||||
final int size = wrapper.passthrough(Type.VAR_INT);
|
||||
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.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))); // Input
|
||||
wrapper.write(Type.ITEM1_20_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2))); // Output
|
||||
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.INT); // Number of tools uses
|
||||
@ -230,7 +231,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
@Override
|
||||
public void register() {
|
||||
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() {
|
||||
@ -253,7 +254,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
final int data = wrapper.read(Type.VAR_INT);
|
||||
wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(data));
|
||||
} 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);
|
||||
|
||||
final Item result = wrapper.read(itemType());
|
||||
rewrite(result);
|
||||
rewrite(wrapper.user(), result);
|
||||
wrapper.write(Type.ITEM1_20_2, result);
|
||||
}
|
||||
|
||||
@ -278,7 +279,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
handleIngredient(wrapper);
|
||||
|
||||
final Item result = wrapper.read(itemType());
|
||||
rewrite(result);
|
||||
rewrite(wrapper.user(), result);
|
||||
wrapper.write(Type.ITEM1_20_2, result);
|
||||
|
||||
wrapper.passthrough(Type.FLOAT); // EXP
|
||||
@ -295,7 +296,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
}
|
||||
|
||||
final Item result = wrapper.read(itemType());
|
||||
rewrite(result);
|
||||
rewrite(wrapper.user(), result);
|
||||
wrapper.write(Type.ITEM1_20_2, result);
|
||||
|
||||
wrapper.passthrough(Type.BOOLEAN); // Show notification
|
||||
@ -307,7 +308,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
handleIngredient(wrapper);
|
||||
|
||||
final Item result = wrapper.read(itemType());
|
||||
rewrite(result);
|
||||
rewrite(wrapper.user(), result);
|
||||
wrapper.write(Type.ITEM1_20_2, result);
|
||||
}
|
||||
|
||||
@ -317,7 +318,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
handleIngredient(wrapper); // Addition
|
||||
|
||||
final Item result = wrapper.read(itemType());
|
||||
rewrite(result);
|
||||
rewrite(wrapper.user(), result);
|
||||
wrapper.write(Type.ITEM1_20_2, result);
|
||||
}
|
||||
|
||||
@ -328,7 +329,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
handleIngredient(wrapper); // Additions
|
||||
|
||||
final Item result = wrapper.read(itemType());
|
||||
rewrite(result);
|
||||
rewrite(wrapper.user(), 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());
|
||||
wrapper.write(Type.ITEM1_20_2_ARRAY, items);
|
||||
for (final Item item : items) {
|
||||
rewrite(item);
|
||||
rewrite(wrapper.user(), item);
|
||||
}
|
||||
}
|
||||
}.register(ClientboundPackets1_19_4.DECLARE_RECIPES);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(@Nullable final Item item) {
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
@ -353,11 +354,11 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
to1_20_2Effects(item);
|
||||
}
|
||||
|
||||
return super.handleItemToClient(item);
|
||||
return super.handleItemToClient(connection, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(@Nullable final Item item) {
|
||||
public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
@ -366,7 +367,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
|
||||
to1_20_1Effects(item);
|
||||
}
|
||||
|
||||
return super.handleItemToServer(item);
|
||||
return super.handleItemToServer(connection, item);
|
||||
}
|
||||
|
||||
public static void to1_20_2Effects(final Item item) {
|
||||
|
@ -138,7 +138,7 @@ public final class Protocol1_20_3To1_20_2 extends AbstractProtocol<ClientboundPa
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||
convertComponent(wrapper); // Title
|
||||
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
|
||||
final int flags = wrapper.passthrough(Type.INT);
|
||||
if ((flags & 1) != 0) {
|
||||
|
@ -23,6 +23,7 @@ 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.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
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++) {
|
||||
handleIngredient(wrapper);
|
||||
}
|
||||
rewrite(wrapper.passthrough(itemType())); // Result
|
||||
rewrite(wrapper.user(), wrapper.passthrough(itemType())); // Result
|
||||
wrapper.passthrough(Type.BOOLEAN); // Show notification
|
||||
}
|
||||
}.register(ClientboundPackets1_20_2.DECLARE_RECIPES);
|
||||
@ -139,7 +140,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(@Nullable final Item item) {
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
@ -149,7 +150,7 @@ public final class BlockItemPacketRewriter1_20_3 extends ItemRewriter<Clientboun
|
||||
updatePages(tag, "pages");
|
||||
updatePages(tag, "filtered_pages");
|
||||
}
|
||||
return super.handleItemToClient(item);
|
||||
return super.handleItemToClient(connection, item);
|
||||
}
|
||||
|
||||
private void updatePages(final CompoundTag tag, final String key) {
|
||||
|
@ -126,7 +126,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
|
||||
}
|
||||
}
|
||||
|
||||
rewriteParticle(particle);
|
||||
rewriteParticle(event.user(), particle);
|
||||
});
|
||||
|
||||
registerMetaTypeHandler(
|
||||
|
@ -39,7 +39,7 @@ public class RecipeRewriter1_20_3<C extends ClientboundPacketType> extends Recip
|
||||
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.passthrough(Type.BOOLEAN); // Show notification
|
||||
}
|
||||
|
@ -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.StringTag;
|
||||
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.minecraft.GameProfile;
|
||||
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);
|
||||
particle.add(Type.VAR_INT, protocol.getMappingData().getNewBlockStateId(blockStateId));
|
||||
} 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);
|
||||
}
|
||||
|
||||
@ -143,9 +144,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
wrapper.passthrough(Type.VAR_INT); // Container id
|
||||
final int size = wrapper.passthrough(Type.VAR_INT);
|
||||
for (int i = 0; i < size; i++) {
|
||||
final Item input = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
||||
final Item output = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
||||
final Item secondItem = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
|
||||
final Item input = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
|
||||
final Item output = handleItemToClient(wrapper.user(), 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, output);
|
||||
wrapper.write(Types1_20_5.ITEM, secondItem);
|
||||
@ -177,18 +178,18 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(@Nullable final Item item) {
|
||||
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
super.handleItemToClient(item);
|
||||
super.handleItemToClient(connection, item);
|
||||
return toStructuredItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(@Nullable final Item item) {
|
||||
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
super.handleItemToServer(item);
|
||||
super.handleItemToServer(connection, item);
|
||||
return toOldItem(item);
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
||||
if (wrapper.passthrough(Type.BOOLEAN)) {
|
||||
wrapper.passthrough(Type.COMPONENT); // Title
|
||||
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
|
||||
int flags = wrapper.passthrough(Type.INT); // Flags
|
||||
if ((flags & 1) != 0) {
|
||||
|
@ -224,7 +224,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
filter().handler((event, meta) -> {
|
||||
final MetaType type = meta.metaType();
|
||||
if (type == itemType) {
|
||||
meta.setValue(protocol.getItemRewriter().handleItemToClient(meta.value()));
|
||||
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), meta.value()));
|
||||
} else if (type == blockStateType) {
|
||||
int data = meta.value();
|
||||
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));
|
||||
}
|
||||
} 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();
|
||||
int id = particle.getId();
|
||||
int id = particle.id();
|
||||
if (mappings.isBlockParticle(id)) {
|
||||
Particle.ParticleData<Integer> data = particle.getArgument(0);
|
||||
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
|
||||
} else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) {
|
||||
Particle.ParticleData<Item> data = particle.getArgument(0);
|
||||
Item item = data.getValue();
|
||||
protocol.getItemRewriter().handleItemToClient(item);
|
||||
protocol.getItemRewriter().handleItemToClient(connection, item);
|
||||
}
|
||||
|
||||
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 {
|
||||
final Particle particle = wrapper.read(from);
|
||||
rewriteParticle(particle);
|
||||
rewriteParticle(wrapper.user(), particle);
|
||||
wrapper.write(to, particle);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
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.ParticleMappings;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
@ -51,7 +52,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(@Nullable Item item) {
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
|
||||
item.setIdentifier(protocol.getMappingData().getNewItemId(item.identifier()));
|
||||
@ -60,7 +61,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(@Nullable Item item) {
|
||||
public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
if (protocol.getMappingData() != null && protocol.getMappingData().getItemMappings() != null) {
|
||||
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);
|
||||
wrapper.write(mappedItemArrayType, items);
|
||||
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);
|
||||
wrapper.write(mappedItemArrayType, items);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = handleItemToClient(items[i]);
|
||||
items[i] = handleItemToClient(wrapper.user(), items[i]);
|
||||
}
|
||||
|
||||
handleClientboundItem(wrapper);
|
||||
@ -455,7 +456,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
map(Type.INT); // Particle Count
|
||||
handler(wrapper -> {
|
||||
final Particle particle = wrapper.read(unmappedParticleType);
|
||||
rewriteParticle(particle);
|
||||
rewriteParticle(wrapper.user(), particle);
|
||||
wrapper.write(mappedParticleType, particle);
|
||||
});
|
||||
}
|
||||
@ -484,8 +485,8 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
final Particle largeExplosionParticle = wrapper.read(unmappedParticleType);
|
||||
wrapper.write(mappedParticleType, smallExplosionParticle);
|
||||
wrapper.write(mappedParticleType, largeExplosionParticle);
|
||||
rewriteParticle(smallExplosionParticle);
|
||||
rewriteParticle(largeExplosionParticle);
|
||||
rewriteParticle(wrapper.user(), smallExplosionParticle);
|
||||
rewriteParticle(wrapper.user(), largeExplosionParticle);
|
||||
|
||||
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 {
|
||||
final Item item = handleItemToClient(wrapper.read(itemType));
|
||||
final Item item = handleItemToClient(wrapper.user(), wrapper.read(itemType));
|
||||
wrapper.write(mappedItemType, item);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected void rewriteParticle(Particle particle) {
|
||||
protected void rewriteParticle(UserConnection connection, Particle particle) {
|
||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||
int id = particle.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()));
|
||||
} else if (mappings.isItemParticle(id)) {
|
||||
Particle.ParticleData<Item> data = particle.getArgument(0);
|
||||
data.setValue(handleItemToClient(data.getValue()));
|
||||
data.setValue(handleItemToClient(connection, data.getValue()));
|
||||
}
|
||||
|
||||
particle.setId(protocol.getMappingData().getNewParticleId(id));
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
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.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
@ -96,21 +97,21 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
handleIngredient(wrapper);
|
||||
}
|
||||
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), result);
|
||||
}
|
||||
|
||||
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
handleIngredients(wrapper);
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), result);
|
||||
}
|
||||
|
||||
public void handleSmelting(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
handleIngredient(wrapper);
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), result);
|
||||
wrapper.passthrough(Type.FLOAT); // EXP
|
||||
wrapper.passthrough(Type.VAR_INT); // Cooking time
|
||||
@ -119,14 +120,14 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
|
||||
wrapper.passthrough(Type.STRING); // Group
|
||||
handleIngredient(wrapper);
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), result);
|
||||
}
|
||||
|
||||
public void handleSmithing(PacketWrapper wrapper) throws Exception {
|
||||
handleIngredient(wrapper); // Base
|
||||
handleIngredient(wrapper); // Addition
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), result);
|
||||
}
|
||||
|
||||
@ -138,7 +139,7 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
handleIngredient(wrapper); // Template
|
||||
handleIngredient(wrapper); // Base
|
||||
handleIngredient(wrapper); // Additions
|
||||
final Item result = rewrite(wrapper.read(itemType()));
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
wrapper.write(mappedItemType(), result);
|
||||
}
|
||||
|
||||
@ -148,9 +149,9 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
handleIngredient(wrapper); // Additions
|
||||
}
|
||||
|
||||
protected @Nullable Item rewrite(@Nullable Item item) {
|
||||
protected @Nullable Item rewrite(UserConnection connection, @Nullable Item item) {
|
||||
if (protocol.getItemRewriter() != null) {
|
||||
return protocol.getItemRewriter().handleItemToClient(item);
|
||||
return protocol.getItemRewriter().handleItemToClient(connection, item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
@ -160,7 +161,7 @@ public class RecipeRewriter<C extends ClientboundPacketType> {
|
||||
wrapper.write(mappedItemArrayType(), items);
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
Item item = items[i];
|
||||
items[i] = rewrite(item);
|
||||
items[i] = rewrite(wrapper.user(), item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
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.Mappings;
|
||||
import com.viaversion.viaversion.api.data.ParticleMappings;
|
||||
@ -44,7 +45,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(@Nullable Item item) {
|
||||
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
@ -62,7 +63,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(@Nullable Item item) {
|
||||
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren