当前位置: 首页>>代码示例>>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;未经允许,请勿转载。