Handle changed sign nbt

This commit is contained in:
Nassim Jahnke 2023-03-24 11:36:32 +01:00
parent c1383baf14
commit ef1b062449
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
5 changed files with 111 additions and 17 deletions

View File

@ -8,5 +8,5 @@ repositories {
dependencies { dependencies {
// version must be manually kept in sync with the one in root project settings.gradle.kts // version must be manually kept in sync with the one in root project settings.gradle.kts
implementation("com.github.johnrengelman", "shadow", "8.1.0") implementation("com.github.johnrengelman", "shadow", "8.1.1")
} }

View File

@ -18,8 +18,13 @@
package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets; package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20; import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.storage.BackSignEditStorage;
import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Position;
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.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
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;
@ -40,8 +45,8 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
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);
@ -56,26 +61,60 @@ public final class BlockItemPackets1_20 extends ItemRewriter<ClientboundPackets1
registerSpawnParticle1_19(ClientboundPackets1_19_4.SPAWN_PARTICLE); registerSpawnParticle1_19(ClientboundPackets1_19_4.SPAWN_PARTICLE);
protocol.registerClientbound(ClientboundPackets1_19_4.OPEN_SIGN_EDITOR, wrapper -> { protocol.registerClientbound(ClientboundPackets1_19_4.OPEN_SIGN_EDITOR, wrapper -> {
wrapper.passthrough(Type.POSITION1_14); final Position position = wrapper.passthrough(Type.POSITION1_14);
final boolean frontSide = wrapper.read(Type.BOOLEAN); final boolean frontSide = wrapper.read(Type.BOOLEAN);
if (!frontSide) { if (frontSide) {
// TODO track front side to check in serverbound wrapper.user().remove(BackSignEditStorage.class);
wrapper.cancel(); } else {
wrapper.user().put(new BackSignEditStorage(position));
} }
}); });
protocol.registerServerbound(ServerboundPackets1_19_4.UPDATE_SIGN, wrapper -> { protocol.registerServerbound(ServerboundPackets1_19_4.UPDATE_SIGN, wrapper -> {
final Position position = wrapper.passthrough(Type.POSITION1_14); final Position position = wrapper.passthrough(Type.POSITION1_14);
wrapper.write(Type.BOOLEAN, true); // Front side final BackSignEditStorage backSignEditStorage = wrapper.user().remove(BackSignEditStorage.class);
final boolean frontSide = backSignEditStorage == null || !backSignEditStorage.position().equals(position);
//TODO Track lines to send back with edited wrapper.write(Type.BOOLEAN, frontSide);
/*final CompoundTag tag = new CompoundTag();
final PacketWrapper signUpdate = wrapper.create(ClientboundPackets1_19_4.BLOCK_ENTITY_DATA);
signUpdate.send(Protocol1_19_4To1_20.class);
signUpdate.write(Type.POSITION1_14, position);
signUpdate.write(Type.VAR_INT, 5); // Sign
signUpdate.write(Type.NBT, tag);*/
}); });
new RecipeRewriter1_19_4<>(protocol).register(ClientboundPackets1_19_4.DECLARE_RECIPES); new RecipeRewriter1_19_4<>(protocol).register(ClientboundPackets1_19_4.DECLARE_RECIPES);
} }
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 = tag.remove("front_text");
tag.remove("back_text");
if (frontText != null) {
writeMessages(frontText, tag, false);
writeMessages(frontText, tag, true);
final Tag color = frontText.remove("color");
if (color != null) {
tag.put("Color", color);
}
final Tag glowing = frontText.remove("has_glowing_text");
if (glowing != null) {
tag.put("GlowingText", glowing);
}
}
}
private void writeMessages(final CompoundTag frontText, final CompoundTag tag, final boolean filtered) {
final ListTag messages = frontText.get(filtered ? "filtered_messages" : "messages");
if (messages == null) {
return;
}
int i = 0;
for (final Tag message : messages) {
tag.put((filtered ? "FilteredText" : "Text") + ++i, message);
}
}
} }

View File

@ -17,6 +17,7 @@
*/ */
package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets; package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.packets;
import com.google.common.collect.Sets;
import com.viaversion.viabackwards.api.rewriters.EntityRewriter; import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20; import com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.Protocol1_19_4To1_20;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_19_4Types;
@ -25,10 +26,19 @@ 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.api.type.types.version.Types1_19_4; import com.viaversion.viaversion.api.type.types.version.Types1_19_4;
import com.viaversion.viaversion.api.type.types.version.Types1_20; import com.viaversion.viaversion.api.type.types.version.Types1_20;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
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.util.Key;
import java.util.Set;
public final class EntityPackets1_20 extends EntityRewriter<ClientboundPackets1_19_4, Protocol1_19_4To1_20> { public final class EntityPackets1_20 extends EntityRewriter<ClientboundPackets1_19_4, Protocol1_19_4To1_20> {
private final Set<String> newTrimPatterns = Sets.newHashSet("host_armor_trim_smithing_template", "raiser_armor_trim_smithing_template",
"silence_armor_trim_smithing_template", "shaper_armor_trim_smithing_template", "wayfinder_armor_trim_smithing_template");
public EntityPackets1_20(final Protocol1_19_4To1_20 protocol) { public EntityPackets1_20(final Protocol1_19_4To1_20 protocol) {
super(protocol); super(protocol);
} }
@ -53,6 +63,17 @@ public final class EntityPackets1_20 extends EntityRewriter<ClientboundPackets1_
handler(dimensionDataHandler()); // Caches dimensions to access data like height later handler(dimensionDataHandler()); // Caches dimensions to access data like height later
handler(biomeSizeTracker()); // Tracks the amount of biomes sent for chunk data handler(biomeSizeTracker()); // Tracks the amount of biomes sent for chunk data
handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking handler(worldDataTrackerHandlerByKey()); // Tracks world height and name for chunk data and entity (un)tracking
handler(wrapper -> {
final CompoundTag registry = wrapper.get(Type.NBT, 0);
final ListTag values = ((CompoundTag) registry.get("minecraft:trim_pattern")).get("value");
for (final Tag entry : values) {
final CompoundTag element = ((CompoundTag) entry).get("element");
final StringTag templateItem = element.get("template_item");
if (newTrimPatterns.contains(Key.stripMinecraftNamespace(templateItem.getValue()))) {
templateItem.setValue("minecraft:spire_armor_trim_smithing_template");
}
}
});
} }
}); });

View File

@ -0,0 +1,34 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2023 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.protocol1_19_4to1_20.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.minecraft.Position;
public final class BackSignEditStorage implements StorableObject {
private final Position position;
public BackSignEditStorage(final Position position) {
this.position = position;
}
public Position position() {
return position;
}
}

View File

@ -16,7 +16,7 @@ dependencyResolutionManagement {
pluginManagement { pluginManagement {
plugins { plugins {
id("net.kyori.blossom") version "1.2.0" id("net.kyori.blossom") version "1.2.0"
id("com.github.johnrengelman.shadow") version "8.1.0" id("com.github.johnrengelman.shadow") version "8.1.1"
} }
} }