Jump to content

Item right click to alter blocks attributes


dev909

Recommended Posts

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 :D):

 

http://pastebin.com/cTYit0MT

 

Again...sorry for no formatting

 

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
}

}

Link to comment
Share on other sites

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;
    }

}

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.