Nethseaar Posted June 19, 2013 Share Posted June 19, 2013 Disclaimer: I am new to both Java and Forge. Probably I'm overlooking many things. I thank you for your patience! Is it possible to make stairs out of only specific metadata sub blocks? I have functioning stairs out of metadata sub blocks, but it makes stairs for each sub block, all of them with the first sub block's texture. Is there a way to specify which sub block to make stairs out of, in the same way you specify which sub block to use in crafting recipes? The stairs constructor doesn't call for, and doesn't accept, a metadata value. I tried changing the constructor in my own stair class (the class that extends BlockStairs), but that didn't go over so well. Maybe if I add a constructor that handles metadata? Here's example code with working stairs from metadata blocks, but too many of them, and mostly the wrong texture (Don't mind the bacon; it's a result of being able to put any string I wanted as the mod title, which people should probably not let me do): Block Class: public class BaconBlocks { public static String[] deathstoneNames = { "Deathstone", "Cracked Deathstone", "Condensed Deathstone", "Smooth Deathstone", "Deathstone Brick", "Carved Deathstone" }; //add blocks ----------------------------------------------------------------------------------------------------------------------------------------- public static Block deathstone; public static BlockStairs deathstoneStairs; public static BlockStairs smoothDeathstoneStairs; public static BlockStairs deathstoneBrickStairs; @Init public static void init() { //initialize blocks ------------------------------------------------------------------------------------------------------------------------------- deathstone = new BlockDeathstone(BlockIDs.deathstone, Material.cactus).setUnlocalizedName("deathstone"); deathstoneStairs = new StairBacon(BlockIDs.deathstoneStairs, BaconBlocks.deathstone, 0); smoothDeathstoneStairs = new StairBacon(BlockIDs.smoothDeathstoneStairs, BaconBlocks.deathstone, 0); deathstoneBrickStairs = new StairBacon(BlockIDs.deathstoneBrickStairs, BaconBlocks.deathstone, 0); //register blocks --------------------------------------------------------------------------------------------------------------------------------- GameRegistry.registerBlock(deathstone, ItemBlockBacon.class, "Bacon" + (deathstone.getUnlocalizedName().substring(5))); GameRegistry.registerBlock(deathstoneStairs, "deathstoneStairs"); GameRegistry.registerBlock(smoothDeathstoneStairs, "smoothDeathstoneStairs"); GameRegistry.registerBlock(deathstoneBrickStairs, "deathstoneBrickStairs"); //name blocks ------------------------------------------------------------------------------------------------------------------------------------- for (int i = 0; i< deathstoneNames.length; i++) {LanguageRegistry.addName(new ItemStack(deathstone, 1, i), deathstoneNames[i]); } LanguageRegistry.addName(deathstoneStairs, "Deathstone Stairs"); LanguageRegistry.addName(smoothDeathstoneStairs, "Smooth Deathstone Stairs"); LanguageRegistry.addName(deathstoneBrickStairs, "Deathstone Brick Stairs"); //set block harvest level ------------------------------------------------------------------------------------------------------------------------- MinecraftForge.setBlockHarvestLevel(deathstone, "pickaxe", 3); MinecraftForge.setBlockHarvestLevel(deathstoneStairs, "pickaxe", 3); MinecraftForge.setBlockHarvestLevel(smoothDeathstoneStairs, "pickaxe", 3); MinecraftForge.setBlockHarvestLevel(deathstoneBrickStairs, "pickaxe", 3); } } Deathstone Class: public class BlockDeathstone extends Block { public BlockDeathstone(int id, Material material) { super(id, material); setStepSound(Block.soundStoneFootstep); setHardness(4.0F); setResistance(5.0F); setCreativeTab(CreativeTabs.tabBlock); setLightValue(1.0F); } public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { float f = 0.0625F; return AxisAlignedBB.getAABBPool().getAABB((double)((float)par2 + f), (double)par3, (double)((float)par4 + f), (double)((float)(par2 + 1) - f), (double)((float)(par3 + 1) - f), (double)((float)(par4 + 1) - f)); } public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) { par5Entity.attackEntityFrom(DamageSource.lava, 3); } @SideOnly(Side.CLIENT) private Icon[] icons; @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister) { icons = new Icon[5]; icons[0] = par1IconRegister.registerIcon("deathstone"); icons[1] = par1IconRegister.registerIcon("condensedDeathstone"); icons[2] = par1IconRegister.registerIcon("smoothDeathstone"); icons[3] = par1IconRegister.registerIcon("deathstoneBrick"); icons[4] = par1IconRegister.registerIcon("carvedDeathstone"); } @SideOnly(Side.CLIENT) public Icon getIcon(int par1, int par2) { return icons[par2]; } public int quantityDropped(Random random){ return 1; } public int damageDropped(int metadata) { return metadata; } @SideOnly(Side.CLIENT) public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) { for (int var4 = 0; var4 < 5; ++var4) { par3List.add(new ItemStack(par1, 1, var4)); } } } ItemBlock Class: public class ItemBlockBacon extends ItemBlock { public ItemBlockBacon(int par1) { super(par1); setHasSubtypes(true); } public String getUnlocalizedName(ItemStack itemstack) { String name = ""; switch(itemstack.getItemDamage()) { case 0: { name = "deathstone"; break; } case 1: { name = "crackedDeathstone"; break; } case 2: { name = "condensedDeathstone"; break; } case 3: { name = "smoothDeathstone"; break; } case 4: { name = "deathstoneBrick"; break; } case 6: { name = "carvedDarkstone"; break; } default: name = "broken"; } return getUnlocalizedName() + "." + name; } public int getMetadata(int par1) { return par1; } } Stair Class: public class StairBacon extends BlockStairs { protected StairBacon(int par1, Block par2Block, int par3) { super(par1, par2Block, par3); // TODO Auto-generated constructor stub } public void updateIcons(IconRegister par1iconregister){ this.blockIcon = par1iconregister.registerIcon("Bacon.BLOCK_ID"); } } Have any ideas how I could get this to work? I have way too many blocks for me not to use metadata blocks, but I would really like to have stairs of some of them. I'll keep fiddling with things in the meantime. Quote New to Java / Programming? Link to comment Share on other sites More sharing options...
ObsequiousNewt Posted June 19, 2013 Share Posted June 19, 2013 That's not how you do metadata blocks. You create one block for the entire ID, then have functions in your block (especially getIcon()) return different values based on the metadata passed in. Quote BEWARE OF GOD --- Co-author of Pentachoron Labs' SBFP Tech. Link to comment Share on other sites More sharing options...
Nethseaar Posted June 19, 2013 Author Share Posted June 19, 2013 Indeed. That's what I have done with the Deathstone block -- it has five metadata sub blocks. What I'm trying to do now is make stair blocks out of only three of those sub blocks. Stair blocks with their own IDs. So, there's one ID for all the Deathstone blocks, then one ID each for Deathstone Stairs, Smooth Deathstone Stairs, and Deathstone Brick stairs. But I can't reference the individual sub blocks. So right now each instance of stairs that points toward Deathstone creates 5 stair blocks, all with the same texture. Quote New to Java / Programming? Link to comment Share on other sites More sharing options...
Darkprince97 Posted June 19, 2013 Share Posted June 19, 2013 You can use the metadata in your Block.class like so: deathstoneBrickStairs = new StairBacon(BlockIDs.deathstoneBrickStairs, BaconBlocks.deathstone, Metadata of deathStoneBricks); Quote Link to comment Share on other sites More sharing options...
Nethseaar Posted June 19, 2013 Author Share Posted June 19, 2013 Fantastic! Exactly what I was overlooking. Thank you! As an aside, all my stairs have the same name. Do stairs register names differently than other blocks? EDIT: Didn't set unlocalized names for my stairs. *facepalm* Quote New to Java / Programming? Link to comment Share on other sites More sharing options...
Recommended Posts
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.