Helper class, ManualItem with helper text and more

This commit is contained in:
Michael Hillcox 2020-11-28 14:51:41 +00:00
parent 2d97ed3916
commit 2b63de3345
No known key found for this signature in database
GPG key ID: 971C5B254742488F
6 changed files with 63 additions and 4 deletions

View file

@ -1,5 +1,6 @@
package de.ellpeck.actuallyadditions.common.items; package de.ellpeck.actuallyadditions.common.items;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import net.minecraft.item.Item; import net.minecraft.item.Item;
/** /**
@ -10,4 +11,8 @@ public abstract class ActuallyItem extends Item implements IActuallyItem {
public ActuallyItem(Properties properties) { public ActuallyItem(Properties properties) {
super(properties); super(properties);
} }
protected static Item.Properties baseProps() {
return new Item.Properties().group(ActuallyAdditions.ACTUALLY_GROUP);
}
} }

View file

@ -3,6 +3,7 @@ package de.ellpeck.actuallyadditions.common.items;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import de.ellpeck.actuallyadditions.common.ActuallyAdditions; import de.ellpeck.actuallyadditions.common.ActuallyAdditions;
import de.ellpeck.actuallyadditions.common.items.useables.AllInOneTool; 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.ArmorMaterials;
import de.ellpeck.actuallyadditions.common.materials.ToolMaterials; import de.ellpeck.actuallyadditions.common.materials.ToolMaterials;
import net.minecraft.item.*; import net.minecraft.item.*;
@ -13,7 +14,7 @@ import net.minecraftforge.registries.ForgeRegistries;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier; import java.util.function.Supplier;
public class ActuallyItems { public final class ActuallyItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ActuallyAdditions.MOD_ID); public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ActuallyAdditions.MOD_ID);
// tools // tools
@ -52,7 +53,7 @@ public class ActuallyItems {
public static final RegistryObject<Item> EMERADIC_CRYSTAL = ITEMS.register("emeradic_crystal", basicItem()); public static final RegistryObject<Item> EMERADIC_CRYSTAL = ITEMS.register("emeradic_crystal", basicItem());
public static final RegistryObject<Item> ENORI_CRYSTAL = ITEMS.register("enori_crystal", basicItem()); public static final RegistryObject<Item> ENORI_CRYSTAL = ITEMS.register("enori_crystal", basicItem());
public static final RegistryObject<Item> BOOKLET = ITEMS.register("booklet", basicItem()); public static final RegistryObject<Item> BOOKLET = ITEMS.register("booklet", ManualItem::new);
public static final Set<RegistryObject<Item>> SIMPLE_ITEMS = ImmutableSet.of( public static final Set<RegistryObject<Item>> SIMPLE_ITEMS = ImmutableSet.of(
// Crystals // Crystals

View file

@ -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<ITextComponent> 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));
}
}

View file

@ -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);
}
}

View file

@ -26,6 +26,7 @@ public class GeneratorItemModels extends ItemModelProvider {
ActuallyItems.SIMPLE_ITEMS.forEach(this::simpleItem); ActuallyItems.SIMPLE_ITEMS.forEach(this::simpleItem);
// Toolsets // Toolsets
ActuallyItems.ALL_TOOL_SETS.stream() ActuallyItems.ALL_TOOL_SETS.stream()
.map(ToolSet::getItemGroup) .map(ToolSet::getItemGroup)

View file

@ -167,8 +167,11 @@ public class GeneratorLanguage extends LanguageProvider {
addItem(ActuallyItems.EMERADIC_CRYSTAL, "Emeradic Crystal"); addItem(ActuallyItems.EMERADIC_CRYSTAL, "Emeradic Crystal");
addItem(ActuallyItems.ENORI_CRYSTAL, "Enori Crystal"); addItem(ActuallyItems.ENORI_CRYSTAL, "Enori Crystal");
// Misc // Booklet
addItem(ActuallyItems.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"); add("itemGroup.actuallyadditions", "Actually Additions");