Crow Posted September 8, 2014 Posted September 8, 2014 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; } ?????*/ } Quote
Eternaldoom Posted September 8, 2014 Posted September 8, 2014 Maybe look at how grass color is changed per biome? Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
Crow Posted September 8, 2014 Author Posted September 8, 2014 I wouldn't know how to translate it from being texture & biome dependent to being dependent on only RGB. Quote
Eternaldoom Posted September 8, 2014 Posted September 8, 2014 You could just have a white texture and color it with RGB Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
Crow Posted September 8, 2014 Author Posted September 8, 2014 That's what I was thinking but I don't know how... Quote
Eternaldoom Posted September 8, 2014 Posted September 8, 2014 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); } Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
Eternaldoom Posted September 8, 2014 Posted September 8, 2014 And make sure you are importing java.awt.Color Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
Crow Posted September 8, 2014 Author Posted September 8, 2014 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; Quote
Crow Posted September 8, 2014 Author Posted September 8, 2014 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.. Quote
Eternaldoom Posted September 8, 2014 Posted September 8, 2014 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 Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
Crow Posted September 8, 2014 Author Posted September 8, 2014 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. Quote
Crow Posted September 8, 2014 Author Posted September 8, 2014 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. Quote
Crow Posted September 8, 2014 Author Posted September 8, 2014 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? Quote
Crow Posted September 8, 2014 Author Posted September 8, 2014 Got it. Thanks for the help. Looks like I got a little more to learn before attempting this. Thanks Quote
Crow Posted September 9, 2014 Author Posted September 9, 2014 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? Quote
TheGreyGhost Posted September 9, 2014 Posted September 9, 2014 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 Quote
Crow Posted September 9, 2014 Author Posted September 9, 2014 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. Quote
TheGreyGhost Posted September 10, 2014 Posted September 10, 2014 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 Quote
Recommended Posts
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.