Posted February 8, 201411 yr Hey, ok i have a block for emitting light but i want it to change texture to whatever block it's been placed on (including modded blocks if possible) So how can i go about this?
February 8, 201411 yr Author light class package a.Screens; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class Light extends Block { public Light(int par1, Material par2Material) { super(par1, par2Material); this.setCreativeTab(CreativeTabs.tabBlock); this.setHardness(10.0F); this.setResistance(10.0F); this.setLightValue(15.0F);}}
February 8, 201411 yr This is both really easy to do and really difficult, due to edge cases and weirdness the player can do if you're not careful. Namely if someone places this light block on top of another one. Here's some code I have that will steal the texture for the next not-this block in an orthogonal direction (that is, it looks for a not itself block in a direction until it hits air, if it finds air it tries another direction, if it fails it uses grass). Its not the greatest code, but it works. public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) { //int mymeta = world.getBlockMetadata(x, y, z); //if(mymeta == 0) { int[] id = {world.getBlockId(x, y-1, z),world.getBlockId(x-1, y, z),world.getBlockId(x+1, y, z),world.getBlockId(x, y, z-1),world.getBlockId(x, y, z+1),world.getBlockId(x, y+1, z)}; int[] meta = {world.getBlockMetadata(x, y-1, z),world.getBlockMetadata(x-1, y, z),world.getBlockMetadata(x+1, y, z),world.getBlockMetadata(x, y, z-1),world.getBlockMetadata(x, y, z+1),world.getBlockMetadata(x, y+1, z)}; //.get.getBlockTextureFromSideAndMetadata(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4)); for(int i = 0; i < id.length; i++) { Block block = Block.blocksList[id[i]]; if(block != null) { if(block != this && block.isOpaqueCube()) { Icon icon = block.getIcon(side, meta[i]); if(icon != null) { return icon; } } else if(block == this) { Icon icon = Block.grass.getBlockTextureFromSide(1); switch(i) { case 0: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y-1, z, side, 0); break; case 1: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x-1, y, z, side, 2); break; case 2: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x+1, y, z, side, 3); break; case 3: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z-1, side, 4); break; case 4: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z+1, side, 5); break; case 5: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y+1, z, side, 1); break; } if(icon != null && icon != Block.grass.getBlockTextureFromSide(1)) { return icon; } } } } return Block.grass.getBlockTextureFromSide(1); /*} else { return blockIcon; }*/ } public Icon getBlockTextureDirectional(IBlockAccess world, int x, int y, int z, int side, int direction) { int id = world.getBlockId(x, y, z); int meta = world.getBlockMetadata(x, y, z); Block block = Block.blocksList[id]; if(block != null) { if(block != this) { Icon icon = block.getIcon(side, meta); if(icon != null) { return icon; } } else { Icon icon = Block.grass.getBlockTextureFromSide(1); switch(direction) { case 0: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y-1, z, side, 0); break; case 1: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y+1, z, side, 1); break; case 2: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x-1, y, z, side, 2); break; case 3: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x+1, y, z, side, 3); break; case 4: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z-1, side, 4); break; case 5: icon = ((BlockIllusionary)block).getBlockTextureDirectional(world, x, y, z+1, side, 5); break; } return icon; } } return Block.grass.getBlockTextureFromSide(1); } The cast to BlockIllusionary will need to be replaced with a cast to your block type. (Bad intenting due to copy/paste from github, original here: https://github.com/Draco18s/Artifacts/blob/master/draco18s/artifacts/block/BlockIllusionary.java ) 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.
February 8, 201411 yr Author ok the block now captures the other textures, but it won't give out light still and the other mod blocks have washed out colours and are partly transparent. but when a menu/command/chat is open the texture is normal. Light Class package a.Screens; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.ForgeDirection; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class Light extends Block { public static Block instance; public int renderType = 0; public Light(int par1, Material air) { super(par1, Material.rock); setUnlocalizedName("Light"); setResistance(2F); setStepSound(soundStoneFootstep); setHardness(0.5F); this.setCreativeTab(CreativeTabs.tabBlock); } @Override public void registerIcons(IconRegister iconRegister) { blockIcon = iconRegister.registerIcon("oomod:Light"); } @Override public boolean isBlockSolidOnSide(World world, int x, int y, int z, ForgeDirection side) { return true; } public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) { //int mymeta = world.getBlockMetadata(x, y, z); //if(mymeta == 0) { int[] id = {world.getBlockId(x, y-1, z),world.getBlockId(x-1, y, z),world.getBlockId(x+1, y, z),world.getBlockId(x, y, z-1),world.getBlockId(x, y, z+1),world.getBlockId(x, y+1, z)}; int[] meta = {world.getBlockMetadata(x, y-1, z),world.getBlockMetadata(x-1, y, z),world.getBlockMetadata(x+1, y, z),world.getBlockMetadata(x, y, z-1),world.getBlockMetadata(x, y, z+1),world.getBlockMetadata(x, y+1, z)}; //.get.getBlockTextureFromSideAndMetadata(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4)); for(int i = 0; i < id.length; i++) { Block block = Block.blocksList[id]; if(block != null) { if(block != this && block.isOpaqueCube()) { Icon icon = block.getIcon(side, meta); if(icon != null) { return icon; } } else if(block == this) { Icon icon = Block.grass.getBlockTextureFromSide(1); switch(i) { case 0: icon = ((Light)block).getBlockTextureDirectional(world, x, y-1, z, side, 0); break; case 1: icon = ((Light)block).getBlockTextureDirectional(world, x-1, y, z, side, 2); break; case 2: icon = ((Light)block).getBlockTextureDirectional(world, x+1, y, z, side, 3); break; case 3: icon = ((Light)block).getBlockTextureDirectional(world, x, y, z-1, side, 4); break; case 4: icon = ((Light)block).getBlockTextureDirectional(world, x, y, z+1, side, 5); break; case 5: icon = ((Light)block).getBlockTextureDirectional(world, x, y+1, z, side, 1); break; } if(icon != null && icon != Block.grass.getBlockTextureFromSide(1)) { return icon; } } } } return Block.grass.getBlockTextureFromSide(1); /*} else { return blockIcon; }*/ } public Icon getBlockTextureDirectional(IBlockAccess world, int x, int y, int z, int side, int direction) { int id = world.getBlockId(x, y, z); int meta = world.getBlockMetadata(x, y, z); Block block = Block.blocksList[id]; if(block != null) { if(block != this) { Icon icon = block.getIcon(side, meta); if(icon != null) { return icon; } } else { Icon icon = Block.grass.getBlockTextureFromSide(1); switch(direction) { case 0: icon = ((Light)block).getBlockTextureDirectional(world, x, y-1, z, side, 0); break; case 1: icon = ((Light)block).getBlockTextureDirectional(world, x, y+1, z, side, 1); break; case 2: icon = ((Light)block).getBlockTextureDirectional(world, x-1, y, z, side, 2); break; case 3: icon = ((Light)block).getBlockTextureDirectional(world, x+1, y, z, side, 3); break; case 4: icon = ((Light)block).getBlockTextureDirectional(world, x, y, z-1, side, 4); break; case 5: icon = ((Light)block).getBlockTextureDirectional(world, x, y, z+1, side, 5); break; } return icon; } } return Block.grass.getBlockTextureFromSide(1); } public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { return null; } public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } public boolean isOpaqueCube() { return false; } public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { return false; } /** * Returns which pass should this block be rendered on. 0 for solids and 1 for alpha */ public int getRenderBlockPass() { return 1; } public boolean renderAsNormalBlock() { return false; } @Override public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side) { if(world.getBlockId(x, y, z) == blockID || world.isBlockOpaqueCube(x, y, z)) return false; return true; } @Override public int getRenderType() { return renderType; } @Override public int quantityDropped(Random par1Random) { return 0; } }
February 8, 201411 yr Have you even set the amount of light level you want it to give off? I see NOTHING relating to light level, expect changing the texture corresponding to the block.
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.