Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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;
}
?????*/
}

Maybe look at how grass color is changed per biome?

Check out my mod, Realms of Chaos, here.

 

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

  • Author

I wouldn't know how to translate it from being texture & biome dependent to

being dependent on only RGB.

You could just have a white texture and color it with RGB

Check out my mod, Realms of Chaos, here.

 

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

  • Author

That's what I was thinking but I don't know how...

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!

And make sure you are importing java.awt.Color

Check out my mod, Realms of Chaos, here.

 

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

  • Author

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;

  • Author

I was editing my post when you replied.

 

and you'll have to forgive me, I don't know what to do with that exactly..

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!

  • Author

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.

  • Author

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.

  • Author

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?

  • Author

Got it. Thanks for the help. Looks like I got a little more to learn before attempting this. Thanks

  • Author

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?

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

  • Author

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.

Hi

 

You might find this link useful

http://greyminecraftcoder.blogspot.com.au/2013/08/lighting.html

 

Make your texture grey scale (or fully white if you want uniform colour)

 

colorMultiplier returns a colour in RGB format.

 

If you return 0xFFFFFF it will be white (no colour change)

return 0x0000FF it will be shaded blue

etc

 

Try it and see....

 

-TGG

 

 

 

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.