/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Jan 25, 2014, 10:04:25 PM (GMT)]
*/
package vazkii.botania.common.block;
import java.util.List;
import javax.annotation.Nonnull;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.lexicon.ILexiconable;
import vazkii.botania.api.lexicon.LexiconEntry;
import vazkii.botania.api.state.BotaniaStateProps;
import vazkii.botania.api.state.enums.LivingWoodVariant;
import vazkii.botania.client.core.handler.ModelHandler;
import vazkii.botania.common.item.block.ItemBlockWithMetadataAndName;
import vazkii.botania.common.lexicon.LexiconData;
import vazkii.botania.common.lib.LibBlockNames;
public class BlockLivingwood extends BlockMod implements ILexiconable {
public BlockLivingwood() {
this(LibBlockNames.LIVING_WOOD);
}
public BlockLivingwood(String name) {
super(Material.WOOD, name);
setHardness(2.0F);
setSoundType(SoundType.WOOD);
}
@Nonnull
@Override
public BlockStateContainer createBlockState() {
return new BlockStateContainer(this, BotaniaStateProps.LIVINGWOOD_VARIANT);
}
@Override
protected IBlockState pickDefaultState() {
return blockState.getBaseState().withProperty(BotaniaStateProps.LIVINGWOOD_VARIANT, LivingWoodVariant.DEFAULT);
}
@Override
public int getMetaFromState(IBlockState state) {
return state.getValue(BotaniaStateProps.LIVINGWOOD_VARIANT).ordinal();
}
@Nonnull
@Override
public IBlockState getStateFromMeta(int meta) {
if (meta >= LivingWoodVariant.values().length) {
meta = 0;
}
return getDefaultState().withProperty(BotaniaStateProps.LIVINGWOOD_VARIANT, LivingWoodVariant.values()[meta]);
}
@Override
public int damageDropped(IBlockState state) {
return getMetaFromState(state);
}
@Override
public void registerItemForm() {
GameRegistry.register(new ItemBlockWithMetadataAndName(this), getRegistryName());
}
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks(@Nonnull Item item, CreativeTabs tab, NonNullList<ItemStack> stacks) {
for(int i = 0; i < LivingWoodVariant.values().length; i++)
stacks.add(new ItemStack(item, 1, i));
}
@Nonnull
@Override
public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) {
return new ItemStack(this, 1, getMetaFromState(state));
}
@Override
public int getLightValue(@Nonnull IBlockState state, IBlockAccess world, @Nonnull BlockPos pos) {
if(world.getBlockState(pos).getBlock() != this)
return world.getBlockState(pos).getLightValue(world, pos);
return state.getValue(BotaniaStateProps.LIVINGWOOD_VARIANT) == LivingWoodVariant.GLIMMERING ? 12 : 0;
}
@Override
public LexiconEntry getEntry(World world, BlockPos pos, EntityPlayer player, ItemStack lexicon) {
boolean defaultVariant = world.getBlockState(pos).getValue(BotaniaStateProps.LIVINGWOOD_VARIANT) == LivingWoodVariant.DEFAULT;
return defaultVariant ? LexiconData.pureDaisy : LexiconData.decorativeBlocks;
}
@Override
public boolean canSustainLeaves(IBlockState state, IBlockAccess world, BlockPos pos) {
return state.getValue(BotaniaStateProps.LIVINGWOOD_VARIANT) == LivingWoodVariant.DEFAULT;
}
@SideOnly(Side.CLIENT)
@Override
public void registerModels() {
ModelHandler.registerBlockToState(this, LivingWoodVariant.values().length);
}
}