Jump to content

2D Block Texture


ninjapancakes87

Recommended Posts

Try making an item which places the block. Then just remove the block's creative visibility and use the item instead. Use this code:

 

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class ItemBlockPlacer extends Item
{
    public int blockID;
    public String textureName;

    public ItemFlintAndSteel(int par1, String textureName, int blockID)
    {
        super(par1);
        this.blockID = blockID;
    }

    /**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
        if (par7 == 0)
        {
            --par5;
        }

        if (par7 == 1)
        {
            ++par5;
        }

        if (par7 == 2)
        {
            --par6;
        }

        if (par7 == 3)
        {
            ++par6;
        }

        if (par7 == 4)
        {
            --par4;
        }

        if (par7 == 5)
        {
            ++par4;
        }

        if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
        {
            return false;
        }
        else
        {
            if (par3World.isAirBlock(par4, par5, par6))
            {
                par3World.playSoundEffect((double)par4 + 0.5D, (double)par5 + 0.5D, (double)par6 + 0.5D, Block.blocksList[blockID].stepSound.getPlaceSound(), 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
                par3World.setBlock(par4, par5, par6, blockID);
            }

            --par1ItemStack.stackSize;
            return true;
        }
    }

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister ir) {

this.itemIcon = ir.registerIcon(textureName);

}
}

 

and when setting it up in the mod file, type this:

 

myBlockPlacer = new ItemBlockPlacer(/* TODO item ID */, /* TODO texture name e.g. "mymod:myitemplacer" */, myBlock.blockID)/* .setCreativeTab(CreativeTabs.tabBlock) etc. */;

 

Hope I helped!

 

Romejanic

Romejanic

 

Creator of Witch Hats, Explosive Chickens and Battlefield!

Link to comment
Share on other sites

For your block to be 3D in your inventory you need an ItemRenderer. If you don't want that, delete the ItemRenderer and just make a texture for it just like you do with normal blocks.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Try making an item which places the block. Then just remove the block's creative visibility and use the item instead. Use this code:

 

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class ItemBlockPlacer extends Item
{
    public int blockID;
    public String textureName;

    public ItemFlintAndSteel(int par1, String textureName, int blockID)
    {
        super(par1);
        this.blockID = blockID;
    }

    /**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
        if (par7 == 0)
        {
            --par5;
        }

        if (par7 == 1)
        {
            ++par5;
        }

        if (par7 == 2)
        {
            --par6;
        }

        if (par7 == 3)
        {
            ++par6;
        }

        if (par7 == 4)
        {
            --par4;
        }

        if (par7 == 5)
        {
            ++par4;
        }

        if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
        {
            return false;
        }
        else
        {
            if (par3World.isAirBlock(par4, par5, par6))
            {
                par3World.playSoundEffect((double)par4 + 0.5D, (double)par5 + 0.5D, (double)par6 + 0.5D, Block.blocksList[blockID].stepSound.getPlaceSound(), 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
                par3World.setBlock(par4, par5, par6, blockID);
            }

            --par1ItemStack.stackSize;
            return true;
        }
    }

@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister ir) {

this.itemIcon = ir.registerIcon(textureName);

}
}

 

and when setting it up in the mod file, type this:

 

myBlockPlacer = new ItemBlockPlacer(/* TODO item ID */, /* TODO texture name e.g. "mymod:myitemplacer" */, myBlock.blockID)/* .setCreativeTab(CreativeTabs.tabBlock) etc. */;

 

Hope I helped!

 

Romejanic

That's what I was hoping to avoid, but ended up using anyway.  Thanks for the help anyway!

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.