From 1788295291c1fc114e0e3c803175ee0b905d3e53 Mon Sep 17 00:00:00 2001 From: Konicai <71294714+Konicai@users.noreply.github.com> Date: Fri, 9 Jun 2023 12:33:50 -0400 Subject: [PATCH] Translate nbt of decorated pots (#3847) --- .../java/org/geysermc/geyser/item/Items.java | 2 +- .../geyser/item/type/DecoratedPotItem.java | 50 +++++++++++++++++ .../DecoratedPotBlockEntityTranslator.java | 53 +++++++++++++++++++ core/src/main/resources/mappings | 2 +- 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/item/type/DecoratedPotItem.java create mode 100644 core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java diff --git a/core/src/main/java/org/geysermc/geyser/item/Items.java b/core/src/main/java/org/geysermc/geyser/item/Items.java index 7f1ea51bf..e50879445 100644 --- a/core/src/main/java/org/geysermc/geyser/item/Items.java +++ b/core/src/main/java/org/geysermc/geyser/item/Items.java @@ -304,7 +304,7 @@ public final class Items { public static final Item BRICKS = register(new BlockItem("bricks", builder())); public static final Item BOOKSHELF = register(new BlockItem("bookshelf", builder())); public static final Item CHISELED_BOOKSHELF = register(new BlockItem("chiseled_bookshelf", builder())); - public static final Item DECORATED_POT = register(new BlockItem("decorated_pot", builder().stackSize(1))); + public static final Item DECORATED_POT = register(new DecoratedPotItem("decorated_pot", builder().stackSize(1))); public static final Item MOSSY_COBBLESTONE = register(new BlockItem("mossy_cobblestone", builder())); public static final Item OBSIDIAN = register(new BlockItem("obsidian", builder())); public static final Item TORCH = register(new BlockItem("torch", builder())); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/DecoratedPotItem.java b/core/src/main/java/org/geysermc/geyser/item/type/DecoratedPotItem.java new file mode 100644 index 000000000..10d2a1bcc --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/item/type/DecoratedPotItem.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.item.type; + +import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import com.github.steveice10.opennbt.tag.builtin.ListTag; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.geysermc.geyser.session.GeyserSession; + +public class DecoratedPotItem extends BlockItem { + + public DecoratedPotItem(String javaIdentifier, Builder builder) { + super(javaIdentifier, builder); + } + + @Override + public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) { + super.translateNbtToBedrock(session, tag); + + if (tag.remove("BlockEntityTag") instanceof CompoundTag blockEntityTag) { + if (blockEntityTag.remove("sherds") instanceof ListTag sherds) { + // bedrock wants it on the root level + tag.put(sherds); + } + } + } +} diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java new file mode 100644 index 000000000..e60342b27 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/DecoratedPotBlockEntityTranslator.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2019-2023 GeyserMC. http://geysermc.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * @author GeyserMC + * @link https://github.com/GeyserMC/Geyser + */ + +package org.geysermc.geyser.translator.level.block.entity; + +import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType; +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 org.cloudburstmc.nbt.NbtMapBuilder; +import org.cloudburstmc.nbt.NbtType; + +import java.util.ArrayList; +import java.util.List; + +@BlockEntity(type = BlockEntityType.DECORATED_POT) +public class DecoratedPotBlockEntityTranslator extends BlockEntityTranslator { + + @Override + public void translateTag(NbtMapBuilder builder, CompoundTag tag, int blockState) { + // exact same format + if (tag.get("sherds") instanceof ListTag sherds) { + List translated = new ArrayList<>(4); + for (Tag sherd : sherds) { + translated.add(((StringTag) sherd).getValue()); + } + builder.putList("sherds", NbtType.STRING, translated); + } + } +} diff --git a/core/src/main/resources/mappings b/core/src/main/resources/mappings index 1e56dfc99..cf6fdf31f 160000 --- a/core/src/main/resources/mappings +++ b/core/src/main/resources/mappings @@ -1 +1 @@ -Subproject commit 1e56dfc998e60255873822bab1e077f8aea02213 +Subproject commit cf6fdf31fe7c607d7fb3a4a42b86def45fe86385