Merge branch 'refs/heads/dev' into preview

# Conflicts:
#	common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java
#	common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java
#	common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java
This commit is contained in:
Nassim Jahnke 2024-04-21 22:51:45 +02:00
commit 5e4f25efeb
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
54 changed files with 243 additions and 217 deletions

View File

@ -27,8 +27,6 @@ import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;
import it.unimi.dsi.fastutil.ints.IntSet;
import org.checkerframework.checker.nullness.qual.Nullable;
public interface ViaVersionConfig extends Config {
@ -235,13 +233,6 @@ public interface ViaVersionConfig extends Config {
*/
boolean isChunkBorderFix();
/**
* Force json transform
*
* @return true if enabled
*/
boolean isForceJsonTransform();
/**
* Should we fix nbt array's in json chat messages for 1.12 clients
*
@ -452,4 +443,11 @@ public interface ViaVersionConfig extends Config {
* @return true if enabled
*/
boolean isArmorToggleFix();
/**
* If disabled, tamed cats will be displayed as ocelots to 1.14+ clients on 1.13 servers. Otherwise, ocelots (tamed and untamed) will be displayed as cats.
*
* @return true if enabled
*/
boolean translateOcelotToCat();
}

View File

@ -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.

View File

@ -63,7 +63,7 @@ public class DeathListener extends ViaBukkitListener {
wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
wrapper.write(Type.INT, p.getEntityId()); // Entity ID
Protocol1_9To1_8.FIX_JSON.write(wrapper, msg); // Message
Protocol1_9To1_8.STRING_TO_JSON.write(wrapper, msg); // Message
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {

View File

@ -63,7 +63,6 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private int pistonReplacementId;
private boolean chunkBorderFix;
private boolean autoTeam;
private boolean forceJsonTransform;
private boolean nbtArrayFix;
private BlockedProtocolVersions blockedProtocolVersions;
private String blockedDisconnectMessage;
@ -89,6 +88,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private JsonElement resourcePack1_17PromptMessage;
private WorldIdentifiers map1_16WorldNames;
private boolean cache1_17Light;
private boolean translateOcelotToCat;
protected AbstractViaConfig(final File configFile) {
super(configFile);
@ -128,7 +128,6 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
pistonReplacementId = getInt("replacement-piston-id", 0);
chunkBorderFix = getBoolean("chunk-border-fix", false);
autoTeam = getBoolean("auto-team", true);
forceJsonTransform = getBoolean("force-json-transform", false);
nbtArrayFix = getBoolean("chat-nbt-fix", true);
blockedProtocolVersions = loadBlockedProtocolVersions();
blockedDisconnectMessage = getString("block-disconnect-msg", "You are using an unsupported Minecraft version!");
@ -157,6 +156,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
worlds.getOrDefault("nether", WorldIdentifiers.NETHER_DEFAULT),
worlds.getOrDefault("end", WorldIdentifiers.END_DEFAULT));
cache1_17Light = getBoolean("cache-1_17-light", true);
translateOcelotToCat = getBoolean("translate-ocelot-to-cat", true);
}
private BlockedProtocolVersions loadBlockedProtocolVersions() {
@ -369,11 +369,6 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
return preventCollision && autoTeam;
}
@Override
public boolean isForceJsonTransform() {
return forceJsonTransform;
}
@Override
public boolean is1_12NBTArrayFix() {
return nbtArrayFix;
@ -528,4 +523,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
public boolean isArmorToggleFix() {
return false;
}
@Override
public boolean translateOcelotToCat() {
return translateOcelotToCat;
}
}

View File

@ -29,6 +29,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.ClientboundPackets1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
@ -245,7 +246,7 @@ public class CommonBoss implements BossBar {
wrapper.write(Type.VAR_INT, action.getId());
switch (action) {
case ADD:
Protocol1_9To1_8.FIX_JSON.write(wrapper, title);
wrapper.write(Type.COMPONENT, ComponentUtil.plainToJson(title));
wrapper.write(Type.FLOAT, health);
wrapper.write(Type.VAR_INT, color.getId());
wrapper.write(Type.VAR_INT, style.getId());
@ -257,7 +258,7 @@ public class CommonBoss implements BossBar {
wrapper.write(Type.FLOAT, health);
break;
case UPDATE_TITLE:
Protocol1_9To1_8.FIX_JSON.write(wrapper, title);
wrapper.write(Type.COMPONENT, ComponentUtil.plainToJson(title));
break;
case UPDATE_STYLE:
wrapper.write(Type.VAR_INT, color.getId());

View File

@ -37,8 +37,8 @@ import com.viaversion.viaversion.protocol.ServerProtocolVersionSingleton;
import com.viaversion.viaversion.protocols.base.packet.BaseClientboundPacket;
import com.viaversion.viaversion.protocols.base.packet.BasePacketTypesProvider;
import com.viaversion.viaversion.protocols.base.packet.BaseServerboundPacket;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.util.ChatColorUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.GsonUtil;
import io.netty.channel.ChannelFuture;
import java.util.List;
@ -163,8 +163,10 @@ public class BaseProtocol1_7 extends AbstractProtocol<BaseClientboundPacket, Bas
if (!wrapper.user().getChannel().isOpen()) return;
if (!wrapper.user().shouldApplyBlockProtocol()) return;
final String disconnectMessage = ChatColorUtil.translateAlternateColorCodes(Via.getConfig().getBlockedDisconnectMsg());
PacketWrapper disconnectPacket = PacketWrapper.create(ClientboundLoginPackets.LOGIN_DISCONNECT, wrapper.user()); // Disconnect Packet
Protocol1_9To1_8.FIX_JSON.write(disconnectPacket, ChatColorUtil.translateAlternateColorCodes(Via.getConfig().getBlockedDisconnectMsg()));
wrapper.write(Type.COMPONENT, ComponentUtil.plainToJson(disconnectMessage));
wrapper.cancel(); // cancel current
// Send and close

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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()));
}
});

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -528,7 +528,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
@ -597,7 +597,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);

View File

@ -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()) {

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -39,7 +39,12 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPack
public MetadataRewriter1_14To1_13_2(Protocol1_14To1_13_2 protocol) {
super(protocol);
mapTypes(EntityTypes1_13.EntityType.values(), EntityTypes1_14.class);
mapEntityType(EntityTypes1_13.EntityType.OCELOT, EntityTypes1_14.CAT);
if (Via.getConfig().translateOcelotToCat()) {
// A better solution for this would be to despawn the ocelot and spawn a cat in its place, but that would
// require a lot of data tracking and is not worth the effort.
mapEntityType(EntityTypes1_13.EntityType.OCELOT, EntityTypes1_14.CAT);
}
}
@Override
@ -163,6 +168,12 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter<ClientboundPack
}
});
filter().type(EntityTypes1_14.OCELOT).removeIndex(17); // variant
// Ocelot is not tamable anymore
filter().type(EntityTypes1_14.OCELOT).removeIndex(16); // owner uuid
filter().type(EntityTypes1_14.OCELOT).removeIndex(15); // data
filter().handler((event, meta) -> {
EntityType type = event.entityType();
if (type.is(EntityTypes1_14.WITCH) || type.is(EntityTypes1_14.RAVAGER) || type.isOrHasParent(EntityTypes1_14.ABSTRACT_ILLAGER_BASE)) {

View File

@ -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()));

View File

@ -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;

View File

@ -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);
}

View File

@ -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));
}
});
}

View File

@ -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);
}

View File

@ -22,7 +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.github.steveice10.opennbt.tag.builtin.Tag;
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;
@ -120,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));
});
}
});
@ -135,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();
@ -170,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()));

View File

@ -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();

View File

@ -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);
}
});

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -336,7 +336,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);

View File

@ -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);
}

View File

@ -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 -> {
@ -149,7 +150,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) {
@ -178,7 +179,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);
});
}
@ -197,11 +198,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)));
});
}
});
@ -209,9 +210,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
@ -227,7 +228,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() {
@ -250,7 +251,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)));
}
});
}
@ -264,7 +265,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);
}
@ -275,7 +276,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
@ -292,7 +293,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
@ -304,7 +305,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);
}
@ -314,7 +315,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);
}
@ -325,7 +326,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);
}
@ -334,14 +335,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;
}
@ -350,11 +351,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;
}
@ -363,7 +364,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) {

View File

@ -134,7 +134,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) {

View File

@ -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"); // TODO This isn't a list
}
return super.handleItemToClient(item);
return super.handleItemToClient(connection, item);
}
private void updatePages(final CompoundTag tag, final String key) {

View File

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

View File

@ -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
}

View File

@ -27,6 +27,7 @@ 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.Via;
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.GlobalPosition;
@ -224,7 +225,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 = handleNonNullItemToClient(wrapper.read(Type.ITEM1_20_2));
final Item item = handleNonNullItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
particle.add(Types1_20_5.ITEM, item);
} else if (particleId == mappings.id("dust")) {
// R, g, b, scale
@ -278,13 +279,13 @@ 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 input = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
wrapper.write(Types1_20_5.ITEM_COST, input);
final Item output = handleNonNullItemToClient(wrapper.read(Type.ITEM1_20_2));
final Item output = handleNonNullItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
wrapper.write(Types1_20_5.ITEM, output);
final Item secondInput = handleItemToClient(wrapper.read(Type.ITEM1_20_2));
final Item secondInput = handleItemToClient(wrapper.user(), wrapper.read(Type.ITEM1_20_2));
wrapper.write(Types1_20_5.OPTIONAL_ITEM_COST, secondInput);
wrapper.passthrough(Type.BOOLEAN); // Out of stock
@ -331,7 +332,7 @@ 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;
// Add the original as custom data, to be re-used for creative clients as well
@ -341,14 +342,14 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
final Item structuredItem = toStructuredItem(item);
return super.handleItemToClient(structuredItem);
return super.handleItemToClient(connection, structuredItem);
}
@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, DATA_CONVERTER);
}

View File

@ -72,7 +72,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) {

View File

@ -283,7 +283,7 @@ public class ItemRewriter {
for (int i = 0; i < pages.size(); i++) {
final StringTag page = pages.get(i);
page.setValue(ComponentUtil.convertJson(page.getValue(), SerializerVersion.V1_8, SerializerVersion.V1_9).toString());
page.setValue(ComponentUtil.convertJsonOrEmpty(page.getValue(), SerializerVersion.V1_8, SerializerVersion.V1_9).toString());
}
item.setTag(tag);
}

View File

@ -18,7 +18,6 @@
package com.viaversion.viaversion.protocols.protocol1_9to1_8;
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.ClientWorld;
@ -49,13 +48,15 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.CommandBlock
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.InventoryTracker;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.SerializerVersion;
public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, ClientboundPackets1_9, ServerboundPackets1_8, ServerboundPackets1_9> {
public static final ValueTransformer<String, JsonElement> FIX_JSON = new ValueTransformer<String, JsonElement>(Type.COMPONENT) {
public static final ValueTransformer<String, JsonElement> STRING_TO_JSON = new ValueTransformer<String, JsonElement>(Type.COMPONENT) {
@Override
public JsonElement transform(PacketWrapper wrapper, String line) {
return fixJson(line);
return ComponentUtil.convertJsonOrEmpty(line, SerializerVersion.V1_8, SerializerVersion.V1_9);
}
};
private final MetadataRewriter1_9To1_8 metadataRewriter = new MetadataRewriter1_9To1_8(this);
@ -64,35 +65,6 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
super(ClientboundPackets1_8.class, ClientboundPackets1_9.class, ServerboundPackets1_8.class, ServerboundPackets1_9.class);
}
public static JsonElement fixJson(String line) {
if (line == null || line.equalsIgnoreCase("null")) {
line = "{\"text\":\"\"}";
} else {
if ((!line.startsWith("\"") || !line.endsWith("\"")) && (!line.startsWith("{") || !line.endsWith("}"))) {
return constructJson(line);
}
if (line.startsWith("\"") && line.endsWith("\"")) {
line = "{\"text\":" + line + "}";
}
}
try {
return GsonUtil.getGson().fromJson(line, JsonObject.class);
} catch (Exception e) {
if (Via.getConfig().isForceJsonTransform()) {
return constructJson(line);
} else {
Via.getPlatform().getLogger().warning("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage());
return GsonUtil.getGson().fromJson("{\"text\":\"\"}", JsonObject.class);
}
}
}
private static JsonElement constructJson(String text) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("text", text);
return jsonObject;
}
public static Item getHandItem(final UserConnection info) {
return Via.getManager().getProviders().get(HandItemProvider.class).getHandItem(info);
}
@ -121,7 +93,7 @@ public class Protocol1_9To1_8 extends AbstractProtocol<ClientboundPackets1_8, Cl
return;
}
wrapper.write(Type.COMPONENT, fixJson(wrapper.read(Type.STRING)));
STRING_TO_JSON.write(wrapper, wrapper.read(Type.STRING));
});
// Other Handlers

View File

@ -163,7 +163,7 @@ public enum MetaIndex {
ABSTRACT_MINECART_BLOCK_Y(MINECART_ABSTRACT, 21, MetaType1_8.Int, 9, MetaType1_9.VarInt),
ABSTRACT_MINECART_SHOW_BLOCK(MINECART_ABSTRACT, 22, MetaType1_8.Byte, 10, MetaType1_9.Boolean),
// Command minecart (they are still broken)
// Command minecart
MINECART_COMMAND_BLOCK_COMMAND(MINECART_ABSTRACT, 23, MetaType1_8.String, 11, MetaType1_9.String),
MINECART_COMMAND_BLOCK_OUTPUT(MINECART_ABSTRACT, 24, MetaType1_8.String, 12, MetaType1_9.Chat),

View File

@ -30,6 +30,8 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.ItemRewriter;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.SerializerVersion;
import java.util.UUID;
public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1_8, Protocol1_9To1_8> {
@ -127,8 +129,9 @@ public class MetadataRewriter1_9To1_8 extends EntityRewriter<ClientboundPackets1
metadata.setValue(angle);
break;
case Chat:
value = Protocol1_9To1_8.fixJson(value.toString());
metadata.setValue(value);
// Was previously also a component, so just convert it
String text = (String) value;
metadata.setValue(ComponentUtil.convertJsonOrEmpty(text, SerializerVersion.V1_8, SerializerVersion.V1_9));
break;
case BlockID:
// Convert from int, short, byte

View File

@ -253,7 +253,7 @@ public class EntityPackets {
if (wrapper.get(Type.VAR_INT, 0) == 2) { // entity dead
wrapper.passthrough(Type.VAR_INT); //Player id
wrapper.passthrough(Type.INT); //Entity id
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
Protocol1_9To1_8.STRING_TO_JSON.write(wrapper, wrapper.read(Type.STRING));
}
});
}

View File

@ -69,7 +69,7 @@ public class InventoryPackets {
public void register() {
map(Type.UNSIGNED_BYTE); // 0 - Window ID
map(Type.STRING); // 1 - Window Type
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 2 - Window Title
map(Type.STRING, Protocol1_9To1_8.STRING_TO_JSON); // 2 - Window Title
map(Type.UNSIGNED_BYTE); // 3 - Slot Count
// There is a horse parameter after this, we don't handle it and let it passthrough
// Inventory tracking

View File

@ -37,6 +37,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MainHandPr
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.logging.Level;
public class PlayerPackets {
@ -44,7 +45,7 @@ public class PlayerPackets {
protocol.registerClientbound(ClientboundPackets1_8.CHAT_MESSAGE, new PacketHandlers() {
@Override
public void register() {
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Chat Message (json)
map(Type.STRING, Protocol1_9To1_8.STRING_TO_JSON); // 0 - Chat Message (json)
map(Type.BYTE); // 1 - Chat Position
handler(wrapper -> {
@ -61,15 +62,15 @@ public class PlayerPackets {
protocol.registerClientbound(ClientboundPackets1_8.TAB_LIST, new PacketHandlers() {
@Override
public void register() {
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Header
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 1 - Footer
map(Type.STRING, Protocol1_9To1_8.STRING_TO_JSON); // 0 - Header
map(Type.STRING, Protocol1_9To1_8.STRING_TO_JSON); // 1 - Footer
}
});
protocol.registerClientbound(ClientboundPackets1_8.DISCONNECT, new PacketHandlers() {
@Override
public void register() {
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 0 - Reason
map(Type.STRING, Protocol1_9To1_8.STRING_TO_JSON); // 0 - Reason
}
});
@ -81,7 +82,7 @@ public class PlayerPackets {
handler(wrapper -> {
int action = wrapper.get(Type.VAR_INT, 0);
if (action == 0 || action == 1) {
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
Protocol1_9To1_8.STRING_TO_JSON.write(wrapper, wrapper.read(Type.STRING));
}
});
// Everything else is handled.
@ -248,13 +249,13 @@ public class PlayerPackets {
wrapper.passthrough(Type.VAR_INT); // ping
String displayName = wrapper.read(Type.OPTIONAL_STRING);
wrapper.write(Type.OPTIONAL_COMPONENT, displayName != null ?
Protocol1_9To1_8.FIX_JSON.transform(wrapper, displayName) : null);
Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, displayName) : null);
} else if ((action == 1) || (action == 2)) { // update gamemode || update latency
wrapper.passthrough(Type.VAR_INT);
} else if (action == 3) { // update display name
String displayName = wrapper.read(Type.OPTIONAL_STRING);
wrapper.write(Type.OPTIONAL_COMPONENT, displayName != null ?
Protocol1_9To1_8.FIX_JSON.transform(wrapper, displayName) : null);
Protocol1_9To1_8.STRING_TO_JSON.transform(wrapper, displayName) : null);
}
}
});

View File

@ -45,6 +45,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.Effect;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.sounds.SoundEffect;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.ClientChunks;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
import com.viaversion.viaversion.util.ComponentUtil;
import java.util.ArrayList;
import java.util.Optional;
@ -54,10 +55,12 @@ public class WorldPackets {
@Override
public void register() {
map(Type.POSITION1_8); // 0 - Sign Position
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 1 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 2 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 3 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 4 - Sign Line (json)
handler(wrapper -> {
for (int i = 0; i < 4; i++) {
final String line = wrapper.read(Type.STRING); // Should be Type.COMPONENT but would break in some cases
Protocol1_9To1_8.STRING_TO_JSON.write(wrapper, line);
}
});
}
});
@ -245,10 +248,12 @@ public class WorldPackets {
@Override
public void register() {
map(Type.POSITION1_8); // 0 - Sign Position
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 1 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 2 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 3 - Sign Line (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON); // 4 - Sign Line (json)
handler(wrapper -> {
for (int i = 0; i < 4; i++) {
final String line = wrapper.read(Type.STRING);
wrapper.write(Type.COMPONENT, ComponentUtil.plainToJson(line));
}
});
}
});

View File

@ -227,7 +227,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));
@ -237,11 +237,11 @@ 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());
} else if (type == particlesType) {
final Particle[] particles = meta.value();
for (final Particle particle : particles) {
rewriteParticle(particle);
rewriteParticle(event.user(), particle);
}
}
});
@ -596,7 +596,7 @@ 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.id();
if (mappings.isBlockParticle(id)) {
@ -605,7 +605,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
} else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) {
Particle.ParticleData<Item> data = particle.getArgument(0);
ItemRewriter<?> itemRewriter = protocol.getItemRewriter();
Item item = itemRewriter.handleItemToClient(data.getValue());
Item item = itemRewriter.handleItemToClient(connection, data.getValue());
if (itemRewriter.mappedItemType() != null && itemRewriter.itemType() != itemRewriter.mappedItemType()) {
// Replace the type
particle.set(0, itemRewriter.mappedItemType(), item);
@ -619,7 +619,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);
}

View File

@ -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);
@ -456,7 +457,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);
});
}
@ -485,8 +486,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);
});
@ -519,16 +520,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)) {
@ -536,7 +537,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);
Item item = handleItemToClient(data.getValue());
Item item = handleItemToClient(connection, data.getValue());
if (mappedItemType() != null && itemType() != mappedItemType()) {
// Replace the type
particle.set(0, mappedItemType(), item);

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -117,11 +117,19 @@ public final class ComponentUtil {
}
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
return element != null ? convert(from, to, from.jsonSerializer.deserialize(element)) : null;
return element != null ? convert(from, to, from.toComponent(element)) : null;
}
public static @Nullable JsonElement convertJson(@Nullable final String json, final SerializerVersion from, final SerializerVersion to) {
return json != null ? convert(from, to, from.jsonSerializer.deserializeReader(json)) : null;
return json != null ? convert(from, to, from.toComponent(json)) : null;
}
public static @Nullable JsonElement convertJsonOrEmpty(@Nullable final String json, final SerializerVersion from, final SerializerVersion to) {
final ATextComponent component = from.toComponent(json);
if (component == null) {
return emptyJsonComponent();
}
return to.toJson(component);
}
private static JsonElement convert(final SerializerVersion from, final SerializerVersion to, final ATextComponent component) {

View File

@ -78,7 +78,13 @@ public enum SerializerVersion {
}
public ATextComponent toComponent(final String json) {
return jsonSerializer.deserializeReader(json);
if (ordinal() >= SerializerVersion.V1_20_3.ordinal()) {
return jsonSerializer.deserializeParser(json);
} else if (ordinal() >= SerializerVersion.V1_9.ordinal()) {
return jsonSerializer.deserializeReader(json);
} else {
return jsonSerializer.deserialize(json);
}
}
public ATextComponent toComponent(final Tag tag) {

View File

@ -175,6 +175,9 @@ map-1_16-world-names:
nether: "minecraft:the_nether"
end: "minecraft:the_end"
#
# If disabled, tamed cats will be displayed as ocelots to 1.14+ clients on 1.13 servers. Otherwise, ocelots (tamed and untamed) will be displayed as cats.
translate-ocelot-to-cat: false
#
#----------------------------------------------------------#
# 1.9+ CLIENTS ON 1.8 SERVERS OPTIONS #
#----------------------------------------------------------#
@ -216,8 +219,6 @@ replace-pistons: false
replacement-piston-id: 0
# Fix 1.9+ clients not rendering the far away chunks and improve chunk rendering when moving fast (Increases network usage and decreases client fps slightly)
chunk-border-fix: false
# Force the string -> json transform
force-json-transform: false
# Minimize the cooldown animation in 1.8 servers
minimize-cooldown: true
# Allows 1.9+ left-handedness (main hand) on 1.8 servers