How do you add a lore to a custom block or item (lore being the description line(s) that appear under the title when you hover over it in the inventory view)? In the mod I am developing I wish to add it to some custom items (and blocks if possible).
This is a example how to use this (If you don't understand it). Simply put this in you item class:
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List itemInformation, boolean par4)
{
itemInformation.add("Your Text");
}
If you don't know what a List is, you should definitely watch a tutorial or something like this.
TechMage66
@TechMage66 unfortuently the code when copied and pasted into the project creates an error in eclipse on the .add part saying "The method add(String) is undefined for the type List"
What are you doing there? MItems is your item initialize/register class, right? Why extends that Item? And why did you put addInformation there? That's a totally wrong place for it.
First of all you need to create a new class for your Stick, here is a example how this class could look like:
You could simply change the ItemMageTech_Magic to Item, this class is only for setting creative tab ... If you still wanna take a look, feel free to check it out in my github:
I don't understand why you're going to go through all this work just to add lore to a block! You could use Forge's event's to add ToolTip to an itemstack. I've used it before and it'll even add to Blocks. I think the Event is ItemTooltipEvent. You could add all the strings you want to the list in the event instance!
How could there be a "correct" and incorrect way? Does one of them not work? Creating an ItemBlock just to add lore will most likely be more CPU intensive. There's a clear, easy, and working way right in front of you and you want to go the harder, more-work way? That just does't make any sense. Please explain if I have something "incorrect'. Also, what do you mean by "Because that is more for if you want to add tooltips to things you don't add."
For blocks, you would have to mess around with ItemBlocks which I am not to well versed in yet.
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List itemInformation, boolean par4)
{
itemInformation.add("Your Text");
}
If you don't know what a List is, you should definitely watch a tutorial or something like this.
TechMage66
You register your ItemBlock (you have to leave the block parameter there if you're not using custom parameters!) with your block.
Ex: GameRegistry.registerBlock(new BlockMOD(), ItemBlockMod.class, "modBlock");
@master801 @TechMage66 But it is essentially the same steps as an item just inside the class of a custom block?
Kinda.
Instead what you must do is make a item class for your block that extends ItemBlock (net.minecraft.item.ItemBlock).
Ex (Note, this is my implementation of a custom itemblock that all my mods use. Do not copy any code unless you know what you're doing): https://bitbucket.org/master801/801-core/src/c66f1b23795132c94656798cb8e2e0efaccb840c/src/main/java/core/itemblock/ItemBlockCoreBase.java?at=1.7.10#cl-17
Ex (Basically the same thing as a normal one.): https://bitbucket.org/master801/801-core/src/c66f1b23795132c94656798cb8e2e0efaccb840c/src/main/java/core/itemblock/test/ItemBlockTestRotation.java?at=1.7.10#cl-12
@TechMage66 unfortuently the code when copied and pasted into the project creates an error in eclipse on the .add part saying "The method add(String) is undefined for the type List"
Only now the lore doesn't appear in game even though I added it to my class :-( Does the "boolean par4" need something it?
Here is the code:
package me.Markyroson.item;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import com.Markyroson.lib.RefStrings;
import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
public class MItems extends Item {
public static void mainRegistry() {
initializeItem();
registerItem();
}
public static Item Stick;
public static void initializeItem() {
Stick = new Item().setUnlocalizedName("oStick")
.setCreativeTab(CreativeTabs.tabMaterials)
.setTextureName(RefStrings.MODID + ":" + "stick");
}
public static void registerItem() {
GameRegistry.registerItem(Stick, Stick.getUnlocalizedName());
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List itemInformation, boolean par4)
{
itemInformation.add("This is lore!");
}
}
And code for Main Registry/class:
package com.Markyroson.Main;
import me.Markyroson.item.DiamondMinecartItem;
import me.Markyroson.item.MItems;
import com.Markyroson.blocks.BurnedDirt;
import com.Markyroson.blocks.MBlocks;
import com.Markyroson.entities.DiamondMinecart;
import com.Markyroson.lib.RefStrings;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
@Mod(modid = RefStrings.MODID, name = RefStrings.NAME, version = RefStrings.VERSION)
public class MainRegistry {
@SidedProxy(clientSide = RefStrings.CLIENTSIDE, serverSide = RefStrings.SERVERSIDE)
public static ServerProxy proxy;
@Instance(RefStrings.MODID)
public static MainRegistry modInstance;
@EventHandler
public static void PreLoad(FMLPreInitializationEvent PreEvent) {
proxy.registerRendererInfo();
MItems.mainRegistry();
MBlocks.mainRegistry();
CraftingManager.mainRegistry();
DiamondMinecart.mainRegistry();
DiamondMinecartItem.mainRegistry();
BurnedDirt.mainRegistry();
}
@EventHandler
public static void load(FMLInitializationEvent event) {
}
@EventHandler
public static void PostLoad(FMLPostInitializationEvent PostEvent) {
}
}
First of all you need to create a new class for your Stick, here is a example how this class could look like:
ItemTalismanFire (of course you have to change some things ...)
In this class you can put the addInformation methode.
Now have have to change this:
Stick = new Item().setUnlocalizedName("oStick").setCreativeTab(CreativeTabs.tabMaterials).setTextureName(RefStrings.MODID + ":" + "stick");
to
Stick = new YourItemClass().setCreativeTab(CreativeTabs.tabMaterials);
So now your lore should work ... Hope that helps
TechMage66
Item Block
Block Registry
https://github.com/TechMage66/MageTech/blob/master/src/main/java/com/techmage/magetech/item/ItemMageTech_Magic.java
If you don't understand how this works I can just recommend you to watch a tutorial ...
TechMage66
Hello!
Hello!