Posted January 23, 201411 yr I'm trying to create an item that when right click, will grab the blockId of the current coordinates, compare it to another blockId, then if true to change the current block's getColorMultiplier(). It looks like I need to change the return value of Block.getColorMultiplier(). So I heard of overloading and overriding so I create a new class that extends Block and tried my hand at it. Heres the code(apologies as none of the editing tools work...so no code or spoilers formatting): ~~~paintBrush(item)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class paintBrush extends Item { public paintBrush(int par1) { super(par1); maxStackSize = 1; setCreativeTab(CreativeTabs.tabTools); setUnlocalizedName("paintBrush"); } private static blockCO block; public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { block = blockCO.blocksList[par3World.getBlockId(par4, par5, par6)]; if (block.blockID == 4) { block.colorMultiplier(par3World,46,56,141); } return true; } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~blockCO(block)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class blockCO extends Block { public blockCO(int par1, Material par2Material) { super(par1, par2Material); } public static final blockCO[] blocksList = new blockCO[4096]; public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { return ((par2*65536)+(par3*256)+par4); } } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ So I'm trying to send Red, Green and Blue values to the block.getColorMultiplier() and in blockCO I changed the method so that it accepts the RGB values and return the converted int. When I go in game to test I get this error (using pastebin so the thread ain't too bad for you guys ): http://pastebin.com/cTYit0MT Again...sorry for no formatting
January 23, 201411 yr Your crash log says that the element in your blocksList array is null. But the real question is why do you make an array of 4096 elements, when you only want to change one block. Calling yourself Block#colorMultiplier isn't doing anything, by the way.
January 23, 201411 yr Author Your crash log says that the element in your blocksList array is null. But the real question is why do you make an array of 4096 elements, when you only want to change one block. Calling yourself Block#colorMultiplier isn't doing anything, by the way. I saw it in a thread somewhere. So get rid of the array and set block = par3World.getBlockId(par4, par5, par6)? Why is Block.colorMultiplier not doing anything? I was messing around earlier in the base class and set a random int to pull the 16 different color codes, and let colorMultiplier return a random one. Resulted in a very disco-ish minecraft hahha. But I noticed that the colors all changed after a few seconds, or during alot of movement, which makes me think that colorMultiplier is getting called alot, maybe every few render cycles?
January 23, 201411 yr Yes, changing the method works. Calling it, not. What you want is changing the block to your own block, with world.setBlockId(x, y, z, newId); /----------------------------------------------------------/ public class ColoredBlock extends the-original-block-class{ @Override public int getColorMultiplier(){ return your-own-value-here } }
January 23, 201411 yr Author world.setBlockId(x, y, z, newId); /----------------------------------------------------------/ public class ColoredBlock extends the-original-block-class{ @Override public int getColorMultiplier(){ return your-own-value-here } } So declare a new child class object (ColoredBlock block), remove the blocklist, then on right click it will get the current blocks attributes, store it into the new child block, then use the new override method to get a new return type from colorMultiplier? private static ColoredBlock block public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { block = par3World.getBlockId(par4, par5, par6); if (block.blockID == 4) { block.colorMultiplier(par3World,46,56,141); } return true; } }
January 24, 201411 yr Author private static int selectedBlockId; public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { selectedBlockId = par3World.getBlockId(par4, par5, par6); if (selectedBlockId == 4) { par3World.setBlock(par4, par5, par6, 400, 0, 0); baseCO.blockCO.colorMultiplier(par3World,46,56,141); } return true; } This works! I just have a problem with getting a texture to the "new" block now.
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.