Im still new to modding in minecraft and my programing skills are relatively low but I was wondering if anyone knew if its possible to and if so how to render a block such as a slab or fence then using metadata to apply more several skin SETs to the block. For example, I want to make a two tone chair. One chair will be black and white wool, the next red and blue, then next purple and white, green and black, and so on. Can this be rendered with metadata so I dont have to use a block ID for each chair? Here is a copy of my test code Ive been playing around with while learning how the rendering works.
public String getVersion()
{
return "Tutorial by riccardoNL";
}
public void load()
{
MinecraftForgeClient.preloadTexture("tutorialblock.png");
}
public static Block TutorialBlock;
public static int tutorialBlockRenderID;
public mod_TutorialBlock()
{
ModLoader.addName(TutorialBlock, "Tutorial Block by riccardoNL");
ModLoader.registerBlock(TutorialBlock);
tutorialBlockRenderID = ModLoader.getUniqueBlockModelID(this, false);
}
static
{
TutorialBlock = (new BlockTutorialBlock(200, 3)).setHardness(0.5F).setResistance(1.0F).setLightValue(1.0F).setStepSound(Block.soundWoodFootstep).setBlockName("TutorialBlock");
//note that the 200 = the block ID, and the TutorialBlockTexture after it is the icon it shows ingame, in your inventory
}
public boolean renderWorldBlock(RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block, int l)
{
if (l == tutorialBlockRenderID)
{
return renderTutorialBlock(block, i, j, k, renderblocks);
}
return false;
}
public boolean renderTutorialBlock(Block block, int i, int j, int k, RenderBlocks renderblocks)
{
renderblocks.overrideBlockTexture = 234;
block.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.3125F, 0.25F, .9375F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
public void addCreativeItems(ArrayList itemList)
{
itemList.add(new ItemStack(this));
}
public boolean isOpaqueCube()
{
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}
public int getRenderType()
{
return mod_TutorialBlock.tutorialBlockRenderID;
}
public String getTextureFile()
{
return "tutorialblock.png";
}
}
If anyone knows of a good tutorial on how to use metadata with a rendered block please let me know. Any information is useful not to just me but anyone whom might asking a similar question.
P.S. this code currently works as a single block render.
I have the same problem , too.
I have no problem rendering them in my inventory. Each item has it own colour in the inventory, but when I spawn the entity, the texture is not correct.
mod_TutorialBlock
import java.util.*;
import net.minecraft.src.*;
import net.minecraft.src.Temp.BlockTutorialBlock;
import net.minecraft.src.forge.MinecraftForgeClient;
public class mod_TutorialBlock extends BaseMod
{
public String getVersion()
{
return "Tutorial by riccardoNL";
}
public void load()
{
MinecraftForgeClient.preloadTexture("tutorialblock.png");
}
public static Block TutorialBlock;
public static int tutorialBlockRenderID;
public mod_TutorialBlock()
{
ModLoader.addName(TutorialBlock, "Tutorial Block by riccardoNL");
ModLoader.registerBlock(TutorialBlock);
tutorialBlockRenderID = ModLoader.getUniqueBlockModelID(this, false);
}
static
{
TutorialBlock = (new BlockTutorialBlock(200, 3)).setHardness(0.5F).setResistance(1.0F).setLightValue(1.0F).setStepSound(Block.soundWoodFootstep).setBlockName("TutorialBlock");
//note that the 200 = the block ID, and the TutorialBlockTexture after it is the icon it shows ingame, in your inventory
}
public boolean renderWorldBlock(RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block, int l)
{
if (l == tutorialBlockRenderID)
{
return renderTutorialBlock(block, i, j, k, renderblocks);
}
return false;
}
public boolean renderTutorialBlock(Block block, int i, int j, int k, RenderBlocks renderblocks)
{
renderblocks.overrideBlockTexture = 234;
block.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.3125F, 0.25F, .9375F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
renderblocks.overrideBlockTexture = 235;
block.setBlockBounds(0.34375F, 0.0F, 0.03125F, 0.59375F, 0.25F, 0.96875F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
renderblocks.overrideBlockTexture = 236;
block.setBlockBounds(0.6875F, 0.0F, 0.09375F, 0.9375F, 0.25F, 0.90625F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
renderblocks.overrideBlockTexture = 237;
block.setBlockBounds(0.1875F, 0.25F, 0.0625F, 0.4375F, 0.5F, 0.875F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
renderblocks.overrideBlockTexture = 234;
block.setBlockBounds(0.53125F, 0.25F, 0.03125F, 0.78125F, 0.5F, 0.90625F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
renderblocks.overrideBlockTexture = 238;
block.setBlockBounds(0.375F, 0.5F, 0.0625F, 0.625F, 0.75F, 0.9375F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.25F, 1.0F);
return true;
}
}
BlockTutorialBlock
import java.util.ArrayList;
import java.util.Random;
import net.minecraft.src.*;
public class BlockTutorialBlock extends Block
{
public BlockTutorialBlock(int i, int j)
{
super(i, Material.wood);
blockIndexInTexture = j;
}
public void randomDisplayTick(World world, int i, int j, int k, Random random)
{
float f = (float)i + 0.5F; //Location Width
float f1 = (float)j + 1.0F + (random.nextFloat() * 6F) / 10F; //Location Height
float f2 = (float)k + 0.5F; //Location Length
float f3 = (float)j + 0.03125F;
float f4 = (float)i + 0.03125F;
float f5 = random.nextFloat() * 0.6F - 0.3F;
world.spawnParticle("smoke", f, f1, f2 + f5, 0.0D, 0.0D, 0.0D);
world.spawnParticle("largesmoke", f, f1, f2 + f5, 0.0D, 0.0D, 0.0D);
}
public void addCreativeItems(ArrayList itemList)
{
itemList.add(new ItemStack(this));
}
public boolean isOpaqueCube()
{
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}
public int getRenderType()
{
return mod_TutorialBlock.tutorialBlockRenderID;
}
public String getTextureFile()
{
return "tutorialblock.png";
}
}
If anyone knows of a good tutorial on how to use metadata with a rendered block please let me know. Any information is useful not to just me but anyone whom might asking a similar question.
P.S. this code currently works as a single block render.
I have no problem rendering them in my inventory. Each item has it own colour in the inventory, but when I spawn the entity, the texture is not correct.