From 11a0bd145ea66bc54d67689a6aa10889a0520870 Mon Sep 17 00:00:00 2001 From: Roman Gräf Date: Wed, 12 Aug 2020 14:22:21 +0200 Subject: tagtooltip v1.0 --- build.gradle | 20 +++--- settings.gradle | 1 + .../java/com/example/examplemod/ExampleMod.java | 84 ---------------------- .../java/com/romangraef/tagtooltip/TagTooltip.java | 70 ++++++++++++++++++ src/main/resources/META-INF/mods.toml | 67 ++++------------- .../resources/assets/tagtooltip/lang/en_us.json | 5 ++ 6 files changed, 101 insertions(+), 146 deletions(-) create mode 100644 settings.gradle delete mode 100644 src/main/java/com/example/examplemod/ExampleMod.java create mode 100644 src/main/java/com/romangraef/tagtooltip/TagTooltip.java create mode 100644 src/main/resources/assets/tagtooltip/lang/en_us.json diff --git a/build.gradle b/build.gradle index cb7eb3c..375214f 100644 --- a/build.gradle +++ b/build.gradle @@ -13,9 +13,9 @@ apply plugin: 'net.minecraftforge.gradle' apply plugin: 'eclipse' apply plugin: 'maven-publish' -version = '1.0' -group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'modid' +version = '1.16.1-1.0' +group = 'com.romangraef.tagtooltip' // http://maven.apache.org/guides/mini/guide-naming-conventions.html +archivesBaseName = 'tagtooltip' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly. @@ -44,7 +44,7 @@ minecraft { property 'forge.logging.console.level', 'debug' mods { - examplemod { + tagtooltip { source sourceSets.main } } @@ -60,7 +60,7 @@ minecraft { property 'forge.logging.console.level', 'debug' mods { - examplemod { + tagtooltip { source sourceSets.main } } @@ -75,10 +75,10 @@ minecraft { // Recommended logging level for the console property 'forge.logging.console.level', 'debug' - args '--mod', 'examplemod', '--all', '--output', file('src/generated/resources/') + args '--mod', 'tagtooltip', '--all', '--output', file('src/generated/resources/') mods { - examplemod { + tagtooltip { source sourceSets.main } } @@ -116,12 +116,12 @@ dependencies { jar { manifest { attributes([ - "Specification-Title": "examplemod", - "Specification-Vendor": "examplemodsareus", + "Specification-Title": "tagtooltip", + "Specification-Vendor": "romangraef", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", - "Implementation-Vendor" :"examplemodsareus", + "Implementation-Vendor" :"romangraef", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..47c647f --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'tagtooltip' \ No newline at end of file diff --git a/src/main/java/com/example/examplemod/ExampleMod.java b/src/main/java/com/example/examplemod/ExampleMod.java deleted file mode 100644 index a436462..0000000 --- a/src/main/java/com/example/examplemod/ExampleMod.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.example.examplemod; - -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.event.RegistryEvent; -import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.InterModComms; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent; -import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent; -import net.minecraftforge.fml.event.server.FMLServerStartingEvent; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.stream.Collectors; - -// The value here should match an entry in the META-INF/mods.toml file -@Mod("examplemod") -public class ExampleMod -{ - // Directly reference a log4j logger. - private static final Logger LOGGER = LogManager.getLogger(); - - public ExampleMod() { - // Register the setup method for modloading - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); - // Register the enqueueIMC method for modloading - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC); - // Register the processIMC method for modloading - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC); - // Register the doClientStuff method for modloading - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); - - // Register ourselves for server and other game events we are interested in - MinecraftForge.EVENT_BUS.register(this); - } - - private void setup(final FMLCommonSetupEvent event) - { - // some preinit code - LOGGER.info("HELLO FROM PREINIT"); - LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName()); - } - - private void doClientStuff(final FMLClientSetupEvent event) { - // do something that can only be done on the client - LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings); - } - - private void enqueueIMC(final InterModEnqueueEvent event) - { - // some example code to dispatch IMC to another mod - InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";}); - } - - private void processIMC(final InterModProcessEvent event) - { - // some example code to receive and process InterModComms from other mods - LOGGER.info("Got IMC {}", event.getIMCStream(). - map(m->m.getMessageSupplier().get()). - collect(Collectors.toList())); - } - // You can use SubscribeEvent and let the Event Bus discover methods to call - @SubscribeEvent - public void onServerStarting(FMLServerStartingEvent event) { - // do something when the server starts - LOGGER.info("HELLO from server starting"); - } - - // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD - // Event bus for receiving Registry Events) - @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) - public static class RegistryEvents { - @SubscribeEvent - public static void onBlocksRegistry(final RegistryEvent.Register blockRegistryEvent) { - // register a new block here - LOGGER.info("HELLO from Register Block"); - } - } -} diff --git a/src/main/java/com/romangraef/tagtooltip/TagTooltip.java b/src/main/java/com/romangraef/tagtooltip/TagTooltip.java new file mode 100644 index 0000000..8d419b9 --- /dev/null +++ b/src/main/java/com/romangraef/tagtooltip/TagTooltip.java @@ -0,0 +1,70 @@ +package com.romangraef.tagtooltip; + +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.client.util.InputMappings; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.KeybindTextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.settings.KeyConflictContext; +import net.minecraftforge.client.settings.KeyModifier; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.eventbus.api.EventPriority; +import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ExtensionPoint; +import net.minecraftforge.fml.ModLoadingContext; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.loading.FMLEnvironment; +import net.minecraftforge.fml.network.FMLNetworkConstants; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.lwjgl.glfw.GLFW; + +import java.util.List; + +import static com.romangraef.tagtooltip.TagTooltip.MODID; + +@Mod(MODID) +@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) +public class TagTooltip { + public static final String MODID = "tagtooltip"; + public static final Logger log = LogManager.getLogger(MODID); + public KeyBinding showTagsBinding = new KeyBinding("key.showtags", KeyConflictContext.GUI, InputMappings.Type.KEYSYM, GLFW.GLFW_KEY_M, "key.categories.inventory"); + + public TagTooltip() { + if (FMLEnvironment.dist == Dist.DEDICATED_SERVER) { + log.warn("#########################################"); + log.warn("# ReAuth was loaded on Server #"); + log.warn("# Consider removing it to save some RAM #"); + log.warn("#########################################"); + } else { + IEventBus eventBus = MinecraftForge.EVENT_BUS; + eventBus.addListener(EventPriority.NORMAL, false, ItemTooltipEvent.class, this::onTooltip); + ClientRegistry.registerKeyBinding(showTagsBinding); + } + } + + public void onTooltip(ItemTooltipEvent event) { + if (event == null) return; + List toolTip = event.getToolTip(); + if (!showTagsBinding.isKeyDown()) { + toolTip.add(new TranslationTextComponent("tooltip.showTags", new TranslationTextComponent(showTagsBinding.getTranslationKey()))); + return; + } + for (ResourceLocation tag : event.getItemStack().getItem().getTags()) { + toolTip.add(new TranslationTextComponent("tooltip.tag.prefix",new StringTextComponent(tag.toString()))); + } + } + + @SubscribeEvent + public static void setup(FMLCommonSetupEvent event) { + ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); + } +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index f3a5af7..ccb4756 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,59 +1,22 @@ -# This is an example mods.toml file. It contains the data relating to the loading mods. -# There are several mandatory fields (#mandatory), and many more that are optional (#optional). -# The overall format is standard TOML format, v0.5.0. -# Note that there are a couple of TOML lists in this file. -# Find more information on toml format here: https://github.com/toml-lang/toml -# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml -modLoader="javafml" #mandatory -# A version range to match for said mod loader - for regular FML @Mod it will be the forge version -loaderVersion="[32,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions. -# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties. -# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here. +modLoader="javafml" +loaderVersion="[32,)" license="All rights reserved" -# A URL to refer people to when problems occur with this mod -issueTrackerURL="http://my.issue.tracker/" #optional -# A list of mods - how many allowed here is determined by the individual mod loader -[[mods]] #mandatory -# The modid of the mod -modId="examplemod" #mandatory -# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it -version="${file.jarVersion}" #mandatory - # A display name for the mod -displayName="Example Mod" #mandatory -# A URL to query for updates for this mod. See the JSON update specification -updateJSONURL="http://myurl.me/" #optional -# A URL for the "homepage" for this mod, displayed in the mod UI -displayURL="http://example.com/" #optional -# A file name (in the root of the mod JAR) containing a logo for display -logoFile="examplemod.png" #optional -# A text field displayed in the mod UI -credits="Thanks for this example mod goes to Java" #optional -# A text field displayed in the mod UI -authors="Love, Cheese and small house plants" #optional -# The description text for the mod (multi line!) (#mandatory) +issueTrackerURL="http://github.com/romangraef/tagtooltip" +[[mods]] +modId="tagtooltip" +version="${file.jarVersion}" +displayName="Tag Tooltips" +updateJSONURL="http://myurl.me/" +displayURL="http://example.com/" +logoFile="examplemod.png" +credits="" +authors="Roman Gräf " description=''' -This is a long form description of the mod. You can write whatever you want here - -Have some lorem ipsum. - -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mollis lacinia magna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed sagittis luctus odio eu tempus. Interdum et malesuada fames ac ante ipsum primis in faucibus. Pellentesque volutpat ligula eget lacus auctor sagittis. In hac habitasse platea dictumst. Nunc gravida elit vitae sem vehicula efficitur. Donec mattis ipsum et arcu lobortis, eleifend sagittis sem rutrum. Cras pharetra quam eget posuere fermentum. Sed id tincidunt justo. Lorem ipsum dolor sit amet, consectetur adipiscing elit. +Adds tooltips to items to show the tags that they have. ''' -# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. -[[dependencies.examplemod]] #optional - # the modid of the dependency - modId="forge" #mandatory - # Does this dependency have to exist - if not, ordering below must be specified - mandatory=true #mandatory - # The version range of the dependency - versionRange="[32,)" #mandatory - # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory - ordering="NONE" - # Side this dependency is applied on - BOTH, CLIENT or SERVER - side="BOTH" -# Here's another dependency -[[dependencies.examplemod]] +[[dependencies.tagtooltip]] modId="minecraft" mandatory=true versionRange="[1.16.1]" ordering="NONE" - side="BOTH" + side="CLIENT" diff --git a/src/main/resources/assets/tagtooltip/lang/en_us.json b/src/main/resources/assets/tagtooltip/lang/en_us.json new file mode 100644 index 0000000..88bcad5 --- /dev/null +++ b/src/main/resources/assets/tagtooltip/lang/en_us.json @@ -0,0 +1,5 @@ +{ + "key.showtags": "Show Ore Dictionary / Item Tags", + "tooltip.showTags": "Press %s to show Oredictionary/Tag Tooltips", + "tooltip.tag.prefix": "Tag: %s" +} \ No newline at end of file -- cgit