package com.miningmark48.pearcelmod.block;
import com.google.common.base.Predicate;
import com.miningmark48.pearcelmod.init.ModBlocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.*;
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;
import javax.annotation.Nullable;
public class BlockPearcelTorch extends BlockPearcelMod {
private static final String __OBFID = "CL_00000325";
protected static final AxisAlignedBB STANDING_AABB = new AxisAlignedBB(0.4000000059604645D, 0.0D, 0.4000000059604645D, 0.6000000238418579D, 0.6000000238418579D, 0.6000000238418579D);
protected static final AxisAlignedBB TORCH_NORTH_AABB = new AxisAlignedBB(0.3499999940395355D, 0.20000000298023224D, 0.699999988079071D, 0.6499999761581421D, 0.800000011920929D, 1.0D);
protected static final AxisAlignedBB TORCH_SOUTH_AABB = new AxisAlignedBB(0.3499999940395355D, 0.20000000298023224D, 0.0D, 0.6499999761581421D, 0.800000011920929D, 0.30000001192092896D);
protected static final AxisAlignedBB TORCH_WEST_AABB = new AxisAlignedBB(0.699999988079071D, 0.20000000298023224D, 0.3499999940395355D, 1.0D, 0.800000011920929D, 0.6499999761581421D);
protected static final AxisAlignedBB TORCH_EAST_AABB = new AxisAlignedBB(0.0D, 0.20000000298023224D, 0.3499999940395355D, 0.30000001192092896D, 0.800000011920929D, 0.6499999761581421D);
public BlockPearcelTorch()
{
super();
this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.UP));
this.setTickRandomly(true);
setHardness(0.0F);
setLightLevel(0.85F);
}
public void onBlockHarvested(World world, int par2, int par3, int par4, int par5, EntityPlayer player) {
if (!player.capabilities.isCreativeMode) {
player.inventory.addItemStackToInventory(new ItemStack(ModBlocks.pearcel_torch));
}
}
public static final PropertyDirection FACING = PropertyDirection.create("facing", new Predicate<EnumFacing>()
{
public boolean apply(EnumFacing p_apply_1_)
{
return p_apply_1_ != EnumFacing.DOWN;
}
});
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
{
return null;
}
public boolean isOpaqueCube()
{
return false;
}
public boolean isFullCube()
{
return false;
}
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
{
switch ((EnumFacing)state.getValue(FACING))
{
case EAST:
return TORCH_EAST_AABB;
case WEST:
return TORCH_WEST_AABB;
case SOUTH:
return TORCH_SOUTH_AABB;
case NORTH:
return TORCH_NORTH_AABB;
default:
return STANDING_AABB;
}
}
@Nullable
public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World worldIn, BlockPos pos)
{
return NULL_AABB;
}
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
public boolean isOpaqueCube(IBlockState state)
{
return false;
}
public boolean isFullCube(IBlockState state)
{
return false;
}
private boolean canPlaceOn(World worldIn, BlockPos pos)
{
IBlockState state = worldIn.getBlockState(pos);
if (state.isSideSolid(worldIn, pos, EnumFacing.UP))
{
return true;
}
else
{
return state.getBlock().canPlaceTorchOnTop(state, worldIn, pos);
}
}
public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
{
for (EnumFacing enumfacing : FACING.getAllowedValues())
{
if (this.canPlaceAt(worldIn, pos, enumfacing))
{
return true;
}
}
return false;
}
private boolean canPlaceAt(World worldIn, BlockPos pos, EnumFacing facing)
{
BlockPos blockpos = pos.offset(facing.getOpposite());
boolean flag = facing.getAxis().isHorizontal();
return flag && worldIn.isSideSolid(blockpos, facing, true) || facing.equals(EnumFacing.UP) && this.canPlaceOn(worldIn, blockpos);
}
/**
* Called by ItemBlocks just before a block is actually set in the world, to allow for adjustments to the
* IBlockstate
*/
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
{
if (this.canPlaceAt(worldIn, pos, facing))
{
return this.getDefaultState().withProperty(FACING, facing);
}
else
{
for (EnumFacing enumfacing : EnumFacing.Plane.HORIZONTAL)
{
if (worldIn.isSideSolid(pos.offset(enumfacing.getOpposite()), enumfacing, true))
{
return this.getDefaultState().withProperty(FACING, enumfacing);
}
}
return this.getDefaultState();
}
}
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
this.checkForDrop(worldIn, pos, state);
}
/**
* Called when a neighboring block was changed and marks that this state should perform any checks during a neighbor
* change. Cases may include when redstone power is updated, cactus blocks popping off due to a neighboring solid
* block, etc.
*/
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn)
{
this.onNeighborChangeInternal(worldIn, pos, state);
}
protected boolean onNeighborChangeInternal(World worldIn, BlockPos pos, IBlockState state)
{
if (!this.checkForDrop(worldIn, pos, state))
{
return true;
}
else
{
EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
EnumFacing.Axis enumfacing$axis = enumfacing.getAxis();
EnumFacing enumfacing1 = enumfacing.getOpposite();
boolean flag = false;
if (enumfacing$axis.isHorizontal() && !worldIn.isSideSolid(pos.offset(enumfacing1), enumfacing, true))
{
flag = true;
}
else if (enumfacing$axis.isVertical() && !this.canPlaceOn(worldIn, pos.offset(enumfacing1)))
{
flag = true;
}
if (flag)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
return true;
}
else
{
return false;
}
}
}
protected boolean checkForDrop(World worldIn, BlockPos pos, IBlockState state)
{
if (state.getBlock() == this && this.canPlaceAt(worldIn, pos, (EnumFacing)state.getValue(FACING)))
{
return true;
}
else
{
if (worldIn.getBlockState(pos).getBlock() == this)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
worldIn.setBlockToAir(pos);
}
return false;
}
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
EnumFacing enumfacing = (EnumFacing)stateIn.getValue(FACING);
double d0 = (double)pos.getX() + 0.5D;
double d1 = (double)pos.getY() + 0.7D;
double d2 = (double)pos.getZ() + 0.5D;
double d3 = 0.22D;
double d4 = 0.27D;
if (enumfacing.getAxis().isHorizontal())
{
EnumFacing enumfacing1 = enumfacing.getOpposite();
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4 * (double)enumfacing1.getFrontOffsetX(), d1 + d3, d2 + d4 * (double)enumfacing1.getFrontOffsetZ(), 0.0D, 0.0D, 0.0D, new int[0]);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4 * (double)enumfacing1.getFrontOffsetX(), d1 + d3, d2 + d4 * (double)enumfacing1.getFrontOffsetZ(), 0.0D, 0.0D, 0.0D, new int[0]);
}
else
{
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
}
}
/**
* Convert the given metadata into a BlockState for this Block
*/
public IBlockState getStateFromMeta(int meta)
{
IBlockState iblockstate = this.getDefaultState();
switch (meta)
{
case 1:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.EAST);
break;
case 2:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.WEST);
break;
case 3:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.SOUTH);
break;
case 4:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.NORTH);
break;
case 5:
default:
iblockstate = iblockstate.withProperty(FACING, EnumFacing.UP);
}
return iblockstate;
}
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.CUTOUT;
}
/**
* Convert the BlockState into the correct metadata value
*/
public int getMetaFromState(IBlockState state)
{
int i = 0;
switch ((EnumFacing)state.getValue(FACING))
{
case EAST:
i = i | 1;
break;
case WEST:
i = i | 2;
break;
case SOUTH:
i = i | 3;
break;
case NORTH:
i = i | 4;
break;
case DOWN:
case UP:
default:
i = i | 5;
}
return i;
}
/**
* Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withRotation(IBlockState state, Rotation rot)
{
return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
}
/**
* Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
* blockstate.
*/
public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
{
return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
}
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] {FACING});
}
// @SideOnly(Side.CLIENT)
// public EnumWorldBlockLayer getBlockLayer()
// {
// return EnumWorldBlockLayer.CUTOUT;
// }
//
// protected BlockState createBlockState()
// {
// return new BlockState(this, new IProperty[] {FACING});
// }
}