From 9656f9523366034f4a843ba4a4ea1a8f7eed9b00 Mon Sep 17 00:00:00 2001 From: onebeastchris Date: Thu, 13 Jun 2024 19:10:13 +0200 Subject: [PATCH] debug stick changes --- .../java/org/geysermc/geyser/item/Items.java | 2 +- .../geyser/item/type/DebugStickItem.java | 59 +++++++++++++++++++ .../org/geysermc/geyser/item/type/Item.java | 4 ++ .../translator/item/ItemTranslator.java | 2 +- 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/org/geysermc/geyser/item/type/DebugStickItem.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 1ddd14982..23136d96c 100644 --- a/core/src/main/java/org/geysermc/geyser/item/Items.java +++ b/core/src/main/java/org/geysermc/geyser/item/Items.java @@ -1204,7 +1204,7 @@ public final class Items { public static final Item SHULKER_SHELL = register(new Item("shulker_shell", builder())); public static final Item IRON_NUGGET = register(new Item("iron_nugget", builder())); public static final Item KNOWLEDGE_BOOK = register(new Item("knowledge_book", builder().stackSize(1))); - public static final Item DEBUG_STICK = register(new Item("debug_stick", builder().stackSize(1))); + public static final Item DEBUG_STICK = register(new DebugStickItem("debug_stick", builder().stackSize(1))); public static final Item MUSIC_DISC_13 = register(new Item("music_disc_13", builder().stackSize(1))); public static final Item MUSIC_DISC_CAT = register(new Item("music_disc_cat", builder().stackSize(1))); public static final Item MUSIC_DISC_BLOCKS = register(new Item("music_disc_blocks", builder().stackSize(1))); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/DebugStickItem.java b/core/src/main/java/org/geysermc/geyser/item/type/DebugStickItem.java new file mode 100644 index 000000000..b9766b463 --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/item/type/DebugStickItem.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 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 org.cloudburstmc.nbt.NbtMap; +import org.cloudburstmc.nbt.NbtMapBuilder; +import org.cloudburstmc.nbt.NbtType; +import org.geysermc.geyser.session.GeyserSession; +import org.geysermc.geyser.text.ChatColor; +import org.geysermc.geyser.text.MinecraftLocale; +import org.geysermc.geyser.translator.item.BedrockItemBuilder; + +import java.util.ArrayList; + +public class DebugStickItem extends Item { + public DebugStickItem(String javaIdentifier, Builder builder) { + super(javaIdentifier, builder); + } + + @Override + public NbtMap build(GeyserSession session, BedrockItemBuilder builder) { + NbtMapBuilder nbt = builder.getOrCreateNbt(); + + // No enchantments -> no glint! Let's add it. + if (!nbt.containsKey("ench")) { + nbt.putList("ench", NbtType.COMPOUND, new ArrayList<>()); + } + + // Custom name + if (builder.getCustomName() == null) { + builder.setCustomName(ChatColor.DARK_PURPLE + MinecraftLocale.getLocaleString("item.minecraft.debug_stick", session.locale())); + } + + return builder.build(); + } +} diff --git a/core/src/main/java/org/geysermc/geyser/item/type/Item.java b/core/src/main/java/org/geysermc/geyser/item/type/Item.java index 362b760c7..d7f180b1f 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/Item.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/Item.java @@ -112,6 +112,10 @@ public class Item { return builder; } + public NbtMap build(GeyserSession session, BedrockItemBuilder builder) { + return builder.build(); + } + public @NonNull GeyserItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) { return GeyserItemStack.of(javaId, itemData.getCount()); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java index 7572f5e61..1f13d52af 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/item/ItemTranslator.java @@ -163,7 +163,7 @@ public final class ItemTranslator { ItemData.Builder builder = javaItem.translateToBedrock(count, components, bedrockItem, session.getItemMappings()); // Finalize the Bedrock NBT - builder.tag(nbtBuilder.build()); + builder.tag(javaItem.build(session, nbtBuilder)); if (bedrockItem.isBlock()) { CustomBlockData customBlockData = BlockRegistries.CUSTOM_BLOCK_ITEM_OVERRIDES.getOrDefault( bedrockItem.getJavaItem().javaIdentifier(), null);