package net.geforcemods.securitycraft.blocks;
import java.util.Random;
import net.geforcemods.securitycraft.main.mod_SecurityCraft;
import net.geforcemods.securitycraft.tileentity.TileEntityScannerDoor;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDoor;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.Item;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockScannerDoor extends BlockDoor implements ITileEntityProvider
{
public BlockScannerDoor(Material materialIn)
{
super(materialIn);
this.isBlockContainer = true;
}
/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
* their own) Args: x, y, z, neighbor Block
*/
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock)
{
if(state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER)
{
BlockPos blockpos1 = pos.down();
IBlockState iblockstate1 = worldIn.getBlockState(blockpos1);
if(iblockstate1.getBlock() != this)
worldIn.setBlockToAir(pos);
else if (neighborBlock != this)
this.onNeighborBlockChange(worldIn, blockpos1, iblockstate1, neighborBlock);
}
else
{
boolean flag1 = false;
BlockPos blockpos2 = pos.up();
IBlockState iblockstate2 = worldIn.getBlockState(blockpos2);
if(iblockstate2.getBlock() != this)
{
worldIn.setBlockToAir(pos);
flag1 = true;
}
if(!World.doesBlockHaveSolidTopSurface(worldIn, pos.down()))
{
worldIn.setBlockToAir(pos);
flag1 = true;
if(iblockstate2.getBlock() == this)
worldIn.setBlockToAir(blockpos2);
}
if(flag1)
{
if(!worldIn.isRemote)
this.dropBlockAsItem(worldIn, pos, state, 0);
}
}
}
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
super.breakBlock(worldIn, pos, state);
worldIn.removeTileEntity(pos);
}
public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam)
{
super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam);
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam);
}
@SideOnly(Side.CLIENT)
public Item getItem(World world, BlockPos pos)
{
return mod_SecurityCraft.scannerDoorItem;
}
public Item getItemDropped(IBlockState state, Random rand, int fortune)
{
return state.getValue(HALF) == BlockDoor.EnumDoorHalf.UPPER ? null : mod_SecurityCraft.scannerDoorItem;
}
public TileEntity createNewTileEntity(World var1, int var2)
{
return new TileEntityScannerDoor().activatedByView();
}
}