Java Code Examples for net.minecraft.entity.EntityLivingBase#getHorizontalFacing()

The following examples show how to use net.minecraft.entity.EntityLivingBase#getHorizontalFacing() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockMagiciansWorktable.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Nonnull
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
	EnumFacing placerFacing = placer.getHorizontalFacing();
	EnumFacing offsetDir = placerFacing.rotateY();
	BlockPos part2Pos = pos.offset(offsetDir);
	Block block = worldIn.getBlockState(part2Pos).getBlock();
	if (block.isReplaceable(worldIn, part2Pos)) {
		worldIn.setBlockState(part2Pos, getDefaultState().withProperty(FACING, placerFacing.getOpposite()).withProperty(ISLEFTSIDE, false));
		return getDefaultState().withProperty(FACING, placerFacing.getOpposite()).withProperty(ISLEFTSIDE, true);
	} else {
		block = worldIn.getBlockState(part2Pos.offset(offsetDir.getOpposite(), 2)).getBlock();
		part2Pos = part2Pos.offset(offsetDir.getOpposite(), 2);
		if (block.isReplaceable(worldIn, part2Pos)) {
			worldIn.setBlockState(part2Pos, getDefaultState().withProperty(FACING, placerFacing.getOpposite()).withProperty(ISLEFTSIDE, true));
		} else {
			return Blocks.AIR.getDefaultState();
		}
		return getDefaultState().withProperty(FACING, placerFacing.getOpposite()).withProperty(ISLEFTSIDE, false);
	}
}
 
Example 2
Source File: BlockSignalBase.java    From Signals with GNU General Public License v3.0 6 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer){
    List<EnumFacing> railFacings = new ArrayList<>(4);
    for(EnumFacing horFacing : EnumFacing.HORIZONTALS) {
        BlockPos railPos = pos.offset(horFacing);
        if(RailManager.getInstance().getRail(worldIn, railPos, worldIn.getBlockState(railPos)) != null) {
            railFacings.add(horFacing);
        }
    }

    EnumFacing orientation;
    if(railFacings.size() == 1) { //When exactly one rail is connecting, connect the signal to the rail
        orientation = railFacings.get(0).rotateY();
    } else { //Else, fall back onto player orientation.
        orientation = placer.getHorizontalFacing();
    }
    return getDefaultState().withProperty(FACING, orientation);
}
 
Example 3
Source File: ToolJackHammer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entity) {
    if(entity instanceof EntityPlayer && !(entity instanceof FakePlayer)) {
        EntityPlayer entityPlayer = (EntityPlayer) entity;
        EnumFacing sideHit = ToolUtility.getSideHit(world, pos, entityPlayer);
        int damagePerBlockBreak = getToolDamagePerBlockBreak(stack);
        JackHammerMode jackHammerMode = MODE_SWITCH_BEHAVIOR.getModeFromItemStack(stack);
        EnumFacing horizontalFacing = entity.getHorizontalFacing();
        int xSizeExtend = (jackHammerMode.getHorizontalSize() - 1) / 2;
        int ySizeExtend = (jackHammerMode.getVerticalSize() - 1) / 2;
        for (int x = -xSizeExtend; x <= xSizeExtend; x++) {
            for (int y = -ySizeExtend; y <= ySizeExtend; y++) {
                //do not check center block - it's handled now
                if (x == 0 && y == 0) continue;
                BlockPos offsetPos = rotate(pos, x, y, sideHit, horizontalFacing);
                IBlockState blockState = world.getBlockState(offsetPos);
                if(world.isBlockModifiable(entityPlayer, offsetPos) &&
                    blockState.getBlock().canHarvestBlock(world, offsetPos, entityPlayer) &&
                    blockState.getPlayerRelativeBlockHardness(entityPlayer, world, offsetPos) > 0.0f &&
                    stack.canHarvestBlock(blockState)) {
                    GTUtility.harvestBlock(world, offsetPos, entityPlayer);
                    ((ToolMetaItem) stack.getItem()).damageItem(stack, damagePerBlockBreak, false);
                }
            }
        }
    }
}
 
Example 4
Source File: BlockSpeedTelegraph.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();

    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }

    return this.getDefaultState().withProperty(FACING, facingHorizontal);
}
 
Example 5
Source File: BlockShipHelm.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();

    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }

    return this.getDefaultState().withProperty(FACING, facingHorizontal);
}
 
Example 6
Source File: BlockGearbox.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();
    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }
    return this.getDefaultState().withProperty(BlockHorizontal.FACING, facingHorizontal);
}
 
Example 7
Source File: BlockLiftLever.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
@Nonnull
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();
    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }
    return this.getDefaultState().withProperty(BlockHorizontal.FACING, facingHorizontal);
}
 
Example 8
Source File: BlockCaptainsChair.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX,
    float hitY, float hitZ, int meta, EntityLivingBase placer) {
    EnumFacing facingHorizontal = placer.getHorizontalFacing();

    if (!placer.isSneaking()) {
        facingHorizontal = facingHorizontal.getOpposite();
    }

    return this.getDefaultState().withProperty(FACING, facingHorizontal);
}
 
Example 9
Source File: BlockPhysicsInfuser.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing,
    float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
    EnumFacing playerFacing = placer.getHorizontalFacing();
    if (!placer.isSneaking()) {
        playerFacing = playerFacing.getOpposite();
    }

    // Find the facing that's closest to what the player wanted.
    EnumFacing facingHorizontal;
    if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing)) {
        facingHorizontal = playerFacing;
    } else if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing.rotateY())) {
        facingHorizontal = playerFacing.rotateY();
    } else if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing.rotateYCCW())) {
        facingHorizontal = playerFacing.rotateYCCW();
    } else if (canPlaceBlockAtWithFacing(worldIn, pos, playerFacing.getOpposite())) {
        facingHorizontal = playerFacing.getOpposite();
    } else {
        // There was no valid facing! How the did this method even get called!
        throw new IllegalStateException(
            "Cannot find valid state for placement for Physics Infuser!");
    }

    return this.getDefaultState()
        .withProperty(FACING, facingHorizontal)
        .withProperty(INFUSER_LIGHT_ON, false);
}
 
Example 10
Source File: BlockBackpack.java    From WearableBackpacks with MIT License 5 votes vote down vote up
@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state,
                            EntityLivingBase placer, ItemStack stack) {
	// Set the facing value of the backpack when placed.
	TileEntity tileEntity = worldIn.getTileEntity(pos);
	if (tileEntity instanceof TileEntityBackpack)
		((TileEntityBackpack)tileEntity).facing = placer.getHorizontalFacing();
}
 
Example 11
Source File: BlockUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
public static EnumFacing get3dOrientation(EntityLivingBase entity, BlockPos pos) {
	if (MathHelper.abs((float)entity.posX - pos.getX()) < 2.0F && MathHelper.abs((float)entity.posZ - pos.getZ()) < 2.0F) {
		final double entityEyes = entity.posY + entity.getEyeHeight();
		if (entityEyes - pos.getY() > 2.0D) return EnumFacing.DOWN;
		if (pos.getY() - entityEyes > 0.0D) return EnumFacing.UP;
	}

	return entity.getHorizontalFacing();
}
 
Example 12
Source File: BlockUtils.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Deprecated
public static EnumFacing get2dOrientation(EntityLivingBase entity) {
	return entity.getHorizontalFacing();
}