Posted March 7, 20169 yr Hi, I am creating a grass block with the top texture on all faces, but can't get the biome color to work : I'm stuck with the grey texture. I tried to do like the vanilla grass is done so here's my grass class : public class BlockRagagrass extends Block { protected BlockRagagrass() { super(Material.grass); this.setCreativeTab(Ragamod.tabRagamod); } @SideOnly(Side.CLIENT) public int getBlockColor() { return ColorizerGrass.getGrassColor(0.5D, 1.0D); } @SideOnly(Side.CLIENT) public int getRenderColor(IBlockState state) { return this.getBlockColor(); } @SideOnly(Side.CLIENT) public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) { return BiomeColorHelper.getGrassColorAtPos(worldIn, pos); } } And here's a part of my init method : grass_full = (new BlockRagagrass()).setHardness(0.6F).setResistance(2.0F).setStepSound(Block.soundTypeGrass).setUnlocalizedName("grass_full"); Did i miss something or there's a trick? Thanks. edit : is it something with the json block model?
March 7, 20169 yr If you look at assets/minecraft/models/block/grass.json, you'll see that it sets the "tintindex" property for the "up" face of the first element (the base cube) and all faces of the second element (the side overlay). This allows the textures of those faces to be coloured and is passed as the renderPass argument of Block#colorMultiplier(IBlockAccess, BlockPos, int) . Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
March 7, 20169 yr Author It works! Thanks a lot dude! Is it the same trick to get the "item" block colored?
March 8, 20169 yr If you use ItemColored for the block's item form, Item#getColorFromItemStack is overridden to call Block#getRenderColor with the state corresponding to the item metadata. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
March 9, 20169 yr Author I've tried a lot on my own, but didn't succeed just by looking at the Grass's code. Do I have to create a new class that inherit from ItemColored like they did for LilyPad?
March 9, 20169 yr ItemColored would work fine, but GameRegistry can't actually instantiate it because of the way it uses reflection to find the constructor. Essentially the ItemColored constructor takes a primitive boolean argument, but passing a primitive boolean value in a vararg boxes it to a Boolean ; so GameRegistry tries (and fails) to find a constructor with a Boolean argument. Vanilla doesn't have this issue because it instantiates its ItemBlock s directly instead of using reflection. You can create your own class that extends ItemColored and has a (Block, Boolean) constructor (like this) and then use this as the item form of your block. You shouldn't actually need to override anything. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
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.