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

Merge branch 'refs/heads/dev' into preview

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-04-21 23:05:00 +02:00
Commit 89cd8aec1d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
17 geänderte Dateien mit 100 neuen und 90 gelöschten Zeilen

Datei anzeigen

@ -101,7 +101,7 @@ public class Protocol1_12To1_11_1 extends AbstractProtocol<ClientboundPackets1_9
if (!Via.getConfig().is1_12NBTArrayFix()) return;
try {
final JsonElement element = wrapper.passthrough(Type.COMPONENT);
TranslateRewriter.toClient(element);
TranslateRewriter.toClient(wrapper.user(), element);
ChatItemRewriter.toClient(element);
wrapper.set(Type.COMPONENT, 0, element);

Datei anzeigen

@ -21,6 +21,7 @@ import com.google.gson.JsonArray;
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.protocols.protocol1_12to1_11_1.data.AchievementTranslationMapping;
import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
@ -39,10 +40,10 @@ public class TranslateRewriter {
}
@Override
protected void handleHoverEvent(JsonObject hoverEvent) {
protected void handleHoverEvent(UserConnection connection, JsonObject hoverEvent) {
String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
if (!action.equals("show_achievement")) {
super.handleHoverEvent(hoverEvent);
super.handleHoverEvent(connection, hoverEvent);
return;
}
@ -54,7 +55,7 @@ public class TranslateRewriter {
invalidText.addProperty("color", "red");
hoverEvent.addProperty("action", "show_text");
hoverEvent.add("value", invalidText);
super.handleHoverEvent(hoverEvent);
super.handleHoverEvent(connection, hoverEvent);
return;
}
@ -95,17 +96,17 @@ public class TranslateRewriter {
hoverEvent.addProperty("action", "show_text");
hoverEvent.add("value", invalidText);
}
super.handleHoverEvent(hoverEvent);
super.handleHoverEvent(connection, hoverEvent);
}
};
public static void toClient(JsonElement element) {
public static void toClient(UserConnection connection, JsonElement element) {
if (element instanceof JsonObject) {
JsonObject obj = (JsonObject) element;
JsonElement translate = obj.get("translate");
if (translate != null) {
if (translate.getAsString().startsWith("chat.type.achievement")) {
ACHIEVEMENT_TEXT_REWRITER.processText(obj);
ACHIEVEMENT_TEXT_REWRITER.processText(connection, obj);
}
}
}

Datei anzeigen

@ -170,7 +170,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
EntityPackets.register(this);
WorldPackets.register(this);
registerClientbound(State.LOGIN, 0x00, 0x00, wrapper -> componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
registerClientbound(State.LOGIN, 0x00, 0x00, wrapper -> componentRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)));
registerClientbound(State.STATUS, 0x00, 0x00, new PacketHandlers() {
@Override
@ -296,7 +296,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
public void register() {
map(Type.UNSIGNED_BYTE); // Id
map(Type.STRING); // Window type
handler(wrapper -> componentRewriter.processText(wrapper.passthrough(Type.COMPONENT))); // Title
handler(wrapper -> componentRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT))); // Title
}
});
@ -511,8 +511,8 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
new SoundRewriter<>(this).registerSound(ClientboundPackets1_12_1.SOUND);
registerClientbound(ClientboundPackets1_12_1.TAB_LIST, wrapper -> {
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT));
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT));
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT));
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT));
});
registerClientbound(ClientboundPackets1_12_1.ADVANCEMENTS, wrapper -> {
@ -525,8 +525,8 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)); // Title
componentRewriter.processText(wrapper.passthrough(Type.COMPONENT)); // Description
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)); // Title
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)); // Description
Item icon = wrapper.read(Type.ITEM1_8);
itemRewriter.handleItemToClient(wrapper.user(), icon);
wrapper.write(Type.ITEM1_13, icon); // Translate item to flat item

Datei anzeigen

@ -24,6 +24,7 @@ import com.google.gson.JsonArray;
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.Protocol;
@ -41,8 +42,8 @@ public class ComponentRewriter1_13<C extends ClientboundPacketType> extends Comp
}
@Override
protected void handleHoverEvent(JsonObject hoverEvent) {
super.handleHoverEvent(hoverEvent);
protected void handleHoverEvent(UserConnection connection, JsonObject hoverEvent) {
super.handleHoverEvent(connection, hoverEvent);
final String action = hoverEvent.getAsJsonPrimitive("action").getAsString();
if (!action.equals("show_item")) return;

Datei anzeigen

@ -41,7 +41,7 @@ public class CommandBlockHandler implements BlockEntityProvider.BlockEntityHandl
StringTag out = tag.getStringTag("LastOutput");
if (out != null) {
JsonElement value = JsonParser.parseString(out.getValue());
protocol.getComponentRewriter().processText(value);
protocol.getComponentRewriter().processText(user, value);
out.setValue(value.toString());
}
return -1;

Datei anzeigen

@ -72,7 +72,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_13, Serve
Short windowId = wrapper.read(Type.UNSIGNED_BYTE);
String type = wrapper.read(Type.STRING);
JsonElement title = wrapper.read(Type.COMPONENT);
COMPONENT_REWRITER.processText(title);
COMPONENT_REWRITER.processText(wrapper.user(), title);
Short slots = wrapper.read(Type.UNSIGNED_BYTE);
if (type.equals("EntityHorse")) {

Datei anzeigen

@ -127,7 +127,7 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
map(Type.COMPONENT);
map(Type.BYTE);
handler(wrapper -> {
componentRewriter.processText(wrapper.get(Type.COMPONENT, 0));
componentRewriter.processText(wrapper.user(), wrapper.get(Type.COMPONENT, 0));
wrapper.write(Type.UUID, ZERO_UUID); // Sender uuid - always send as 'system'
});
}

Datei anzeigen

@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_16to1_15_2.data;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
@ -67,8 +68,8 @@ public class TranslationMappings extends ComponentRewriter<ClientboundPackets1_1
}
@Override
public void processText(JsonElement element) {
super.processText(element);
public void processText(UserConnection connection, JsonElement element) {
super.processText(connection, element);
if (element == null || !element.isJsonObject()) return;
// Score components no longer contain value fields

Datei anzeigen

@ -159,7 +159,7 @@ public class InventoryPackets extends ItemRewriter<ClientboundPackets1_15, Serve
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
if (pages != null) {
for (StringTag pageTag : pages) {
pageTag.setValue(protocol.getComponentRewriter().processText(pageTag.getValue()).toString());
pageTag.setValue(protocol.getComponentRewriter().processText(connection, pageTag.getValue()).toString());
}
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
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.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;
@ -35,6 +36,7 @@ import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPacke
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.CompactArrayUtil;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.UUIDUtil;
import java.util.Map;
import java.util.UUID;
@ -87,7 +89,7 @@ public class WorldPackets {
if (chunk.getBlockEntities() == null) return;
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
handleBlockEntity(protocol, blockEntity);
handleBlockEntity(protocol, wrapper.user(), blockEntity);
}
});
@ -95,17 +97,17 @@ public class WorldPackets {
wrapper.passthrough(Type.POSITION1_14); // Position
wrapper.passthrough(Type.UNSIGNED_BYTE); // Action
CompoundTag tag = wrapper.passthrough(Type.NAMED_COMPOUND_TAG);
handleBlockEntity(protocol, tag);
handleBlockEntity(protocol, wrapper.user(), tag);
});
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
}
private static void handleBlockEntity(Protocol1_16To1_15_2 protocol, CompoundTag compoundTag) {
private static void handleBlockEntity(Protocol1_16To1_15_2 protocol, UserConnection connection, CompoundTag compoundTag) {
StringTag idTag = compoundTag.getStringTag("id");
if (idTag == null) return;
String id = idTag.getValue();
String id = Key.namespaced(idTag.getValue());
if (id.equals("minecraft:conduit")) {
Tag targetUuidTag = compoundTag.remove("target_uuid");
if (!(targetUuidTag instanceof StringTag)) return;
@ -131,7 +133,7 @@ public class WorldPackets {
for (int i = 1; i <= 4; i++) {
StringTag line = compoundTag.getStringTag("Text" + i);
if (line != null) {
JsonElement text = protocol.getComponentRewriter().processText(line.getValue());
JsonElement text = protocol.getComponentRewriter().processText(connection, line.getValue());
compoundTag.putString("Text" + i, text.toString());
}
}

Datei anzeigen

@ -134,14 +134,14 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
blockRewriter.registerBlockChange(ClientboundPackets1_20_3.BLOCK_CHANGE);
blockRewriter.registerVarLongMultiBlockChange1_20(ClientboundPackets1_20_3.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_20_3.EFFECT, 1010, 2001);
blockRewriter.registerChunkData1_19(ClientboundPackets1_20_3.CHUNK_DATA, ChunkType1_20_2::new, blockEntity -> updateBlockEntityTag(null, blockEntity.tag()));
blockRewriter.registerChunkData1_19(ClientboundPackets1_20_3.CHUNK_DATA, ChunkType1_20_2::new, (user, blockEntity) -> updateBlockEntityTag(user, null, blockEntity.tag()));
protocol.registerClientbound(ClientboundPackets1_20_3.BLOCK_ENTITY_DATA, wrapper -> {
wrapper.passthrough(Type.POSITION1_14); // Position
wrapper.passthrough(Type.VAR_INT); // Block entity type
CompoundTag tag = wrapper.read(Type.COMPOUND_TAG);
if (tag != null) {
updateBlockEntityTag(null, tag);
updateBlockEntityTag(wrapper.user(), null, tag);
} else {
// No longer nullable
tag = new CompoundTag();
@ -175,7 +175,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
wrapper.passthrough(Type.TAG); // Title
wrapper.passthrough(Type.TAG); // Description
Item item = handleNonNullItemToClient(wrapper.read(itemType()));
Item item = handleNonNullItemToClient(wrapper.user(), wrapper.read(itemType()));
wrapper.write(mappedItemType(), item);
wrapper.passthrough(Type.VAR_INT); // Frame type
@ -300,8 +300,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final RecipeRewriter1_20_3<ClientboundPacket1_20_3> recipeRewriter = new RecipeRewriter1_20_3<ClientboundPacket1_20_3>(protocol) {
@Override
protected Item rewrite(@Nullable Item item) {
item = super.rewrite(item);
protected Item rewrite(final UserConnection connection, @Nullable Item item) {
item = super.rewrite(connection, item);
if (item == null || item.isEmpty()) {
// Does not allow empty items
return new StructuredItem(1, 1);
@ -322,8 +322,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
});
}
public Item handleNonNullItemToClient(@Nullable Item item) {
item = handleItemToClient(item);
public Item handleNonNullItemToClient(final UserConnection connection, @Nullable Item item) {
item = handleItemToClient(connection, item);
// Items are no longer nullable in a few places
if (item == null || item.isEmpty()) {
return new StructuredItem(1, 1);
@ -332,7 +332,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
@Override
public @Nullable Item handleItemToClient(UserConnection connection, @Nullable final Item item) {
public @Nullable Item handleItemToClient(final 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,7 +341,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
tag.putBoolean(nbtTagName(), true);
}
final Item structuredItem = toStructuredItem(item);
final Item structuredItem = toStructuredItem(connection, item);
return super.handleItemToClient(connection, structuredItem);
}
@ -372,7 +372,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return dataItem;
}
public Item toStructuredItem(final Item old) {
public Item toStructuredItem(final UserConnection connection, final Item old) {
final CompoundTag tag = old.tag();
final StructuredItem item = new StructuredItem(old.identifier(), (byte) old.amount(), new StructuredDataContainer());
final StructuredDataContainer data = item.structuredData();
@ -418,7 +418,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final CompoundTag blockEntityTag = tag.getCompoundTag("BlockEntityTag");
if (blockEntityTag != null) {
final CompoundTag clonedTag = blockEntityTag.copy();
updateBlockEntityTag(data, clonedTag);
updateBlockEntityTag(connection, data, clonedTag);
item.structuredData().set(StructuredDataKey.BLOCK_ENTITY_DATA, clonedTag);
}
@ -489,9 +489,9 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
updateMobTags(data, tag);
updateItemList(data, tag, "ChargedProjectiles", StructuredDataKey.CHARGED_PROJECTILES, false);
updateItemList(connection, data, tag, "ChargedProjectiles", StructuredDataKey.CHARGED_PROJECTILES, false);
if (old.identifier() == 927) {
updateItemList(data, tag, "Items", StructuredDataKey.BUNDLE_CONTENTS, false);
updateItemList(connection, data, tag, "Items", StructuredDataKey.BUNDLE_CONTENTS, false);
}
updateEnchantments(data, tag, "Enchantments", StructuredDataKey.ENCHANTMENTS, (hideFlagsValue & StructuredDataConverter.HIDE_ENCHANTMENTS) == 0);
@ -1101,12 +1101,13 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
data.set(StructuredDataKey.WRITTEN_BOOK_CONTENT, writtenBook);
}
private void updateItemList(final StructuredDataContainer data, final CompoundTag tag, final String key, final StructuredDataKey<Item[]> dataKey, final boolean allowEmpty) {
private void updateItemList(final UserConnection connection, final StructuredDataContainer data, final CompoundTag tag,
final String key, final StructuredDataKey<Item[]> dataKey, final boolean allowEmpty) {
final ListTag<CompoundTag> itemsTag = tag.getListTag(key, CompoundTag.class);
if (itemsTag != null) {
final Item[] items = itemsTag.stream()
.limit(256)
.map(this::itemFromTag)
.map(item -> itemFromTag(connection, item))
.filter(Objects::nonNull)
.filter(item -> allowEmpty || !item.isEmpty())
.toArray(Item[]::new);
@ -1114,7 +1115,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
}
private @Nullable Item itemFromTag(final CompoundTag item) {
private @Nullable Item itemFromTag(final UserConnection connection, final CompoundTag item) {
final String id = item.getString("id");
if (id == null) {
return null;
@ -1127,7 +1128,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final byte count = item.getByte("Count", (byte) 1);
final CompoundTag tag = item.getCompoundTag("tag");
return handleItemToClient(new DataItem(itemId, count, (short) 0, tag));
return handleItemToClient(connection, new DataItem(itemId, count, (short) 0, tag));
}
private void updateEnchantments(final StructuredDataContainer data, final CompoundTag tag, final String key,
@ -1282,7 +1283,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
}
}
private void updateBlockEntityTag(@Nullable final StructuredDataContainer data, final CompoundTag tag) {
private void updateBlockEntityTag(final UserConnection connection, @Nullable final StructuredDataContainer data, final CompoundTag tag) {
if (tag == null) {
return;
}
@ -1333,7 +1334,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
data.set(StructuredDataKey.BASE_COLOR, ((NumberTag) baseColorTag).asInt());
}
updateItemList(data, tag, "Items", StructuredDataKey.CONTAINER, true);
updateItemList(connection, data, tag, "Items", StructuredDataKey.CONTAINER, true);
}
final Tag skullOwnerTag = tag.remove("SkullOwner");

Datei anzeigen

@ -28,6 +28,7 @@ import com.github.steveice10.opennbt.tag.builtin.Tag;
import com.google.common.base.Preconditions;
import com.google.common.primitives.UnsignedBytes;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.GameProfile;
import com.viaversion.viaversion.api.minecraft.GlobalPosition;
import com.viaversion.viaversion.api.minecraft.Holder;
@ -158,7 +159,7 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
}
@Override
protected void handleHoverEvent(final CompoundTag hoverEventTag) {
protected void handleHoverEvent(final UserConnection connection, final CompoundTag hoverEventTag) {
final StringTag actionTag = hoverEventTag.getStringTag("action");
if (actionTag == null) return;
@ -211,7 +212,7 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
oldItem.setTag(tagTag);
}
final Item newItem = protocol.getItemRewriter().handleItemToClient(oldItem);
final Item newItem = protocol.getItemRewriter().handleItemToClient(connection, oldItem);
if (newItem == null) {
return;
}

Datei anzeigen

@ -427,8 +427,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
}
@Override
public void rewriteParticle(final Particle particle) {
super.rewriteParticle(particle);
public void rewriteParticle(final UserConnection connection, final Particle particle) {
super.rewriteParticle(connection, particle);
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
particle.add(Type.INT, 0); // Default color, changed in the area effect handler
}

Datei anzeigen

@ -108,7 +108,7 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
protocol.registerClientbound(ClientboundPackets1_19_4.CHUNK_DATA, new PacketHandlers() {
@Override
protected void register() {
handler(blockRewriter.chunkDataHandler1_19(ChunkType1_18::new, InventoryPackets.this::handleBlockEntity));
handler(blockRewriter.chunkDataHandler1_19(ChunkType1_18::new, (user, blockEntity) -> handleBlockEntity(blockEntity)));
read(Type.BOOLEAN); // Trust edges
}
});

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.rewriter;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.Mappings;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
@ -36,6 +37,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.util.MathUtil;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -178,11 +180,11 @@ public class BlockRewriter<C extends ClientboundPacketType> {
registerChunkData1_19(packetType, chunkTypeSupplier, null);
}
public void registerChunkData1_19(C packetType, ChunkTypeSupplier chunkTypeSupplier, @Nullable Consumer<BlockEntity> blockEntityHandler) {
public void registerChunkData1_19(C packetType, ChunkTypeSupplier chunkTypeSupplier, @Nullable BiConsumer<UserConnection, BlockEntity> blockEntityHandler) {
protocol.registerClientbound(packetType, chunkDataHandler1_19(chunkTypeSupplier, blockEntityHandler));
}
public PacketHandler chunkDataHandler1_19(ChunkTypeSupplier chunkTypeSupplier, @Nullable Consumer<BlockEntity> blockEntityHandler) {
public PacketHandler chunkDataHandler1_19(ChunkTypeSupplier chunkTypeSupplier, @Nullable BiConsumer<UserConnection, BlockEntity> blockEntityHandler) {
return wrapper -> {
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
Preconditions.checkArgument(tracker.biomesSent() != -1, "Biome count not set");
@ -209,7 +211,7 @@ public class BlockRewriter<C extends ClientboundPacketType> {
}
if (blockEntityHandler != null && blockEntity.tag() != null) {
blockEntityHandler.accept(blockEntity);
blockEntityHandler.accept(wrapper.user(), blockEntity);
}
}
}

Datei anzeigen

@ -28,6 +28,7 @@ import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
@ -84,7 +85,7 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
if (wrapper.passthrough(Type.VAR_INT) == 2) {
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.INT);
processText(wrapper.passthrough(Type.COMPONENT));
processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT));
}
});
}
@ -96,14 +97,14 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
protocol.registerClientbound(packetType, wrapper -> {
final int action = wrapper.passthrough(Type.VAR_INT);
if (action >= 0 && action <= 2) {
processText(wrapper.passthrough(Type.COMPONENT));
processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT));
}
});
}
public void registerPing() {
// Always json
protocol.registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_DISCONNECT, wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
protocol.registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_DISCONNECT, wrapper -> processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)));
}
public void registerLegacyOpenWindow(final C packetType) {
@ -112,7 +113,7 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
public void register() {
map(Type.UNSIGNED_BYTE); // Id
map(Type.STRING); // Window Type
handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
handler(wrapper -> processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)));
}
});
}
@ -141,7 +142,7 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
public void register() {
map(Type.VAR_INT);
map(Type.INT);
handler(wrapper -> processText(wrapper.passthrough(Type.COMPONENT)));
handler(wrapper -> processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT)));
}
});
}
@ -159,18 +160,18 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
public void passthroughAndProcess(final PacketWrapper wrapper) throws Exception {
switch (type) {
case JSON:
processText(wrapper.passthrough(Type.COMPONENT));
processText(wrapper.user(), wrapper.passthrough(Type.COMPONENT));
break;
case NBT:
processTag(wrapper.passthrough(Type.TAG));
processTag(wrapper.user(), wrapper.passthrough(Type.TAG));
break;
}
}
public JsonElement processText(final String value) {
public JsonElement processText(final UserConnection connection, final String value) {
try {
final JsonElement root = JsonParser.parseString(value);
processText(root);
processText(connection, root);
return root;
} catch (final JsonSyntaxException e) {
if (Via.getManager().isDebug()) {
@ -182,43 +183,43 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
}
}
public void processText(final JsonElement element) {
public void processText(final UserConnection connection, final JsonElement element) {
if (element == null || element.isJsonNull()) {
return;
}
if (element.isJsonArray()) {
processJsonArray(element.getAsJsonArray());
processJsonArray(connection, element.getAsJsonArray());
} else if (element.isJsonObject()) {
processJsonObject(element.getAsJsonObject());
processJsonObject(connection, element.getAsJsonObject());
}
}
protected void processJsonArray(final JsonArray array) {
protected void processJsonArray(final UserConnection connection, final JsonArray array) {
for (final JsonElement jsonElement : array) {
processText(jsonElement);
processText(connection, jsonElement);
}
}
protected void processJsonObject(final JsonObject object) {
protected void processJsonObject(final UserConnection connection, final JsonObject object) {
final JsonElement translate = object.get("translate");
if (translate != null && translate.isJsonPrimitive()) {
handleTranslate(object, translate.getAsString());
final JsonElement with = object.get("with");
if (with != null && with.isJsonArray()) {
processJsonArray(with.getAsJsonArray());
processJsonArray(connection, with.getAsJsonArray());
}
}
final JsonElement extra = object.get("extra");
if (extra != null && extra.isJsonArray()) {
processJsonArray(extra.getAsJsonArray());
processJsonArray(connection, extra.getAsJsonArray());
}
final JsonElement hoverEvent = object.get("hoverEvent");
if (hoverEvent != null && hoverEvent.isJsonObject()) {
handleHoverEvent(hoverEvent.getAsJsonObject());
handleHoverEvent(connection, hoverEvent.getAsJsonObject());
}
}
@ -226,7 +227,7 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
// To override if needed
}
protected void handleHoverEvent(final JsonObject hoverEvent) {
protected void handleHoverEvent(final UserConnection connection, final JsonObject hoverEvent) {
// To override if needed (don't forget to call super)
final JsonPrimitive actionElement = hoverEvent.getAsJsonPrimitive("action");
if (!actionElement.isString()) {
@ -236,11 +237,11 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
final String action = actionElement.getAsString();
if (action.equals("show_text")) {
final JsonElement value = hoverEvent.get("value");
processText(value != null ? value : hoverEvent.get("contents"));
processText(connection, value != null ? value : hoverEvent.get("contents"));
} else if (action.equals("show_entity")) {
final JsonElement contents = hoverEvent.get("contents");
if (contents != null && contents.isJsonObject()) {
processText(contents.getAsJsonObject().get("name"));
processText(connection, contents.getAsJsonObject().get("name"));
}
}
}
@ -248,51 +249,51 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
// -----------------------------------------------------------------------
// Tag methods
public void processTag(@Nullable final Tag tag) {
public void processTag(final UserConnection connection, @Nullable final Tag tag) {
if (tag == null) {
return;
}
if (tag instanceof ListTag) {
processListTag((ListTag<?>) tag);
processListTag(connection, (ListTag<?>) tag);
} else if (tag instanceof CompoundTag) {
processCompoundTag((CompoundTag) tag);
processCompoundTag(connection, (CompoundTag) tag);
}
}
private void processListTag(final ListTag<?> tag) {
private void processListTag(final UserConnection connection, final ListTag<?> tag) {
for (final Tag entry : tag) {
processTag(entry);
processTag(connection, entry);
}
}
protected void processCompoundTag(final CompoundTag tag) {
protected void processCompoundTag(final UserConnection connection, final CompoundTag tag) {
final StringTag translate = tag.getStringTag("translate");
if (translate != null) {
handleTranslate(tag, translate);
handleTranslate(connection, tag, translate);
final ListTag<?> with = tag.getListTag("with");
if (with != null) {
processListTag(with);
processListTag(connection, with);
}
}
final ListTag<?> extra = tag.getListTag("extra");
if (extra != null) {
processListTag(extra);
processListTag(connection, extra);
}
final CompoundTag hoverEvent = tag.getCompoundTag("hoverEvent");
if (hoverEvent != null) {
handleHoverEvent(hoverEvent);
handleHoverEvent(connection, hoverEvent);
}
}
protected void handleTranslate(final CompoundTag parentTag, final StringTag translateTag) {
protected void handleTranslate(final UserConnection connection, final CompoundTag parentTag, final StringTag translateTag) {
// To override if needed
}
protected void handleHoverEvent(final CompoundTag hoverEventTag) {
protected void handleHoverEvent(final UserConnection connection, final CompoundTag hoverEventTag) {
// To override if needed (don't forget to call super)
final StringTag actionTag = hoverEventTag.getStringTag("action");
if (actionTag == null) {
@ -302,11 +303,11 @@ public class ComponentRewriter<C extends ClientboundPacketType> {
final String action = actionTag.getValue();
if (action.equals("show_text")) {
final Tag value = hoverEventTag.get("value");
processTag(value != null ? value : hoverEventTag.get("contents"));
processTag(connection, value != null ? value : hoverEventTag.get("contents"));
} else if (action.equals("show_entity")) {
final CompoundTag contents = hoverEventTag.getCompoundTag("contents");
if (contents != null) {
processTag(contents.get("name"));
processTag(connection, contents.get("name"));
}
}
}

Datei anzeigen

@ -291,12 +291,12 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
final Item input = wrapper.read(costType);
wrapper.write(mappedCostType, handleItemToClient(input));
wrapper.write(mappedCostType, handleItemToClient(wrapper.user(), input));
handleClientboundItem(wrapper); // Result
final Item secondInput = wrapper.read(optionalCostType);
wrapper.write(mappedOptionalCostType, handleItemToClient(secondInput));
wrapper.write(mappedOptionalCostType, handleItemToClient(wrapper.user(), secondInput));
wrapper.passthrough(Type.BOOLEAN); // Out of stock
wrapper.passthrough(Type.INT); // Number of trade uses