Jump to content

[1.10.2] Leaves too transparents


JimiIT92

Recommended Posts

I'm making a cherry tree, but the leaves are rendering too transparents. Right now they render like this

pLqrv9u.png

what i want is that they render like vanilla leaves, like this

oLYX4Iq.png

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?

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

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.

 

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.

Link to comment
Share on other sites

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 :D Thank you so much for your help :)

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

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 :D 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?

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

×
×
  • Create New...

Important Information

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