net.minecraft.util.math.BlockPos#offset ( )源码实例Demo

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

public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door, boolean isRightHinge) {
    BlockPos blockpos = pos.offset(facing.rotateY());
    BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
    int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
    int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
    boolean flag = worldIn.getBlockState(blockpos1).getBlock() == door || worldIn.getBlockState(blockpos1.up()).getBlock() == door;
    boolean flag1 = worldIn.getBlockState(blockpos).getBlock() == door || worldIn.getBlockState(blockpos.up()).getBlock() == door;

    if ((!flag || flag1) && j <= i) {
        if (flag1 && !flag || j < i) {
            isRightHinge = false;
        }
    } else {
        isRightHinge = true;
    }

    BlockPos blockpos2 = pos.up();
    boolean flag2 = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos2);
    IBlockState iblockstate = door.getDefaultState().withProperty(BlockDoor.FACING, facing).withProperty(BlockDoor.HINGE, isRightHinge ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(BlockDoor.POWERED, Boolean.valueOf(flag2)).withProperty(BlockDoor.OPEN, Boolean.valueOf(flag2));
    worldIn.setBlockState(pos, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.LOWER), 2);
    worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2);
    worldIn.notifyNeighborsOfStateChange(pos, door, false);
    worldIn.notifyNeighborsOfStateChange(blockpos2, door, false);
}
 
源代码2 项目: litematica   文件: SchematicPlacementManager.java
public void setPositionOfCurrentSelectionToRayTrace(Minecraft mc, double maxDistance)
{
    SchematicPlacement schematicPlacement = this.getSelectedSchematicPlacement();

    if (schematicPlacement != null)
    {
        Entity entity = fi.dy.masa.malilib.util.EntityUtils.getCameraEntity();
        RayTraceResult trace = fi.dy.masa.malilib.util.RayTraceUtils.getRayTraceFromEntity(mc.world, entity, RayTraceFluidHandling.NONE, false, maxDistance);

        if (trace.typeOfHit != RayTraceResult.Type.BLOCK)
        {
            return;
        }

        BlockPos pos = trace.getBlockPos();

        // Sneaking puts the position inside the targeted block, not sneaking puts it against the targeted face
        if (mc.player.isSneaking() == false)
        {
            pos = pos.offset(trace.sideHit);
        }

        this.setPositionOfCurrentSelectionTo(pos, mc);
    }
}
 
源代码3 项目: customstuff4   文件: ItemSlab.java
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
{
    BlockPos blockpos = pos;
    int subtype = getMetadata(stack);
    IBlockState clickedState = worldIn.getBlockState(pos);

    if (clickedState.getBlock() == this.singleSlab)
    {
        boolean flag = clickedState.getValue(net.minecraft.block.BlockSlab.HALF) == net.minecraft.block.BlockSlab.EnumBlockHalf.TOP;

        if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && subtype == singleSlabCS.getSubtype(clickedState))
        {
            return true;
        }
    }

    pos = pos.offset(side);
    IBlockState existingState = worldIn.getBlockState(pos);
    return existingState.getBlock() == this.singleSlab && subtype == singleSlabCS.getSubtype(existingState) || super.canPlaceBlockOnSide(worldIn, blockpos, side, player, stack);
}
 
源代码4 项目: BetterChests   文件: CocoaHandler.java
@Override
public boolean canHandlePlant(Collection<ItemStack> items, World world, BlockPos pos, IBlockState state) {
	if (!WorldUtil.isBlockAir(state)) {
		return false;
	}
	boolean found = false;
	for (EnumFacing dir : EnumFacing.HORIZONTALS) {
		BlockPos toCheck = pos.offset(dir);
		IBlockState other = world.getBlockState(toCheck);
		if (other.getBlock() == Blocks.LOG && other.getValue(BlockOldLog.VARIANT) == EnumType.JUNGLE) {
			found = true;
			break;
		}
	}
	return found && items.stream().anyMatch(this::canPlantStack);
}
 
源代码5 项目: multiconnect   文件: ChunkUpgrader.java
private static void doFix(WorldAccess world, BlockPos pos, int flags) {
    BlockState state = world.getBlockState(pos);
    for (Direction dir : Direction.values()) {
        BlockPos otherPos = pos.offset(dir);
        state = applyAdjacentBlock(state, dir, world, pos, otherPos);
    }
    world.setBlockState(pos, state, flags | 16);

    inPlaceFix(world.getChunk(pos), state, pos, new BlockPos.Mutable());
}
 
源代码6 项目: Signals   文件: CapabilityMinecartDestination.java
/**
 * 
 * @param cart
 * @return true if there was a valid hopper (not necessarily if extracted an item)
 */
private boolean extractFuelFromHopper(EntityMinecart cart, BlockPos pos){
    boolean foundHopper = false;
    for(EnumFacing dir : EnumFacing.VALUES) {
        BlockPos neighbor = pos;
        for(int offsetTimes = 0; offsetTimes < (dir == EnumFacing.UP ? 2 : 1); offsetTimes++) {
            neighbor = neighbor.offset(dir);
            TileEntity te = cart.world.getTileEntity(neighbor);
            if(te instanceof TileEntityHopper) {
                EnumFacing hopperDir = cart.world.getBlockState(neighbor).getValue(BlockHopper.FACING);
                if(hopperDir.getOpposite() == dir) {
                    TileEntityHopper hopper = (TileEntityHopper)te;
                    for(int i = 0; i < hopper.getSizeInventory(); i++) {
                        ItemStack stack = hopper.getStackInSlot(i);
                        if(!stack.isEmpty() && getFuelInv().isItemValidForSlot(0, stack)) {
                            ItemStack inserted = stack.copy();
                            inserted.setCount(1);
                            ItemStack left = ItemHandlerHelper.insertItemStacked(getEngineItemHandler(), inserted, false);
                            if(left.isEmpty()) {
                                stack.shrink(1);
                                hopper.markDirty();
                                return true;
                            }
                        }
                    }
                    foundHopper = true;
                }
            }
        }
    }
    return foundHopper;
}
 
源代码7 项目: Sakura_mod   文件: BlockMapleSpile.java
public static boolean canWork(World worldIn, BlockPos pos, IBlockState state) {
   	EnumFacing facing = state.getValue(FACING);
   	BlockPos blockpos = pos.offset(facing.getOpposite());
       IBlockState iblockstate = worldIn.getBlockState(blockpos);
       Block block = iblockstate.getBlock();
       if(block instanceof BlockMapleSapLog&&iblockstate.getValue(BlockMapleSapLog.SAP_AGE).intValue()<5)
       	return true;
	return false;
}
 
源代码8 项目: enderutilities   文件: ItemEnderBucket.java
public EnumActionResult useBucketOnBlock(World world, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
{
    // Adjust the target block position to be the block touching the side of the block we targeted
    pos = pos.offset(side);

    if (this.isTargetUsable(world, pos, side, player, stack) == false)
    {
        return EnumActionResult.PASS;
    }

    // Check if there is a fluid block on the side of the targeted block
    if (world.getBlockState(pos).getMaterial().isLiquid())
    {
        // Note: the side is technically wrong unless we ray trace it again, but it won't matter with fluid blocks... right?
        return this.useBucketOnFluidBlock(world, pos, side, player, stack);
    }

    // There was no fluid block where we are targeting

    // Get the stored fluid, if any
    FluidStack fluidStack = this.getFluid(stack, player);
    int storedFluidAmount = fluidStack != null ? fluidStack.amount : 0;

    // target block is not fluid, try to place a fluid block in world in the adjusted block position
    if (storedFluidAmount >= Fluid.BUCKET_VOLUME && BucketMode.fromStack(stack) != BucketMode.FILL)
    {
        fluidStack = this.drain(stack, Fluid.BUCKET_VOLUME, false, player);

        if (fluidStack != null && fluidStack.amount == Fluid.BUCKET_VOLUME &&
            this.tryPlaceFluidBlock(world, pos, fluidStack))
        {
            this.drain(stack, Fluid.BUCKET_VOLUME, true, player);
            return EnumActionResult.SUCCESS;
        }
    }

    return EnumActionResult.PASS;
}
 
源代码9 项目: enderutilities   文件: ItemBuildersWand.java
@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side,
        float hitX, float hitY, float hitZ, EnumHand hand)
{
    ItemStack stack = player.getHeldItem(hand);
    Mode mode = Mode.getMode(stack);

    if (mode == Mode.REPLACE_3D && player.isSneaking() && WandOption.BIND_MODE.isEnabled(stack, mode))
    {
        if (world.isRemote == false)
        {
            this.setSelectedFixedBlockType(stack, player, world, pos, true);
            return EnumActionResult.SUCCESS;
        }

        return EnumActionResult.PASS;
    }
    else if (mode.hasTwoPlacableCorners())
    {
        if (world.isRemote == false)
        {
            BlockPosEU posEU = new BlockPosEU(player.isSneaking() ? pos : pos.offset(side), world.provider.getDimension(), side);
            this.setPosition(posEU, POS_END, stack, player);
            return EnumActionResult.SUCCESS;
        }

        return EnumActionResult.SUCCESS;
    }

    return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
 
源代码10 项目: GregTech   文件: MetaTileEntityPump.java
private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) {
    IBlockState blockHere = getWorld().getBlockState(checkPos);
    boolean shouldCheckNeighbours = isStraightInPumpRange(checkPos);

    if (blockHere.getBlock() instanceof BlockLiquid ||
        blockHere.getBlock() instanceof IFluidBlock) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), checkPos, null);
        FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
        if (drainStack != null && drainStack.amount > 0) {
            this.fluidSourceBlocks.add(checkPos);
        }
        shouldCheckNeighbours = true;
    }

    if (shouldCheckNeighbours) {
        int maxPumpRange = getMaxPumpRange();
        for (EnumFacing facing : EnumFacing.VALUES) {
            BlockPos offsetPos = checkPos.offset(facing);
            if (offsetPos.distanceSq(pumpHeadPos) > maxPumpRange * maxPumpRange)
                continue; //do not add blocks outside bounds
            if (!fluidSourceBlocks.contains(offsetPos) &&
                !blocksToCheck.contains(offsetPos)) {
                this.blocksToCheck.add(offsetPos);
            }
        }
    }
}
 
源代码11 项目: enderutilities   文件: PortalFormer.java
private boolean walkFrameLoop(BlockPos pos, EnumFacing.Axis axis, EnumFacing frameSide, int distanceLimit)
{
    int counter = 0;
    int turns = 0;
    int tries = 0;
    IBlockState state;
    Block block;
    BlockPos startPos = pos;
    BlockPos posLast = startPos;
    EnumFacing firstTrySide = frameSide;
    EnumFacing moveDirection = frameSide;

    while (counter < distanceLimit)
    {
        moveDirection = firstTrySide;

        for (tries = 0; tries < 4; tries++)
        {
            pos = posLast.offset(moveDirection);
            state = this.world.getBlockState(pos);
            block = state.getBlock();

            if (block.isAir(state, this.world, pos))
            {
                posLast = pos;

                // The firstTrySide is facing into the adjacent portal frame when traveling
                // along a straight frame. Thus we need to rotate it once to keep going straight.
                // If we need to rotate it more than once, then we have hit a "right hand corner".
                if (tries > 1)
                {
                    turns++;
                }
                // If we didn't have to rotate the firstTrySide at all, then we hit a "left hand turn"
                // ie. traveled through an outer bend.
                else if (tries == 0)
                {
                    turns--;
                }

                // Set the firstTrySide one rotation back from the side that we successfully moved to
                // so that we can go around possible outer bends.
                firstTrySide = moveDirection.rotateAround(axis).getOpposite();

                break;
            }
            // Found a portal frame block, try the next adjacent side...
            else if (block == this.blockFrame)
            {
                moveDirection = moveDirection.rotateAround(axis);
            }
            // Found a non-air, non-portal-frame block -> invalid area.
            else
            {
                return false;
            }
        }

        // If we can return to the starting position hugging the portal frame,
        // then this is a valid portal frame loop.
        // Note that it is only valid if it forms an inside area, thus the turns check.
        // the tries == 4 && counter == 0 check is for a 1x1 area special case
        if ((tries == 4 && counter == 0) || pos.equals(startPos))
        {
            return turns >= 0;
        }

        counter++;
    }

    return false;
}
 
源代码12 项目: litematica   文件: BlockModelRendererSchematic.java
private void renderQuadsFlat(IBlockAccess blockAccessIn, IBlockState stateIn, BlockPos posIn, int brightnessIn, boolean ownBrightness, BufferBuilder buffer, List<BakedQuad> list, BitSet bitSet)
{
    Vec3d vec3d = stateIn.getOffset(blockAccessIn, posIn);
    double d0 = (double)posIn.getX() + vec3d.x;
    double d1 = (double)posIn.getY() + vec3d.y;
    double d2 = (double)posIn.getZ() + vec3d.z;
    int i = 0;

    for (int j = list.size(); i < j; ++i)
    {
        BakedQuad bakedquad = list.get(i);

        if (ownBrightness)
        {
            this.fillQuadBounds(stateIn, bakedquad.getVertexData(), bakedquad.getFace(), (float[])null, bitSet);
            BlockPos blockpos = bitSet.get(0) ? posIn.offset(bakedquad.getFace()) : posIn;
            brightnessIn = stateIn.getPackedLightmapCoords(blockAccessIn, blockpos);
        }

        buffer.addVertexData(bakedquad.getVertexData());
        buffer.putBrightness4(brightnessIn, brightnessIn, brightnessIn, brightnessIn);

        if (bakedquad.hasTintIndex())
        {
            int k = this.blockColors.colorMultiplier(stateIn, blockAccessIn, posIn, bakedquad.getTintIndex());

            if (EntityRenderer.anaglyphEnable)
            {
                k = TextureUtil.anaglyphColor(k);
            }

            float f = (float)(k >> 16 & 255) / 255.0F;
            float f1 = (float)(k >> 8 & 255) / 255.0F;
            float f2 = (float)(k & 255) / 255.0F;
            buffer.putColorMultiplier(f, f1, f2, 4);
            buffer.putColorMultiplier(f, f1, f2, 3);
            buffer.putColorMultiplier(f, f1, f2, 2);
            buffer.putColorMultiplier(f, f1, f2, 1);
        }

        buffer.putPosition(d0, d1, d2);
    }
}
 
源代码13 项目: TofuCraftReload   文件: BlockTofuPortal.java
protected int getDistanceUntilEdge(BlockPos p_180120_1_, EnumFacing p_180120_2_) {

            int i;


            for (i = 0; i < 22; ++i) {

                BlockPos blockpos = p_180120_1_.offset(p_180120_2_, i);


                if (!this.isEmptyBlock(this.world.getBlockState(blockpos)) ||

                        this.world.getBlockState(blockpos.down()).getBlock() != BlockLoader.GRILD) {

                    break;

                }

            }


            Block block = this.world.getBlockState(p_180120_1_.offset(p_180120_2_, i)).getBlock();

            return block == BlockLoader.GRILD ? i : 0;

        }
 
源代码14 项目: BetterChests   文件: UpgradePlacer.java
@Override
public void update(IUpgradableBlock chest, ItemStack stack) {
	if (getTickTime(chest, stack) != 0 || !hasUpgradeOperationCost(chest)) {
		return;
	}

	IBetterChest inv = (IBetterChest) chest;

	IFilter filter = ((IBetterChest) chest).getFilterFor(stack);

	int slot = InvUtil.findInInvInternal(inv, null, filter::matchesStack);

	ItemStack targetItem;
	if (slot != -1) {
		targetItem = inv.getStackInSlot(slot);
	} else if (!filter.hasStackFilter()) {
		targetItem = ItemStack.EMPTY;
	} else {
		return;
	}

	EntityPlayerMP player = chest.getFakePlayer();
	if (player == null) {
		return;
	}

	EnumFacing side = getCurrentSide(stack, chest);
	BlockPos targetPos = chest.getPosition().offset(side);

	if (WorldUtil.isBlockAir(chest.getWorldObj(), targetPos)) {
		BlockPos nextPos = targetPos.offset(side);
		if (!WorldUtil.isBlockAir(chest.getWorldObj(), nextPos)) {
			targetPos = nextPos;
		}
	}

	player.inventory.clear();
	player.setHeldItem(EnumHand.MAIN_HAND, targetItem);
	player.rotationPitch = (float) -Math.toDegrees(Math.asin(side.getFrontOffsetY()));
	player.rotationYaw = side.getHorizontalAngle();

	Vec3d playerTargetPos = player.getPositionVector().add(player.getLookVec().normalize());
	player.setPosition(playerTargetPos.x, playerTargetPos.y, playerTargetPos.z);

	if (placeBlock(player, targetPos, side)) {
		drawUpgradeOperationCode(chest);
	}
	if (slot != -1) {
		inv.setInventorySlotContents(slot, player.getHeldItem(EnumHand.MAIN_HAND));
		player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY);
		for (ItemStack current : InvUtil.getFromInv(player.inventory)) {
			current.setCount(InvUtil.putStackInInventoryInternal(current, inv, false).getCount());
		}
		player.inventory.dropAllItems();
	}
}
 
源代码15 项目: enderutilities   文件: ItemBuildersWand.java
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos,
        EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ)
{
    ItemStack stack = player.getHeldItem(hand);
    TileEntity te = world.getTileEntity(pos);

    if (te != null && (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, side) || te.getClass() == TileEntityEnderChest.class))
    {
        return super.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ);
    }

    Mode mode = Mode.getMode(stack);

    if (mode.hasTwoPlacableCorners())
    {
        if (world.isRemote == false)
        {
            if (mode == Mode.REPLACE_3D && player.isSneaking() && WandOption.BIND_MODE.isEnabled(stack, mode))
            {
                this.setSelectedFixedBlockType(stack, player, world, pos, true);
            }
            else
            {
                BlockPosEU posEU = new BlockPosEU(player.isSneaking() ? pos : pos.offset(side), world.provider.getDimension(), side);
                this.setPosition(posEU, POS_END, stack, player);
            }
        }

        return EnumActionResult.SUCCESS;
    }

    // Don't allow targeting the top face of blocks while sneaking
    // This should make sneak building a platform a lot less annoying
    if (world.isRemote == false && (player.isSneaking() == false || side != EnumFacing.UP || mode == Mode.REPLACE))
    {
        // Don't offset the position in Replace mode
        if (mode != Mode.REPLACE)
        {
            pos = pos.offset(side);
        }

        return this.useWand(stack, world, player, new BlockPosEU(pos, world.provider.getDimension(), side));
    }

    return EnumActionResult.SUCCESS;
}
 
源代码16 项目: Wizardry   文件: ModuleEffectFrost.java
@Override
public boolean run(@NotNull World world, ModuleInstanceEffect instance, @Nonnull SpellData spell, @Nonnull SpellRing spellRing) {
	Entity targetEntity = spell.getVictim(world);
	BlockPos targetPos = spell.getTargetPos();
	Entity caster = spell.getCaster(world);

	double range = spellRing.getAttributeValue(world, AttributeRegistry.AREA, spell) / 2;
	double time = spellRing.getAttributeValue(world, AttributeRegistry.DURATION, spell) * 10;

	if (!spellRing.taxCaster(world, spell, true)) return false;

	if (targetEntity != null) {
		world.playSound(null, targetEntity.getPosition(), ModSounds.FROST_FORM, SoundCategory.NEUTRAL, 1, 1);
		targetEntity.extinguish();
		if (targetEntity instanceof EntityLivingBase) {
			((EntityLivingBase) targetEntity).addPotionEffect(new PotionEffect(ModPotions.SLIPPERY, (int) time, 0, true, false));
		}
	}

	if (targetPos != null) {
		world.playSound(null, targetPos, ModSounds.FROST_FORM, SoundCategory.NEUTRAL, 1, 1);
		for (BlockPos pos : BlockPos.getAllInBox(targetPos.add(-range, -range, -range), targetPos.add(range + 1, range + 1, range + 1))) {
			double dist = pos.distanceSq(targetPos);
			if (dist > range) continue;

			for (EnumFacing facing : EnumFacing.VALUES) {
				IBlockState state = world.getBlockState(pos.offset(facing));
				if (state.getBlock() == Blocks.FIRE) {
					BlockUtils.breakBlock(world, pos.offset(facing), state, BlockUtils.makeBreaker(world, pos, caster));
				}
			}

			BlockPos up = pos.offset(EnumFacing.UP);
			if (world.getBlockState(pos).isSideSolid(world, pos, EnumFacing.UP) && world.isAirBlock(up)) {
				int layerSize = (int) (Math.max(1, Math.min(8, Math.max(1, (dist / range) * 6.0))));
				layerSize = Math.max(1, Math.min(layerSize + RandUtil.nextInt(-1, 1), 8));
				BlockUtils.placeBlock(world, up, Blocks.SNOW_LAYER.getDefaultState().withProperty(BlockSnow.LAYERS, layerSize), BlockUtils.makePlacer(world, up, caster));
			}

			if (world.getBlockState(pos).getBlock() == Blocks.WATER) {
				BlockUtils.placeBlock(world, pos, Blocks.ICE.getDefaultState(), BlockUtils.makePlacer(world, pos, caster));
			}
		}
	}
	return true;
}
 
源代码17 项目: customstuff4   文件: BlockWall.java
private boolean canWallConnectTo(IBlockAccess world, BlockPos pos, EnumFacing facing)
{
    BlockPos other = pos.offset(facing);
    Block block = world.getBlockState(other).getBlock();
    return block.canBeConnectedTo(world, other, facing.getOpposite()) || canConnectTo(world, other, facing.getOpposite());
}
 
源代码18 项目: enderutilities   文件: ItemDolly.java
private boolean tryPlaceDownBlock(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side)
{
    pos = pos.offset(side);

    if (this.isCarryingBlock(stack) == false || world.isBlockModifiable(player, pos) == false)
    {
        return false;
    }

    NBTTagCompound tagCarrying = NBTUtils.getCompoundTag(stack, "Carrying", false);
    String name = tagCarrying.getString("Block");
    int meta = tagCarrying.getByte("Meta");
    Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(name));

    try
    {
        if (block != null && block != Blocks.AIR && world.mayPlace(block, pos, false, side, player))
        {
            @SuppressWarnings("deprecation")
            IBlockState state = block.getStateFromMeta(meta);
            EnumFacing pickupFacing = EnumFacing.byIndex(tagCarrying.getByte("PickupFacing"));
            EnumFacing currentFacing = EntityUtils.getHorizontalLookingDirection(player);
            Rotation rotation = PositionUtils.getRotation(pickupFacing, currentFacing);
            state = state.withRotation(rotation);

            if (world.setBlockState(pos, state))
            {
                TileEntity te = world.getTileEntity(pos);

                if (te != null && tagCarrying.hasKey("te", Constants.NBT.TAG_COMPOUND))
                {
                    NBTTagCompound nbt = tagCarrying.getCompoundTag("te");
                    TileUtils.createAndAddTileEntity(world, pos, nbt, rotation, Mirror.NONE);
                }

                NBTUtils.removeCompoundTag(stack, null, "Carrying");
                return true;
            }
        }
    }
    catch (Exception e)
    {
        EnderUtilities.logger.warn("Failed to place down a block from the Dolly", e);
    }

    return false;
}
 
源代码19 项目: AdvancedRocketry   文件: BlockPress.java
private boolean doMove(World worldIn, BlockPos pos, EnumFacing direction, boolean extending)
{
	if (!extending)
	{
		worldIn.setBlockToAir(pos.offset(direction));
	}

	BlockPistonStructureHelper blockpistonstructurehelper = new BlockPistonStructureHelper(worldIn, pos, direction, extending);

	if (!blockpistonstructurehelper.canMove())
	{
		return false;
	}
	else
	{
		List<BlockPos> list = blockpistonstructurehelper.getBlocksToMove();
		List<IBlockState> list1 = Lists.<IBlockState>newArrayList();

		for (int i = 0; i < list.size(); ++i)
		{
			BlockPos blockpos = (BlockPos)list.get(i);
			list1.add(worldIn.getBlockState(blockpos).getActualState(worldIn, blockpos));
		}

		List<BlockPos> list2 = blockpistonstructurehelper.getBlocksToDestroy();
		int k = list.size() + list2.size();
		IBlockState[] aiblockstate = new IBlockState[k];
		EnumFacing enumfacing = extending ? direction : direction.getOpposite();

		for (int j = list2.size() - 1; j >= 0; --j)
		{
			BlockPos blockpos1 = (BlockPos)list2.get(j);
			IBlockState iblockstate = worldIn.getBlockState(blockpos1);
			// Forge: With our change to how snowballs are dropped this needs to disallow to mimic vanilla behavior.
			float chance = iblockstate.getBlock() instanceof BlockSnow ? -1.0f : 1.0f;
			iblockstate.getBlock().dropBlockAsItemWithChance(worldIn, blockpos1, iblockstate, chance, 0);
			worldIn.setBlockToAir(blockpos1);
			--k;
			aiblockstate[k] = iblockstate;
		}

		for (int l = list.size() - 1; l >= 0; --l)
		{
			BlockPos blockpos3 = (BlockPos)list.get(l);
			IBlockState iblockstate2 = worldIn.getBlockState(blockpos3);
			worldIn.setBlockState(blockpos3, Blocks.AIR.getDefaultState(), 2);
			blockpos3 = blockpos3.offset(enumfacing);
			worldIn.setBlockState(blockpos3, Blocks.PISTON_EXTENSION.getDefaultState().withProperty(FACING, direction), 4);
			worldIn.setTileEntity(blockpos3, BlockPistonMoving.createTilePiston((IBlockState)list1.get(l), direction, extending, false));
			--k;
			aiblockstate[k] = iblockstate2;
		}

		BlockPos blockpos2 = pos.offset(direction);

		if (extending)
		{
			BlockPistonExtension.EnumPistonType blockpistonextension$enumpistontype = BlockPistonExtension.EnumPistonType.DEFAULT;
			IBlockState iblockstate3 = Blocks.PISTON_HEAD.getDefaultState().withProperty(BlockPistonExtension.FACING, direction).withProperty(BlockPistonExtension.TYPE, blockpistonextension$enumpistontype);
			IBlockState iblockstate1 = Blocks.PISTON_EXTENSION.getDefaultState().withProperty(BlockPistonMoving.FACING, direction).withProperty(BlockPistonMoving.TYPE, BlockPistonExtension.EnumPistonType.DEFAULT);
			worldIn.setBlockState(blockpos2, iblockstate1, 4);
			worldIn.setTileEntity(blockpos2, BlockPistonMoving.createTilePiston(iblockstate3, direction, true, false));
		}

		for (int i1 = list2.size() - 1; i1 >= 0; --i1)
		{
			worldIn.notifyNeighborsOfStateChange((BlockPos)list2.get(i1), aiblockstate[k++].getBlock(), true);
		}

		for (int j1 = list.size() - 1; j1 >= 0; --j1)
		{
			worldIn.notifyNeighborsOfStateChange((BlockPos)list.get(j1), aiblockstate[k++].getBlock(), true);
		}

		if (extending)
		{
			worldIn.notifyNeighborsOfStateChange(blockpos2, Blocks.PISTON_HEAD, true);
			worldIn.notifyNeighborsOfStateChange(pos, this, true);
		}

		return true;
	}
}
 
源代码20 项目: TofuCraftReload   文件: BlockTofuPortal.java
public Size(World worldIn, BlockPos p_i45694_2_, EnumFacing.Axis p_i45694_3_) {

            this.world = worldIn;

            this.axis = p_i45694_3_;


            if (p_i45694_3_ == EnumFacing.Axis.X) {

                this.leftDir = EnumFacing.EAST;

                this.rightDir = EnumFacing.WEST;

            } else {

                this.leftDir = EnumFacing.NORTH;

                this.rightDir = EnumFacing.SOUTH;

            }


            for (BlockPos blockpos = p_i45694_2_; p_i45694_2_.getY() > blockpos.getY() - 21 && p_i45694_2_.getY() > 0 &&

                    this.isEmptyBlock(worldIn.getBlockState(p_i45694_2_.down())); p_i45694_2_ = p_i45694_2_.down()) {

            }


            int i = this.getDistanceUntilEdge(p_i45694_2_, this.leftDir) - 1;


            if (i >= 0) {

                this.bottomLeft = p_i45694_2_.offset(this.leftDir, i);

                this.width = this.getDistanceUntilEdge(this.bottomLeft, this.rightDir);


                if (this.width < 2 || this.width > 21) {

                    this.bottomLeft = null;

                    this.width = 0;

                }

            }


            if (this.bottomLeft != null) {

                this.height = this.calculatePortalHeight();

            }

        }