Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mightydanp.eot.common.block;
- import java.util.List;
- import java.util.Locale;
- import java.util.Random;
- import javax.annotation.Nullable;
- import com.mightydanp.eot.api.common.block.IMetaBlock;
- import com.mightydanp.eot.common.EoT;
- import net.minecraft.block.SoundType;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.entity.Entity;
- 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.BlockRenderLayer;
- import net.minecraft.util.IStringSerializable;
- 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.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- public class BlockTwigs extends IMetaBlock implements net.minecraftforge.common.IPlantable {
- private static final AxisAlignedBB BOUNDING_BOX = new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 0.0625, 1.0);
- public static final PropertyEnum TYPE = PropertyEnum.create("twigs", TwigsType.class);
- public BlockTwigs(String unlocalizedName) {
- super(Material.GRASS, TYPE, TwigsType.class, unlocalizedName);
- this.setCreativeTab(EoT.tabEoT);
- this.setUnlocalizedName(unlocalizedName);
- this.setHardness(0.5F);
- this.setSoundType(SoundType.PLANT);
- this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, TwigsType.TWIGS));
- }
- public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
- if (state.getBlock() == this) {
- IBlockState soil = worldIn.getBlockState(pos.down());
- return soil.getBlock().canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
- }
- return this.canSustainBush(worldIn.getBlockState(pos.down()));
- }
- protected boolean canSustainBush(IBlockState state) {
- return state.getBlock() == Blocks.GRASS || state.getBlock() == Blocks.DIRT || state.getBlock() == Blocks.SAND || state.getBlock() == Blocks.STONE;
- }
- @Override
- public boolean isFullCube(IBlockState state) {
- return false;
- }
- @Override
- public boolean isOpaqueCube(IBlockState state) {
- return false;
- }
- @SideOnly(Side.CLIENT)
- @Override
- public BlockRenderLayer getBlockLayer() {
- return BlockRenderLayer.TRANSLUCENT;
- }
- @Override
- public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn) {
- super.addCollisionBoxToList(pos, entityBox, collidingBoxes, BOUNDING_BOX);
- }
- @Override
- public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
- return BOUNDING_BOX;
- }
- @Override
- public Item getItemDropped(IBlockState state, Random rand, int fortune) {
- return null;
- }
- @Override
- public int quantityDropped(Random rand) {
- return 0;
- }
- @Override
- public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack) {
- if (!worldIn.isRemote && stack != null && stack.getItem() == Items.SHEARS) {
- player.addStat(StatList.getBlockStats(this));
- spawnAsEntity(worldIn, pos, new ItemStack(Item.getItemFromBlock(ModBlocks.twigs)));
- } else {
- Random rand = null;
- player.addStat(StatList.getBlockStats(this));
- spawnAsEntity(worldIn, pos, new ItemStack(Items.STICK, 1 + this.RANDOM.nextInt(3), 0));
- }
- }
- @Override
- public net.minecraftforge.common.EnumPlantType getPlantType(net.minecraft.world.IBlockAccess world, BlockPos pos) {
- if (this == ModBlocks.twigs) return net.minecraftforge.common.EnumPlantType.Desert;
- return net.minecraftforge.common.EnumPlantType.Plains;
- }
- @Override
- public IBlockState getPlant(net.minecraft.world.IBlockAccess world, BlockPos pos) {
- IBlockState state = world.getBlockState(pos);
- if (state.getBlock() != this) return getDefaultState();
- return state;
- }
- public enum TwigsType implements IStringSerializable,IMetaBlock.IEnumMeta {
- TWIGS;
- public final int meta;
- TwigsType() {
- meta = ordinal();
- }
- @Override
- public String getName() {
- return this.toString().toLowerCase(Locale.US);
- }
- @Override
- public int getMeta() {
- return meta;
- }
- }
- }
Add Comment
Please, Sign In to add comment