Okay, so I have just made a lamp using custom block rendering, but when I break it the item it drops has no texture, it's completely empty. How would I go about adding a texture to the lamp so it appears in the inventory?
Here is my mod_Lamp code:
package net.minecraft.src;
import java.util.Random;
public class mod_Lamp extends Block
{
protected mod_Lamp(int i, int j)
{
super(i, j, Material.circuits);
}
public boolean isOpaqueCube()
{
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}
public int getRenderType()
{
return mod_More_Resources.lampRenderID;
}
public int idDropped(int i, Random random)
{
return mod_More_Resources.lamp.blockID;
}
public void onBlockPlaced(World world, int i, int j, int k, int l)
{
onNeighborBlockChange(world, i, j, k, l);
}
public void onNeighborBlockChange(World world, int i, int j, int k, int l)
{
if(l > 0 && Block.blocksList[l].canProvidePower() && (world.isBlockIndirectlyGettingPowered(i, j, k)))
{
world.setBlockWithNotify(i, j, k, mod_More_Resources.lampGlowing.blockID);
}
if (world.isBlockIndirectlyGettingPowered(i, j, k))
{
world.setBlockWithNotify(i, j, k, mod_More_Resources.lampGlowing.blockID);
}
else
{
world.setBlockWithNotify(i, j, k, mod_More_Resources.lamp.blockID);
}
return;
}
}
and here are the relevant parts of my mod class that apply to the lamp:
public class mod_More_Resources extends BaseMod
{
public static final Block lamp = new mod_Lamp(103, 0).setHardness(1.0F).setBlockName("lamp");
public static final Block lampGlowing = new mod_Lamp(104,0).setHardness(1.0F).setLightValue(.9375F).setBlockName("lampGlowing");
public static int lampRenderID;
public static int lampbrass = ModLoader.addOverride("/terrain.png", "/more_resources/textures/lampbrass.png");
public static int lampleather = ModLoader.addOverride("/terrain.png", "/more_resources/textures/lampleather.png");
public mod_More_Resources()
{
ModLoader.RegisterBlock(lamp);
ModLoader.RegisterBlock(lampGlowing);
ModLoader.AddName(lamp, "Lamp");
ModLoader.AddName(lampGlowing, "Lamp");
ModLoader.AddRecipe(new ItemStack(lamp, 1), new Object[]{
"CGC", "CBC", "BBB", Character.valueOf('C'), Block.cloth, Character.valueOf('B'), ingotBrass, Character.valueOf('G'), Block.glass
});
lampRenderID = ModLoader.getUniqueBlockModelID(this, true);
}
public boolean RenderWorldBlock(RenderBlocks renderblocks, IBlockAccess iblockaccess, int i, int j, int k, Block block, int l)
{
if (l == lampRenderID)
{
return RenderLamp(block, i, j, k, renderblocks, iblockaccess);
}
else
{
return false;
}
}
public boolean RenderLamp(Block block, int i, int j, int k, RenderBlocks renderblocks, IBlockAccess iblockaccess)
{
renderblocks.overrideBlockTexture = lampbrass;
block.setBlockBounds(0.2F, 0.0F, 0.2F, 0.8F, 0.1F, 0.8F);
renderblocks.renderStandardBlock(block, i, j, k);
block.setBlockBounds(0.4F, 0.1F, 0.4F, 0.6F, 0.5F, 0.6F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = lampleather;
block.setBlockBounds(0.0F, 0.5F, 0.0F, 1.0F, 0.6F, 1.0F);
renderblocks.renderStandardBlock(block, i, j, k);
block.setBlockBounds(0.1F, 0.6F, 0.1F, 0.9F, 0.7F, 0.9F);
renderblocks.renderStandardBlock(block, i, j, k);
block.setBlockBounds(0.2F, 0.7F, 0.2F, 0.8F, 0.8F, 0.8F);
renderblocks.renderStandardBlock(block, i, j, k);
block.setBlockBounds(0.3F, 0.8F, 0.3F, 0.7F, 0.9F, 0.7F);
renderblocks.renderStandardBlock(block, i, j, k);
block.setBlockBounds(0.4F, 0.9F, 0.4F, 0.6F, 1.0F, 0.6F);
renderblocks.renderStandardBlock(block, i, j, k);
renderblocks.overrideBlockTexture = -1;
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
return true;
}
}
I found out that the boolean decides whether or not the block should be rendered as a 3D object in the inventory, and sense that wasn't working, I just set it to false and gave it a texture. That didn't work right away though, I also had to put this:
ItemBlock lampItem = new ItemBlock(lamp.blockID - 256);
Item.itemsList[lamp.blockID] = lampItem;
Which is needed to render a custom image in the inventory.
Here is my mod_Lamp code:
and here are the relevant parts of my mod class that apply to the lamp:
Hopefully it's not just a stupid error on my part...
Please post sollution. I want to know how as well. :biggrin.gif:
All I did was changed this:
to this:
I found out that the boolean decides whether or not the block should be rendered as a 3D object in the inventory, and sense that wasn't working, I just set it to false and gave it a texture. That didn't work right away though, I also had to put this:
Which is needed to render a custom image in the inventory.