Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

How does this function work? I'm trying to use it to get a block via an unlocalized name I'm getting from the nbt data of an item. Currently, however, it doesn't really do anything :/

 

public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean par4)
{
	itemstack.stackTagCompound = new NBTTagCompound();
	itemstack.stackTagCompound.setString("Block", Blocks.stone.getUnlocalizedName());

	list.add("Magic Wand");
	list.add(itemstack.stackTagCompound.getString("Block").substring(5));
}

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
	if(!par2World.isRemote){

		int minWX = (int)par3EntityPlayer.posX & ~0x0f;  // throws away the bottom four bits, i.e. truncates to the next lowest multiple of 16, eg 32, 16, 0, -16, -32 etc
		int minWZ = (int)par3EntityPlayer.posZ & ~0x0f;
		int maxWX = minWX + 15;
		int maxWZ = minWZ + 15;

		Reference.fillChunk(minWX, minWZ, maxWX, maxWZ, par2World, par3EntityPlayer, Recipes.Stick2);
	}
	return par1ItemStack;
}

public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int x, int y, int z, int side, float hitX, float hitY, float hitZ){
	if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT))
	{
		if (!par3World.isRemote)
		{
			par1ItemStack.stackTagCompound.setString("Block", par3World.getBlock(x, y, z).getUnlocalizedName());
			return true;
		}
		return false;
	}

 

Then this is the fillChunk function:

 

public static void fillChunk(int minWX, int minWZ, int maxWX, int maxWZ, World par1World, EntityPlayer Player, ItemStack par1ItemStack){
        for (int wx = minWX; wx <= maxWX; ++wx) {
            for (int wz = minWZ; wz <= maxWZ; ++wz) {
               // setblock (wx, playerYpos - 1, wz)
            	par1World.setBlock(wx, (int)Player.posY -1, wz, Block.getBlockFromName(par1ItemStack.stackTagCompound.getString("Block").substring(5)));
            }
       }

  • Author

Use Block.blockRegistry.getNameForObject() to get the name from a Block and Block.blockRegistry.getObject(name) to get a Block from a name.

Then: Why do you modify the ItemStack inside addInformation? This method is called every frame on the CLIENT. That is not the right place to modify data.

Also: You should get the Block object before the loop, don't look it up again and again and again.

 

If I modify the NBT data inside the onCreated method, the game freezes since there is no data for the tooltip :/ So I don't know where else to put it .-.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.