Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-03 14:50:30 +01:00
Handle sign nbt changes
Dieser Commit ist enthalten in:
Ursprung
364cfad9d8
Commit
9682b68251
@ -27,6 +27,10 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public interface BlockEntity {
|
public interface BlockEntity {
|
||||||
|
|
||||||
|
static byte pack(int sectionX, int sectionZ) {
|
||||||
|
return (byte) (((sectionX) & 15) << 4 | (sectionZ & 15));
|
||||||
|
}
|
||||||
|
|
||||||
default byte sectionX() {
|
default byte sectionX() {
|
||||||
return (byte) ((packedXZ() >> 4) & 15);
|
return (byte) ((packedXZ() >> 4) & 15);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2;
|
package com.viaversion.viaversion.protocols.protocol1_13to1_12_2;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.viaversion.viaversion.api.Via;
|
import com.viaversion.viaversion.api.Via;
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
|
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
|
||||||
@ -28,9 +29,15 @@ import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.Leg
|
|||||||
|
|
||||||
public final class ChatRewriter {
|
public final class ChatRewriter {
|
||||||
public static final GsonComponentSerializer HOVER_GSON_SERIALIZER = GsonComponentSerializer.builder().emitLegacyHoverEvent().legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get()).build();
|
public static final GsonComponentSerializer HOVER_GSON_SERIALIZER = GsonComponentSerializer.builder().emitLegacyHoverEvent().legacyHoverEventSerializer(NBTLegacyHoverEventSerializer.get()).build();
|
||||||
public static final JsonElement EMPTY_COMPONENT = GsonComponentSerializer.gson().serializeToTree(Component.empty());
|
|
||||||
|
|
||||||
public static void init() {
|
public static JsonObject emptyComponent() {
|
||||||
|
final JsonObject object = new JsonObject();
|
||||||
|
object.addProperty("text", "");
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String emptyComponentString() {
|
||||||
|
return "{\"text\":\"\"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String legacyTextToJsonString(String message, boolean itemData) {
|
public static String legacyTextToJsonString(String message, boolean itemData) {
|
||||||
|
@ -26,8 +26,6 @@ import com.viaversion.viaversion.api.type.Type;
|
|||||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
|
import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
|
||||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
|
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
||||||
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
|
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ClientboundPackets1_19_3;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
|
import com.viaversion.viaversion.protocols.protocol1_19_3to1_19_1.ServerboundPackets1_19_3;
|
||||||
@ -78,11 +76,14 @@ public final class Protocol1_19_4To1_19_3 extends AbstractProtocol<ClientboundPa
|
|||||||
if (element != null) {
|
if (element != null) {
|
||||||
wrapper.write(Type.COMPONENT, element);
|
wrapper.write(Type.COMPONENT, element);
|
||||||
} else {
|
} else {
|
||||||
wrapper.write(Type.COMPONENT, ChatRewriter.EMPTY_COMPONENT);
|
wrapper.write(Type.COMPONENT, ChatRewriter.emptyComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
final String iconBase64 = wrapper.read(Type.OPTIONAL_STRING);
|
final String iconBase64 = wrapper.read(Type.OPTIONAL_STRING);
|
||||||
final byte[] iconBytes = iconBase64 != null ? Base64.getDecoder().decode(iconBase64.substring("data:image/png;base64,".length()).getBytes(StandardCharsets.UTF_8)) : null;
|
byte[] iconBytes = null;
|
||||||
|
if (iconBase64 != null && iconBase64.startsWith("data:image/png;base64,")) {
|
||||||
|
iconBytes = Base64.getDecoder().decode(iconBase64.substring("data:image/png;base64,".length()).getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
wrapper.write(Type.OPTIONAL_BYTE_ARRAY_PRIMITIVE, iconBytes);
|
wrapper.write(Type.OPTIONAL_BYTE_ARRAY_PRIMITIVE, iconBytes);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -30,10 +30,9 @@ import com.viaversion.viaversion.api.type.Type;
|
|||||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||||
import com.viaversion.viaversion.api.type.types.version.Types1_19;
|
import com.viaversion.viaversion.api.type.types.version.Types1_19;
|
||||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.Component;
|
|
||||||
import com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
||||||
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
|
||||||
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
|
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.data.MappingData;
|
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.data.MappingData;
|
||||||
@ -124,7 +123,7 @@ public final class Protocol1_19To1_18_2 extends AbstractProtocol<ClientboundPack
|
|||||||
if (!isTextComponentNull(component)) {
|
if (!isTextComponentNull(component)) {
|
||||||
wrapper.write(Type.COMPONENT, component);
|
wrapper.write(Type.COMPONENT, component);
|
||||||
} else {
|
} else {
|
||||||
wrapper.write(Type.COMPONENT, GsonComponentSerializer.gson().serializeToTree(Component.empty()));
|
wrapper.write(Type.COMPONENT, ChatRewriter.emptyComponent());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
registerClientbound(ClientboundPackets1_18.TITLE_TEXT, titleHandler);
|
registerClientbound(ClientboundPackets1_18.TITLE_TEXT, titleHandler);
|
||||||
|
@ -17,7 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.protocols.protocol1_20to1_19_4.packets;
|
package com.viaversion.viaversion.protocols.protocol1_20to1_19_4.packets;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type;
|
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.types.Chunk1_18Type;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
|
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
|
||||||
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4;
|
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ServerboundPackets1_19_4;
|
||||||
@ -41,8 +47,8 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
|||||||
blockRewriter.registerBlockChange(ClientboundPackets1_19_4.BLOCK_CHANGE);
|
blockRewriter.registerBlockChange(ClientboundPackets1_19_4.BLOCK_CHANGE);
|
||||||
blockRewriter.registerVarLongMultiBlockChange(ClientboundPackets1_19_4.MULTI_BLOCK_CHANGE);
|
blockRewriter.registerVarLongMultiBlockChange(ClientboundPackets1_19_4.MULTI_BLOCK_CHANGE);
|
||||||
blockRewriter.registerEffect(ClientboundPackets1_19_4.EFFECT, 1010, 2001);
|
blockRewriter.registerEffect(ClientboundPackets1_19_4.EFFECT, 1010, 2001);
|
||||||
blockRewriter.registerChunkData1_19(ClientboundPackets1_19_4.CHUNK_DATA, Chunk1_18Type::new);
|
blockRewriter.registerChunkData1_19(ClientboundPackets1_19_4.CHUNK_DATA, Chunk1_18Type::new, this::handleBlockEntity);
|
||||||
blockRewriter.registerBlockEntityData(ClientboundPackets1_19_4.BLOCK_ENTITY_DATA);
|
blockRewriter.registerBlockEntityData(ClientboundPackets1_19_4.BLOCK_ENTITY_DATA, this::handleBlockEntity);
|
||||||
|
|
||||||
registerOpenWindow(ClientboundPackets1_19_4.OPEN_WINDOW);
|
registerOpenWindow(ClientboundPackets1_19_4.OPEN_WINDOW);
|
||||||
registerSetCooldown(ClientboundPackets1_19_4.COOLDOWN);
|
registerSetCooldown(ClientboundPackets1_19_4.COOLDOWN);
|
||||||
@ -92,4 +98,39 @@ public final class InventoryPackets extends ItemRewriter<ClientboundPackets1_19_
|
|||||||
wrapper.set(Type.VAR_INT, 0, newSize);
|
wrapper.set(Type.VAR_INT, 0, newSize);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleBlockEntity(final BlockEntity blockEntity) {
|
||||||
|
// Check for signs
|
||||||
|
if (blockEntity.typeId() != 7 && blockEntity.typeId() != 8) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final CompoundTag tag = blockEntity.tag();
|
||||||
|
final CompoundTag frontText = new CompoundTag();
|
||||||
|
tag.put("front_text", frontText);
|
||||||
|
|
||||||
|
final ListTag messages = new ListTag(StringTag.class);
|
||||||
|
for (int i = 1; i < 5; i++) {
|
||||||
|
final Tag text = tag.get("Text" + i);
|
||||||
|
messages.add(text != null ? text : new StringTag(ChatRewriter.emptyComponentString()));
|
||||||
|
}
|
||||||
|
frontText.put("messages", messages);
|
||||||
|
|
||||||
|
final ListTag filteredMessages = new ListTag(StringTag.class);
|
||||||
|
for (int i = 1; i < 5; i++) {
|
||||||
|
final Tag text = tag.get("FilteredText" + i);
|
||||||
|
filteredMessages.add(text != null ? text : new StringTag(ChatRewriter.emptyComponentString()));
|
||||||
|
}
|
||||||
|
frontText.put("filtered_messages", filteredMessages);
|
||||||
|
|
||||||
|
final Tag color = tag.remove("Color");
|
||||||
|
if (color != null) {
|
||||||
|
frontText.put("color", color);
|
||||||
|
}
|
||||||
|
|
||||||
|
final Tag glowing = tag.remove("GlowingText");
|
||||||
|
if (glowing != null) {
|
||||||
|
frontText.put("has_glowing_text", glowing);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -17,12 +17,14 @@
|
|||||||
*/
|
*/
|
||||||
package com.viaversion.viaversion.rewriter;
|
package com.viaversion.viaversion.rewriter;
|
||||||
|
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.viaversion.viaversion.api.data.Mappings;
|
import com.viaversion.viaversion.api.data.Mappings;
|
||||||
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||||
import com.viaversion.viaversion.api.minecraft.Position;
|
import com.viaversion.viaversion.api.minecraft.Position;
|
||||||
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntityImpl;
|
||||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||||
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
import com.viaversion.viaversion.api.minecraft.chunks.DataPalette;
|
||||||
@ -33,6 +35,8 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
|||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.util.MathUtil;
|
import com.viaversion.viaversion.util.MathUtil;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class BlockRewriter<C extends ClientboundPacketType> {
|
public class BlockRewriter<C extends ClientboundPacketType> {
|
||||||
private final Protocol<C, ?, ?, ?> protocol;
|
private final Protocol<C, ?, ?, ?> protocol;
|
||||||
@ -137,6 +141,10 @@ public class BlockRewriter<C extends ClientboundPacketType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void registerChunkData1_19(C packetType, ChunkTypeSupplier chunkTypeSupplier) {
|
public void registerChunkData1_19(C packetType, ChunkTypeSupplier chunkTypeSupplier) {
|
||||||
|
registerChunkData1_19(packetType, chunkTypeSupplier, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerChunkData1_19(C packetType, ChunkTypeSupplier chunkTypeSupplier, @Nullable Consumer<BlockEntity> blockEntityHandler) {
|
||||||
protocol.registerClientbound(packetType, wrapper -> {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
|
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
|
||||||
Preconditions.checkArgument(tracker.biomesSent() != 0, "Biome count not set");
|
Preconditions.checkArgument(tracker.biomesSent() != 0, "Biome count not set");
|
||||||
@ -154,28 +162,42 @@ public class BlockRewriter<C extends ClientboundPacketType> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final Mappings blockEntityMappings = protocol.getMappingData().getBlockEntityMappings();
|
final Mappings blockEntityMappings = protocol.getMappingData().getBlockEntityMappings();
|
||||||
if (blockEntityMappings != null) {
|
if (blockEntityMappings != null || blockEntityHandler != null) {
|
||||||
List<BlockEntity> blockEntities = chunk.blockEntities();
|
List<BlockEntity> blockEntities = chunk.blockEntities();
|
||||||
for (int i = 0; i < blockEntities.size(); i++) {
|
for (int i = 0; i < blockEntities.size(); i++) {
|
||||||
final BlockEntity blockEntity = blockEntities.get(i);
|
final BlockEntity blockEntity = blockEntities.get(i);
|
||||||
blockEntities.set(i, blockEntity.withTypeId(protocol.getMappingData().getBlockEntityMappings().getNewIdOrDefault(blockEntity.typeId(), blockEntity.typeId())));
|
if (blockEntityMappings != null) {
|
||||||
|
blockEntities.set(i, blockEntity.withTypeId(blockEntityMappings.getNewIdOrDefault(blockEntity.typeId(), blockEntity.typeId())));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blockEntityHandler != null && blockEntity.tag() != null) {
|
||||||
|
blockEntityHandler.accept(blockEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerBlockEntityData(C packetType) {
|
public void registerBlockEntityData(C packetType) {
|
||||||
protocol.registerClientbound(packetType, new PacketHandlers() {
|
registerBlockEntityData(packetType, null);
|
||||||
@Override
|
}
|
||||||
public void register() {
|
|
||||||
map(Type.POSITION1_14);
|
public void registerBlockEntityData(C packetType, @Nullable Consumer<BlockEntity> blockEntityHandler) {
|
||||||
handler(wrapper -> {
|
protocol.registerClientbound(packetType, wrapper -> {
|
||||||
|
final Position position = wrapper.passthrough(Type.POSITION1_14);
|
||||||
|
|
||||||
|
final int blockEntityId = wrapper.read(Type.VAR_INT);
|
||||||
final Mappings mappings = protocol.getMappingData().getBlockEntityMappings();
|
final Mappings mappings = protocol.getMappingData().getBlockEntityMappings();
|
||||||
if (mappings != null) {
|
if (mappings != null) {
|
||||||
final int blockEntityId = wrapper.read(Type.VAR_INT);
|
|
||||||
wrapper.write(Type.VAR_INT, mappings.getNewIdOrDefault(blockEntityId, blockEntityId));
|
wrapper.write(Type.VAR_INT, mappings.getNewIdOrDefault(blockEntityId, blockEntityId));
|
||||||
|
} else {
|
||||||
|
wrapper.write(Type.VAR_INT, blockEntityId);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
final CompoundTag tag;
|
||||||
|
if (blockEntityHandler != null && (tag = wrapper.passthrough(Type.NBT)) != null) {
|
||||||
|
final BlockEntity blockEntity = new BlockEntityImpl(BlockEntity.pack(position.x(), position.z()), (short) position.y(), blockEntityId, tag);
|
||||||
|
blockEntityHandler.accept(blockEntity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren