Jump to content

Custom Quartz Blocks


darthvader45

Recommended Posts

Okay, I've created a custom quartz block and have begun creation of a custom quartz slab and item.  However, I have not been able to give the blocks a unique unlocalized name (i.e. they all have the name tile.smokyquartz.name) and also cannot seem to get them to be metadata.

 

BlockSmokyQuartz.java:

package net.lastdragonborn.smokyquartz.blocks;

import java.util.List;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.lastdragonborn.smokyquartz.SmokyQuartz;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
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 net.minecraft.world.World;

public class BlockSmokyQuartz extends Block 
{
 public static final String[] field_150191_a = new String[] {"default", "chiseled", "lines"};
    private static final String[] field_150189_b = new String[] {"side", "chiseled", "lines", null, null};
    @SideOnly(Side.CLIENT)
    private IIcon[] field_150192_M;
    @SideOnly(Side.CLIENT)
    private IIcon field_150193_N;
    @SideOnly(Side.CLIENT)
    private IIcon field_150194_O;
    @SideOnly(Side.CLIENT)
    private IIcon field_150190_P;
    @SideOnly(Side.CLIENT)
    private IIcon field_150188_Q;
    private static final String __OBFID = "CL_00000292";

public BlockSmokyQuartz(Material material)
{
	super(material = Material.rock);
	setCreativeTab(CreativeTabs.tabBlock);

}

 @SideOnly(Side.CLIENT)
    public IIcon getIcon(int p_149691_1_, int p_149691_2_)
    {
        if (p_149691_2_ != 2 && p_149691_2_ != 3 && p_149691_2_ != 4)
        {
            if (p_149691_1_ != 1 && (p_149691_1_ != 0 || p_149691_2_ != 1))
            {
                if (p_149691_1_ == 0)
                {
                    return this.field_150188_Q;
                }
                else
                {
                    if (p_149691_2_ < 0 || p_149691_2_ >= this.field_150192_M.length)
                    {
                        p_149691_2_ = 0;
                    }

                    return this.field_150192_M[p_149691_2_];
                }
            }
            else
            {
                return p_149691_2_ == 1 ? this.field_150193_N : this.field_150190_P;
            }
        }
        else
        {
            return p_149691_2_ == 2 && (p_149691_1_ == 1 || p_149691_1_ == 0) ? this.field_150194_O : (p_149691_2_ == 3 && (p_149691_1_ == 5 || p_149691_1_ == 4) ? this.field_150194_O : (p_149691_2_ == 4 && (p_149691_1_ == 2 || p_149691_1_ == 3) ? this.field_150194_O : this.field_150192_M[p_149691_2_]));
        }
    }

    /**
     * Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
     */
    public int onBlockPlaced(World p_149660_1_, int p_149660_2_, int p_149660_3_, int p_149660_4_, int p_149660_5_, float p_149660_6_, float p_149660_7_, float p_149660_8_, int p_149660_9_)
    {
        if (p_149660_9_ == 2)
        {
            switch (p_149660_5_)
            {
                case 0:
                case 1:
                    p_149660_9_ = 2;
                    break;
                case 2:
                case 3:
                    p_149660_9_ = 4;
                    break;
                case 4:
                case 5:
                    p_149660_9_ = 3;
            }
        }

        return p_149660_9_;
    }

    /**
     * Determines the damage on the item the block drops. Used in cloth and wood.
     */
    public int damageDropped(int p_149692_1_)
    {
        return p_149692_1_ != 3 && p_149692_1_ != 4 ? p_149692_1_ : 2;
    }

    /**
     * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
     * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
     */
    protected ItemStack createStackedBlock(int p_149644_1_)
    {
        return p_149644_1_ != 3 && p_149644_1_ != 4 ? super.createStackedBlock(p_149644_1_) : new ItemStack(Item.getItemFromBlock(this), 1, 2);
    }

    /**
     * The type of render function that is called for this block
     */
    public int getRenderType()
    {
        return 39;
    }

    /**
     * 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));
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 1));
        p_149666_3_.add(new ItemStack(p_149666_1_, 1, 2));
    }

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

        for (int i = 0; i < this.field_150192_M.length; ++i)
        {
            if (field_150189_b[i] == null)
            {
                this.field_150192_M[i] = this.field_150192_M[i - 1];
            }
            else
            {
                this.field_150192_M[i] = p_149651_1_.registerIcon(SmokyQuartz.MODID + ":" + "smoky_quartz_block" + "_" + field_150189_b[i]);
            }
        }

        this.field_150190_P = p_149651_1_.registerIcon(SmokyQuartz.MODID + ":" + "smoky_quartz_block" + "_" + "top");
        this.field_150193_N = p_149651_1_.registerIcon(SmokyQuartz.MODID + ":" + "smoky_quartz_block" + "_" + "chiseled_top");
        this.field_150194_O = p_149651_1_.registerIcon(SmokyQuartz.MODID + ":" + "smoky_quartz_block" + "_" + "lines_top");
        this.field_150188_Q = p_149651_1_.registerIcon(SmokyQuartz.MODID + ":" + "smoky_quartz_block" + "_" + "bottom");
   
    }
    

}

 

 

 

Link to comment
Share on other sites

You need an ItemBlock for that.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

	@Override
    public String getUnlocalizedName(ItemStack itemStack)
    {
        return "item." + names[itemStack.getItemDamage()];
    }

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

	@Override
    public String getUnlocalizedName(ItemStack itemStack)
    {
        return "item." + names[itemStack.getItemDamage()];
    }

 

Alrighty, then.  Here's what I have so far:

 

BlockSmokyQuartz.java:

package net.lastdragonborn.smokyquartz.blocks;

import java.util.List;

import net.lastdragonborn.smokyquartz.proxy.CommonProxy;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
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 BlockSmokyQuartz extends Block 
{
@SideOnly(Side.CLIENT)
private IIcon[] texture;
public BlockSmokyQuartz (Material material) {
	super(material);
	setCreativeTab(CreativeTabs.tabBlock);
}

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister par1IconRegister){
texture = new IIcon[16];
for(int i = 0; i < 16; i++)
texture[i] = par1IconRegister.registerIcon("sokobanMod:BlockConcreteLamp" + i);
}

@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for(int var4 = 0; var4 < 16; ++var4)
	{
par3List.add(new ItemStack(ModBlocks.smokyQuartz, 1, var4));
	}
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta){
return texture[meta];
}

@Override
public int damageDropped(int meta){
return meta;
}


}

 

ItemBlockSmokyQuartz.java:

 

package net.lastdragonborn.smokyquartz.items;

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

public class ItemBlockSmokyQuartz extends ItemBlock {

private String[] names = {"Block of", "Column", "Chiseled"};

public ItemBlockSmokyQuartz(Block block1, Block block2) {
	super(block1);
	setHasSubtypes(true);
	}

@Override
public String getItemStackDisplayName(ItemStack is){
return names[is.getItemDamage()] + "Smoky Quartz";
}

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

}

 

Now my block isn't getting registered.  What could be the problem?

 

Link to comment
Share on other sites

Ok, for one, you didn't implement getUnlocalizedName anywhere.  It goes in the ItemBlock class.  Instead you're using getItemStackDisplayName, which is supposed to return the localized name (and you're not using

StatCollector.translateToLocal

).  You don't want that.

 

As for the block not getting registered, I don't know, you didn't include your main class!

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Ok, here's what I have for my blocks(made sure to call the init() method from ModBlocks in my main class):

 

BlockSmokyQuartz.java:

package net.lastdragonborn.smokyquartz.blocks;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BlockSmokyQuartz extends Block 
{
public BlockSmokyQuartz (Material material) 
{
	super(material);
	this.setUnlocalizedName("smokyQuartz");
	setCreativeTab(CreativeTabs.tabBlock);
	setStepSound(Block.soundTypeStone);
}

private String setUnlocalizedName(String string) {
	// TODO Auto-generated method stub
	return "smokyQuartz";
}

@Override
public int damageDropped (int metadata) {
	return metadata;
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(int unknown, CreativeTabs tab, List subItems) {
	for (int ix = 0; ix < 16; ix++) {
		subItems.add(new ItemStack(this, 1, ix));
	}
}

}

 

ItemBlockSmokyQuartz.java:

 

package net.lastdragonborn.smokyquartz.items;

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

public class ItemBlockSmokyQuartz extends ItemBlock {

private final static String[] subNames = {
	"default", "chiseled",  "lines"
};

public ItemBlockSmokyQuartz(Block id) {
	super(id);
	setHasSubtypes(true);

}

@Override
public int getMetadata (int damageValue) {
	return damageValue;
}

@Override
public String getUnlocalizedName(ItemStack itemstack) {
	return getUnlocalizedName() + "." + subNames[itemstack.getItemDamage()];
}


}

Link to comment
Share on other sites

Ok, and what's the problem currently?  Those classes look fine.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

That's not an answer to the question I asked.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Did you register the block as having an ItemBlock?

 

E.g.

GameRegistry.registerBlock(blockOreFlowers, ItemBlockOreFlower.class, "ore_flowers");

 

Because if you didn't, you won't see their names.  And if you do, it'll crash (because you're telling the game it has 16 sub items and your ItemBlock class only has 3 names.  As soon as it tries to get the name for meta-4 to 15, it'll ArrayIndexOutOfBounds on you).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I'll double-check the number of sub-types it has and make sure it's only 3 everywhere it's mentioned.  Whenever I make a mod, I tend to register all my blocks as having an ItemBlock if they are supposed to.  Should I register my ItemBlock in my ModItems.java file?

 

Edit: Changed the ItemBlock to only have 3 variations, and I don't get any ArrayIndexOutOfBounds exceptions, yet I still don't see the other variations at all.  I did register it as having an ItemBlock, just like your example showed.

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.