Jump to content

Recommended Posts

Posted

I am adding alot of blocks to my mod. 1000+. All just solid colors.

I am wondering, is there a way to have the texture generate for each

block using RGB without each block needing a texture?

 

Idea is something like this...

 

whiteBlock = new ModBlocks("White"), Material.iron, 1.5F, 10F, Block.soundTypeMetal, 255, 255, 255);

 

public class MODBlocks extends Block 
{
protected MODBlocks(String name, Material mat, float hard, float resi, SoundType sound, int R, int G, int B) 
{
	super(mat);
	this.setBlockName(name);
	this.setHardness(hard);
	this.setResistance(resi);
	this.setStepSound(sound);
	this.setCreativeTab(MOD.tabMODTabs);
        
        GameRegistry.registerBlock(this, this.getUnlocalizedName().substring(5));
}

/*	?????
@SideOnly(Side.CLIENT)
protected IIcon blockIcon;

@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister p_149651_1_)
{
blockIcon = p_149651_1_.registerIcon(MOD.modid + ":" + this.getUnlocalizedName().substring(5));
}

@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int p_149691_1_, int p_149691_2_)
{
return blockIcon;
}
?????*/
}

Posted

Heres an example for RGB. Try putting this in a block:

int red = 0, green = 0, blue = 255;

@Override
@SideOnly(Side.CLIENT)
    public int getRenderColor(int par)
    {
        String hex = String.format("#%02x%02x%02x", red, green, blue);        
        return Integer.parseInt(hex.replaceFirst("#", ""), 16);
    }

@Override
@SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess p_149720_1_, int p_149720_2_, int p_149720_3_, int p_149720_4_)
    {
	String hex = String.format("#%02x%02x%02x", red, green, blue);        
        return Integer.parseInt(hex.replaceFirst("#", ""), 16);
    }

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Posted

Error..

 

java.util.IllegalFormatConversionException: x != java.lang.String

 

on

 

String hex = String.format("#%02x%02x%02x", red, green, blue); 

 

Just to make sure you know I am calling the RGB values from the constructor as in the op.

I changed the int to String and added private Strings for red, green and blue.

 

Blue = new MODBlocks("Blue", Material.iron, 1.5F, 10F, Block.soundTypeMetal, "0", "0", "255");

 

public class MODBlocks extends Block 
{
private String red;
private String green;
private String blue;

public MODBlocks(String name, Material mat, float hard, float resi, SoundType sound, String R, String G, String B) 
{
	super(mat);
	this.setBlockName(name);
	this.setHardness(hard);
	this.setResistance(resi);
	this.setStepSound(sound);
	this.setCreativeTab(NEC.tabNECTabs);
	red = R;
	green = G;
	blue = B;

Posted

I posted that code instead of just using hex colors because he said he wanted to use RGB. You're right, just using hex is better

Check out my mod, Realms of Chaos, here.

 

If I helped you, be sure to press the "Thank You" button!

Posted

Seems that is what I would use if I were to have a class for each block.

But am predicting little over 1000 blocks. So I would prefer to just have all of them

pass through one block class.

 

What if I already have the hex for all the colors I need? couldn't I take that from the constructor as a string?

I would prefer to use RGB personally but if its easier to use hex without conversion I can, just don't know how.

lol.. I am still a noob at all this but learning fast. Thanks for helping.

Posted

ID's shouldn't be a problem anymore once we get a 1.8 update right?

and i know absolutely nothing about TileEntitys... Might be time to learn.

Posted

Is there an easy way to assign meta using the format I have?

Maybe just making 16 blocks the same unlocalizedname and setting a meta?

or is it a bit more complicated than that?

Posted

Ok so I have done my research and checked out a few tutorials and came up with this..

 

public class colorBlocks01 extends Block
{
@SideOnly(Side.CLIENT)
private IIcon[] texture;

final static String[] subBlocks = new String[] {"white","orange","magenta","yellow",
												"lightblue","lime","pink","gray",
												"lightgray","cyan","purple","brown",
												"blue","green","red","black"};

public colorBlocks01() 
{
	super(Material.rock);
	this.setHardness(3.5F);
	this.setResistance(5.0F);
	this.setCreativeTab(NEC.NECTab);
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
	texture = new IIcon[subBlocks.length];
	for(int i = 0; i < subBlocks.length; i++)
	{
		texture[i] = iconRegister.registerIcon(NEC.modid + ":" + "colors-" + subBlocks[i]);
	}
}

@SideOnly(Side.CLIENT)
public void getSubBlocks(Item block, CreativeTabs tab, List list)
{
	for (int i = 0; i < subBlocks.length; i++)
	{
		list.add(new ItemStack(block, 1, i));
	}
}

@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
	return texture[meta];
}

public int damageDropped(int meta)
{
	return meta;
}

}

 

public class ItemColorBlocks01 extends ItemBlock
{

final static String[] subBlocks = new String[] {"white","orange","magenta","yellow",
												"lightblue","lime","pink","gray",
												"lightgray","cyan","purple","brown",
												"blue","green","red","black"};

public ItemColorBlocks01(Block block) {
	super(block);
	this.setHasSubtypes(true);
}

public String getUnlocalizedName(ItemStack itemstack)
{
	int i = itemstack.getItemDamage();
	if(i < 0 || i >= subBlocks.length)
	{
		i = 0;
	}

	return super.getUnlocalizedName() + "." + subBlocks[i];
}

public int getMetaData(int meta)
{
	return meta;
}
}

 

QUESTION- Now that I have that and it works, how could I go about swapping the texture for an RGB value (preferable), or hex?

Posted

Hi

 

> QUESTION- Now that I have that and it works, how could I go about swapping the texture for an RGB value (preferable), or hex?

You can probably achieve this by overriding Block.colorMultiplier().

Change the return value to the colour you want; assuming you are encoding your 1024 colours using a mixture of block and metadata, you will probably need

IBlockAccess.getBlockMetadata(wx, wy, wz) too

 

-TGG

Posted

I kinda figured colorMultiplier might come into play but I have no idea how to modify it to make it do what I want it to do.

It would have to process 16 different blocks with individual colors.

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.