當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockPos.offset方法代碼示例

本文整理匯總了Java中net.minecraft.util.math.BlockPos.offset方法的典型用法代碼示例。如果您正苦於以下問題:Java BlockPos.offset方法的具體用法?Java BlockPos.offset怎麽用?Java BlockPos.offset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.util.math.BlockPos的用法示例。


在下文中一共展示了BlockPos.offset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: canPlaceBlockOnSide

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
{
    Block block = worldIn.getBlockState(pos).getBlock();

    if (block == Blocks.SNOW_LAYER && block.isReplaceable(worldIn, pos))
    {
        side = EnumFacing.UP;
    }
    else if (!block.isReplaceable(worldIn, pos))
    {
        pos = pos.offset(side);
    }

    return worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:17,代碼來源:ItemBlock.java

示例2: onItemUse

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	ItemStack stack = playerIn.getHeldItem(hand);
	if (!worldIn.isRemote && stack.hasTagCompound() && stack.getTagCompound().hasKey("Statue")) {
		EntityStatue statue =new EntityStatue(worldIn);
		statue.readEntityFromNBT(stack.getTagCompound().getCompoundTag("Statue"));
		BlockPos off = pos.offset(facing);
		statue.setPosition(off.getX()+0.5, off.getY(), off.getZ()+0.5);
		statue.rotationYaw = playerIn.rotationYawHead;
		statue.renderYawOffset = playerIn.rotationYawHead;

		statue.ticksLeft = -1;
		worldIn.spawnEntity(statue);
		if (!playerIn.capabilities.isCreativeMode)
			stack.shrink(1);
		return EnumActionResult.SUCCESS;
	}
	return EnumActionResult.SUCCESS;
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:21,代碼來源:ItemStatue.java

示例3: transformSourceBlock

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
protected void transformSourceBlock(Block turningBlockSource, Block turningBlockFlowing) {
    if (FluidUtils.isSourceBlock(getWorld(), getPos())) {
        getWorld().setBlockState(getPos(), turningBlockSource.getDefaultState());
    } else {
        Set<BlockPos> traversed = new HashSet<BlockPos>();
        Stack<BlockPos> pending = new Stack<BlockPos>();
        pending.push(getPos());
        traversed.add(getPos());
        while (!pending.isEmpty()) {
            BlockPos pos = pending.pop();
            for (EnumFacing d : EnumFacing.VALUES) {
                BlockPos newPos = pos.offset(d);
                Block checkingBlock = getWorld().getBlockState(newPos).getBlock();
                if ((checkingBlock == getBlockState().getBlock() || getBlockState().getBlock() == Blocks.FLOWING_WATER && checkingBlock == Blocks.WATER || getBlockState().getBlock() == Blocks.FLOWING_LAVA && checkingBlock == Blocks.LAVA) && traversed.add(newPos)) {
                    if (FluidUtils.isSourceBlock(getWorld(), newPos)) {
                        getWorld().setBlockState(newPos, turningBlockSource.getDefaultState());
                        onTransition(newPos);
                        return;
                    } else {
                        getWorld().setBlockState(newPos, turningBlockFlowing.getDefaultState());
                        onTransition(newPos);
                        pending.push(newPos);
                    }
                }
            }
        }
    }
}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:29,代碼來源:HeatBehaviourLiquidTransition.java

示例4: getBlockToDig

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
private BlockPos getBlockToDig(BlockPos p, EnumFacing facing, int blockidx) {
    switch (blockidx) {
        case 0:
            return p.up(1).offset(facing.rotateY());
        case 1:
            return p.up(1);
        case 2:
            return p.up(1).offset(facing.rotateYCCW());
        case 3:
            return p.offset(facing.rotateY());
        case 4:
            return p;
        case 5:
            return p.offset(facing.rotateYCCW());
        case 6:
            return p.down(1).offset(facing.rotateYCCW());
        case 7:
            return p.down(1);
        case 8:
            return p.down(1).offset(facing.rotateY());
        case 9:
            return p.up(2).offset(facing.rotateY());
        case 10:
            return p.up(2);
        case 11:
            return p.up(2).offset(facing.rotateYCCW());
        case 12:
            return p.up(3).offset(facing.rotateY());
        case 13:
            return p.up(3);
        case 14:
            return p.up(3).offset(facing.rotateYCCW());
    }
    return p;
}
 
開發者ID:McJty,項目名稱:MeeCreeps,代碼行數:36,代碼來源:DigdownStairsActionWorker.java

示例5: onItemUse

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        int startY = pos.getY();
        while (pos.getY() > 0) {
            pos = pos.offset(EnumFacing.DOWN);
            if (world.getBlockState(pos).getBlock() == FluidRegistry.getFluid(Fluids.OIL.getName()).getBlock()) {
                Set<BlockPos> oilPositions = new HashSet<>();
                Stack<BlockPos> pendingPositions = new Stack<>();
                pendingPositions.add(new BlockPos(pos));
                while (!pendingPositions.empty()) {
                    BlockPos checkingPos = pendingPositions.pop();
                    for (EnumFacing d : EnumFacing.VALUES) {
                        BlockPos newPos = checkingPos.offset(d);
                        if (world.getBlockState(newPos).getBlock() == Fluids.OIL.getBlock() && FluidUtils.isSourceBlock(world, newPos) && oilPositions.add(newPos)) {
                            pendingPositions.add(newPos);
                        }
                    }
                }
                player.sendStatusMessage(new TextComponentTranslation(
                        "message.seismicSensor.foundOilDetails",
                        TextFormatting.GREEN.toString() + (startY - pos.getY()),
                        TextFormatting.GREEN.toString() + oilPositions.size() / 10 * 10),
                        false);
                return EnumActionResult.SUCCESS;
            }
        }
        player.sendStatusMessage(new TextComponentTranslation("message.seismicSensor.noOilFound"), false);
    }
    return EnumActionResult.SUCCESS; // we don't want to use the item.

}
 
開發者ID:TeamPneumatic,項目名稱:pnc-repressurized,代碼行數:33,代碼來源:ItemSeismicSensor.java

示例6: placeDoor

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
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);
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:30,代碼來源:ItemDoor.java

示例7: slightlyMelt

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
protected void slightlyMelt(World p_185681_1_, BlockPos p_185681_2_, IBlockState p_185681_3_, Random p_185681_4_, boolean p_185681_5_)
{
    int i = ((Integer)p_185681_3_.getValue(AGE)).intValue();

    if (i < 3)
    {
        p_185681_1_.setBlockState(p_185681_2_, p_185681_3_.withProperty(AGE, Integer.valueOf(i + 1)), 2);
        p_185681_1_.scheduleUpdate(p_185681_2_, this, MathHelper.getRandomIntegerInRange(p_185681_4_, 20, 40));
    }
    else
    {
        this.turnIntoWater(p_185681_1_, p_185681_2_);

        if (p_185681_5_)
        {
            for (EnumFacing enumfacing : EnumFacing.values())
            {
                BlockPos blockpos = p_185681_2_.offset(enumfacing);
                IBlockState iblockstate = p_185681_1_.getBlockState(blockpos);

                if (iblockstate.getBlock() == this)
                {
                    this.slightlyMelt(p_185681_1_, blockpos, iblockstate, p_185681_4_, false);
                }
            }
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:29,代碼來源:BlockFrostedIce.java

示例8: calculateInputStrength

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
protected int calculateInputStrength(World worldIn, BlockPos pos, IBlockState state)
{
    int i = super.calculateInputStrength(worldIn, pos, state);
    EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
    BlockPos blockpos = pos.offset(enumfacing);
    IBlockState iblockstate = worldIn.getBlockState(blockpos);

    if (iblockstate.hasComparatorInputOverride())
    {
        i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
    }
    else if (i < 15 && iblockstate.isNormalCube())
    {
        blockpos = blockpos.offset(enumfacing);
        iblockstate = worldIn.getBlockState(blockpos);

        if (iblockstate.hasComparatorInputOverride())
        {
            i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
        }
        else if (iblockstate.getMaterial() == Material.AIR)
        {
            EntityItemFrame entityitemframe = this.findItemFrame(worldIn, enumfacing, blockpos);

            if (entityitemframe != null)
            {
                i = entityitemframe.getAnalogOutput();
            }
        }
    }

    return i;
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:34,代碼來源:BlockRedstoneComparator.java

示例9: onItemUse

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();

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

    if (stack.stackSize != 0 && playerIn.canPlayerEdit(pos, facing, stack) && worldIn.canBlockBePlaced(this.block, pos, false, facing, (Entity)null, stack))
    {
        int i = this.getMetadata(stack.getMetadata());
        IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, playerIn, stack);

        if (placeBlockAt(stack, playerIn, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1))
        {
            SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, playerIn);
            worldIn.playSound(playerIn, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            --stack.stackSize;
        }

        return EnumActionResult.SUCCESS;
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:33,代碼來源:ItemBlock.java

示例10: slightlyMelt

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
protected void slightlyMelt(World p_185681_1_, BlockPos p_185681_2_, IBlockState p_185681_3_, Random p_185681_4_, boolean p_185681_5_)
{
    int i = ((Integer)p_185681_3_.getValue(AGE)).intValue();

    if (i < 3)
    {
        p_185681_1_.setBlockState(p_185681_2_, p_185681_3_.withProperty(AGE, Integer.valueOf(i + 1)), 2);
        p_185681_1_.scheduleUpdate(p_185681_2_, this, MathHelper.getInt(p_185681_4_, 20, 40));
    }
    else
    {
        this.turnIntoWater(p_185681_1_, p_185681_2_);

        if (p_185681_5_)
        {
            for (EnumFacing enumfacing : EnumFacing.values())
            {
                BlockPos blockpos = p_185681_2_.offset(enumfacing);
                IBlockState iblockstate = p_185681_1_.getBlockState(blockpos);

                if (iblockstate.getBlock() == this)
                {
                    this.slightlyMelt(p_185681_1_, blockpos, iblockstate, p_185681_4_, false);
                }
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:29,代碼來源:BlockFrostedIce.java

示例11: canPlaceAt

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
private boolean canPlaceAt(World worldIn, BlockPos pos, EnumFacing facing)
{
    BlockPos blockpos = pos.offset(facing.getOpposite());
    boolean flag = facing.getAxis().isHorizontal();
    return flag && worldIn.isSideSolid(blockpos, facing, true) || facing.equals(EnumFacing.UP) && this.canPlaceOn(worldIn, blockpos);
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:7,代碼來源:BlockTorch.java

示例12: absorb

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
private boolean absorb(World worldIn, BlockPos pos)
{
    Queue<Tuple<BlockPos, Integer>> queue = Lists.<Tuple<BlockPos, Integer>>newLinkedList();
    List<BlockPos> list = Lists.<BlockPos>newArrayList();
    queue.add(new Tuple(pos, Integer.valueOf(0)));
    int i = 0;

    while (!((Queue)queue).isEmpty())
    {
        Tuple<BlockPos, Integer> tuple = (Tuple)queue.poll();
        BlockPos blockpos = (BlockPos)tuple.getFirst();
        int j = ((Integer)tuple.getSecond()).intValue();

        for (EnumFacing enumfacing : EnumFacing.values())
        {
            BlockPos blockpos1 = blockpos.offset(enumfacing);

            if (worldIn.getBlockState(blockpos1).getMaterial() == Material.WATER)
            {
                worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 2);
                list.add(blockpos1);
                ++i;

                if (j < 6)
                {
                    queue.add(new Tuple(blockpos1, Integer.valueOf(j + 1)));
                }
            }
        }

        if (i > 64)
        {
            break;
        }
    }

    for (BlockPos blockpos2 : list)
    {
        worldIn.notifyNeighborsOfStateChange(blockpos2, Blocks.AIR, false);
    }

    return i > 0;
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:44,代碼來源:BlockSponge.java

示例13: getMasterPos

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
/**
 * Tries to search for the position of the given fake block's master block.
 * 
 * @param world - The {@link net.minecraft.world.World World} object the block is in.
 * @param thisPos - The block's {@link net.minecraft.util.math.BlockPos position}.
 * @return The master block's position, or {@code null} if none was found.
 */
public static BlockPos getMasterPos(World world, final BlockPos thisPos) {

	List<BlockPos> testedBlocks = new ArrayList<BlockPos>();
	List<BlockPos> blocksToTest = new ArrayList<BlockPos>();
	testedBlocks.add(thisPos);
	blocksToTest.add(thisPos);

	/* Run while the list isn't empty. */
	while (!blocksToTest.isEmpty()) {

		BlockPos testingPos = blocksToTest.get(0);
		for (EnumFacing searchOffset : EnumFacing.VALUES) {

			if (testedBlocks.contains(testingPos.offset(searchOffset))) {
				/* Block already tested from another block. Don't test it again. */
				continue;
			}
			else if (testingPos.offset(searchOffset).distanceSq(thisPos) > 150*150) {
				/* Block is too far to possibly be the master TE for this block. */
				continue;
			}

			if (world.getTileEntity(testingPos.offset(searchOffset)) instanceof TileEntityTrack) {

				/* Found a track TE. See if it's the parent for this fake track block. */
				TileEntity tile = world.getTileEntity(testingPos.offset(searchOffset));
				if (tile instanceof TileEntityTrack &&
						((TileEntityTrack) tile).getFakeTracks().contains(thisPos)) {

					return testingPos.offset(searchOffset);
				}
			}
			else if (world.getBlockState(testingPos.offset(searchOffset)).getBlock().equals(OFTRegistry.trackStructureFake)) {

				/* Found another fake track. Check to see if this has been tested and add to lists if not so. */
				if (!testedBlocks.contains(testingPos.offset(searchOffset))) {
					/* First make sure block hasn't been tested already. */
					if (!blocksToTest.contains(testingPos.offset(searchOffset))) {
						/* If the blocks to test from don't contain this block, add it now. */
						blocksToTest.add(testingPos.offset(searchOffset));
					}
				}
			}
		}

		/* End of the facing loop for this block. Set block as tested and remove from the toTestFrom list. */
		blocksToTest.remove(testingPos);
		testedBlocks.add(testingPos);
	}

	return null;
}
 
開發者ID:DonBruce64,項目名稱:OpenFlexiTrack,代碼行數:60,代碼來源:BlockTrackFake.java

示例14: canPlaceAt

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
private boolean canPlaceAt(World worldIn, BlockPos pos, EnumFacing facing)
{
    BlockPos blockpos = pos.offset(facing.getOpposite());
    boolean flag = facing.getAxis().isHorizontal();
    return flag && worldIn.isBlockNormalCube(blockpos, true) || facing.equals(EnumFacing.UP) && this.canPlaceOn(worldIn, blockpos);
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:7,代碼來源:BlockTorch.java

示例15: onItemUse

import net.minecraft.util.math.BlockPos; //導入方法依賴的package包/類
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    if (worldIn.isRemote)
    {
        return EnumActionResult.SUCCESS;
    }
    else if (!playerIn.canPlayerEdit(pos.offset(facing), facing, stack))
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);

        if (iblockstate.getBlock() == Blocks.MOB_SPAWNER)
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityMobSpawner)
            {
                MobSpawnerBaseLogic mobspawnerbaselogic = ((TileEntityMobSpawner)tileentity).getSpawnerBaseLogic();
                mobspawnerbaselogic.setEntityName(getEntityIdFromItem(stack));
                tileentity.markDirty();
                worldIn.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);

                if (!playerIn.capabilities.isCreativeMode)
                {
                    --stack.stackSize;
                }

                return EnumActionResult.SUCCESS;
            }
        }

        pos = pos.offset(facing);
        double d0 = 0.0D;

        if (facing == EnumFacing.UP && iblockstate.getBlock() instanceof BlockFence) //Forge: Fix Vanilla bug comparing state instead of block
        {
            d0 = 0.5D;
        }

        Entity entity = spawnCreature(worldIn, getEntityIdFromItem(stack), (double)pos.getX() + 0.5D, (double)pos.getY() + d0, (double)pos.getZ() + 0.5D);

        if (entity != null)
        {
            if (entity instanceof EntityLivingBase && stack.hasDisplayName())
            {
                entity.setCustomNameTag(stack.getDisplayName());
            }

            applyItemEntityDataToEntity(worldIn, playerIn, stack, entity);

            if (!playerIn.capabilities.isCreativeMode)
            {
                --stack.stackSize;
            }
        }

        return EnumActionResult.SUCCESS;
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:66,代碼來源:ItemMonsterPlacer.java


注:本文中的net.minecraft.util.math.BlockPos.offset方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。