<commit_before>package com.ferreusveritas.dynamictrees.blocks;

import java.util.List;

import javax.annotation.Nullable;

import com.ferreusveritas.dynamictrees.api.TreeHelper;
import com.ferreusveritas.dynamictrees.api.cells.CellNull;
import com.ferreusveritas.dynamictrees.api.cells.ICell;
import com.ferreusveritas.dynamictrees.api.network.MapSignal;
import com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties;
import com.ferreusveritas.dynamictrees.api.treedata.ITreePart;
import com.ferreusveritas.dynamictrees.systems.GrowSignal;
import com.ferreusveritas.dynamictrees.trees.Species;
import com.ferreusveritas.dynamictrees.util.MathHelper;
import com.google.common.base.Predicate;

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockBranchCactus extends BlockBranch {
	
	// The direction it grew from. Can't be up, since cacti can't grow down.
	public static final PropertyEnum<EnumFacing> ORIGIN = PropertyEnum.<EnumFacing>create("origin", EnumFacing.class, new Predicate<EnumFacing>() {
		@Override
		public boolean apply(@Nullable EnumFacing dir) {
			return dir != EnumFacing.UP;
		}
	});
	 // Not sure it's technically called the 'trunk' on cacti, but whatever
	public static final PropertyBool TRUNK = PropertyBool.create("trunk");
	
	public BlockBranchCactus(String name) {
		super(Material.CACTUS);
		setSoundType(SoundType.CLOTH);
		setHarvestLevel("axe", 0);
		setDefaultState(this.blockState.getBaseState().withProperty(TRUNK, true).withProperty(ORIGIN, EnumFacing.DOWN));
		setUnlocalizedName(name);
		setRegistryName(name);
	}
	
	@Override
	public void cacheBranchStates() {
		//Do nothing
	}
	
	///////////////////////////////////////////
	// BLOCKSTATES
	///////////////////////////////////////////
	
	@Override
	protected BlockStateContainer createBlockState() {
		IProperty[] listedProperties = { ORIGIN, TRUNK };
		return new ExtendedBlockState(this, listedProperties, CONNECTIONS);
	}
	
	/**
	* Convert the given metadata into a BlockState for this Block
	*/
	@Override
	public IBlockState getStateFromMeta(int meta) {
		EnumFacing rootDir = EnumFacing.getFront((meta & 7) % 6);
		boolean trunk = rootDir == EnumFacing.UP;
			
		return this.getDefaultState().withProperty(ORIGIN, trunk ? EnumFacing.DOWN : rootDir).withProperty(TRUNK, trunk);
	}
	
	/**
	* Convert the BlockState into the correct metadata value
	*/
	@Override
	public int getMetaFromState(IBlockState state) {
		if (state.getValue(TRUNK)) {
			return EnumFacing.UP.getIndex();
		}
		return state.getValue(ORIGIN).getIndex();
	}
	
	@Override
	public IBlockState getExtendedState(IBlockState state, IBlockAccess blockAcess, BlockPos pos) {
		if (state instanceof IExtendedBlockState) {
			IExtendedBlockState retval = (IExtendedBlockState) state;
			int thisRadius = getRadius(state, blockAcess, pos);
	
			for (EnumFacing dir : EnumFacing.VALUES) {
				retval = retval.withProperty(CONNECTIONS[dir.getIndex()], getSideConnectionRadius(blockAcess, pos, thisRadius, dir));
			}
			return retval;
		}
	
		return state;
	}
	
	///////////////////////////////////////////
	// INTERACTION
	///////////////////////////////////////////
	
	@Override
	public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
        entityIn.attackEntityFrom(DamageSource.CACTUS, 1.0F);
    }
	
	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
		IBlockState returnState = this.getDefaultState();
		
		IBlockState adjState = world.getBlockState(pos.offset(facing.getOpposite()));
		boolean trunk = (facing == EnumFacing.UP && (adjState.isSideSolid(world, pos.offset(facing.getOpposite()), facing) || (adjState.getBlock() == this && adjState.getValue(TRUNK))));
		
		return returnState.withProperty(TRUNK, trunk).withProperty(ORIGIN, facing != EnumFacing.DOWN ? facing.getOpposite() : EnumFacing.DOWN);
	}
	
	///////////////////////////////////////////
	// RENDERING
	///////////////////////////////////////////
	
	@Override
	public boolean isOpaqueCube(IBlockState state) {
		return false;
	}
	
	@Override
	public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,	EnumFacing side) {
		return true;
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public BlockRenderLayer getBlockLayer() {
		return BlockRenderLayer.CUTOUT_MIPPED;
	}
	
	///////////////////////////////////////////
	// GROWTH
	///////////////////////////////////////////
    
    @Override
	public ICell getHydrationCell(IBlockAccess blockAccess, BlockPos pos, IBlockState blockState, EnumFacing dir, ILeavesProperties leavesProperties) {
		return CellNull.NULLCELL;
	}
    
    @Override
	public int getRadius(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos) {
    	
		if(blockState == null) {
			blockState = blockAccess.getBlockState(pos);
		}
    	
		if (blockState.getBlock() == this) {
			return blockState.getValue(TRUNK) ? 5 : 4;
		} else {
			return 0;
		}
	}
	
	@Override<commit_msg>Fix crash with Cactus render<commit_after>package com.ferreusveritas.dynamictrees.blocks;

import java.util.List;

import javax.annotation.Nullable;

import com.ferreusveritas.dynamictrees.api.TreeHelper;
import com.ferreusveritas.dynamictrees.api.cells.CellNull;
import com.ferreusveritas.dynamictrees.api.cells.ICell;
import com.ferreusveritas.dynamictrees.api.network.MapSignal;
import com.ferreusveritas.dynamictrees.api.treedata.ILeavesProperties;
import com.ferreusveritas.dynamictrees.api.treedata.ITreePart;
import com.ferreusveritas.dynamictrees.systems.GrowSignal;
import com.ferreusveritas.dynamictrees.trees.Species;
import com.ferreusveritas.dynamictrees.util.MathHelper;
import com.google.common.base.Predicate;

import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.property.ExtendedBlockState;
import net.minecraftforge.common.property.IExtendedBlockState;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockBranchCactus extends BlockBranch {
	
	// The direction it grew from. Can't be up, since cacti can't grow down.
	public static final PropertyEnum<EnumFacing> ORIGIN = PropertyEnum.<EnumFacing>create("origin", EnumFacing.class, new Predicate<EnumFacing>() {
		@Override
		public boolean apply(@Nullable EnumFacing dir) {
			return dir != EnumFacing.UP;
		}
	});
	 // Not sure it's technically called the 'trunk' on cacti, but whatever
	public static final PropertyBool TRUNK = PropertyBool.create("trunk");
	
	public BlockBranchCactus(String name) {
		super(Material.CACTUS);
		setSoundType(SoundType.CLOTH);
		setHarvestLevel("axe", 0);
		setDefaultState(this.blockState.getBaseState().withProperty(TRUNK, true).withProperty(ORIGIN, EnumFacing.DOWN));
		setUnlocalizedName(name);
		setRegistryName(name);
	}
	
	@Override
	public void cacheBranchStates() {
		//Do nothing
	}
	
	///////////////////////////////////////////
	// BLOCKSTATES
	///////////////////////////////////////////
	
	@Override
	protected BlockStateContainer createBlockState() {
		IProperty[] listedProperties = { ORIGIN, TRUNK };
		return new ExtendedBlockState(this, listedProperties, CONNECTIONS);
	}
	
	/**
	* Convert the given metadata into a BlockState for this Block
	*/
	@Override
	public IBlockState getStateFromMeta(int meta) {
		EnumFacing rootDir = EnumFacing.getFront((meta & 7) % 6);
		boolean trunk = rootDir == EnumFacing.UP;
			
		return this.getDefaultState().withProperty(ORIGIN, trunk ? EnumFacing.DOWN : rootDir).withProperty(TRUNK, trunk);
	}
	
	/**
	* Convert the BlockState into the correct metadata value
	*/
	@Override
	public int getMetaFromState(IBlockState state) {
		if (state.getValue(TRUNK)) {
			return EnumFacing.UP.getIndex();
		}
		return state.getValue(ORIGIN).getIndex();
	}
	
	@Override
	public IBlockState getExtendedState(IBlockState state, IBlockAccess blockAcess, BlockPos pos) {
		if (state instanceof IExtendedBlockState) {
			IExtendedBlockState retval = (IExtendedBlockState) state;
			int thisRadius = getRadius(state, blockAcess, pos);
	
			for (EnumFacing dir : EnumFacing.VALUES) {
				retval = retval.withProperty(CONNECTIONS[dir.getIndex()], getSideConnectionRadius(blockAcess, pos, thisRadius, dir));
			}
			return retval;
		}
	
		return state;
	}
	
	///////////////////////////////////////////
	// INTERACTION
	///////////////////////////////////////////
	
	@Override
	public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) {
        entityIn.attackEntityFrom(DamageSource.CACTUS, 1.0F);
    }
	
	@Override
	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
		IBlockState returnState = this.getDefaultState();
		
		IBlockState adjState = world.getBlockState(pos.offset(facing.getOpposite()));
		boolean trunk = (facing == EnumFacing.UP && (adjState.isSideSolid(world, pos.offset(facing.getOpposite()), facing) || (adjState.getBlock() == this && adjState.getValue(TRUNK))));
		
		return returnState.withProperty(TRUNK, trunk).withProperty(ORIGIN, facing != EnumFacing.DOWN ? facing.getOpposite() : EnumFacing.DOWN);
	}
	
	///////////////////////////////////////////
	// RENDERING
	///////////////////////////////////////////
	
	@Override
	public boolean isOpaqueCube(IBlockState state) {
		return false;
	}
	
	@Override
	public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos,	EnumFacing side) {
		return true;
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public BlockRenderLayer getBlockLayer() {
		return BlockRenderLayer.CUTOUT_MIPPED;
	}
	
	///////////////////////////////////////////
	// GROWTH
	///////////////////////////////////////////
    
    @Override
	public ICell getHydrationCell(IBlockAccess blockAccess, BlockPos pos, IBlockState blockState, EnumFacing dir, ILeavesProperties leavesProperties) {
		return CellNull.NULLCELL;
	}
	
	@Override
	public int getRawRadius(IBlockState blockState) {
		return blockState.getValue(TRUNK) ? 5 : 4;
	}
    
	@Override
{'fraction_non_alphanumeric': 0.153826443457465, 'fraction_numerical': 0.0012811752647762214, 'mean_word_length': 3.7830882352941178, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5565727', 'n_tokens_mistral': 3759, 'n_tokens_neox': 3547, 'n_words': 709}