Posted May 1, 201510 yr I'm updating my mod and I have a strange issue. I have 11 types of leaves. I finally got the coloring to work on placed block, but I noticed that leaves are not transparent,colors are little bit off and also they aren't colored in inventory(water level is another mod): Why is this happening? Here's my leaf class: package com.lessoner.treeores.trees; import java.util.List; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockPlanks; import net.minecraft.block.BlockPlanks.EnumType; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.stats.StatList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.ColorizerFoliage; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import com.google.common.base.Predicate; import com.lessoner.treeores.TreeOresBlocks; public class TreeOresLeaf1 extends BlockLeaves { public static final PropertyEnum VARIANT = PropertyEnum.create("variant", TreeOresLog1.EnumType.class, new Predicate() { public boolean apply(TreeOresLog1.EnumType type) { return type.getMetadata() < 4; } public boolean apply(Object p_apply_1_) { return this.apply((TreeOresLog1.EnumType) p_apply_1_); } }); public TreeOresLeaf1() { this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, TreeOresLog1.EnumType.IRON) .withProperty(CHECK_DECAY, Boolean.valueOf(true)).withProperty(DECAYABLE, Boolean.valueOf(true))); } public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(TreeOresBlocks.Saplings1); } @SideOnly(Side.CLIENT) public int getRenderColor(IBlockState state) { if (state.getBlock() != this) { return super.getRenderColor(state); } else { TreeOresLog1.EnumType enumtype = (TreeOresLog1.EnumType) state.getValue(VARIANT); return enumtype == TreeOresLog1.EnumType.GOLD ? LeaveColours.gold() : (enumtype == TreeOresLog1.EnumType.COAL ? LeaveColours.coal() : (enumtype == TreeOresLog1.EnumType.IRON ? LeaveColours.iron() : (enumtype == TreeOresLog1.EnumType.REDSTONE ? LeaveColours .redstone() : super.getRenderColor(state)))); } } @SideOnly(Side.CLIENT) public int colorMultiplier(IBlockAccess worldIn, BlockPos pos, int renderPass) { IBlockState iblockstate = worldIn.getBlockState(pos); if (iblockstate.getBlock() == this) { TreeOresLog1.EnumType enumtype = (TreeOresLog1.EnumType) iblockstate.getValue(VARIANT); if (enumtype == TreeOresLog1.EnumType.IRON) { return LeaveColours.iron(); } if (enumtype == TreeOresLog1.EnumType.GOLD) { return LeaveColours.gold(); } if (enumtype == TreeOresLog1.EnumType.COAL) { return LeaveColours.coal(); } if (enumtype == TreeOresLog1.EnumType.REDSTONE) { return LeaveColours.redstone(); } } return super.colorMultiplier(worldIn, pos, renderPass); } protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance) { if (state.getValue(VARIANT) == TreeOresLog1.EnumType.IRON && worldIn.rand.nextInt(chance) == 0) { spawnAsEntity(worldIn, pos, new ItemStack(Items.iron_ingot, 1, 0)); } if (state.getValue(VARIANT) == TreeOresLog1.EnumType.GOLD && worldIn.rand.nextInt(chance) == 0) { spawnAsEntity(worldIn, pos, new ItemStack(Items.gold_ingot, 1, 0)); } if (state.getValue(VARIANT) == TreeOresLog1.EnumType.COAL && worldIn.rand.nextInt(chance) == 0) { spawnAsEntity(worldIn, pos, new ItemStack(Items.coal, 1, 0)); } if (state.getValue(VARIANT) == TreeOresLog1.EnumType.REDSTONE && worldIn.rand.nextInt(chance) == 0) { spawnAsEntity(worldIn, pos, new ItemStack(Items.redstone, 1, 0)); } } protected int getSaplingDropChance(IBlockState state) { return state.getValue(VARIANT) == TreeOresLog1.EnumType.REDSTONE ? 40 : super.getSaplingDropChance(state); } @SideOnly(Side.CLIENT) public void getSubBlocks(Item itemIn, CreativeTabs tab, List list) { list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.IRON.getMetadata())); list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.GOLD.getMetadata())); list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.COAL.getMetadata())); list.add(new ItemStack(itemIn, 1, TreeOresLog1.EnumType.REDSTONE.getMetadata())); } protected ItemStack createStackedBlock(IBlockState state) { return new ItemStack(Item.getItemFromBlock(this), 1, ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata()); } public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(VARIANT, TreeOresLog1.EnumType.byMetadata((meta & 3) % 4)) .withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)).withProperty(CHECK_DECAY, Boolean.valueOf((meta & > 0)); } public int getMetaFromState(IBlockState state) { byte b0 = 0; int i = b0 | ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata(); if (!((Boolean) state.getValue(DECAYABLE)).booleanValue()) { i |= 4; } if (((Boolean) state.getValue(CHECK_DECAY)).booleanValue()) { i |= 8; } return i; } protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { VARIANT, CHECK_DECAY, DECAYABLE }); } public int damageDropped(IBlockState state) { return ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata(); } public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te) { if (!worldIn.isRemote && player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.shears) { player.triggerAchievement(StatList.mineBlockStatArray[block.getIdFromBlock(this)]); spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(this), 1, ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata())); } else { super.harvestBlock(worldIn, player, pos, state, te); } } @Override public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { IBlockState state = world.getBlockState(pos); return new java.util.ArrayList( java.util.Arrays.asList(new ItemStack(this, 1, ((TreeOresLog1.EnumType) state.getValue(VARIANT)).getMetadata()))); } @Override public EnumType getWoodType(int meta) { return null; } } LeaveColours class just has 11 integers with rgb values. (this class just has 4 leaves) Thanks in advance.
May 1, 201510 yr Add a adapter to your class: @Override @SideOnly(Side.CLIENT) public EnumWorldBlockLayer getBlockLayer() { return Blocks.leaves.getBlockLayer(); } Author of Tao Land Mod. http://taoland.herbix.me/images/1/14/TaoLandLogo.png[/img] Also, author of RenderTo ---- I'm not an English native speaker. I just try my best.
May 1, 201510 yr Hi look at Block.isOpaqueCube(). if your isOpaqueCube() returns true, but your leaves are see-through, this is what you get. -TGG
May 2, 201510 yr Author That fixed it. Thanks! Do you have any suggestions about coloring leaves in inventory?
May 2, 201510 yr I suggest - look at ItemLeaves. You have created a custom ItemBlock corresponding to your Block, yeah? This looks promising... @SideOnly(Side.CLIENT) public int getColorFromItemStack(ItemStack stack, int renderPass) { return this.leaves.getRenderColor(this.leaves.getStateFromMeta(stack.getMetadata())); } -TGG
July 19, 201510 yr I suggest - look at ItemLeaves. You have created a custom ItemBlock corresponding to your Block, yeah? This looks promising... @SideOnly(Side.CLIENT) public int getColorFromItemStack(ItemStack stack, int renderPass) { return this.leaves.getRenderColor(this.leaves.getStateFromMeta(stack.getMetadata())); } -TGG how do i do that exactly?
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.