package micdoodle8.mods.galacticraft.core.blocks; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.core.items.IShiftDescription; import micdoodle8.mods.galacticraft.core.tile.TileEntityCrafting; import micdoodle8.mods.galacticraft.core.util.EnumSortCategoryBlock; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class BlockCrafting extends BlockAdvancedTile implements ITileEntityProvider, ISortableBlock, IShiftDescription { public static final PropertyDirection FACING = PropertyDirection.create("facing"); public BlockCrafting(String assetName) { super(Material.iron); this.setUnlocalizedName(assetName); } @Override public CreativeTabs getCreativeTabToDisplayOn() { return GalacticraftCore.galacticraftBlocksTab; } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (this.useWrench(worldIn, pos, playerIn, side, hitX, hitY, hitZ)) { return true; } if (playerIn.isSneaking()) { if (this.onSneakMachineActivated(worldIn, pos, playerIn, side, hitX, hitY, hitZ)) { return true; } } if (!worldIn.isRemote) { playerIn.openGui(GalacticraftCore.instance, -1, worldIn, pos.getX(), pos.getY(), pos.getZ()); } return true; } @Override public boolean onUseWrench(World world, BlockPos pos, EntityPlayer entityPlayer, EnumFacing side, float hitX, float hitY, float hitZ) { this.rotate6Ways(world, pos); return true; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityCrafting(); } @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { worldIn.setBlockState(pos, state.withProperty(FACING, getFacingFromEntity(worldIn, pos, placer)), 2); } public static EnumFacing getFacingFromEntity(World worldIn, BlockPos clickedBlock, EntityLivingBase entityIn) { if (MathHelper.abs((float)entityIn.posX - (float)clickedBlock.getX()) < 3.0F && MathHelper.abs((float)entityIn.posZ - (float)clickedBlock.getZ()) < 3.0F) { double d0 = entityIn.posY + (double)entityIn.getEyeHeight(); if (d0 - (double)clickedBlock.getY() > 2.0D) { return EnumFacing.UP; } if ((double)clickedBlock.getY() - d0 > 1.0D) { return EnumFacing.DOWN; } } return entityIn.getHorizontalFacing().getOpposite(); } @Override public EnumSortCategoryBlock getCategory(int meta) { return EnumSortCategoryBlock.GENERAL; } @Override public String getShiftDescription(int meta) { return GCCoreUtil.translate(this.getUnlocalizedName() + ".description"); } @Override public boolean showDescription(int meta) { return true; } @Override public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getFront(meta)); } @Override public int getMetaFromState(IBlockState state) { return (state.getValue(FACING)).getIndex(); } @Override protected BlockState createBlockState() { return new BlockState(this, new IProperty[] { FACING }); } }