2016-08-14 18:53:25 +00:00
package WayofTime.bloodmagic.block ;
import javax.annotation.Nullable ;
2017-01-02 05:43:34 +00:00
import WayofTime.bloodmagic.block.base.BlockEnum ;
2016-08-14 18:53:25 +00:00
import net.minecraft.block.Block ;
import net.minecraft.block.SoundType ;
import net.minecraft.block.material.Material ;
import net.minecraft.block.state.IBlockState ;
import net.minecraft.entity.player.EntityPlayer ;
2017-01-02 05:43:34 +00:00
import net.minecraft.init.Blocks ;
2016-08-14 18:53:25 +00:00
import net.minecraft.item.ItemBlock ;
import net.minecraft.item.ItemStack ;
import net.minecraft.tileentity.TileEntity ;
import net.minecraft.util.BlockRenderLayer ;
2016-08-22 23:55:15 +00:00
import net.minecraft.util.EnumBlockRenderType ;
2016-08-14 18:53:25 +00:00
import net.minecraft.util.EnumFacing ;
import net.minecraft.util.EnumHand ;
import net.minecraft.util.math.AxisAlignedBB ;
import net.minecraft.util.math.BlockPos ;
import net.minecraft.world.IBlockAccess ;
import net.minecraft.world.World ;
2016-08-14 19:32:21 +00:00
import net.minecraftforge.fml.relauncher.Side ;
import net.minecraftforge.fml.relauncher.SideOnly ;
2016-08-14 23:14:08 +00:00
2016-08-14 18:53:25 +00:00
import WayofTime.bloodmagic.BloodMagic ;
2016-10-16 02:02:16 +00:00
import WayofTime.bloodmagic.api.altar.EnumAltarComponent ;
import WayofTime.bloodmagic.api.altar.IAltarComponent ;
import WayofTime.bloodmagic.block.enums.EnumMimic ;
2017-08-15 03:53:42 +00:00
import WayofTime.bloodmagic.registry.RegistrarBloodMagicBlocks ;
2016-08-14 18:53:25 +00:00
import WayofTime.bloodmagic.tile.TileMimic ;
2016-10-16 02:02:16 +00:00
import WayofTime.bloodmagic.util.Utils ;
2016-08-14 18:53:25 +00:00
2017-08-15 03:53:42 +00:00
public class BlockMimic extends BlockEnum < EnumMimic > implements IAltarComponent
2016-08-14 18:53:25 +00:00
{
2016-08-23 23:41:05 +00:00
public static final int sentientMimicMeta = 4 ;
2016-08-14 18:53:25 +00:00
public BlockMimic ( )
{
2016-10-16 02:02:16 +00:00
super ( Material . ROCK , EnumMimic . class ) ;
2016-08-14 18:53:25 +00:00
2017-08-15 03:53:42 +00:00
setUnlocalizedName ( BloodMagic . MODID + " .mimic. " ) ;
setCreativeTab ( BloodMagic . TAB_BM ) ;
2016-08-14 18:53:25 +00:00
setHardness ( 2 . 0F ) ;
setResistance ( 5 . 0F ) ;
setSoundType ( SoundType . STONE ) ;
setHarvestLevel ( " pickaxe " , 0 ) ;
2016-08-14 23:14:08 +00:00
setLightOpacity ( 15 ) ;
2016-08-14 18:53:25 +00:00
}
@Nullable
2017-01-02 05:43:34 +00:00
@Override
public AxisAlignedBB getCollisionBoundingBox ( IBlockState state , IBlockAccess world , BlockPos pos )
2016-08-14 18:53:25 +00:00
{
2016-08-23 21:35:43 +00:00
switch ( this . getMetaFromState ( state ) )
{
case 1 :
case 2 :
case 3 :
case 4 :
TileMimic tileMimic = ( TileMimic ) world . getTileEntity ( pos ) ;
2017-01-02 05:43:34 +00:00
if ( tileMimic ! = null & & ! tileMimic . getStackInSlot ( 0 ) . isEmpty ( ) )
2016-08-23 21:35:43 +00:00
{
Block mimicBlock = Block . getBlockFromItem ( tileMimic . getStackInSlot ( 0 ) . getItem ( ) ) ;
2017-01-02 05:43:34 +00:00
if ( mimicBlock = = Blocks . AIR )
2016-08-23 21:35:43 +00:00
{
return FULL_BLOCK_AABB ;
}
IBlockState mimicState = mimicBlock . getStateFromMeta ( tileMimic . metaOfReplacedBlock ) ;
if ( mimicBlock ! = this )
{
return mimicState . getCollisionBoundingBox ( world , pos ) ;
}
} else
{
return FULL_BLOCK_AABB ;
}
case 0 :
default :
return NULL_AABB ;
}
2016-08-14 18:53:25 +00:00
}
2016-08-14 19:32:21 +00:00
@Override
@SideOnly ( Side . CLIENT )
2016-08-14 23:14:08 +00:00
public AxisAlignedBB getSelectedBoundingBox ( IBlockState state , World world , BlockPos pos )
{
2016-08-14 19:32:21 +00:00
TileMimic tileMimic = ( TileMimic ) world . getTileEntity ( pos ) ;
2017-01-02 05:43:34 +00:00
if ( tileMimic ! = null & & ! tileMimic . getStackInSlot ( 0 ) . isEmpty ( ) )
2016-08-14 23:14:08 +00:00
{
2016-08-14 19:32:21 +00:00
Block mimicBlock = Block . getBlockFromItem ( tileMimic . getStackInSlot ( 0 ) . getItem ( ) ) ;
2017-01-02 05:43:34 +00:00
if ( mimicBlock = = Blocks . AIR )
2016-08-22 23:55:15 +00:00
{
return FULL_BLOCK_AABB ;
}
2016-08-14 19:32:21 +00:00
IBlockState mimicState = mimicBlock . getStateFromMeta ( tileMimic . getStackInSlot ( 0 ) . getItemDamage ( ) ) ;
2016-08-22 23:55:15 +00:00
if ( mimicBlock ! = this )
{
return mimicState . getSelectedBoundingBox ( world , pos ) ;
}
2016-08-14 19:32:21 +00:00
}
return FULL_BLOCK_AABB ;
}
2016-08-22 23:55:15 +00:00
@Override
public int getLightOpacity ( IBlockState state )
{
2016-08-23 21:35:43 +00:00
switch ( this . getMetaFromState ( state ) )
{
case 2 :
case 4 :
return 0 ;
default :
return this . lightOpacity ;
}
}
@Override
public int getLightValue ( IBlockState state )
{
switch ( this . getMetaFromState ( state ) )
{
case 3 :
return 15 ;
default :
return this . lightValue ;
}
2016-08-22 23:55:15 +00:00
}
2016-08-14 23:16:31 +00:00
@Override
public int getMetaFromState ( IBlockState state )
{
if ( state . getBlock ( ) = = this )
{
return super . getMetaFromState ( state ) ;
}
return state . getBlock ( ) . getMetaFromState ( state ) ;
}
2016-08-14 18:53:25 +00:00
@Override
2017-01-02 05:43:34 +00:00
public boolean onBlockActivated ( World world , BlockPos pos , IBlockState state , EntityPlayer player , EnumHand hand , EnumFacing side , float hitX , float hitY , float hitZ ) {
2016-08-14 18:53:25 +00:00
TileMimic mimic = ( TileMimic ) world . getTileEntity ( pos ) ;
2017-01-02 05:43:34 +00:00
return mimic ! = null & & mimic . onBlockActivated ( world , pos , state , player , hand , player . getHeldItem ( hand ) , side ) ;
2016-08-14 18:53:25 +00:00
}
@Override
public IBlockState getActualState ( IBlockState state , IBlockAccess world , BlockPos pos )
{
TileEntity tile = world . getTileEntity ( pos ) ;
if ( tile instanceof TileMimic )
{
TileMimic mimic = ( TileMimic ) tile ;
ItemStack stack = mimic . getStackInSlot ( 0 ) ;
2017-01-02 05:43:34 +00:00
if ( stack . getItem ( ) instanceof ItemBlock )
2016-08-14 18:53:25 +00:00
{
Block block = ( ( ItemBlock ) stack . getItem ( ) ) . getBlock ( ) ;
2016-11-12 00:50:44 +00:00
IBlockState mimicState = block . getStateFromMeta ( stack . getItemDamage ( ) ) ;
2016-08-22 23:55:15 +00:00
if ( block ! = this )
{
if ( block . getRenderType ( mimicState ) = = EnumBlockRenderType . ENTITYBLOCK_ANIMATED )
{
2017-08-15 03:53:42 +00:00
return RegistrarBloodMagicBlocks . BLOOD_LIGHT . getDefaultState ( ) ; //Small and invisible-ish, basically this is returned in order to not render over the animated block (TESR)
2016-08-22 23:55:15 +00:00
}
return block . getActualState ( mimicState , world , pos ) ;
}
2016-08-14 18:53:25 +00:00
}
}
return state ;
}
@Override
public boolean isFullCube ( IBlockState state )
{
return false ;
}
@Override
public boolean isNormalCube ( IBlockState state , IBlockAccess world , BlockPos pos )
{
return false ;
}
@Override
2017-01-02 05:43:34 +00:00
public boolean causesSuffocation ( IBlockState state )
2016-08-14 18:53:25 +00:00
{
return false ;
}
@Override
public boolean isOpaqueCube ( IBlockState state )
{
return false ;
}
@Override
public boolean canRenderInLayer ( IBlockState state , BlockRenderLayer layer )
{
2016-08-26 21:11:03 +00:00
return layer = = BlockRenderLayer . CUTOUT_MIPPED | | layer = = BlockRenderLayer . CUTOUT ;
2016-08-14 18:53:25 +00:00
}
2016-08-14 23:14:08 +00:00
@Override
public void breakBlock ( World world , BlockPos blockPos , IBlockState blockState )
{
TileEntity tile = world . getTileEntity ( blockPos ) ;
if ( tile instanceof TileMimic )
{
TileMimic TileMimic = ( TileMimic ) world . getTileEntity ( blockPos ) ;
if ( TileMimic ! = null )
TileMimic . dropItems ( ) ;
}
super . breakBlock ( world , blockPos , blockState ) ;
}
2016-08-14 18:53:25 +00:00
@Override
2016-10-18 23:38:56 +00:00
public boolean hasTileEntity ( IBlockState state ) {
return true ;
}
@Override
public TileEntity createTileEntity ( World world , IBlockState state ) {
2016-08-14 18:53:25 +00:00
return new TileMimic ( ) ;
}
2016-10-08 23:47:04 +00:00
// IAltarComponent
@Nullable
@Override
2016-10-16 02:02:16 +00:00
public EnumAltarComponent getType ( World world , IBlockState state , BlockPos pos )
{
2016-10-08 23:47:04 +00:00
TileEntity tile = world . getTileEntity ( pos ) ;
if ( tile instanceof TileMimic )
{
TileMimic mimic = ( TileMimic ) tile ;
ItemStack stack = mimic . getStackInSlot ( 0 ) ;
2017-01-02 05:43:34 +00:00
if ( stack . getItem ( ) instanceof ItemBlock )
2016-10-08 23:47:04 +00:00
{
Block block = ( ( ItemBlock ) stack . getItem ( ) ) . getBlock ( ) ;
if ( block instanceof IAltarComponent )
{
return ( ( IAltarComponent ) block ) . getType ( world , block . getStateFromMeta ( mimic . metaOfReplacedBlock ) , pos ) ;
2016-10-16 02:02:16 +00:00
} else
{
2016-10-08 23:47:04 +00:00
for ( EnumAltarComponent altarComponent : EnumAltarComponent . values ( ) )
2016-10-16 02:02:16 +00:00
if ( block = = Utils . getBlockForComponent ( altarComponent ) )
return altarComponent ;
2016-10-08 23:47:04 +00:00
}
}
}
return null ;
}
2016-08-14 18:53:25 +00:00
}