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


Java ItemStack.onBlockDestroyed方法代码示例

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


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

示例1: tryHarvestBlock

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Attempts to harvest a block
 */
public boolean tryHarvestBlock(BlockPos pos)
{
    if (this.gameType.isCreative() && this.thisPlayerMP.getHeldItem() != null && this.thisPlayerMP.getHeldItem().getItem() instanceof ItemSword)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = this.theWorld.getBlockState(pos);
        TileEntity tileentity = this.theWorld.getTileEntity(pos);

        if (this.gameType.isAdventure())
        {
            if (this.gameType == WorldSettings.GameType.SPECTATOR)
            {
                return false;
            }

            if (!this.thisPlayerMP.isAllowEdit())
            {
                ItemStack itemstack = this.thisPlayerMP.getCurrentEquippedItem();

                if (itemstack == null)
                {
                    return false;
                }

                if (!itemstack.canDestroy(iblockstate.getBlock()))
                {
                    return false;
                }
            }
        }

        this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
        boolean flag1 = this.removeBlock(pos);

        if (this.isCreative())
        {
            this.thisPlayerMP.playerNetServerHandler.sendPacket(new S23PacketBlockChange(this.theWorld, pos));
        }
        else
        {
            ItemStack itemstack1 = this.thisPlayerMP.getCurrentEquippedItem();
            boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate.getBlock());

            if (itemstack1 != null)
            {
                itemstack1.onBlockDestroyed(this.theWorld, iblockstate.getBlock(), pos, this.thisPlayerMP);

                if (itemstack1.stackSize == 0)
                {
                    this.thisPlayerMP.destroyCurrentEquippedItem();
                }
            }

            if (flag1 && flag)
            {
                iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity);
            }
        }

        return flag1;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:69,代码来源:ItemInWorldManager.java

示例2: onPlayerDestroyBlock

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Called when a player completes the destruction of a block
 */
public boolean onPlayerDestroyBlock(BlockPos pos, EnumFacing side)
{
    if (this.currentGameType.isAdventure())
    {
        if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
        {
            return false;
        }

        if (!this.mc.thePlayer.isAllowEdit())
        {
            Block block = this.mc.theWorld.getBlockState(pos).getBlock();
            ItemStack itemstack = this.mc.thePlayer.getCurrentEquippedItem();

            if (itemstack == null)
            {
                return false;
            }

            if (!itemstack.canDestroy(block))
            {
                return false;
            }
        }
    }

    if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItem() != null && this.mc.thePlayer.getHeldItem().getItem() instanceof ItemSword)
    {
        return false;
    }
    else
    {
        World world = this.mc.theWorld;
        IBlockState iblockstate = world.getBlockState(pos);
        Block block1 = iblockstate.getBlock();

        if (block1.getMaterial() == Material.air)
        {
            return false;
        }
        else
        {
            world.playAuxSFX(2001, pos, Block.getStateId(iblockstate));
            boolean flag = world.setBlockToAir(pos);

            if (flag)
            {
                block1.onBlockDestroyedByPlayer(world, pos, iblockstate);
            }

            this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());

            if (!this.currentGameType.isCreative())
            {
                ItemStack itemstack1 = this.mc.thePlayer.getCurrentEquippedItem();

                if (itemstack1 != null)
                {
                    itemstack1.onBlockDestroyed(world, block1, pos, this.mc.thePlayer);

                    if (itemstack1.stackSize == 0)
                    {
                        this.mc.thePlayer.destroyCurrentEquippedItem();
                    }
                }
            }

            return flag;
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:75,代码来源:PlayerControllerMP.java

示例3: tryHarvestBlock

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Attempts to harvest a block
 */
public boolean tryHarvestBlock(BlockPos pos)
{
    if (this.gameType.isCreative() && !this.thisPlayerMP.getHeldItemMainhand().func_190926_b() && this.thisPlayerMP.getHeldItemMainhand().getItem() instanceof ItemSword)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = this.theWorld.getBlockState(pos);
        TileEntity tileentity = this.theWorld.getTileEntity(pos);
        Block block = iblockstate.getBlock();

        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock())
        {
            this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
            return false;
        }
        else
        {
            if (this.gameType.isAdventure())
            {
                if (this.gameType == GameType.SPECTATOR)
                {
                    return false;
                }

                if (!this.thisPlayerMP.isAllowEdit())
                {
                    ItemStack itemstack = this.thisPlayerMP.getHeldItemMainhand();

                    if (itemstack.func_190926_b())
                    {
                        return false;
                    }

                    if (!itemstack.canDestroy(block))
                    {
                        return false;
                    }
                }
            }

            this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
            boolean flag1 = this.removeBlock(pos);

            if (this.isCreative())
            {
                this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
            }
            else
            {
                ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand();
                ItemStack itemstack2 = itemstack1.func_190926_b() ? ItemStack.field_190927_a : itemstack1.copy();
                boolean flag = this.thisPlayerMP.canHarvestBlock(iblockstate);

                if (!itemstack1.func_190926_b())
                {
                    itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP);
                }

                if (flag1 && flag)
                {
                    iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2);
                }
            }

            return flag1;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:74,代码来源:PlayerInteractionManager.java

示例4: onPlayerDestroyBlock

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public boolean onPlayerDestroyBlock(BlockPos pos)
{
    if (this.currentGameType.isAdventure())
    {
        if (this.currentGameType == GameType.SPECTATOR)
        {
            return false;
        }

        if (!this.mc.thePlayer.isAllowEdit())
        {
            ItemStack itemstack = this.mc.thePlayer.getHeldItemMainhand();

            if (itemstack == null)
            {
                return false;
            }

            if (!itemstack.canDestroy(this.mc.theWorld.getBlockState(pos).getBlock()))
            {
                return false;
            }
        }
    }

    ItemStack stack = mc.thePlayer.getHeldItemMainhand();
    if (stack != null && stack.getItem() != null && stack.getItem().onBlockStartBreak(stack, pos, mc.thePlayer))
    {
        return false;
    }

    if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItemMainhand() != null && this.mc.thePlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
    {
        return false;
    }
    else
    {
        World world = this.mc.theWorld;
        IBlockState iblockstate = world.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.mc.thePlayer.canUseCommandBlock())
        {
            return false;
        }
        else if (iblockstate.getMaterial() == Material.AIR)
        {
            return false;
        }
        else
        {
            world.playEvent(2001, pos, Block.getStateId(iblockstate));

            this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());

            if (!this.currentGameType.isCreative())
            {
                ItemStack itemstack1 = this.mc.thePlayer.getHeldItemMainhand();

                if (itemstack1 != null)
                {
                    itemstack1.onBlockDestroyed(world, iblockstate, pos, this.mc.thePlayer);

                    if (itemstack1.stackSize <= 0)
                    {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.mc.thePlayer, itemstack1, EnumHand.MAIN_HAND);
                        this.mc.thePlayer.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
                    }
                }
            }

            boolean flag = block.removedByPlayer(iblockstate, world, pos, mc.thePlayer, false);

            if (flag)
            {
                block.onBlockDestroyedByPlayer(world, pos, iblockstate);
            }
            return flag;
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:82,代码来源:PlayerControllerMP.java

示例5: tryHarvestBlock

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Attempts to harvest a block
 */
public boolean tryHarvestBlock(BlockPos pos)
{
    int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(theWorld, gameType, thisPlayerMP, pos);
    if (exp == -1)
    {
        return false;
    }
    else
    {
        IBlockState iblockstate = this.theWorld.getBlockState(pos);
        TileEntity tileentity = this.theWorld.getTileEntity(pos);
        Block block = iblockstate.getBlock();

        if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.thisPlayerMP.canUseCommandBlock())
        {
            this.theWorld.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
            return false;
        }
        else
        {
            ItemStack stack = thisPlayerMP.getHeldItemMainhand();
            if (stack != null && stack.getItem().onBlockStartBreak(stack, pos, thisPlayerMP)) return false;

            this.theWorld.playEvent(this.thisPlayerMP, 2001, pos, Block.getStateId(iblockstate));
            boolean flag1 = false;

            if (this.isCreative())
            {
                flag1 = this.removeBlock(pos);
                this.thisPlayerMP.connection.sendPacket(new SPacketBlockChange(this.theWorld, pos));
            }
            else
            {
                ItemStack itemstack1 = this.thisPlayerMP.getHeldItemMainhand();
                ItemStack itemstack2 = itemstack1 == null ? null : itemstack1.copy();
                boolean flag = iblockstate.getBlock().canHarvestBlock(theWorld, pos, thisPlayerMP);

                if (itemstack1 != null)
                {
                    itemstack1.onBlockDestroyed(this.theWorld, iblockstate, pos, this.thisPlayerMP);

                    if (itemstack1.stackSize <= 0)
                    {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.thisPlayerMP, itemstack1, EnumHand.MAIN_HAND);
                        this.thisPlayerMP.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
                    }
                }

                flag1 = this.removeBlock(pos, flag);
                if (flag1 && flag)
                {
                    iblockstate.getBlock().harvestBlock(this.theWorld, this.thisPlayerMP, pos, iblockstate, tileentity, itemstack2);
                }
            }

            // Drop experience
            if (!this.isCreative() && flag1 && exp > 0)
            {
                iblockstate.getBlock().dropXpOnBlockBreak(theWorld, pos, exp);
            }
            return flag1;
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:68,代码来源:PlayerInteractionManager.java


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