Java Code Examples for net.minecraft.util.EnumFacing#rotateY()

The following examples show how to use net.minecraft.util.EnumFacing#rotateY() . 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: BlockWisdomWoodStairs.java    From Wizardry with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face) {
	if (net.minecraftforge.common.ForgeModContainer.disableStairSlabCulling)
		return super.doesSideBlockRendering(state, world, pos, face);

	if (state.isOpaqueCube())
		return true;

	state = this.getActualState(state, world, pos);

	EnumHalf half = state.getValue(HALF);
	EnumFacing side = state.getValue(FACING);
	EnumShape shape = state.getValue(SHAPE);
	if (face == EnumFacing.UP) return half == EnumHalf.TOP;
	if (face == EnumFacing.DOWN) return half == EnumHalf.BOTTOM;
	if (shape == EnumShape.OUTER_LEFT || shape == EnumShape.OUTER_RIGHT) return false;
	if (face == side) return true;
	if (shape == EnumShape.INNER_LEFT && face.rotateY() == side) return true;
	return shape == EnumShape.INNER_RIGHT && face.rotateYCCW() == side;
}
 
Example 3
Source File: BlockStairsTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean isSideSolid(IBlockState state,IBlockAccess world, BlockPos pos, EnumFacing side)
{
	boolean flipped = state.getValue(BlockStairs.HALF) == EnumHalf.TOP;
	EnumShape shape = (EnumShape)state.getValue(BlockStairs.SHAPE);
	EnumFacing facing = (EnumFacing)state.getValue(BlockStairs.FACING);
	if (side == EnumFacing.UP) return flipped;
	if (side == EnumFacing.DOWN) return !flipped;
	if (facing == side) return true;
	if (flipped)
	{
		if (shape == EnumShape.INNER_LEFT) return side == facing.rotateYCCW();
		if (shape == EnumShape.INNER_RIGHT) return side == facing.rotateY();
	}
	else
	{
		if (shape == EnumShape.INNER_LEFT) return side == facing.rotateY();
		if (shape == EnumShape.INNER_RIGHT) return side == facing.rotateYCCW();
	}
	return false;
}
 
Example 4
Source File: BlockStairsTFC.java    From TFC2 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean doesSideBlockRendering(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing face)
{
	if (net.minecraftforge.common.ForgeModContainer.disableStairSlabCulling)
		return super.doesSideBlockRendering(state, world, pos, face);

	if ( state.isOpaqueCube() )
		return true;

	state = this.getActualState(state, world, pos);

	EnumHalf half = state.getValue(BlockStairs.HALF);
	EnumFacing side = state.getValue(BlockStairs.FACING);
	EnumShape shape = state.getValue(BlockStairs.SHAPE);
	if (face == EnumFacing.UP) return half == EnumHalf.TOP;
	if (face == EnumFacing.DOWN) return half == EnumHalf.BOTTOM;
	if (shape == EnumShape.OUTER_LEFT || shape == EnumShape.OUTER_RIGHT) return false;
	if (face == side) return true;
	if (shape == EnumShape.INNER_LEFT && face.rotateY() == side) return true;
	if (shape == EnumShape.INNER_RIGHT && face.rotateYCCW() == side) return true;
	return false;
}
 
Example 5
Source File: PositionUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the rotation that would transform <b>facingOriginal</b> into <b>facingRotated</b>.
 * @param facingOriginal
 * @param facingRotated
 * @return
 */
public static Rotation getRotation(EnumFacing facingOriginal, EnumFacing facingRotated)
{
    if (facingOriginal.getAxis() == EnumFacing.Axis.Y ||
        facingRotated.getAxis() == EnumFacing.Axis.Y || facingOriginal == facingRotated)
    {
        return Rotation.NONE;
    }

    if (facingRotated == facingOriginal.getOpposite())
    {
        return Rotation.CLOCKWISE_180;
    }

    return facingRotated == facingOriginal.rotateY() ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90;
}
 
Example 6
Source File: TileEntityEnergyBridge.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean isObstructedQuadrant(World world, BlockPos basePos, EnumFacing facing, BlockPos ... positions)
{
    EnumFacing dirNext = facing.rotateY(); // the direction 90 degrees clock wise

    for (BlockPos pos : positions)
    {
        int x = pos.getX() * facing.getXOffset() + pos.getZ() * facing.getZOffset();
        int y = pos.getY();
        int z = pos.getX() * dirNext.getXOffset() + pos.getZ() * dirNext.getZOffset();

        if (world.isAirBlock(basePos.add(x, y, z)) == false)
        {
            return true;
        }
    }

    return false;
}
 
Example 7
Source File: RedstoneUtil.java    From Minecoprocessors with GNU General Public License v3.0 5 votes vote down vote up
private static EnumFacing rotateFacing(EnumFacing facing, int rotation) {
  if (rotation >= 0) {
    for (int i = 0; i < rotation; i++) {
      facing = facing.rotateY();
    }
  } else {
    rotation = -rotation;
    for (int i = 0; i < rotation; i++) {
      facing = facing.rotateYCCW();
    }
  }
  return facing;
}
 
Example 8
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 9
Source File: ShapeGen.java    From pycode-minecraft with MIT License 5 votes vote down vote up
public static void cube(World world, int width, int depth, int height, IBlockState block_state, BlockPos pos, EnumFacing facing) {
    floor(world, width, depth, block_state, pos, facing);
    floor(world, width, depth, block_state, pos.offset(EnumFacing.UP, height), facing);
    for (int i = 0; i < 4; i++) {
        wall(world, depth, height, block_state, pos, facing);
        pos = pos.offset(facing, depth - 1);
        facing = facing.rotateY();
    }
}
 
Example 10
Source File: BlockStairsTFC.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return Can this block attach to other blocks for support checks in this direction
 */
@Override
public boolean canSupportFacing(IBlockState myState, IBlockAccess world, BlockPos pos, EnumFacing facing)
{
	EnumFacing f = (EnumFacing)myState.getValue(BlockStairs.FACING);
	if(facing == f.rotateY() || facing == f.rotateYCCW())
		return true;

	return myState.getBlock().isSideSolid(myState, world, pos, facing);
}
 
Example 11
Source File: BlockStairsTFC.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a bounding box representing an eighth of a block (a block whose three dimensions are halved).
 * Used in all stair shapes except STRAIGHT (gets added alone in the case of OUTER; alone with a quarter block in
 * case of INSIDE).
 */
private static AxisAlignedBB getCollEighthBlock(IBlockState bstate)
{
	EnumFacing enumfacing = (EnumFacing)bstate.getValue(BlockStairs.FACING);
	EnumFacing enumfacing1;

	switch ((BlockStairs.EnumShape)bstate.getValue(BlockStairs.SHAPE))
	{
	case OUTER_LEFT:
	default:
		enumfacing1 = enumfacing;
		break;
	case OUTER_RIGHT:
		enumfacing1 = enumfacing.rotateY();
		break;
	case INNER_RIGHT:
		enumfacing1 = enumfacing.getOpposite();
		break;
	case INNER_LEFT:
		enumfacing1 = enumfacing.rotateYCCW();
	}

	boolean flag = bstate.getValue(BlockStairs.HALF) == BlockStairs.EnumHalf.TOP;

	switch (enumfacing1)
	{
	case NORTH:
	default:
		return flag ? AABB_OCT_BOT_NW : AABB_OCT_TOP_NW;
	case SOUTH:
		return flag ? AABB_OCT_BOT_SE : AABB_OCT_TOP_SE;
	case WEST:
		return flag ? AABB_OCT_BOT_SW : AABB_OCT_TOP_SW;
	case EAST:
		return flag ? AABB_OCT_BOT_NE : AABB_OCT_TOP_NE;
	}
}
 
Example 12
Source File: DirectionalityRenderer.java    From Signals with GNU General Public License v3.0 4 votes vote down vote up
private void build(TIntObjectHashMap<BakedRenderer> bakedRenderers, ImmutableList<NetworkRail<MCPos>> edge){

        for(int edgeIndex = 1; edgeIndex < edge.size() - 1; edgeIndex++) {
            NetworkRail<MCPos> prevRail = edge.get(edgeIndex - 1);
            MCNetworkRail curRail = (MCNetworkRail)edge.get(edgeIndex);
            NetworkRail<MCPos> nextRail = edge.get(edgeIndex + 1);

            EnumHeading prevHeading = curRail.getPos().getRelativeHeading(prevRail.getPos());
            EnumHeading nextHeading = nextRail.getPos().getRelativeHeading(curRail.getPos());
            if(prevHeading == null || nextHeading == null || prevHeading != nextHeading || curRail.getPos().getDimID() != nextRail.getPos().getDimID() || curRail.getPos().getDimID() != prevRail.getPos().getDimID()) continue;

            BakedRenderer bakedRenderer = bakedRenderers.get(curRail.getPos().getDimID());
            if(bakedRenderer == null) {
                bakedRenderer = new BakedRenderer();
                bakedRenderers.put(curRail.getPos().getDimID(), bakedRenderer);
            }

            MCPos pos = curRail.getPos();
            EnumFacing facing = HeadingUtils.toFacing(nextHeading).getOpposite();
            EnumFacing rotatedFacing = facing.rotateY();
            EnumFacing rotatedFacing2 = facing.rotateYCCW();
            int yOffset = AbstractRailRenderer.getRailHeightOffset(curRail, facing);

            Vec3d posVec = new Vec3d(pos.getX() + 0.5, pos.getY() + (yOffset != 0 ? 0.6001 : 0.1001), pos.getZ() + 0.5);

            double arrowSize = 0.1;
            double spacing = 0.1;

            for(int i = -2; i < -1; i++) {
                Vec3d shiftedPosVec = posVec.addVector(facing.getFrontOffsetX() * spacing * i, spacing * i * yOffset + 0.001, facing.getFrontOffsetZ() * spacing * i);
                Vec3d vecBack = shiftedPosVec.addVector(facing.getFrontOffsetX() * arrowSize, arrowSize * yOffset, facing.getFrontOffsetZ() * arrowSize);
                Vec3d c1 = vecBack.addVector(rotatedFacing.getFrontOffsetX() * arrowSize, 0, rotatedFacing.getFrontOffsetZ() * arrowSize);
                Vec3d c2 = vecBack.addVector(rotatedFacing2.getFrontOffsetX() * arrowSize, 0, rotatedFacing2.getFrontOffsetZ() * arrowSize);

                bakedRenderer.add(shiftedPosVec.x, shiftedPosVec.y, shiftedPosVec.z);
                bakedRenderer.add(c1.x, c1.y, c1.z);
                //buffer.pos(shiftedPosVec.x, shiftedPosVec.y, shiftedPosVec.z).color(r, g, b, 1).endVertex();
                bakedRenderer.add(c2.x, c2.y, c2.z);
            }
        }
    }
 
Example 13
Source File: TileEntityRendererEnergyBridge.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void render(TileEntityEnergyBridge teeb, double x, double y, double z, float partialTicks, int destroyStage, float partial)
{
    if (teeb.getIsActive() == false)
    {
        return;
    }

    TileEntityEnergyBridge.Type type = teeb.getType();
    double rot = (teeb.getWorld().getTotalWorldTime() % 100.0d) * Math.PI  / 50.0d + (Math.PI / 50.0d * partialTicks);
    x += 0.5d;
    z += 0.5d;

    BlockPos pos = teeb.getPos();
    // Energy Bridge Transmitter
    if (type == Type.TRANSMITTER)
    {
        this.renderBeamVertical(x, y, z, teeb.beamYMin - pos.getY(), 0.0d, 0.2d, rot, 3.0d, teeb.getIsPowered());
        this.renderBeamVertical(x, y, z, 1.0d, teeb.beamYMax - pos.getY(), 0.2d, rot, 3.0d, teeb.getIsPowered());
    }
    // Energy Bridge Receiver
    else if (type == Type.RECEIVER)
    {
        this.renderBeamVertical(x, y, z, teeb.beamYMin - pos.getY(), 0.0d, 0.2d, rot,  3.0d, teeb.getIsPowered());
        this.renderBeamVertical(x, y, z, 1.0d, teeb.beamYMax - pos.getY(), 0.2d, rot, -3.0d, teeb.getIsPowered());
    }
    // Energy Bridge Resonator
    else if (type == Type.RESONATOR)
    {
        EnumFacing dirFront = teeb.getFacing();
        EnumFacing dirSide = dirFront.rotateY();

        // From Resonator to Receiver
        GlStateManager.pushMatrix();
        GlStateManager.translate(x + 0.5d * dirFront.getXOffset(), y + 0.5d, z + 0.5d * dirFront.getZOffset());
        GlStateManager.rotate(90, -dirSide.getXOffset(), 0, -dirSide.getZOffset());
        GlStateManager.translate(-x, -y, -z);
        this.renderBeamVertical(x, y, z, 0.0d, 2.0d, 0.2d, rot, 3.0d, teeb.getIsPowered());
        GlStateManager.popMatrix();

        // From resonator to next resonator
        GlStateManager.pushMatrix();
        GlStateManager.translate(x + 0.3d * dirSide.getXOffset() - 0.2d * dirFront.getXOffset(), y + 0.5d, z + 0.3d * dirSide.getZOffset() - 0.2d * dirFront.getZOffset());
        GlStateManager.rotate(90, dirFront.getXOffset(), 0, dirFront.getZOffset());
        GlStateManager.rotate(45, -dirSide.getXOffset(), 0, -dirSide.getZOffset());
        GlStateManager.translate(-x, -y, -z);
        this.renderBeamVertical(x, y, z, 0.0d, 4.2d, 0.14d, rot, 3.0d, teeb.getIsPowered());
        GlStateManager.popMatrix();
    }
}