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

I'm wondering how i can differentiate between damage values in my lang file. I'm using a modified copy of minecraft's Log code to make my own. It creates new logs as the same ID with different metadata.

package worlddomination.blocks;

import java.util.List;

import net.minecraft.block.BlockLog;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import worlddomination.util.Reference;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockWDLog extends GenericWDLog
{
    public static final String[] field_150169_M = new String[] {"rubber"};
    private static final String __OBFID = "CL_00000277";

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item p_149666_1_, CreativeTabs p_149666_2_, List p_149666_3_)
    {
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 0));
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister p_149651_1_)
    {
        this.field_150167_a = new IIcon[field_150169_M.length];
        this.field_150166_b = new IIcon[field_150169_M.length];

        for (int i = 0; i < this.field_150167_a.length; ++i)
        {
            this.field_150167_a[i] = p_149651_1_.registerIcon(Reference.MODID + ":" + this.getTextureName() + "_" + field_150169_M[i]);
            this.field_150166_b[i] = p_149651_1_.registerIcon(Reference.MODID + ":" + this.getTextureName() + "_" + field_150169_M[i] + "_top");
        }
    }
}

I saw that the vanilla lang uses, "tile.log.oak.name" How can i do something similar?

  • 1 month later...

I have done something similar with a mod I'm working on.

 

Here's the code for my custom wood logs file:

package net.davidjholland.everytrees;

import java.util.List;

import net.minecraft.block.BlockLog;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockEveryLog extends BlockLog
{
    public static final String[] woodType = new String[] {"diamond", "gold", "iron"};
    private static final String __OBFID = "CL_00000281";

    /**
     * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
     */
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item block, CreativeTabs creativeTabs, List list){
    	for(int i = 0; i < woodType.length; i++){
		list.add(new ItemStack(block, 1, i));
	}
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconRegister)
    {
        this.field_150167_a = new IIcon[woodType.length];
        this.field_150166_b = new IIcon[woodType.length];

        for (int i = 0; i < this.field_150167_a.length; ++i)
        {
            this.field_150167_a[i] = iconRegister.registerIcon(EveryTrees.MODID + ":" + this.getTextureName() + "_" + woodType[i]);
            this.field_150166_b[i] = iconRegister.registerIcon(EveryTrees.MODID + ":" + this.getTextureName() + "_" + woodType[i] + "_top");
        }
    }
    
}

 

Then I created a Item class that extends ItemBlockWithMetadata to go along with.

This is where you get the unlocalized name and add the wood types I set in the previous file.

package net.davidjholland.everytrees;

import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemEveryLog extends ItemBlockWithMetadata {

public ItemEveryLog(Block block) {
	super(block, block);
}

public String getUnlocalizedName(ItemStack itemStack){
	int i = itemStack.getItemDamage();
	if (i < 0 || i >= BlockEveryLog.woodType.length){
		i = 0;
	}

	return super.getUnlocalizedName() + "." + BlockEveryLog.woodType[i];
}

public int getMetadata(int meta){
	return meta;
}

}

 

Then when you register the block, insert the Item.class into it.

blockEveryLog = new BlockEveryLog()
.setBlockTextureName("log")
.setBlockName("blockEveryLog")
.setCreativeTab(tabEveryTrees);

GameRegistry.registerBlock(blockEveryLog, ItemEveryLog.class, blockEveryLog.getUnlocalizedName().substring(5));

 

And in your en_US.lang file, you'd have something like this:

tile.blockEveryLog.diamond.name=Diamond Wood
tile.blockEveryLog.gold.name=Gold Wood
tile.blockEveryLog.iron.name=Iron Wood

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.