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

The following examples show how to use net.minecraft.util.EnumFacing#getXOffset() . 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: 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 2
Source File: ItemTraverseWoodDoor.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (facing != EnumFacing.UP) {
        return EnumActionResult.FAIL;
    }
    else {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if (!block.isReplaceable(worldIn, pos)) {
            pos = pos.offset(facing);
        }

        ItemStack itemstack = player.getHeldItem(hand);

        if (player.canPlayerEdit(pos, facing, itemstack) && this.block.canPlaceBlockAt(worldIn, pos)) {
            EnumFacing enumfacing = EnumFacing.fromAngle((double) player.rotationYaw);
            int i = enumfacing.getXOffset();
            int j = enumfacing.getYOffset();
            boolean flag = i < 0 && hitZ < 0.5F || i > 0 && hitZ > 0.5F || j < 0 && hitX > 0.5F || j > 0 && hitX < 0.5F;
            placeDoor(worldIn, pos, enumfacing, this.block, flag);
            SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
            worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.shrink(1);
            return EnumActionResult.SUCCESS;
        }
        else {
            return EnumActionResult.FAIL;
        }
    }
}
 
Example 3
Source File: EasyPlaceUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Vec3d getHitPositionForSidePosition(BlockPos posSide, EnumFacing sideFromTarget)
{
    EnumFacing.Axis axis = sideFromTarget.getAxis();
    double x = posSide.getX() + 0.5 - sideFromTarget.getXOffset() * 0.5;
    double y = posSide.getY() + (axis == EnumFacing.Axis.Y ? (sideFromTarget == EnumFacing.DOWN ? 1.0 : 0.0) : 0.0);
    double z = posSide.getZ() + 0.5 - sideFromTarget.getZOffset() * 0.5;

    return new Vec3d(x, y, z);
}
 
Example 4
Source File: PositionHelper.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adjust the position so that the given Entity's bounding box is against the block bound
 * of a block on the given side. Note that the entity may still be colliding on other sides.
 * @param entity
 * @param side
 */
public void adjustPositionToTouchFace(Entity entity, EnumFacing facing)
{
    this.posX += (facing.getXOffset() * entity.width / 2);
    this.posZ += (facing.getZOffset() * entity.width / 2);

    // Bottom side
    if (facing.equals(EnumFacing.DOWN))
    {
        this.posY -= entity.height;
    }
}
 
Example 5
Source File: BlockPosEU.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Offset the position by the given amount into the given direction.
 * Returns a new instance with the changes applied and does not modify the original.
 */
public BlockPosEU offset(EnumFacing facing, int distance)
{
    return new BlockPosEU(  this.posX + facing.getXOffset() * distance,
                            this.posY + facing.getYOffset() * distance,
                            this.posZ + facing.getZOffset() * distance,
                            this.dimension, this.facing);
}
 
Example 6
Source File: TileEntityBarrel.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected Vec3d getSpawnedItemPosition(EnumFacing side)
{
    double x = this.getPos().getX() + 0.5 + side.getXOffset() * 0.625;
    double y = this.getPos().getY() + 0.5 + side.getYOffset() * 0.5;
    double z = this.getPos().getZ() + 0.5 + side.getZOffset() * 0.625;

    if (side == EnumFacing.DOWN)
    {
        y -= 0.25;
    }

    return new Vec3d(x, y, z);
}
 
Example 7
Source File: PhasedBlockRenderer.java    From Wizardry with GNU Lesser General Public License v3.0 4 votes vote down vote up
public SurfaceFace(EnumFacing face, BlockPos position, Vec3d shapeLocus) {
	this.face = face;
	this.position = position;

	xNormal = -face.getXOffset();
	yNormal = -face.getYOffset();
	zNormal = -face.getZOffset();

	int direction = -face.getAxisDirection().getOffset();
	int renderDirection = face.getAxis().isHorizontal() ? direction : -direction;

	float xLocus = position.getX() + (1 - xNormal) / 2;
	float yLocus = position.getY() + (1 - yNormal) / 2;
	float zLocus = position.getZ() + (1 - zNormal) / 2;
	float xShear = yNormal - zNormal;
	float yShear = zNormal - xNormal;
	float zShear = xNormal - yNormal;

	float yShearOne = xShear == 0 ? yShear : 0;
	float yShearTwo = xShear != 0 ? yShear : 0;


	int idx = 0;
	for (int shearOne = -renderDirection; shearOne >= -1 && shearOne < 2; shearOne += 2 * renderDirection) {
		for (int shearTwo = shearOne * renderDirection; shearTwo >= -1 && shearTwo < 2; shearTwo -= 2 * shearOne * renderDirection) {

			float directionX = xShear * shearOne;
			float directionY = yShearOne * shearOne + yShearTwo * shearTwo;
			float directionZ = zShear * shearTwo;

			float calculatedX = directionX / 2 + xLocus;
			float calculatedY = directionY / 2 + yLocus;
			float calculatedZ = directionZ / 2 + zLocus;

			float distanceToLocusX = (float) shapeLocus.x - calculatedX;
			float distanceToLocusY = (float) shapeLocus.y - calculatedY;
			float distanceToLocusZ = (float) shapeLocus.z - calculatedZ;

			float descale = distanceToLocusX * distanceToLocusX +
					distanceToLocusY * distanceToLocusY +
					distanceToLocusZ * distanceToLocusZ;

			float positionWarp = MathHelper.sin((calculatedX + calculatedY + calculatedZ) *
					(float) Math.PI / WARP_SPACE_PERIOD);

			shapeData[idx++] = new float[]{calculatedX, calculatedY, calculatedZ,
					distanceToLocusX / descale, distanceToLocusY / descale, distanceToLocusZ / descale, positionWarp};
		}
	}
}
 
Example 8
Source File: ItemLivingManipulator.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private EnumActionResult releaseEntity(ItemStack containerStack, EntityPlayer player, World world,
        BlockPos pos, double x, double y, double z, EnumFacing side)
{
    ItemStack moduleStack = this.getSelectedModuleStack(containerStack, ModuleType.TYPE_MEMORY_CARD_MISC);

    if (moduleStack.isEmpty())
    {
        return EnumActionResult.PASS;
    }

    NBTTagList tagList = NBTUtils.getTagList(moduleStack, WRAPPER_TAG_NAME, "Entities", Constants.NBT.TAG_COMPOUND, false);

    if (tagList == null || tagList.tagCount() == 0)
    {
        return EnumActionResult.PASS;
    }

    int current = NBTUtils.getByte(moduleStack, WRAPPER_TAG_NAME, "Current");
    int numEntities = tagList.tagCount();

    if (current >= numEntities)
    {
        current = (numEntities > 0) ? numEntities - 1 : 0;
    }

    NBTTagCompound tag = tagList.getCompoundTagAt(current);

    if (tag != null)
    {
        boolean isShulker = false;

        if (tag.getString("id").equals("minecraft:shulker") || tag.getString("id").equals("Shulker"))
        {
            // Special case to update the Shulker's attached position and position
            if (tag.hasKey("APX", Constants.NBT.TAG_INT))
            {
                int xi = pos.getX() + side.getXOffset();
                int yi = pos.getY() + side.getYOffset();
                int zi = pos.getZ() + side.getZOffset();

                tag.setTag("Pos", NBTUtils.writeDoubles(new double[] {xi + 0.5d, yi, zi + 0.5d}));
                tag.setInteger("APX", xi);
                tag.setInteger("APY", yi);
                tag.setInteger("APZ", zi);
                tag.setByte("AttachFace", (byte)side.getIndex());
                isShulker = true;
            }
        }

        Entity entity = EntityList.createEntityFromNBT(tag, world);

        if (entity == null)
        {
            return EnumActionResult.FAIL;
        }

        if (isShulker == false)
        {
            if (tag.hasKey("playerYaw", Constants.NBT.TAG_FLOAT))
            {
                float yawDiff = player.rotationYaw - tag.getFloat("playerYaw");
                entity.rotationYaw = (entity.rotationYaw + yawDiff) % 360;
            }

            PositionHelper posHelper = new PositionHelper(x, y, z);
            posHelper.adjustPositionToTouchFace(entity, side);
            entity.setLocationAndAngles(posHelper.posX, posHelper.posY, posHelper.posZ, entity.rotationYaw, entity.rotationPitch);
        }

        entity.motionY = 0.0;
        entity.fallDistance = 0.0f;
        entity.onGround = true;

        if (entity instanceof EntityLiving && this.getInstalledModuleCount(containerStack, ModuleType.TYPE_MOBPERSISTENCE) > 0)
        {
            EntityUtils.applyMobPersistence((EntityLiving)entity);
        }

        world.spawnEntity(entity);
        tagList.removeTag(current);
    }

    numEntities = tagList.tagCount();

    if (current >= numEntities)
    {
        current = (numEntities > 0) ? numEntities - 1 : 0;
    }

    NBTUtils.setByte(moduleStack, WRAPPER_TAG_NAME, "Current", (byte)current);
    this.setSelectedModuleStack(containerStack, ModuleType.TYPE_MEMORY_CARD_MISC, moduleStack);

    return EnumActionResult.SUCCESS;
}
 
Example 9
Source File: RenderEventHandler.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void renderPortalPanelText(String text, EntityPlayer player, BlockPos pos, EnumFacing facing, float partialTicks)
{
    double x = pos.getX();
    double y = pos.getY();
    double z = pos.getZ();

    double dx = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
    double dy = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
    double dz = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;

    float angleH = 0f;
    float angleV = 0f;
    double frontOffset = 0.32D;

    if (facing.getAxis().isHorizontal())
    {
        int frontX = facing.getXOffset();
        int frontZ = facing.getZOffset();

        if (facing == EnumFacing.NORTH || facing == EnumFacing.WEST)
        {
            frontX = -frontX;
            frontZ = -frontZ;
            frontOffset = 1.0D - frontOffset;
        }

        x += frontX * frontOffset + frontZ * 0.5D;
        z += frontZ * frontOffset + frontX * 0.5D;

        y += 1.25D;
        angleH = facing.getHorizontalAngle() + 180f;
    }
    else
    {
        if (facing == EnumFacing.DOWN)
        {
            frontOffset = 1.0D - frontOffset;
            x += 0.5D;
            z -= 0.25D;
        }
        else
        {
            x += 0.5D;
            z += 1.25D;
        }

        y += frontOffset;
        angleV = facing.getYOffset() * -90f;
    }

    this.renderLabel(text, x - dx, y - dy, z - dz, angleH, angleV);
}