當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。