Jump to content

[1.11.2] How to add custom lores to item


Bird

Recommended Posts

Yep, it's me again :P

Any help on this? It does not work.

GymDbellItem.java

package com.bagasmc.gym.items;

import java.util.List;

import com.bagasmc.gym.handlers.CreativeTabHandler;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class GymDbellItem extends Item {

	public static ItemBase gymDumbbell;
	public static ItemStack dumBell;
	
	 public static void init() {
	 gymDumbbell = register(new ItemBase("dumbBell").setCreativeTab(CreativeTabHandler.tabBlocks));
	 }
	 
	 @Override
	 public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean check) {
	  list.add("     STAMINA     ");
	  list.add("3 kilos   6.6 lbs");

	 }
	 
	private static <T extends Item> T register(T item) {
		GameRegistry.register(item);
		
		if(item instanceof ItemModelProvider) {
			((ItemModelProvider)item).registerItemModel(item);
		}
		
		return item;
	}
}

 

 

It does not show the lore :(

Link to comment
Share on other sites

package com.bagasmc.gym.items;

import java.util.List;

import com.bagasmc.gym.handlers.CreativeTabHandler;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class GymDumbbell extends Item {

     public static ItemBase dumbBell;
     gymDumbbell gymdumbbell = new gymDumbbell();
     
     public static void init() {
     dumbBell = register(new ItemBase("dumbbell").setCreativeTab(CreativeTabHandler.tabBlocks));
     }
     
     @Override
     public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean check) {
      list.add("     STAMINA     ");
      list.add("3 kilos   6.6 lbs");

     }
     
    private static <T extends Item> T register(T item) {
        GameRegistry.register(item);
        
        if(item instanceof ItemModelProvider) {
            ((ItemModelProvider)item).registerItemModel(item);
        }
        
        return item;
    }
}
 

Link to comment
Share on other sites

You are registering

ItemBase dumbBell

and not

GymDumbbell gymdumbbell

. dumbBell is just ItemBase and will not have any properties from GymDumbbell.

Also, If you have too many Items your code might begin to look ugly. Move register() and init() to seperate class just for registering and holding Item objects for cleaner code. Normally called ModItems.

Edited by Gortart
giving out copy-paste-ready code is not a good idea.
Link to comment
Share on other sites

9 minutes ago, diesieben07 said:

Why? There is no reason for this if you don't have like 50 items or so. Please don't blindly recommend / follow practices like this if you don't understand why they exist.

 

Also, please don't just post copy-paste-ready code, especially when it's obvious that OP doesn't have the necessary programming experience.

Sorry, should I edit those parts out?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.