Add UserConnection param to item rewriter methods

This commit is contained in:
Nassim Jahnke 2024-04-21 22:48:56 +02:00
parent c64e9acf35
commit 2a4bfb936f
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
40 changed files with 175 additions and 160 deletions

View File

@ -20,6 +20,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappings;
import com.viaversion.viabackwards.api.data.MappedItem;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
@ -45,7 +46,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
}
@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;
}
@ -80,7 +81,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
}
@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;
}

View File

@ -191,7 +191,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
filter().handler((event, meta) -> {
MetaType type = meta.metaType();
if (type == itemType) {
protocol.getItemRewriter().handleItemToClient(meta.value());
protocol.getItemRewriter().handleItemToClient(event.user(), meta.value());
} else if (type == blockStateType) {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
@ -201,7 +201,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
} else if (type == particleType) {
rewriteParticle(meta.value());
rewriteParticle(event.user(), meta.value());
} else if (type == optionalComponentType || type == componentType) {
JsonElement text = meta.value();
protocol.getTranslatableRewriter().processText(text);
@ -220,7 +220,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
filter().handler((event, meta) -> {
MetaType type = meta.metaType();
if (type == itemType) {
protocol.getItemRewriter().handleItemToClient(meta.value());
protocol.getItemRewriter().handleItemToClient(event.user(), meta.value());
} else if (type == blockStateType) {
int data = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
@ -230,7 +230,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
} else if (type == particleType) {
rewriteParticle(meta.value());
rewriteParticle(event.user(), meta.value());
} else if (type == optionalComponentType || type == componentType) {
protocol.getTranslatableRewriter().processTag(meta.value());
}

View File

@ -19,6 +19,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.MappedItem;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
@ -46,7 +47,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
}
@Override
public @Nullable Item handleItemToClient(@Nullable Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
if (item == null) {
return null;
}
@ -83,7 +84,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
MappedItem data = protocol.getMappingData() != null ? protocol.getMappingData().getMappedItem(item.identifier()) : null;
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
return super.handleItemToClient(connection, item);
}
if (item.tag() == null) {
@ -111,10 +112,10 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
}
@Override
public @Nullable Item handleItemToServer(@Nullable Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
if (item.tag() != null) {
Tag originalId = item.tag().remove(nbtTagName("id"));
if (originalId instanceof IntTag) {
@ -150,7 +151,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
translatableRewriter.processText(description);
}
final Item icon = handleItemToClient(wrapper.read(itemType()));
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
@ -198,7 +199,7 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
translatableRewriter.processTag(description);
}
final Item icon = handleItemToClient(wrapper.read(itemType()));
final Item icon = handleItemToClient(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type

View File

@ -18,6 +18,7 @@
package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
@ -44,9 +45,9 @@ public abstract class ItemRewriterBase<C extends ClientboundPacketType, S extend
}
@Override
public @Nullable Item handleItemToServer(@Nullable Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, @Nullable Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
restoreDisplayTag(item);
return item;

View File

@ -22,6 +22,7 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.MappedLegacyBlockItem;
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.BlockColors;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
@ -141,13 +142,13 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
}
@Override
public @Nullable Item handleItemToClient(@Nullable Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable Item item) {
if (item == null) return null;
MappedLegacyBlockItem data = getMappedBlockItem(item.identifier(), item.data());
if (data == null) {
// Just rewrite the id
return super.handleItemToClient(item);
return super.handleItemToClient(connection, item);
}
if (item.tag() == null) {
item.setTag(new CompoundTag());
@ -186,9 +187,9 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
}
@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);
if (item.tag() != null) {
Tag originalId = item.tag().remove(nbtTagName("id"));
if (originalId instanceof IntTag) {

View File

@ -64,7 +64,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
map(Type.SHORT); // 1 - Slot ID
map(Type.ITEM1_8); // 2 - Slot Value
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0)));
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
// Handle Llama
handler(wrapper -> {
@ -90,7 +90,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
handler(wrapper -> {
Item[] stacks = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0);
for (int i = 0; i < stacks.length; i++)
stacks[i] = handleItemToClient(stacks[i]);
stacks[i] = handleItemToClient(wrapper.user(), stacks[i]);
if (isLlama(wrapper.user())) {
Optional<ChestedHorseStorage> horse = getChestedHorse(wrapper.user());
@ -123,12 +123,12 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -150,7 +150,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
map(Type.VAR_INT); // 4 - Mode
map(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)));
// Llama slot
handler(wrapper -> {
@ -267,7 +267,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient((Item) meta.getValue()));
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
});
}
@ -288,9 +288,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
}
@Override
public Item handleItemToClient(Item item) {
public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
CompoundTag tag = item.tag();
if (tag == null) return item;
@ -303,9 +303,9 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
CompoundTag tag = item.tag();
if (tag == null) return item;

View File

@ -58,7 +58,7 @@ public class Protocol1_11_1To1_12 extends BackwardsProtocol<ClientboundPackets1_
int action = wrapper.passthrough(Type.VAR_INT);
if (action >= 0 && action <= 2) {
JsonElement component = wrapper.read(Type.COMPONENT);
wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(component.toString()));
wrapper.write(Type.COMPONENT, Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, component.toString()));
}
});

View File

@ -40,7 +40,11 @@ public class ShoulderTracker extends StoredObject {
public void update() {
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_12.CHAT_MESSAGE, null, getUser());
wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(generateString()));
try {
wrapper.write(Type.COMPONENT, Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, generateString()));
} catch (final Exception e) {
throw new RuntimeException(e);
}
wrapper.write(Type.BYTE, (byte) 2);
try {

View File

@ -21,6 +21,7 @@ package com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.packets;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import com.viaversion.viabackwards.protocol.protocol1_11_1to1_12.data.MapColorMapping;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
@ -99,12 +100,12 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem)
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
@ -146,7 +147,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
}
Item item = wrapper.get(Type.ITEM1_8, 0);
handleItemToServer(item);
handleItemToServer(wrapper.user(), item);
});
}
});
@ -179,7 +180,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient((Item) meta.getValue()));
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
});
protocol.registerServerbound(ServerboundPackets1_9_3.CLIENT_STATUS, new PacketHandlers() {
@ -198,9 +199,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
}
@Override
public @Nullable Item handleItemToClient(Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
if (item.tag() != null) {
CompoundTag backupTag = new CompoundTag();
@ -233,9 +234,9 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
}
@Override
public @Nullable Item handleItemToServer(Item item) {
public @Nullable Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
if (item.tag() != null) {
Tag tag = item.tag().remove("Via|LongArrayTags");

View File

@ -21,6 +21,7 @@ package com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.packets;
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
import com.viaversion.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
import com.viaversion.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
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;
@ -53,12 +54,12 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -76,7 +77,7 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
// Handle item metadata
protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) { // Is Item
meta.setValue(handleItemToClient((Item) meta.getValue()));
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
}
});
}
@ -88,18 +89,18 @@ public class ItemPackets1_11_1 extends LegacyBlockItemRewriter<ClientboundPacket
}
@Override
public Item handleItemToClient(Item item) {
public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
enchantmentRewriter.handleToClient(item);
return item;
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
enchantmentRewriter.handleToServer(item);
return item;

View File

@ -117,7 +117,7 @@ public class ParticleMapping {
}
private int[] rewrite(Protocol1_12_2To1_13 protocol, Item newItem) {
Item item = protocol.getItemRewriter().handleItemToClient(newItem);
Item item = protocol.getItemRewriter().handleItemToClient(null, newItem);
return new int[]{item.identifier(), item.data()};
}
}), // (27->36) minecraft:item -> iconcrack

View File

@ -260,7 +260,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
handler(wrapper -> {
final Item[] items = wrapper.get(Type.ITEM1_8_SHORT_ARRAY, 0);
for (Item item : items) {
handleItemToClient(item);
handleItemToClient(wrapper.user(), item);
}
});
}
@ -273,7 +273,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.SHORT);
map(Type.ITEM1_13, Type.ITEM1_8);
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0)));
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
}
});
@ -443,7 +443,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.VAR_INT);
map(Type.ITEM1_13, Type.ITEM1_8);
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_8, 0)));
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_8, 0)));
}
});
@ -471,7 +471,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.SHORT);
map(Type.ITEM1_8, Type.ITEM1_13);
handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0)));
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0)));
}
});
@ -485,7 +485,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
map(Type.VAR_INT);
map(Type.ITEM1_8, Type.ITEM1_13);
handler(wrapper -> handleItemToServer(wrapper.get(Type.ITEM1_13, 0)));
handler(wrapper -> handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0)));
}
});
}
@ -499,7 +499,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
}
@Override
public Item handleItemToClient(Item item) {
public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
// Custom mappings/super call moved down
@ -519,7 +519,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
if (rawId == null) {
// Look for custom mappings
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
// Handle one-way special case
if (item.identifier() == -1) {
@ -744,7 +744,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
CompoundTag tag = item.tag();
@ -812,7 +812,7 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
// Handle custom mappings
int identifier = item.identifier();
item.setIdentifier(rawId);
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
// Mapped with original data, we can return here
if (item.identifier() != rawId && item.identifier() != -1) return item;

View File

@ -291,7 +291,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
meta.setTypeAndValue(MetaType1_12.String, protocol.jsonToLegacy(element));
} else if (typeId == 6) {
Item item = (Item) meta.getValue();
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getItemRewriter().handleItemToClient(item));
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getItemRewriter().handleItemToClient(event.user(), item));
} else if (typeId == 15) {
// Discontinue particles
event.cancel();
@ -333,7 +333,7 @@ public class EntityPackets1_13 extends LegacyEntityRewriter<ClientboundPackets1_
filter().type(EntityTypes1_13.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, meta) -> {
Particle particle = (Particle) meta.getValue();
ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId());
ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.id());
int firstArg = 0;
int secondArg = 0;

View File

@ -81,16 +81,16 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
for (int i = 0; i < size; i++) {
//Input Item
Item input = wrapper.read(Type.ITEM1_13);
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(input));
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), input));
//Output Item
Item output = wrapper.read(Type.ITEM1_13);
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(output));
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), output));
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); //Has second item
if (secondItem) {
//Second Item
Item second = wrapper.read(Type.ITEM1_13);
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(second));
wrapper.write(Type.ITEM1_8, protocol.getItemRewriter().handleItemToClient(wrapper.user(), second));
}
wrapper.passthrough(Type.BOOLEAN); //Trade disabled
@ -379,7 +379,7 @@ public class PlayerPacket1_13 extends RewriterBase<Protocol1_12_2To1_13> {
case "MC|BEdit":
wrapper.setPacketType(ServerboundPackets1_13.EDIT_BOOK);
Item book = wrapper.read(Type.ITEM1_8);
wrapper.write(Type.ITEM1_13, protocol.getItemRewriter().handleItemToServer(book));
wrapper.write(Type.ITEM1_13, protocol.getItemRewriter().handleItemToServer(wrapper.user(), book));
boolean signing = channel.equals("MC|BSign");
wrapper.write(Type.BOOLEAN, signing);
break;

View File

@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.rewriters.EnchantmentRewriter;
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
@ -69,7 +70,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
@Override
protected void registerPackets() {
protocol.registerServerbound(ServerboundPackets1_13.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
protocol.registerServerbound(ServerboundPackets1_13.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
protocol.registerClientbound(ClientboundPackets1_14.OPEN_WINDOW, wrapper -> {
int windowId = wrapper.read(Type.VAR_INT);
@ -185,20 +186,20 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
for (int i = 0; i < size; i++) {
// Input Item
Item input = wrapper.read(Type.ITEM1_13_2);
input = handleItemToClient(input);
input = handleItemToClient(wrapper.user(), input);
wrapper.write(Type.ITEM1_13_2, input);
// Output Item
Item output = wrapper.read(Type.ITEM1_13_2);
output = handleItemToClient(output);
output = handleItemToClient(wrapper.user(), output);
wrapper.write(Type.ITEM1_13_2, output);
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
// Second Item
Item second = wrapper.read(Type.ITEM1_13_2);
second = handleItemToClient(second);
second = handleItemToClient(wrapper.user(), second);
wrapper.write(Type.ITEM1_13_2, second);
}
@ -228,7 +229,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
map(Type.VAR_INT); // 1 - Slot ID
map(Type.ITEM1_13_2); // 2 - Item
handler(wrapper -> handleItemToClient(wrapper.get(Type.ITEM1_13_2, 0)));
handler(wrapper -> handleItemToClient(wrapper.user(), wrapper.get(Type.ITEM1_13_2, 0)));
handler(wrapper -> {
int entityId = wrapper.get(Type.VAR_INT, 0);
@ -465,9 +466,9 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
}
@Override
public Item handleItemToClient(Item item) {
public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
// Lore now uses JSON
CompoundTag tag = item.tag();
@ -491,7 +492,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
// Lore now uses JSON
@ -510,7 +511,7 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
enchantmentRewriter.handleToServer(item);
// Call this last to check for the backup lore above
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
return item;
}
}

View File

@ -383,7 +383,7 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
});
filter().type(EntityTypes1_14.AREA_EFFECT_CLOUD).index(10).handler((event, meta) -> {
rewriteParticle((Particle) meta.getValue());
rewriteParticle(event.user(), (Particle) meta.getValue());
});
filter().type(EntityTypes1_14.FIREWORK_ROCKET).index(8).handler((event, meta) -> {

View File

@ -92,7 +92,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
map(Type.ITEM1_13);
map(Type.BOOLEAN);
handler(wrapper -> {
itemRewriter.handleItemToServer(wrapper.get(Type.ITEM1_13, 0));
itemRewriter.handleItemToServer(wrapper.user(), wrapper.get(Type.ITEM1_13, 0));
wrapper.write(Type.VAR_INT, 0);
});
}
@ -181,7 +181,7 @@ public class Protocol1_13To1_13_1 extends BackwardsProtocol<ClientboundPackets1_
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
Item icon = wrapper.passthrough(Type.ITEM1_13);
itemRewriter.handleItemToClient(icon);
itemRewriter.handleItemToClient(wrapper.user(), icon);
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0)

View File

@ -133,13 +133,13 @@ public class EntityPackets1_13_1 extends LegacyEntityRewriter<ClientboundPackets
// Rewrite items & blocks
filter().handler((event, meta) -> {
if (meta.metaType() == Types1_13.META_TYPES.itemType) {
protocol.getItemRewriter().handleItemToClient((Item) meta.getValue());
protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue());
} else if (meta.metaType() == Types1_13.META_TYPES.blockStateType) {
// Convert to new block id
int data = (int) meta.getValue();
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (meta.metaType() == Types1_13.META_TYPES.particleType) {
rewriteParticle((Particle) meta.getValue());
rewriteParticle(event.user(), (Particle) meta.getValue());
} else if (meta.metaType() == Types1_13.META_TYPES.optionalComponentType || meta.metaType() == Types1_13.META_TYPES.componentType) {
JsonElement element = meta.value();
protocol.translatableRewriter().processText(element);

View File

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

View File

@ -44,7 +44,7 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit
new RecipeRewriter<>(protocol).register(ClientboundPackets1_15.DECLARE_RECIPES);
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
registerSetCooldown(ClientboundPackets1_15.COOLDOWN);
registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS);
@ -122,7 +122,7 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit
int data = wrapper.passthrough(Type.VAR_INT);
wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data));
} else if (id == 32) {
Item item = handleItemToClient(wrapper.read(Type.ITEM1_13_2));
Item item = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2));
wrapper.write(Type.ITEM1_13_2, item);
}

View File

@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.rewriters.MapColorRewriter;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import com.viaversion.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewrites;
import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.storage.BiomeStorage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
@ -111,7 +112,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
byte slot;
do {
slot = wrapper.read(Type.BYTE);
Item item = handleItemToClient(wrapper.read(Type.ITEM1_13_2));
Item item = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_13_2));
int rawSlot = slot & 0x7F;
equipmentData.add(new EquipmentData(rawSlot, item));
} while ((slot & 0xFFFFFF80) != 0);
@ -248,7 +249,7 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION);
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.passthrough(Type.ITEM1_13_2)));
protocol.registerServerbound(ServerboundPackets1_14.EDIT_BOOK, wrapper -> handleItemToServer(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)));
}
private void handleBlockEntity(CompoundTag tag) {
@ -290,10 +291,10 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
}
@Override
public Item handleItemToClient(Item item) {
public Item handleItemToClient(UserConnection connection, Item item) {
if (item == null) return null;
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
CompoundTag tag = item.tag();
if (item.identifier() == 771 && tag != null) {
@ -324,11 +325,11 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
}
@Override
public Item handleItemToServer(Item item) {
public Item handleItemToServer(UserConnection connection, Item item) {
if (item == null) return null;
int identifier = item.identifier();
super.handleItemToServer(item);
super.handleItemToServer(connection, item);
CompoundTag tag = item.tag();
if (identifier == 771 && tag != null) {

View File

@ -244,11 +244,11 @@ public class EntityPackets1_16 extends EntityRewriter<ClientboundPackets1_16, Pr
MetaType type = meta.metaType();
if (type == Types1_14.META_TYPES.itemType) {
meta.setValue(protocol.getItemRewriter().handleItemToClient((Item) meta.getValue()));
meta.setValue(protocol.getItemRewriter().handleItemToClient(event.user(), (Item) meta.getValue()));
} else if (type == Types1_14.META_TYPES.blockStateType) {
meta.setValue(protocol.getMappingData().getNewBlockStateId((int) meta.getValue()));
} else if (type == Types1_14.META_TYPES.particleType) {
rewriteParticle((Particle) meta.getValue());
rewriteParticle(event.user(), (Particle) meta.getValue());
} else if (type == Types1_14.META_TYPES.optionalComponentType) {
JsonElement text = meta.value();
if (text != null) {

View File

@ -133,7 +133,7 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
registerClickWindow(ServerboundPackets1_16.CLICK_WINDOW);
registerCreativeInvAction(ServerboundPackets1_16.CREATIVE_INVENTORY_ACTION);
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)));
}
private void handleBlockEntity(CompoundTag tag) {

View File

@ -77,7 +77,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
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)));
// TODO Since the carried and modified items are typically set incorrectly, the server sends unnecessary
// set slot packets after practically every window click, since it thinks the client and server
@ -95,7 +95,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
byte button = wrapper.passthrough(Type.BYTE); // Button
wrapper.read(Type.SHORT); // Action id - removed
int mode = wrapper.passthrough(Type.VAR_INT); // Mode
Item clicked = handleItemToServer(wrapper.read(Type.ITEM1_13_2)); // Clicked item
Item clicked = handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)); // Clicked item
// The 1.17 client would check the entire inventory for changes before -> after a click and send the changed slots here
wrapper.write(Type.VAR_INT, 0); // Empty array of slot+item
@ -152,7 +152,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
wrapper.user().get(PlayerLastCursorItem.class).setLastCursorItem(carried);
}
wrapper.write(Type.ITEM1_13_2, handleItemToClient(carried));
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), carried));
});
protocol.registerServerbound(ServerboundPackets1_16_2.WINDOW_CONFIRMATION, null, wrapper -> {

View File

@ -153,17 +153,17 @@ public final class EntityPackets1_17 extends EntityRewriter<ClientboundPackets1_
MetaType type = meta.metaType();
if (type == Types1_16.META_TYPES.particleType) {
Particle particle = (Particle) meta.getValue();
if (particle.getId() == 16) { // Dust / Dust Transition
if (particle.id() == 16) { // Dust / Dust Transition
// Remove transition target color values 4-6
particle.getArguments().subList(4, 7).clear();
} else if (particle.getId() == 37) { // Vibration Signal
} else if (particle.id() == 37) { // Vibration Signal
// No nice mapping possible without tracking entity positions and doing particle tasks
particle.setId(0);
particle.getArguments().clear();
return;
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
} else if (type == Types1_16.META_TYPES.poseType) {
// Goat LONG_JUMP added at 6
int pose = meta.value();

View File

@ -112,7 +112,7 @@ public final class BlockItemPackets1_18 extends ItemRewriter<ClientboundPackets1
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);

View File

@ -99,7 +99,7 @@ public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_
MetaType type = meta.metaType();
if (type == Types1_17.META_TYPES.particleType) {
Particle particle = meta.value();
if (particle.getId() == 3) { // Block marker
if (particle.id() == 3) { // Block marker
Particle.ParticleData<?> data = particle.getArguments().remove(0);
int blockState = (int) data.getValue();
if (blockState == 7786) { // Light block
@ -111,7 +111,7 @@ public final class EntityPackets1_18 extends EntityRewriter<ClientboundPackets1_
return;
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
}
});

View File

@ -70,12 +70,12 @@ public final class BlockItemPackets1_19 extends ItemRewriter<ClientboundPackets1
final int size = wrapper.read(Type.VAR_INT);
wrapper.write(Type.UNSIGNED_BYTE, (short) 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
final Item secondItem = wrapper.read(Type.ITEM1_13_2);
if (secondItem != null) {
handleItemToClient(secondItem);
handleItemToClient(wrapper.user(), secondItem);
wrapper.write(Type.BOOLEAN, true);
wrapper.write(Type.ITEM1_13_2, secondItem);
} else {

View File

@ -243,21 +243,21 @@ public final class EntityPackets1_19 extends EntityRewriter<ClientboundPackets1_
if (type == Types1_18.META_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue();
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
if (particle.getId() == particleMappings.id("sculk_charge")) {
if (particle.id() == particleMappings.id("sculk_charge")) {
//TODO
event.cancel();
return;
} else if (particle.getId() == particleMappings.id("shriek")) {
} else if (particle.id() == particleMappings.id("shriek")) {
//TODO
event.cancel();
return;
} else if (particle.getId() == particleMappings.id("vibration")) {
} else if (particle.id() == particleMappings.id("vibration")) {
// Can't do without the position
event.cancel();
return;
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
} else if (type == Types1_18.META_TYPES.poseType) {
final int pose = meta.value();
if (pose >= 8) {

View File

@ -79,10 +79,10 @@ public final class BlockItemPackets1_19_3 extends ItemRewriter<ClientboundPacket
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": {
@ -92,10 +92,10 @@ public final class BlockItemPackets1_19_3 extends ItemRewriter<ClientboundPacket
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":
@ -106,9 +106,9 @@ public final class BlockItemPackets1_19_3 extends ItemRewriter<ClientboundPacket
wrapper.read(Type.VAR_INT); // 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;

View File

@ -84,7 +84,7 @@ public final class BlockItemPackets1_19_4 extends ItemRewriter<ClientboundPacket
for (int i = 0; i < ingredients; i++) {
handleIngredient(wrapper);
}
rewrite(wrapper.passthrough(Type.ITEM1_13_2)); // Result
rewrite(wrapper.user(), wrapper.passthrough(Type.ITEM1_13_2)); // Result
// Remove notification boolean
wrapper.read(Type.BOOLEAN);

View File

@ -20,6 +20,7 @@ package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets;
import com.viaversion.viabackwards.api.rewriters.ItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.storage.BackSignEditStorage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
@ -109,7 +110,7 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
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) {
@ -150,12 +151,12 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
}
@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);
// Remove new trim tags
final CompoundTag trimTag;
@ -174,12 +175,12 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
}
@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);
// Add back original trim tag
final Tag trimTag;

View File

@ -152,7 +152,7 @@ public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol<ClientboundP
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) {

View File

@ -107,7 +107,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_3.DECLARE_RECIPES);

View File

@ -107,7 +107,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
} else if (type == Types1_20_3.META_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue();
final ParticleMappings particleMappings = protocol.getMappingData().getParticleMappings();
if (particle.getId() == particleMappings.id("vibration")) {
if (particle.id() == particleMappings.id("vibration")) {
// Change the type of the position source type argument
final int positionSourceType = particle.<Integer>removeArgument(0).getValue();
if (positionSourceType == 0) {
@ -117,7 +117,7 @@ public final class EntityPacketRewriter1_20_3 extends EntityRewriter<Clientbound
}
}
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
} else if (type == Types1_20_3.META_TYPES.poseType) {
final int pose = meta.value();
if (pose >= 15) {

View File

@ -20,6 +20,7 @@ package com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.rewriter;
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20_3to1_20_5.Protocol1_20_3To1_20_5;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
@ -77,7 +78,7 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
// Move it to the beginning, move out arguments here
final Particle particle = wrapper.read(Types1_20_5.PARTICLE);
rewriteParticle(particle);
rewriteParticle(wrapper.user(), particle);
wrapper.set(Type.VAR_INT, 0, particle.id());
for (final Particle.ParticleData<?> argument : particle.getArguments()) {
argument.write(wrapper);
@ -119,11 +120,11 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
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(Types1_20_5.ITEM));
final Item input = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, input);
final Item output = handleItemToClient(wrapper.read(Types1_20_5.ITEM));
final Item output = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, output);
final Item secondItem = handleItemToClient(wrapper.read(Types1_20_5.ITEM));
final Item secondItem = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, secondItem);
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -154,19 +155,19 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
}
@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;
super.handleItemToClient(item);
super.handleItemToClient(connection, item);
return vvProtocol.getItemRewriter().toOldItem(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;
// Convert to structured item first
final Item structuredItem = vvProtocol.getItemRewriter().toStructuredItem(item);
return super.handleItemToServer(structuredItem);
return super.handleItemToServer(connection, structuredItem);
}
}

View File

@ -69,7 +69,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
wrapper.write(Type.BYTE, slot);
final Item item = protocol.getItemRewriter().handleItemToClient(wrapper.read(Types1_20_5.ITEM));
final Item item = protocol.getItemRewriter().handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
wrapper.write(Type.ITEM1_20_2, item);
} while (slot < 0);
});

View File

@ -19,6 +19,7 @@ package com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.rewriter;
import com.viaversion.viabackwards.api.rewriters.ItemRewriter;
import com.viaversion.viabackwards.protocol.protocol1_20to1_20_2.Protocol1_20To1_20_2;
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;
@ -149,11 +150,11 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
handler(wrapper -> {
final Item[] items = wrapper.read(Type.ITEM1_20_2_ARRAY);
for (final Item item : items) {
handleItemToClient(item);
handleItemToClient(wrapper.user(), item);
}
wrapper.write(Type.ITEM1_13_2_ARRAY, items);
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Carried item
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Carried item
});
}
});
@ -163,7 +164,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_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))));
handler(wrapper -> wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))));
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.ADVANCEMENTS, wrapper -> {
@ -181,7 +182,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_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Icon
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
final int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0) {
@ -209,7 +210,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
byte slot;
do {
slot = wrapper.passthrough(Type.BYTE);
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2)));
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
} while ((slot & 0xFFFFFF80) != 0);
});
}
@ -228,11 +229,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_20_2, handleItemToServer(wrapper.read(Type.ITEM1_13_2)));
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
}
// Carried item
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.read(Type.ITEM1_13_2)));
wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)));
});
}
});
@ -240,9 +241,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_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Input
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Output
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2))); // Second Item
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Input
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Output
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2))); // Second Item
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
@ -257,7 +258,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_20_2, handleItemToServer(wrapper.read(Type.ITEM1_13_2)))); // 1 - Clicked Item
handler(wrapper -> wrapper.write(Type.ITEM1_20_2, handleItemToServer(wrapper.user(), wrapper.read(Type.ITEM1_13_2)))); // 1 - Clicked Item
}
});
protocol.registerClientbound(ClientboundPackets1_20_2.SPAWN_PARTICLE, new PacketHandlers() {
@ -280,7 +281,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_13_2, handleItemToClient(wrapper.read(Type.ITEM1_20_2)));
wrapper.write(Type.ITEM1_13_2, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2)));
}
});
}
@ -294,7 +295,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_13_2, result);
}
@ -305,7 +306,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_13_2, result);
wrapper.passthrough(Type.FLOAT); // EXP
@ -322,7 +323,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_13_2, result);
wrapper.passthrough(Type.BOOLEAN); // Show notification
@ -334,7 +335,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_13_2, result);
}
@ -344,7 +345,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_13_2, result);
}
@ -355,7 +356,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_13_2, result);
}
@ -364,14 +365,14 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
final Item[] items = wrapper.read(itemArrayType());
wrapper.write(Type.ITEM1_13_2_ARRAY, items);
for (final Item item : items) {
rewrite(item);
rewrite(wrapper.user(), item);
}
}
}.register(ClientboundPackets1_20_2.DECLARE_RECIPES);
}
@Override
public @Nullable Item handleItemToClient(@Nullable final Item item) {
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable final Item item) {
if (item == null) {
return null;
}
@ -379,11 +380,11 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.BlockItemPacketRewriter1_20_2.to1_20_1Effects(item);
}
return super.handleItemToClient(item);
return super.handleItemToClient(connection, 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;
}
@ -391,7 +392,7 @@ public final class BlockItemPacketRewriter1_20_2 extends ItemRewriter<Clientboun
com.viaversion.viaversion.protocols.protocol1_20_2to1_20.rewriter.BlockItemPacketRewriter1_20_2.to1_20_2Effects(item);
}
return super.handleItemToServer(item);
return super.handleItemToServer(connection, item);
}
private @Nullable CompoundTag handleBlockEntity(@Nullable final CompoundTag tag) {

View File

@ -57,12 +57,12 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPac
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Output Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Input Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Output Item
boolean secondItem = wrapper.passthrough(Type.BOOLEAN); // Has second item
if (secondItem) {
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.read(Type.ITEM1_8))); // Second Item
wrapper.write(Type.ITEM1_8, handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_8))); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
@ -89,7 +89,7 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPac
// Rewrite metadata items
protocol.getEntityRewriter().filter().handler((event, meta) -> {
if (meta.metaType().type().equals(Type.ITEM1_8)) // Is Item
meta.setValue(handleItemToClient((Item) meta.getValue()));
meta.setValue(handleItemToClient(event.user(), (Item) meta.getValue()));
});
// Particle