2016-04-29 19:45:45 -04:00
|
|
|
package WayofTime.bloodmagic.block;
|
|
|
|
|
2016-05-02 08:27:38 -04:00
|
|
|
import net.minecraft.block.Block;
|
2016-04-29 19:45:45 -04:00
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
import net.minecraft.block.material.Material;
|
2016-05-01 22:32:15 -04:00
|
|
|
import net.minecraft.block.properties.IProperty;
|
|
|
|
import net.minecraft.block.properties.PropertyBool;
|
|
|
|
import net.minecraft.block.properties.PropertyEnum;
|
|
|
|
import net.minecraft.block.state.BlockStateContainer;
|
2016-04-29 19:45:45 -04:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2016-05-02 08:27:38 -04:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-04-29 19:45:45 -04:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
|
|
|
import net.minecraft.util.EnumBlockRenderType;
|
2016-05-01 22:32:15 -04:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-05-02 08:27:38 -04:00
|
|
|
import net.minecraft.util.EnumHand;
|
2016-04-29 19:45:45 -04:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2016-05-01 22:32:15 -04:00
|
|
|
import WayofTime.bloodmagic.tile.TileAlchemyTable;
|
2016-04-29 19:45:45 -04:00
|
|
|
|
2016-05-01 22:32:15 -04:00
|
|
|
public class BlockAlchemyTable extends BlockContainer
|
2016-04-29 19:45:45 -04:00
|
|
|
{
|
2016-05-01 22:32:15 -04:00
|
|
|
public static final PropertyBool INVISIBLE = PropertyBool.create("invisible");
|
|
|
|
public static final PropertyEnum<EnumFacing> DIRECTION = PropertyEnum.<EnumFacing>create("direction", EnumFacing.class);
|
|
|
|
|
2016-04-29 19:45:45 -04:00
|
|
|
public BlockAlchemyTable()
|
|
|
|
{
|
|
|
|
super(Material.ROCK);
|
2016-05-01 22:32:15 -04:00
|
|
|
// this.setDefaultState(this.blockState.getBaseState().withProperty(DIRECTION, EnumFacing.DOWN).withProperty(INVISIBLE, false));
|
2016-04-29 19:45:45 -04:00
|
|
|
|
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".alchemyTable");
|
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
|
|
|
setHardness(2.0F);
|
|
|
|
setResistance(5.0F);
|
|
|
|
setHarvestLevel("pickaxe", 0);
|
|
|
|
|
|
|
|
// setBlockBounds(0.3F, 0F, 0.3F, 0.72F, 1F, 0.72F);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(IBlockState state)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isNormalCube(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFullCube(IBlockState state)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isVisuallyOpaque()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumBlockRenderType getRenderType(IBlockState state)
|
|
|
|
{
|
|
|
|
return EnumBlockRenderType.MODEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canRenderInLayer(IBlockState state, BlockRenderLayer layer)
|
|
|
|
{
|
|
|
|
return layer == BlockRenderLayer.CUTOUT_MIPPED || layer == BlockRenderLayer.TRANSLUCENT;
|
|
|
|
}
|
|
|
|
|
2016-05-01 22:32:15 -04:00
|
|
|
@Override
|
|
|
|
public IBlockState getStateFromMeta(int meta)
|
|
|
|
{
|
|
|
|
return this.getDefaultState();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the BlockState into the correct metadata value
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int getMetaFromState(IBlockState state)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
|
|
|
|
{
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileAlchemyTable)
|
|
|
|
{
|
|
|
|
return state.withProperty(INVISIBLE, ((TileAlchemyTable) tile).isInvisible()).withProperty(DIRECTION, ((TileAlchemyTable) tile).getDirection());
|
|
|
|
}
|
|
|
|
|
|
|
|
return state.withProperty(INVISIBLE, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected BlockStateContainer createBlockState()
|
|
|
|
{
|
|
|
|
return new BlockStateContainer(this, new IProperty[] { DIRECTION, INVISIBLE });
|
|
|
|
}
|
|
|
|
|
2016-04-29 19:45:45 -04:00
|
|
|
@Override
|
|
|
|
public TileEntity createNewTileEntity(World world, int meta)
|
|
|
|
{
|
2016-05-01 22:32:15 -04:00
|
|
|
return new TileAlchemyTable();
|
2016-04-29 19:45:45 -04:00
|
|
|
}
|
|
|
|
|
2016-05-02 08:27:38 -04: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)
|
|
|
|
{
|
|
|
|
BlockPos position = pos;
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileAlchemyTable)
|
|
|
|
{
|
|
|
|
if (((TileAlchemyTable) tile).isSlave())
|
|
|
|
{
|
|
|
|
position = ((TileAlchemyTable) tile).getConnectedPos();
|
|
|
|
tile = world.getTileEntity(position);
|
|
|
|
if (!(tile instanceof TileAlchemyTable))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player.openGui(BloodMagic.instance, Constants.Gui.ALCHEMY_TABLE_GUI, world, position.getX(), position.getY(), position.getZ());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-04-29 19:45:45 -04:00
|
|
|
|
|
|
|
@Override
|
2016-05-02 08:27:38 -04:00
|
|
|
public void breakBlock(World world, BlockPos pos, IBlockState blockState)
|
2016-04-29 19:45:45 -04:00
|
|
|
{
|
2016-05-02 08:27:38 -04:00
|
|
|
TileAlchemyTable tile = (TileAlchemyTable) world.getTileEntity(pos);
|
|
|
|
if (tile != null && !tile.isSlave())
|
|
|
|
{
|
2016-04-29 19:45:45 -04:00
|
|
|
tile.dropItems();
|
2016-05-02 08:27:38 -04:00
|
|
|
}
|
2016-04-29 19:45:45 -04:00
|
|
|
|
2016-05-02 08:27:38 -04:00
|
|
|
super.breakBlock(world, pos, blockState);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-19 17:43:33 -07:00
|
|
|
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block neighborBlock)
|
2016-05-02 08:27:38 -04:00
|
|
|
{
|
|
|
|
TileAlchemyTable tile = (TileAlchemyTable) world.getTileEntity(pos);
|
|
|
|
if (tile != null)
|
|
|
|
{
|
|
|
|
BlockPos connectedPos = tile.getConnectedPos();
|
|
|
|
TileEntity connectedTile = world.getTileEntity(connectedPos);
|
|
|
|
if (!(connectedTile instanceof TileAlchemyTable && ((TileAlchemyTable) connectedTile).getConnectedPos().equals(pos)))
|
|
|
|
{
|
|
|
|
this.breakBlock(world, pos, state);
|
|
|
|
world.setBlockToAir(pos);
|
|
|
|
}
|
|
|
|
}
|
2016-04-29 19:45:45 -04:00
|
|
|
}
|
|
|
|
}
|