From ff547f9a5ed0104d26a830046216f9b12c1ac2fc Mon Sep 17 00:00:00 2001 From: YuRaNnNzZZ Date: Tue, 24 Oct 2023 08:01:34 +0300 Subject: [PATCH] optional item/block tags display in tooltips --- .../mc/otm/datagen/lang/English.kt | 5 ++ .../mc/otm/datagen/lang/Russian.kt | 4 ++ .../mc/otm/OverdriveThatMatters.java | 1 + .../mc/otm/client/ClientEventHandler.kt | 46 +++++++++++++++++++ .../dbotthepony/mc/otm/config/ClientConfig.kt | 4 ++ 5 files changed, 60 insertions(+) diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt index 224dae1f0..74fe3e236 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/English.kt @@ -865,6 +865,11 @@ private fun gui(provider: MatteryLanguageProvider) { gui("slot_filter.hint", "To remove slot filter press Ctrl + LMB") gui("tooltip.enum.active", "> %s") + + gui("debug.tags.help", "Hold Shift to display tags") + gui("debug.tags.item.title", "Item tags:") + gui("debug.tags.block.title", "Block tags:") + gui("debug.tags.tag.entry", " - %s") } } diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt index 4eb78a3d1..e5b1e6621 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/lang/Russian.kt @@ -862,6 +862,10 @@ private fun gui(provider: MatteryLanguageProvider) { gui("slot_filter.filtered", "Данный слот отфильтрован для автоматизации") gui("slot_filter.forbidden", "Данный слот запрещён для взаимодействия средствами автоматизации") gui("slot_filter.hint", "Для удаления фильтра нажмите Ctrl + ЛКМ") + + gui("debug.tags.help", "Удерживайте Shift для отображения тегов") + gui("debug.tags.item.title", "Теги предмета:") + gui("debug.tags.block.title", "Теги блока:") } } diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index 350d59128..0e62d7403 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -242,6 +242,7 @@ public final class OverdriveThatMatters { EVENT_BUS.addListener(EventPriority.LOWEST, ClientTickHandlerKt::onClientTick); EVENT_BUS.addListener(EventPriority.HIGHEST, ClientTickHandlerKt::onClientConnected); EVENT_BUS.addListener(EventPriority.HIGHEST, ClientTickHandlerKt::onClientDisconnected); + EVENT_BUS.addListener(EventPriority.NORMAL, ClientEventHandlerKt::tooltipEvent); EVENT_BUS.addListener(EventPriority.NORMAL, QuantumBatteryItem.Companion::clientDisconnect); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt index 9f9b08fb0..b6d324cfa 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/ClientEventHandler.kt @@ -2,16 +2,22 @@ package ru.dbotthepony.mc.otm.client import com.mojang.blaze3d.platform.InputConstants import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap +import net.minecraft.ChatFormatting import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.screens.Screen import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen import net.minecraft.client.gui.screens.inventory.InventoryScreen +import net.minecraft.tags.TagKey import net.minecraft.world.inventory.InventoryMenu import net.minecraft.world.inventory.Slot +import net.minecraft.world.item.BlockItem +import net.minecraft.world.item.Item +import net.minecraft.world.level.block.Block import net.minecraftforge.client.event.MovementInputUpdateEvent import net.minecraftforge.client.event.ScreenEvent import net.minecraftforge.client.event.ScreenEvent.MouseDragged import net.minecraftforge.client.event.ScreenEvent.MouseScrolled +import net.minecraftforge.event.entity.player.ItemTooltipEvent import ru.dbotthepony.mc.otm.config.ClientConfig import ru.dbotthepony.mc.otm.android.feature.JumpBoostFeature import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability @@ -27,6 +33,7 @@ import ru.dbotthepony.mc.otm.client.screen.panels.Panel2Widget import ru.dbotthepony.mc.otm.compat.vanilla.InventoryScrollPacket import ru.dbotthepony.mc.otm.compat.cos.isCosmeticArmorScreen import ru.dbotthepony.mc.otm.core.TranslatableComponent +import ru.dbotthepony.mc.otm.core.addAll import ru.dbotthepony.mc.otm.core.math.integerDivisionUp import ru.dbotthepony.mc.otm.menu.MatteryMenu import ru.dbotthepony.mc.otm.network.MenuNetworkChannel @@ -253,3 +260,42 @@ fun onScreenOpen(event: ScreenEvent.Opening) { event.newScreen = ExopackInventoryScreen(player.exoPackMenu) } } + +private val TOOLTIP_TAG_DISPLAY_HELP = TranslatableComponent("otm.gui.debug.tags.help").withStyle(ChatFormatting.GRAY) +private val TOOLTIP_TAG_DISPLAY_ITEM_TITLE = TranslatableComponent("otm.gui.debug.tags.item.title").withStyle(ChatFormatting.DARK_GRAY) +private val TOOLTIP_TAG_DISPLAY_BLOCK_TITLE = TranslatableComponent("otm.gui.debug.tags.block.title").withStyle(ChatFormatting.DARK_GRAY) + +fun tooltipEvent(event: ItemTooltipEvent) { + if (event.flags.isAdvanced && ClientConfig.TOOLTIP_DISPLAY_TAGS && !event.itemStack.isEmpty) { + val itemTags = ArrayList>() + if (event.itemStack.tags.count() > 0) { + itemTags.addAll(event.itemStack.tags) + } + + val blockTags = ArrayList>() + if (event.itemStack.item is BlockItem) { + blockTags.addAll((event.itemStack.item as BlockItem).block.defaultBlockState().tags) + } + + if (itemTags.isNotEmpty() || blockTags.isNotEmpty()) { + if (!minecraft.window.isShiftDown) { + event.toolTip.add(TOOLTIP_TAG_DISPLAY_HELP) + return + } + } + + if (itemTags.isNotEmpty()) { + event.toolTip.add(TOOLTIP_TAG_DISPLAY_ITEM_TITLE) + for (tag in itemTags) { + event.toolTip.add(TranslatableComponent("otm.gui.debug.tags.tag.entry", tag.location).withStyle(ChatFormatting.DARK_GRAY)) + } + } + + if (blockTags.isNotEmpty()) { + event.toolTip.add(TOOLTIP_TAG_DISPLAY_BLOCK_TITLE) + for (tag in blockTags) { + event.toolTip.add(TranslatableComponent("otm.gui.debug.tags.tag.entry", tag.location).withStyle(ChatFormatting.DARK_GRAY)) + } + } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt index 1c4a80cac..64b1f5e91 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/config/ClientConfig.kt @@ -28,4 +28,8 @@ object ClientConfig : AbstractConfig("client", ModConfig.Type.CLIENT) { .comment("Display redstone control button using items instead of custom sprites") .comment("For those who want it.") .define("REDSTONE_CONTROLS_ITEM_ICONS", false) + + var TOOLTIP_DISPLAY_TAGS: Boolean by builder + .comment("Display block/item tags in advanced item tooltips") + .define("TOOLTIP_DISPLAY_TAGS", false) }