Jump to content

[1.7.10] Random item description


Recommended Posts

Hey, I would like to display a random item description among a predefined words list. I tried that :

import java.util.List;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;

public class ItemTest1 extends Item
public ItemTest1()
	this.maxStackSize = 1;

public void addInformation(ItemStack stack, World world, EntityPlayer player, List list, boolean par4)
		String[] randMessages = new String[]{"Alpha", "Bravo", "Charlie"};
        String randMessage = randMessages[world.rand.nextInt(randMessages.length)];
        list.add(EnumChatFormatting.RED + randMessage);


But it doesn't seem to works..


Any idea ?


Thank you very much for your help :)

Link to comment
Share on other sites

Okay so few things here:


1. I am pretty sure addInformation is client-only, used by client for display purposes.

* Said that - you will NOT use and side check - here: !world.isRemote.

2. addInformation is being called every time you are rendering ItemStack's tooltip in FPS manner.

* This fact means that if you would return different (random) stuff every time - it would look like blinking letters.

* Logically - if you want message to be displayed for more than 1 frame of rendering, you need to store your random message.

* Storing can be done by ItemStack's NBT.

3. Knowing point 2:

3.1. How long should be message displayed? (re-randomized every few sec OR forever saved in one ItemStack on creation for the rest of it's existence)?

3.2. Does the server need to know about message or is it PURELY cosmetic?

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

This topic is now closed to further replies.


  • Create New...

Important Information

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