2016-08-14 18:53:25 +00:00
package WayofTime.bloodmagic.block ;
import java.util.ArrayList ;
import java.util.List ;
import javax.annotation.Nullable ;
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 ;
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 org.apache.commons.lang3.tuple.ImmutablePair ;
import org.apache.commons.lang3.tuple.Pair ;
import WayofTime.bloodmagic.BloodMagic ;
import WayofTime.bloodmagic.api.Constants ;
import WayofTime.bloodmagic.block.base.BlockStringContainer ;
import WayofTime.bloodmagic.client.IVariantProvider ;
2016-08-22 23:55:15 +00:00
import WayofTime.bloodmagic.registry.ModBlocks ;
2016-08-14 18:53:25 +00:00
import WayofTime.bloodmagic.tile.TileMimic ;
public class BlockMimic extends BlockStringContainer implements IVariantProvider
{
2016-08-23 23:41:05 +00:00
public static final int sentientMimicMeta = 4 ;
2016-08-23 21:35:43 +00:00
public static final String [ ] names = { " nohitbox " , " solidopaque " , " solidclear " , " solidlight " , " sentient " } ;
2016-08-14 18:53:25 +00:00
public BlockMimic ( )
{
super ( Material . ROCK , names ) ;
setUnlocalizedName ( Constants . Mod . MODID + " .mimic. " ) ;
setCreativeTab ( BloodMagic . tabBloodMagic ) ;
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
2016-08-23 21:35:43 +00:00
public AxisAlignedBB getCollisionBoundingBox ( IBlockState state , World 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 ) ;
if ( tileMimic ! = null & & tileMimic . getStackInSlot ( 0 ) ! = null )
{
Block mimicBlock = Block . getBlockFromItem ( tileMimic . getStackInSlot ( 0 ) . getItem ( ) ) ;
if ( mimicBlock = = null )
{
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 ) ;
2016-08-14 23:14:08 +00:00
if ( tileMimic ! = null & & tileMimic . getStackInSlot ( 0 ) ! = null )
{
2016-08-14 19:32:21 +00:00
Block mimicBlock = Block . getBlockFromItem ( tileMimic . getStackInSlot ( 0 ) . getItem ( ) ) ;
2016-08-22 23:55:15 +00:00
if ( mimicBlock = = null )
{
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
public boolean onBlockActivated ( World world , BlockPos pos , IBlockState state , EntityPlayer player , EnumHand hand , ItemStack heldItem , EnumFacing side , float hitX , float hitY , float hitZ )
{
TileMimic mimic = ( TileMimic ) world . getTileEntity ( pos ) ;
2016-08-22 23:55:15 +00:00
if ( mimic = = null )
2016-08-14 18:53:25 +00:00
return false ;
2016-08-22 23:55:15 +00:00
return mimic . onBlockActivated ( world , pos , state , player , hand , heldItem , 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 ) ;
if ( stack ! = null & & stack . getItem ( ) instanceof ItemBlock )
{
Block block = ( ( ItemBlock ) stack . getItem ( ) ) . getBlock ( ) ;
2016-08-23 19:13:03 +00:00
IBlockState mimicState = block . getStateFromMeta ( mimic . metaOfReplacedBlock ) ;
2016-08-22 23:55:15 +00:00
if ( block ! = this )
{
if ( block . getRenderType ( mimicState ) = = EnumBlockRenderType . ENTITYBLOCK_ANIMATED )
{
2016-09-10 23:13:20 +00:00
return ModBlocks . 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
public boolean isVisuallyOpaque ( )
{
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
public List < Pair < Integer , String > > getVariants ( )
{
List < Pair < Integer , String > > ret = new ArrayList < Pair < Integer , String > > ( ) ;
for ( int i = 0 ; i < names . length ; i + + )
ret . add ( new ImmutablePair < Integer , String > ( i , " type= " + names [ i ] ) ) ;
return ret ;
}
@Override
public TileEntity createNewTileEntity ( World worldIn , int meta )
{
return new TileMimic ( ) ;
}
}