Posted August 16, 201411 yr Hello all, I've been working on a small mod to add some blocks into the game. Currently, I'm adding 16 color variations of Stone, Stone Bricks, Stone Brick Stairs, Stone Slabs, and Stone Brick Slabs. I have everything but the slabs working properly. I've been doing some research and can't really find anything that actually works. The slabs are in game and in my creative tab. However, there's a version for each single slab and each double slab. There's also no textures for them. They also do not stack properly. My git repo is located here, incase you need to look at more code that I haven't posted. Block Slab Class: package com.bkrenz.swervishblocks.blocks; import net.minecraft.block.BlockSlab; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.util.IIcon; import com.bkrenz.swervishblocks.creativetabs.CreativeTabSB; public class BlockSlabSB extends BlockSlab { private IIcon[] sideIcons; // Constructors public BlockSlabSB(boolean p_IsDoubleSlab, Material p_Material) { super(p_IsDoubleSlab, p_Material); this.setCreativeTab(CreativeTabSB.SB_CreativeTab); this.sideIcons = new IIcon[2]; } @Override public String func_150002_b(int var1) { return this.getUnlocalizedName(); } @Override public void registerBlockIcons(IIconRegister p_Registry) { if (this.getUnlocalizedName() == null) return; if (this.getUnlocalizedName().contains("bricks")) { this.sideIcons[0] = p_Registry.registerIcon("swervishblocks:" + this.getUnlocalizedName()); this.sideIcons[1] = p_Registry.registerIcon("swervishblocks:" + this.getUnlocalizedName()); } else { this.sideIcons[0] = p_Registry.registerIcon("swervishblocks:" + this.getUnlocalizedName() + "side"); this.sideIcons[1] = p_Registry.registerIcon("swervishblocks:" + this.getUnlocalizedName() + "top"); } } @Override public IIcon getIcon(int side, int metadata) { if (side == 0 || side == 1) return this.sideIcons[0]; return this.sideIcons[1]; } } Item Slab Class package com.bkrenz.swervishblocks.items; import com.bkrenz.swervishblocks.creativetabs.CreativeTabSB; import com.bkrenz.swervishblocks.init.ModBlocks; import net.minecraft.block.Block; import net.minecraft.block.BlockSlab; import net.minecraft.item.ItemSlab; public class ItemSlabSB extends ItemSlab { public ItemSlabSB(Block p_Block) { super(p_Block, ModBlocks.findSlab(p_Block.getUnlocalizedName().replaceAll("double", "single")), ModBlocks.findSlab(p_Block.getUnlocalizedName().replaceAll("single", "double")), false); this.setCreativeTab(CreativeTabSB.SB_CreativeTab); } } BlockFactory Class package com.bkrenz.swervishblocks.blocks; import java.util.ArrayList; import java.util.Arrays; import net.minecraft.block.Block; import net.minecraft.block.BlockStairs; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import com.bkrenz.swervishblocks.creativetabs.CreativeTabSB; import com.bkrenz.swervishblocks.init.ModBlocks; import com.bkrenz.swervishblocks.items.ItemSlabSB; import com.bkrenz.swervishblocks.reference.Dyes; import cpw.mods.fml.common.registry.GameRegistry; public class BlockFactory { /** * Create a new block, as well as stairs if necessary * @param p_Name Block Name * @param p_Material Block Material * @param p_HasStair Is there a stair variant? * @return Newly create blocks */ public static ArrayList<Block> createBlock(String p_Name, Material p_Material, boolean p_HasStair) { ArrayList<Block> l_NewBlocks = new ArrayList<Block>(); // Create new block System.out.println("Creating block " + p_Name); BlockSB l_Block = new BlockSB(p_Material); l_Block.setBlockTextureName("swervishblocks:" + p_Name); l_Block.setBlockName(p_Name); l_Block.setCreativeTab(CreativeTabSB.SB_CreativeTab); l_NewBlocks.add(l_Block); GameRegistry.registerBlock(l_Block, p_Name); // Add recipes for the blocks if (p_Name.contains("bricks")){ GameRegistry.addRecipe(new ItemStack(l_Block, , new Object[]{ "AAA", "ABA", "AAA", 'A', Blocks.stonebrick, 'B', new ItemStack(Items.dye, 1, getColor(p_Name))}); GameRegistry.addRecipe(new ItemStack(l_Block, 4), new Object[]{ "AA", "AA", 'A', ModBlocks.findBlock(p_Name.replace("bricks", ""))}); if (!p_Name.contains("bricks")) p_Name += "bricks"; } else GameRegistry.addRecipe(new ItemStack(l_Block, , new Object[]{ "AAA", "ABA", "AAA", 'A', Blocks.stone, 'B', new ItemStack(Items.dye, 1, getColor(p_Name)) }); // If block has stair variants, create stairs if (p_HasStair) { BlockStairs l_Stairs = new BlockStairsSB(l_Block, 0); l_Stairs.setBlockTextureName("swervishblocks:" + p_Name); l_Stairs.setBlockName(p_Name + "stairs"); l_Stairs.setCreativeTab(CreativeTabSB.SB_CreativeTab); l_NewBlocks.add(l_Stairs); GameRegistry.registerBlock(l_Stairs, p_Name + "stairs"); // Add the recipes for stairs GameRegistry.addRecipe(new ItemStack(l_Stairs, , new Object[]{ "AAA", "ABA", "AAA", 'A', Blocks.stone_brick_stairs, 'B', new ItemStack(Items.dye, 1, getColor(p_Name))}); GameRegistry.addRecipe(new ItemStack(l_Stairs, 4), new Object[]{ "A ", "AA ", "AAA", 'A', l_Block}); GameRegistry.addRecipe(new ItemStack(l_Stairs, 4), new Object[]{ " A", " AA", "AAA", 'A', l_Block}); } // Return return l_NewBlocks; } /** * Creates colored blocks of the known input specifications * @param p_Name Block Name * @param p_Material Block Material * @param p_HasStair Is there a stair variation of this block? * @return List of new blocks */ public static ArrayList<Block> createColoredBlock(String p_Name, Material p_Material, boolean p_HasStair) { ArrayList<Block> l_NewBlocks = new ArrayList<Block>(); // Iterate through all colors for (String color: Dyes.DYE_COLOR_LIST) { l_NewBlocks.addAll(createBlock(color + p_Name, p_Material, p_HasStair)); } return l_NewBlocks; } /** * Create a slab using the * @param p_Name * @param p_Material * @return */ public static ArrayList<BlockSlabSB> createBlockSlab(String p_Name, Material p_Material) { ArrayList<BlockSlabSB> l_NewBlocks = new ArrayList<BlockSlabSB>(); // Create the single slab BlockSlabSB l_SingleSlab = new BlockSlabSB(false, p_Material); l_SingleSlab.setBlockName(p_Name + "single"); l_SingleSlab.setBlockTextureName(p_Name); l_NewBlocks.add(l_SingleSlab); // Create the double slab BlockSlabSB l_DoubleSlab = new BlockSlabSB(true, p_Material); l_DoubleSlab.setBlockName(p_Name + "double"); l_DoubleSlab.setBlockTextureName(p_Name); l_NewBlocks.add(l_DoubleSlab); // Create ItemSlab GameRegistry.registerBlock(l_SingleSlab, ItemSlabSB.class, p_Name + "single"); GameRegistry.registerBlock(l_DoubleSlab, ItemSlabSB.class, p_Name + "double"); return l_NewBlocks; } public static ArrayList<BlockSlabSB> createColoredSlabs(String p_Name, Material p_Material) { ArrayList<BlockSlabSB> l_NewBlocks = new ArrayList<BlockSlabSB>(); // Iterate through all colors for (String color: Dyes.DYE_COLOR_LIST) { l_NewBlocks.addAll(createBlockSlab(color + p_Name, p_Material)); } return l_NewBlocks; } /** * Find a color's metadata based on name * @param p_Input * @return color's metadat */ public static int getColor(String p_Input) { for (String color: Dyes.DYE_COLOR_LIST) if (p_Input.contains(color)) return Arrays.asList(Dyes.DYE_COLOR_LIST).indexOf(color); return 0; } } A lot of this has been patched together and is going to be cleaned, commented, and reorganized when it's working.
September 12, 201411 yr Have a look at this tutorial, it mentions and fixes the problems you describe. That video is for 1.6 not 1.7 it will fix all the problems except for the main one slabs not stacking.
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.