Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.8.9] Problem with custom block color in inventory


Erfurt
 Share

Recommended Posts

Hey guys,

 

So I have an odd problem here. I'm making an aesthetic mod, that adds hedges to the game. At the moment I have made all the hedges from the different types of vanilla leaves, so oak, birch, and so on. They all have the correct color when the hedges are placed, and everything else is working perfectly. Only one thing that I don't understand is why the blocks is grey (without color), when I have the block in the inventory. I have looked at the vanilla leave code, and I haven't been able to locate what is wrong. It should be mentioned that when I make an item for the block instead, and add this code it have the color on it, I have tried to use that code in the block class for my hedges, but that didn't work. I was hoping that someone could take a look at my code, and see if I did something wrong, or is missing something for it to work.

 

Code from the item

@SideOnly(Side.CLIENT)
    public int getColorFromItemStack(ItemStack stack, int renderPass)
    {
        return this.block.getRenderColor(this.block.getStateFromMeta(stack.getMetadata()));
    }

 

My block class

public class BlockHedge extends Block
{
public static final PropertyBool NORTH = PropertyBool.create("north");
public static final PropertyBool EAST = PropertyBool.create("east");
public static final PropertyBool SOUTH = PropertyBool.create("south");
public static final PropertyBool WEST = PropertyBool.create("west");

public BlockHedge(Material material)
{
	super(Material.leaves);
	setHardness(1.0F);
	setStepSound(Block.soundTypeGrass);
	setDefaultState(this.blockState.getBaseState().withProperty(NORTH, Boolean.valueOf(false)).withProperty(EAST, Boolean.valueOf(false)).withProperty(SOUTH, Boolean.valueOf(false)).withProperty(WEST, Boolean.valueOf(false)));
}

public boolean isOpaqueCube()
{
	return false;
}

public boolean isNormalCube()
{
	return false;
}

public boolean isFullCube()
{
	return false;
}

@SideOnly(Side.CLIENT)
public int getBlockColor()
{
	return ColorizerFoliage.getFoliageColor(0.5D, 1.0D);
}

@SideOnly(Side.CLIENT)
public int getRenderColor(IBlockState state)
{
	if (state.getBlock() != this)
	{
		return super.getRenderColor(state);
	}
	return this == HaWMBlocks.hedge_birch ? ColorizerFoliage.getFoliageColorBirch() : this == HaWMBlocks.hedge_spruce ? ColorizerFoliage.getFoliageColorPine() : ColorizerFoliage.getFoliageColorBasic();
}

@SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass)
    {
	if (this == HaWMBlocks.hedge_spruce)
	{
		return ColorizerFoliage.getFoliageColorPine();
	}
	if (this == HaWMBlocks.hedge_birch)
	{
		return ColorizerFoliage.getFoliageColorBirch();
	}
        return BiomeColorHelper.getFoliageColorAtPos(worldIn, pos);
    }

@SideOnly(Side.CLIENT)
public EnumWorldBlockLayer getBlockLayer()
{

	return EnumWorldBlockLayer.CUTOUT_MIPPED;
}

@SideOnly(Side.CLIENT)
public void setBlockBoundsBasedOnState(IBlockAccess blockAccess, BlockPos pos)
{
	float f = 0.1875F;
	float f1 = 0.8125F;
	float f2 = 0.1875F;
	float f3 = 0.8125F;
	if ((blockAccess.getBlockState(pos.east()).getBlock() instanceof BlockHedge | blockAccess.getBlockState(pos.east()).getBlock() instanceof BlockFenceGate | blockAccess.getBlockState(pos.east()).getBlock().isNormalCube()))
	{
		f1 = 1.0F;
	}
	if ((blockAccess.getBlockState(pos.west()).getBlock() instanceof BlockHedge | blockAccess.getBlockState(pos.west()).getBlock() instanceof BlockFenceGate | blockAccess.getBlockState(pos.west()).getBlock().isNormalCube()))
	{
		f = 0.0F;
	}
	if ((blockAccess.getBlockState(pos.south()).getBlock() instanceof BlockHedge | blockAccess.getBlockState(pos.south()).getBlock() instanceof BlockFenceGate | blockAccess.getBlockState(pos.south()).getBlock().isNormalCube()))
	{
		f3 = 1.0F;
	}
	if ((blockAccess.getBlockState(pos.north()).getBlock() instanceof BlockHedge | blockAccess.getBlockState(pos.north()).getBlock() instanceof BlockFenceGate | blockAccess.getBlockState(pos.north()).getBlock().isNormalCube()))
	{
		f2 = 0.0F;
	}
	setBlockBounds(f, 0.0F, f2, f1, 1.0F, f3);
}

public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity)
{
	setBlockBounds(0.1875F, 0.0F, 0.1875F, 0.8125F, 1.5F, 0.8125F);
	super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
	if ((world.getBlockState(pos.east()).getBlock() instanceof BlockHedge | world.getBlockState(pos.east()).getBlock() instanceof BlockFenceGate))
	{
		setBlockBounds(0.8125F, 0.0F, 0.1875F, 1.0F, 1.5F, 0.8125F);
		super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
	}
	if ((world.getBlockState(pos.west()).getBlock() instanceof BlockHedge | world.getBlockState(pos.west()).getBlock() instanceof BlockFenceGate))
	{
		setBlockBounds(0.0F, 0.0F, 0.1875F, 0.1875F, 1.5F, 0.8125F);
		super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
	}
	if ((world.getBlockState(pos.south()).getBlock() instanceof BlockHedge | world.getBlockState(pos.south()).getBlock() instanceof BlockFenceGate))
	{
		setBlockBounds(0.1875F, 0.0F, 0.8125F, 0.8125F, 1.5F, 1.0F);
		super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
	}
	if ((world.getBlockState(pos.north()).getBlock() instanceof BlockHedge | world.getBlockState(pos.north()).getBlock() instanceof BlockFenceGate))
	{
		setBlockBounds(0.1875F, 0.0F, 0.0F, 0.8125F, 1.5F, 0.1875F);
		super.addCollisionBoxesToList(world, pos, state, mask, list, collidingEntity);
	}
}

public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
	if (this == HaWMBlocks.hedge_birch)
	{
		return HaWMItems.item_hedge_birch;
	}
	if (this == HaWMBlocks.hedge_spruce)
	{
		return HaWMItems.item_hedge_spruce;
	}
	if (this == HaWMBlocks.hedge_jungle)
	{
		return HaWMItems.item_hedge_jungle;
	}
	if (this == HaWMBlocks.hedge_acacia)
	{
		return HaWMItems.item_hedge_acacia;
	}
	if (this == HaWMBlocks.hedge_dark_oak)
	{
		return HaWMItems.item_hedge_dark_oak;
	}
	return HaWMItems.item_hedge_oak;
}

public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos)
{
	if (this == HaWMBlocks.hedge_birch)
	{
		return new ItemStack(HaWMItems.item_hedge_birch);
	}
	if (this == HaWMBlocks.hedge_spruce)
	{
		return new ItemStack(HaWMItems.item_hedge_spruce);
	}
	if (this == HaWMBlocks.hedge_jungle)
	{
		return new ItemStack(HaWMItems.item_hedge_jungle);
	}
	if (this == HaWMBlocks.hedge_acacia)
	{
		return new ItemStack(HaWMItems.item_hedge_acacia);
	}
	if (this == HaWMBlocks.hedge_dark_oak)
	{
		return new ItemStack(HaWMItems.item_hedge_dark_oak);
	}
	return new ItemStack(HaWMItems.item_hedge_oak);
}

public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
	return state.withProperty(NORTH, Boolean.valueOf(isHedge(world, pos.north()))).withProperty(EAST, Boolean.valueOf(isHedge(world, pos.east()))).withProperty(SOUTH, Boolean.valueOf(isHedge(world, pos.south()))).withProperty(WEST, Boolean.valueOf(isHedge(world, pos.west())));
}

public int getMetaFromState(IBlockState state)
{
	return 0;
}

protected BlockState createBlockState()
{
	return new BlockState(this, new IProperty[] { NORTH, EAST, SOUTH, WEST });
}

public boolean isHedge(IBlockAccess world, BlockPos pos)
{
	return world.getBlockState(pos).getBlock() instanceof BlockHedge | world.getBlockState(pos).getBlock() instanceof BlockFenceGate | world.getBlockState(pos).getBlock().isNormalCube();
}
}

 

I should mention that I want to only have the block and no item, just because I believe that is best practis to do so, and because I think that it can quickly become unmanageable, if there's to much code that's not really needed.

Link to comment
Share on other sites

Do you have a texture with colour for your block? If you look at the Minecraft textures I'm pretty sure they have a texture with the colour which is used when it is in your inventory. You can observe this as the leaves obviously don't change colour in your hand when you walk from biome to biome.

 

You haven't checked any of the leave .json files have you? Because the .json files for both block and item, use the exact same texture. I did even look at in the texture folder to see if there was a colored version, which there's not, before posting on here.

 

I also mentioned that if I made an item for the inventory, instead of using the block itself, I was able to make it work by adding this code to the item class.

@SideOnly(Side.CLIENT)
    public int getColorFromItemStack(ItemStack stack, int renderPass)
    {
        return this.block.getRenderColor(this.block.getStateFromMeta(stack.getMetadata()));
    }

 

Look I'm not trying to be a duche, but maybe look at the post before replying.

 

And no, I'm not going to make a colored version of the leave textures, just for the inventory. All my mods are using vanilla textures, so they are as resoucepack friendly as possible, and I intend to keep it that way. :)

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

 Share



×
×
  • Create New...

Important Information

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