JimiIT92 Posted November 10, 2016 Posted November 10, 2016 I'm making a cherry tree, but the leaves are rendering too transparents. Right now they render like this what i want is that they render like vanilla leaves, like this This is the class i'm using for the leaves package com.mineworld.blocks.decorations; import java.util.List; import java.util.Random; import com.mineworld.blocks.plants.BlockPlanksMW; import com.mineworld.core.MWBlocks; import com.mineworld.core.MWItems; import com.mineworld.core.MWTabs; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockPlanks.EnumType; import net.minecraft.block.SoundType; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockFruitLeaves extends BlockLeaves { public BlockFruitLeaves() { this.setDefaultState(this.blockState.getBaseState().withProperty(CHECK_DECAY, Boolean.valueOf(true)) .withProperty(DECAYABLE, Boolean.valueOf(true))); this.setHardness(0.2F); this.setSoundType(SoundType.PLANT); this.setTickRandomly(true); this.setCreativeTab(MWTabs.tabDecorations); } public BlockRenderLayer getBlockLayer() { return Blocks.LEAVES.getBlockLayer(); } public Item getItemDropped(IBlockState state, Random rand, int fortune) { if (this == MWBlocks.cherry_leaves) return Item.getItemFromBlock(MWBlocks.sapling_cherry); else if (this == MWBlocks.orange_leaves) return Item.getItemFromBlock(MWBlocks.sapling_orange); else return Item.getItemFromBlock(MWBlocks.sapling_lemon); } protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance) { if (this.RANDOM.nextInt(5) == 3) { if (this == MWBlocks.cherry_leaves) spawnAsEntity(worldIn, pos, new ItemStack(MWItems.cherry, 1, 0)); else if (this == MWBlocks.orange_leaves) spawnAsEntity(worldIn, pos, new ItemStack(MWItems.orange, 1, 0)); else spawnAsEntity(worldIn, pos, new ItemStack(MWItems.lemon, 1, 0)); } } @Override public boolean isOpaqueCube(IBlockState state) { return false; } protected int getSaplingDropChance(IBlockState state) { return super.getSaplingDropChance(state); } public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().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; if (!((Boolean) state.getValue(DECAYABLE)).booleanValue()) { i |= 4; } if (((Boolean) state.getValue(CHECK_DECAY)).booleanValue()) { i |= 8; } return i; } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { CHECK_DECAY, DECAYABLE }); } @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, 0).getMetadata())); } @Override public EnumType getWoodType(int meta) { return null; } } What should i change to make them rendering correctly? Quote Don't blame me if i always ask for your help. I just want to learn to be better
Matryoshika Posted November 10, 2016 Posted November 10, 2016 You need to override shouldSideBeRendered(IBlockState, IBlockAccess, BlockPos, EnumFacing) . In the super-class (BlockLeaves) the method is checking strictly " block == this " where you now have an instance of that block, leading to the if-check returning false. Quote Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
JimiIT92 Posted November 10, 2016 Author Posted November 10, 2016 I've done this in my class @Override public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { return blockAccess.getBlockState(pos.offset(side)).getBlock() == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side); } But nothing changed EDIT: dumb me, if i just return true it works Thank you so much for your help Quote Don't blame me if i always ask for your help. I just want to learn to be better
Matryoshika Posted November 11, 2016 Posted November 11, 2016 I've done this in my class @Override public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { return blockAccess.getBlockState(pos.offset(side)).getBlock() == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side); } But nothing changed EDIT: dumb me, if i just return true it works Thank you so much for your help Don't copy code from vanilla minecraft. When you do copy, copy the whole thing. You missed the inverse-operator "!" in front of the blockAccess, leaving your code to return false instead of true, if the block next to your block is the same type. Do you know how the ternary operator (statement ? true : default/false) works? Quote Also previously known as eAndPi. "Pi, is there a station coming up where we can board your train of thought?" -Kronnn Published Mods: Underworld Handy links: Vic_'s Forge events Own WIP Tutorials.
JimiIT92 Posted November 11, 2016 Author Posted November 11, 2016 Yes i know, just a bit tired and didn't understand that i would check if the block is NOT "this" Quote Don't blame me if i always ask for your help. I just want to learn to be better
hhggtg3279 Posted November 11, 2016 Posted November 11, 2016 Hey, is there any chance you could link me to a tree tutorial, I'm looking to make a custom tree but I'm not too sure how to go about it. Quote
JimiIT92 Posted November 12, 2016 Author Posted November 12, 2016 Just look at the Vanilla Sapling Class and a Tree Class (Like the Oak Tree class). Change them to your needs and that's it Quote Don't blame me if i always ask for your help. I just want to learn to be better
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.