From 2b63de3345014f372f2c7b71d3d345612c3b698f Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sat, 28 Nov 2020 14:51:41 +0000 Subject: [PATCH] Helper class, ManualItem with helper text and more --- .../common/items/ActuallyItem.java | 5 ++++ .../common/items/ActuallyItems.java | 5 ++-- .../common/items/useables/ManualItem.java | 30 +++++++++++++++++++ .../common/utilities/Help.java | 19 ++++++++++++ .../data/GeneratorItemModels.java | 1 + .../data/GeneratorLanguage.java | 7 +++-- 6 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/items/useables/ManualItem.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItem.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItem.java index 75a8dcb4d..dfd7c8310 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItem.java @@ -1,5 +1,6 @@ package de.ellpeck.actuallyadditions.common.items; +import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import net.minecraft.item.Item; /** @@ -10,4 +11,8 @@ public abstract class ActuallyItem extends Item implements IActuallyItem { public ActuallyItem(Properties properties) { super(properties); } + + protected static Item.Properties baseProps() { + return new Item.Properties().group(ActuallyAdditions.ACTUALLY_GROUP); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java index 3258f80f5..f36eda780 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/ActuallyItems.java @@ -3,6 +3,7 @@ package de.ellpeck.actuallyadditions.common.items; import com.google.common.collect.ImmutableSet; import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import de.ellpeck.actuallyadditions.common.items.useables.AllInOneTool; +import de.ellpeck.actuallyadditions.common.items.useables.ManualItem; import de.ellpeck.actuallyadditions.common.materials.ArmorMaterials; import de.ellpeck.actuallyadditions.common.materials.ToolMaterials; import net.minecraft.item.*; @@ -13,7 +14,7 @@ import net.minecraftforge.registries.ForgeRegistries; import java.util.Set; import java.util.function.Supplier; -public class ActuallyItems { +public final class ActuallyItems { public static final DeferredRegister ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ActuallyAdditions.MOD_ID); // tools @@ -52,7 +53,7 @@ public class ActuallyItems { public static final RegistryObject EMERADIC_CRYSTAL = ITEMS.register("emeradic_crystal", basicItem()); public static final RegistryObject ENORI_CRYSTAL = ITEMS.register("enori_crystal", basicItem()); - public static final RegistryObject BOOKLET = ITEMS.register("booklet", basicItem()); + public static final RegistryObject BOOKLET = ITEMS.register("booklet", ManualItem::new); public static final Set> SIMPLE_ITEMS = ImmutableSet.of( // Crystals diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/ManualItem.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/ManualItem.java new file mode 100644 index 000000000..5a69e7421 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/ManualItem.java @@ -0,0 +1,30 @@ +package de.ellpeck.actuallyadditions.common.items.useables; + +import de.ellpeck.actuallyadditions.common.items.ActuallyItem; +import de.ellpeck.actuallyadditions.common.utilities.Help; +import net.minecraft.client.util.ITooltipFlag; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Rarity; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.List; + +@ParametersAreNonnullByDefault +public class ManualItem extends ActuallyItem { + public ManualItem() { + super(baseProps().maxStackSize(0).setNoRepair().rarity(Rarity.EPIC)); + } + + @Override + public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { + super.addInformation(stack, worldIn, tooltip, flagIn); + + tooltip.add(Help.trans("tooltip.booklet.manual.one").mergeStyle(TextFormatting.GRAY)); + tooltip.add(Help.trans("tooltip.booklet.manual.two")); + tooltip.add(Help.trans("tooltip.booklet.manual.three").mergeStyle(TextFormatting.GOLD)); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java new file mode 100644 index 000000000..6b62e2227 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/Help.java @@ -0,0 +1,19 @@ +package de.ellpeck.actuallyadditions.common.utilities; + +import de.ellpeck.actuallyadditions.common.ActuallyAdditions; +import net.minecraft.util.text.TranslationTextComponent; + +/** + * HELP! FIRE!... I mean, this class should stop fires cure my ocd... + */ +public class Help { + /** + * Builds a TranslationTextComponent using the MOD_ID prefix and a remaining key. + * + * @param key remaining key after prefix of the {@link ActuallyAdditions} MOD_ID + * @return pretty prefixed translated string + */ + public static TranslationTextComponent trans(String key, Object... args) { + return new TranslationTextComponent(String.format("%s.%s", ActuallyAdditions.MOD_ID, key), args); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorItemModels.java b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorItemModels.java index 753bfc816..7f5f05fe0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorItemModels.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorItemModels.java @@ -26,6 +26,7 @@ public class GeneratorItemModels extends ItemModelProvider { ActuallyItems.SIMPLE_ITEMS.forEach(this::simpleItem); + // Toolsets ActuallyItems.ALL_TOOL_SETS.stream() .map(ToolSet::getItemGroup) diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java index abb8e69a3..5c8c1aeae 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/GeneratorLanguage.java @@ -167,8 +167,11 @@ public class GeneratorLanguage extends LanguageProvider { addItem(ActuallyItems.EMERADIC_CRYSTAL, "Emeradic Crystal"); addItem(ActuallyItems.ENORI_CRYSTAL, "Enori Crystal"); - // Misc - addItem(ActuallyItems.BOOKLET, "Booklet"); + // Booklet + addItem(ActuallyItems.BOOKLET, "Actually Additions Manual"); + addPrefixed("tooltip.booklet.manual.one", "Or \"Booklet\", if you will"); + addPrefixed("tooltip.booklet.manual.two", "This book guides you through all of the feature Actually Additions has to over."); + addPrefixed("tooltip.booklet.manual.three", "Use while holding to open."); add("itemGroup.actuallyadditions", "Actually Additions");