当前位置: 首页>>代码示例>>Java>>正文


Java Block.isReplaceable方法代码示例

本文整理汇总了Java中net.minecraft.block.Block.isReplaceable方法的典型用法代码示例。如果您正苦于以下问题:Java Block.isReplaceable方法的具体用法?Java Block.isReplaceable怎么用?Java Block.isReplaceable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.block.Block的用法示例。


在下文中一共展示了Block.isReplaceable方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
@Nonnull
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();
    Block cake = Block.REGISTRY.getObject(new ResourceLocation(FoodCraftReloaded.MODID, NameBuilder.buildRegistryName(fruitType.toString(), "cake")));

    if (block == Blocks.SNOW_LAYER && iblockstate.getValue(BlockSnow.LAYERS) < 1)
        facing = EnumFacing.UP;
    else if (!block.isReplaceable(worldIn, pos))
        pos = pos.offset(facing);

    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(cake, pos, false, facing, null)) {
        IBlockState blockState = cake.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, 0, player, hand);

        if (!worldIn.setBlockState(pos, blockState, 11))
            return EnumActionResult.FAIL;
        else {
            blockState = worldIn.getBlockState(pos);

            if (blockState.getBlock() == cake) {
                ItemBlock.setTileEntityNBT(worldIn, player, pos, itemstack);
                blockState.getBlock().onBlockPlacedBy(worldIn, pos, blockState, player, itemstack);
            }

            SoundType soundtype = blockState.getBlock().getSoundType(blockState, 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;
}
 
开发者ID:LasmGratel,项目名称:FoodCraft-Reloaded,代码行数:36,代码来源:ItemFruitCake.java

示例2: onItemUse

import net.minecraft.block.Block; //导入方法依赖的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 (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);
        }

        if (playerIn.canPlayerEdit(pos, facing, stack) && this.block.canPlaceBlockAt(worldIn, pos))
        {
            EnumFacing enumfacing = EnumFacing.fromAngle((double)playerIn.rotationYaw);
            int i = enumfacing.getFrontOffsetX();
            int j = enumfacing.getFrontOffsetZ();
            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, 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,代码行数:38,代码来源:ItemDoor.java

示例3: onItemUse

import net.minecraft.block.Block; //导入方法依赖的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

示例4: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(EntityPlayer stack, World playerIn, BlockPos worldIn, EnumHand pos, EnumFacing hand, float facing, float hitX, float hitY)
{
    if (hand != EnumFacing.UP)
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        IBlockState iblockstate = playerIn.getBlockState(worldIn);
        Block block = iblockstate.getBlock();

        if (!block.isReplaceable(playerIn, worldIn))
        {
            worldIn = worldIn.offset(hand);
        }

        ItemStack itemstack = stack.getHeldItem(pos);

        if (stack.canPlayerEdit(worldIn, hand, itemstack) && this.block.canPlaceBlockAt(playerIn, worldIn))
        {
            EnumFacing enumfacing = EnumFacing.fromAngle((double)stack.rotationYaw);
            int i = enumfacing.getFrontOffsetX();
            int j = enumfacing.getFrontOffsetZ();
            boolean flag = i < 0 && hitY < 0.5F || i > 0 && hitY > 0.5F || j < 0 && facing > 0.5F || j > 0 && facing < 0.5F;
            placeDoor(playerIn, worldIn, enumfacing, this.block, flag);
            SoundType soundtype = this.block.getSoundType();
            playerIn.playSound(stack, worldIn, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
            itemstack.func_190918_g(1);
            return EnumActionResult.SUCCESS;
        }
        else
        {
            return EnumActionResult.FAIL;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:40,代码来源:ItemDoor.java

示例5: canPlaceBlockOnSide

import net.minecraft.block.Block; //导入方法依赖的package包/类
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack)
{
    Block block = worldIn.getBlockState(pos).getBlock();

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

    return worldIn.func_190527_a(this.block, pos, false, side, (Entity)null);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:16,代码来源:ItemBlock.java

示例6: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (side != EnumFacing.UP)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

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

        if (!playerIn.canPlayerEdit(pos, side, stack))
        {
            return false;
        }
        else if (!this.block.canPlaceBlockAt(worldIn, pos))
        {
            return false;
        }
        else
        {
            placeDoor(worldIn, pos, EnumFacing.fromAngle((double)playerIn.rotationYaw), this.block);
            --stack.stackSize;
            return true;
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:36,代码来源:ItemDoor.java

示例7: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();

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

    if (stack.stackSize == 0)
    {
        return false;
    }
    else if (!playerIn.canPlayerEdit(pos, side, stack))
    {
        return false;
    }
    else if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
    {
        int i = this.getMetadata(stack.getMetadata());
        IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, i, playerIn);

        if (worldIn.setBlockState(pos, iblockstate1, 3))
        {
            iblockstate1 = worldIn.getBlockState(pos);

            if (iblockstate1.getBlock() == this.block)
            {
                setTileEntityNBT(worldIn, playerIn, pos, stack);
                this.block.onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
            }

            worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
            --stack.stackSize;
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:48,代码来源:ItemBlock.java

示例8: onItemUse

import net.minecraft.block.Block; //导入方法依赖的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 (facing != EnumFacing.UP)
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        boolean flag = block.isReplaceable(worldIn, pos);

        if (!flag)
        {
            pos = pos.up();
        }

        int i = MathHelper.floor_double((double)(playerIn.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        EnumFacing enumfacing = EnumFacing.getHorizontal(i);
        BlockPos blockpos = pos.offset(enumfacing);

        if (playerIn.canPlayerEdit(pos, facing, stack) && playerIn.canPlayerEdit(blockpos, facing, stack))
        {
            boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            boolean flag2 = flag || worldIn.isAirBlock(pos);
            boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

            if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isFullyOpaque() && worldIn.getBlockState(blockpos.down()).isFullyOpaque())
            {
                IBlockState iblockstate1 = Blocks.BED.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);

                if (worldIn.setBlockState(pos, iblockstate1, 11))
                {
                    IBlockState iblockstate2 = iblockstate1.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
                    worldIn.setBlockState(blockpos, iblockstate2, 11);
                }

                SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, worldIn, pos, playerIn);
                worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                --stack.stackSize;
                return EnumActionResult.SUCCESS;
            }
            else
            {
                return EnumActionResult.FAIL;
            }
        }
        else
        {
            return EnumActionResult.FAIL;
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:61,代码来源:ItemBed.java

示例9: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    IBlockState iblockstate = worldIn.getBlockState(pos);
    Block block = iblockstate.getBlock();

    if (block == Blocks.snow_layer && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
    {
        side = EnumFacing.UP;
    }
    else if (!block.isReplaceable(worldIn, pos))
    {
        pos = pos.offset(side);
    }

    if (!playerIn.canPlayerEdit(pos, side, stack))
    {
        return false;
    }
    else if (stack.stackSize == 0)
    {
        return false;
    }
    else
    {
        if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
        {
            IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, 0, playerIn);

            if (worldIn.setBlockState(pos, iblockstate1, 3))
            {
                iblockstate1 = worldIn.getBlockState(pos);

                if (iblockstate1.getBlock() == this.block)
                {
                    ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack);
                    iblockstate1.getBlock().onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
                }

                worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
                --stack.stackSize;
                return true;
            }
        }

        return false;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:51,代码来源:ItemReed.java

示例10: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (worldIn.isRemote)
    {
        return true;
    }
    else if (side != EnumFacing.UP)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        boolean flag = block.isReplaceable(worldIn, pos);

        if (!flag)
        {
            pos = pos.up();
        }

        int i = MathHelper.floor_double((double)(playerIn.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        EnumFacing enumfacing = EnumFacing.getHorizontal(i);
        BlockPos blockpos = pos.offset(enumfacing);

        if (playerIn.canPlayerEdit(pos, side, stack) && playerIn.canPlayerEdit(blockpos, side, stack))
        {
            boolean flag1 = worldIn.getBlockState(blockpos).getBlock().isReplaceable(worldIn, blockpos);
            boolean flag2 = flag || worldIn.isAirBlock(pos);
            boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

            if (flag2 && flag3 && World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) && World.doesBlockHaveSolidTopSurface(worldIn, blockpos.down()))
            {
                IBlockState iblockstate1 = Blocks.bed.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);

                if (worldIn.setBlockState(pos, iblockstate1, 3))
                {
                    IBlockState iblockstate2 = iblockstate1.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD);
                    worldIn.setBlockState(blockpos, iblockstate2, 3);
                }

                --stack.stackSize;
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:59,代码来源:ItemBed.java

示例11: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
 * Called when a Block is right-clicked with this Item
 */
public EnumActionResult onItemUse(EntityPlayer stack, World playerIn, BlockPos worldIn, EnumHand pos, EnumFacing hand, float facing, float hitX, float hitY)
{
    if (playerIn.isRemote)
    {
        return EnumActionResult.SUCCESS;
    }
    else if (hand != EnumFacing.UP)
    {
        return EnumActionResult.FAIL;
    }
    else
    {
        IBlockState iblockstate = playerIn.getBlockState(worldIn);
        Block block = iblockstate.getBlock();
        boolean flag = block.isReplaceable(playerIn, worldIn);

        if (!flag)
        {
            worldIn = worldIn.up();
        }

        int i = MathHelper.floor((double)(stack.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
        EnumFacing enumfacing = EnumFacing.getHorizontal(i);
        BlockPos blockpos = worldIn.offset(enumfacing);
        ItemStack itemstack = stack.getHeldItem(pos);

        if (stack.canPlayerEdit(worldIn, hand, itemstack) && stack.canPlayerEdit(blockpos, hand, itemstack))
        {
            IBlockState iblockstate1 = playerIn.getBlockState(blockpos);
            boolean flag1 = iblockstate1.getBlock().isReplaceable(playerIn, blockpos);
            boolean flag2 = flag || playerIn.isAirBlock(worldIn);
            boolean flag3 = flag1 || playerIn.isAirBlock(blockpos);

            if (flag2 && flag3 && playerIn.getBlockState(worldIn.down()).isFullyOpaque() && playerIn.getBlockState(blockpos.down()).isFullyOpaque())
            {
                IBlockState iblockstate2 = Blocks.BED.getDefaultState().withProperty(BlockBed.OCCUPIED, Boolean.valueOf(false)).withProperty(BlockBed.FACING, enumfacing).withProperty(BlockBed.PART, BlockBed.EnumPartType.FOOT);
                playerIn.setBlockState(worldIn, iblockstate2, 10);
                playerIn.setBlockState(blockpos, iblockstate2.withProperty(BlockBed.PART, BlockBed.EnumPartType.HEAD), 10);
                playerIn.notifyNeighborsRespectDebug(worldIn, block, false);
                playerIn.notifyNeighborsRespectDebug(blockpos, iblockstate1.getBlock(), false);
                SoundType soundtype = iblockstate2.getBlock().getSoundType();
                playerIn.playSound((EntityPlayer)null, worldIn, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                itemstack.func_190918_g(1);
                return EnumActionResult.SUCCESS;
            }
            else
            {
                return EnumActionResult.FAIL;
            }
        }
        else
        {
            return EnumActionResult.FAIL;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:60,代码来源:ItemBed.java

示例12: onItemUse

import net.minecraft.block.Block; //导入方法依赖的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 == Blocks.SNOW_LAYER && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
    {
        facing = EnumFacing.UP;
    }
    else if (!block.isReplaceable(worldIn, pos))
    {
        pos = pos.offset(facing);
    }

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

        if (!worldIn.setBlockState(pos, iblockstate1, 11))
        {
            return EnumActionResult.FAIL;
        }
        else
        {
            iblockstate1 = worldIn.getBlockState(pos);

            if (iblockstate1.getBlock() == this.block)
            {
                ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack);
                iblockstate1.getBlock().onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
            }

            SoundType soundtype = iblockstate1.getBlock().getSoundType(iblockstate1, 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,代码行数:47,代码来源:ItemBlockSpecial.java

示例13: onItemUse

import net.minecraft.block.Block; //导入方法依赖的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 (stack.stackSize != 0 && playerIn.canPlayerEdit(pos, facing, stack))
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        BlockPos blockpos = pos;

        if ((facing != EnumFacing.UP || block != this.block) && !block.isReplaceable(worldIn, pos))
        {
            blockpos = pos.offset(facing);
            iblockstate = worldIn.getBlockState(blockpos);
            block = iblockstate.getBlock();
        }

        if (block == this.block)
        {
            int i = ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue();

            if (i <= 7)
            {
                IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, Integer.valueOf(i + 1));
                AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos);

                if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos)) && worldIn.setBlockState(blockpos, iblockstate1, 10))
                {
                    SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, blockpos, playerIn);
                    worldIn.playSound(playerIn, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                    --stack.stackSize;
                    return EnumActionResult.SUCCESS;
                }
            }
        }

        return super.onItemUse(stack, playerIn, worldIn, blockpos, hand, facing, hitX, hitY, hitZ);
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:45,代码来源:ItemSnow.java

示例14: onItemUse

import net.minecraft.block.Block; //导入方法依赖的package包/类
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack))
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();
        BlockPos blockpos = pos;

        if ((facing != EnumFacing.UP || block != this.block) && !block.isReplaceable(worldIn, pos))
        {
            blockpos = pos.offset(facing);
            iblockstate = worldIn.getBlockState(blockpos);
            block = iblockstate.getBlock();
        }

        if (block == this.block)
        {
            int i = iblockstate.getValue(BlockSnow.LAYERS);

            if (i < 8)
            {
                IBlockState iblockstate1 = iblockstate.withProperty(BlockSnow.LAYERS, i + 1);
                AxisAlignedBB axisalignedbb = iblockstate1.getCollisionBoundingBox(worldIn, blockpos);

                if (axisalignedbb != Block.NULL_AABB && worldIn.checkNoEntityCollision(axisalignedbb.offset(blockpos)) && worldIn.setBlockState(blockpos, iblockstate1, 10))
                {
                    SoundType soundtype = this.block.getSoundType(iblockstate1, worldIn, pos, player);
                    worldIn.playSound(player, blockpos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);

                    if (player instanceof EntityPlayerMP)
                    {
                        CriteriaTriggers.PLACED_BLOCK.trigger((EntityPlayerMP)player, pos, itemstack);
                    }

                    itemstack.shrink(1);
                    return EnumActionResult.SUCCESS;
                }
            }
        }

        return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
    }
    else
    {
        return EnumActionResult.FAIL;
    }
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:51,代码来源:ItemSnow.java


注:本文中的net.minecraft.block.Block.isReplaceable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。