net.minecraft.util.EnumFacing#getXOffset ( )源码实例Demo

下面列出了net.minecraft.util.EnumFacing#getXOffset ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: enderutilities   文件: TileEntityEnergyBridge.java
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;
}
 
源代码2 项目: CommunityMod   文件: ItemTraverseWoodDoor.java
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;
        }
    }
}
 
源代码3 项目: litematica   文件: EasyPlaceUtils.java
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);
}
 
源代码4 项目: enderutilities   文件: PositionHelper.java
/**
 * 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;
    }
}
 
源代码5 项目: enderutilities   文件: BlockPosEU.java
/**
 * 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);
}
 
源代码6 项目: enderutilities   文件: TileEntityBarrel.java
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);
}
 
源代码7 项目: Wizardry   文件: PhasedBlockRenderer.java
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};
		}
	}
}
 
源代码8 项目: enderutilities   文件: ItemLivingManipulator.java
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;
}
 
源代码9 项目: enderutilities   文件: RenderEventHandler.java
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);
}