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


Java IBlockState.getPlayerRelativeBlockHardness方法代码示例

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


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

示例1: blockRemoving

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public void blockRemoving(BlockPos pos)
{
    if (pos.equals(this.destroyPos))
    {
        int i = this.curblockDamage - this.initialDamage;
        IBlockState iblockstate = this.theWorld.getBlockState(pos);

        if (iblockstate.getMaterial() != Material.AIR)
        {
            float f = iblockstate.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.world, pos) * (float)(i + 1);

            if (f >= 0.7F)
            {
                this.isDestroyingBlock = false;
                this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), pos, -1);
                this.tryHarvestBlock(pos);
            }
            else if (!this.receivedFinishDiggingPacket)
            {
                this.isDestroyingBlock = false;
                this.receivedFinishDiggingPacket = true;
                this.delayedDestroyPos = pos;
                this.initialBlockDamage = this.initialDamage;
            }
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:28,代码来源:PlayerInteractionManager.java

示例2: blockRemoving

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public void blockRemoving(BlockPos pos)
{
    if (pos.equals(this.destroyPos))
    {
        int i = this.curblockDamage - this.initialDamage;
        IBlockState iblockstate = this.theWorld.getBlockState(pos);

        if (!iblockstate.getBlock().isAir(iblockstate, theWorld, pos))
        {
            float f = iblockstate.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.worldObj, pos) * (float)(i + 1);

            if (f >= 0.7F)
            {
                this.isDestroyingBlock = false;
                this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), pos, -1);
                this.tryHarvestBlock(pos);
            }
            else if (!this.receivedFinishDiggingPacket)
            {
                this.isDestroyingBlock = false;
                this.receivedFinishDiggingPacket = true;
                this.delayedDestroyPos = pos;
                this.initialBlockDamage = this.initialDamage;
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:28,代码来源:PlayerInteractionManager.java

示例3: clickBlock

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Called when the player is hitting a block with an item.
 */
public boolean clickBlock(BlockPos loc, EnumFacing face)
{
    if (this.currentGameType.isAdventure())
    {
        if (this.currentGameType == GameType.SPECTATOR)
        {
            return false;
        }

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

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

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

    if (!this.mc.world.getWorldBorder().contains(loc))
    {
        return false;
    }
    else
    {
        if (this.currentGameType.isCreative())
        {
            this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
            clickBlockCreative(this.mc, this, loc, face);
            this.blockHitDelay = 5;
        }
        else if (!this.isHittingBlock || !this.isHittingPosition(loc))
        {
            if (this.isHittingBlock)
            {
                this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face));
            }

            this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
            IBlockState iblockstate = this.mc.world.getBlockState(loc);
            boolean flag = iblockstate.getMaterial() != Material.AIR;

            if (flag && this.curBlockDamageMP == 0.0F)
            {
                iblockstate.getBlock().onBlockClicked(this.mc.world, loc, this.mc.player);
            }

            if (flag && iblockstate.getPlayerRelativeBlockHardness(this.mc.player, this.mc.player.world, loc) >= 1.0F)
            {
                this.onPlayerDestroyBlock(loc);
            }
            else
            {
                this.isHittingBlock = true;
                this.currentBlock = loc;
                this.currentItemHittingBlock = this.mc.player.getHeldItemMainhand();
                this.curBlockDamageMP = 0.0F;
                this.stepSoundTickCounter = 0.0F;
                this.mc.world.sendBlockBreakProgress(this.mc.player.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
            }
        }

        return true;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:75,代码来源:PlayerControllerMP.java

示例4: onPlayerDamageBlock

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public boolean onPlayerDamageBlock(BlockPos posBlock, EnumFacing directionFacing)
{
    this.syncCurrentPlayItem();

    if (this.blockHitDelay > 0)
    {
        --this.blockHitDelay;
        return true;
    }
    else if (this.currentGameType.isCreative() && this.mc.world.getWorldBorder().contains(posBlock))
    {
        this.blockHitDelay = 5;
        this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, posBlock, directionFacing));
        clickBlockCreative(this.mc, this, posBlock, directionFacing);
        return true;
    }
    else if (this.isHittingPosition(posBlock))
    {
        IBlockState iblockstate = this.mc.world.getBlockState(posBlock);
        Block block = iblockstate.getBlock();

        if (iblockstate.getMaterial() == Material.AIR)
        {
            this.isHittingBlock = false;
            return false;
        }
        else
        {
            this.curBlockDamageMP += iblockstate.getPlayerRelativeBlockHardness(this.mc.player, this.mc.player.world, posBlock);

            if (this.stepSoundTickCounter % 4.0F == 0.0F)
            {
                SoundType soundtype = block.getSoundType();
                this.mc.getSoundHandler().playSound(new PositionedSoundRecord(soundtype.getHitSound(), SoundCategory.NEUTRAL, (soundtype.getVolume() + 1.0F) / 8.0F, soundtype.getPitch() * 0.5F, posBlock));
            }

            ++this.stepSoundTickCounter;

            if (this.curBlockDamageMP >= 1.0F)
            {
                this.isHittingBlock = false;
                this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing));
                this.onPlayerDestroyBlock(posBlock);
                this.curBlockDamageMP = 0.0F;
                this.stepSoundTickCounter = 0.0F;
                this.blockHitDelay = 5;
            }

            this.mc.world.sendBlockBreakProgress(this.mc.player.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
            return true;
        }
    }
    else
    {
        return this.clickBlock(posBlock, directionFacing);
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:58,代码来源:PlayerControllerMP.java

示例5: updateBlockRemoving

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public void updateBlockRemoving()
{
    ++this.curblockDamage;

    if (this.receivedFinishDiggingPacket)
    {
        int i = this.curblockDamage - this.initialBlockDamage;
        IBlockState iblockstate = this.theWorld.getBlockState(this.delayedDestroyPos);
        Block block = iblockstate.getBlock();

        if (iblockstate.getMaterial() == Material.AIR)
        {
            this.receivedFinishDiggingPacket = false;
        }
        else
        {
            float f = iblockstate.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.world, this.delayedDestroyPos) * (float)(i + 1);
            int j = (int)(f * 10.0F);

            if (j != this.durabilityRemainingOnBlock)
            {
                this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.delayedDestroyPos, j);
                this.durabilityRemainingOnBlock = j;
            }

            if (f >= 1.0F)
            {
                this.receivedFinishDiggingPacket = false;
                this.tryHarvestBlock(this.delayedDestroyPos);
            }
        }
    }
    else if (this.isDestroyingBlock)
    {
        IBlockState iblockstate1 = this.theWorld.getBlockState(this.destroyPos);
        Block block1 = iblockstate1.getBlock();

        if (iblockstate1.getMaterial() == Material.AIR)
        {
            this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.destroyPos, -1);
            this.durabilityRemainingOnBlock = -1;
            this.isDestroyingBlock = false;
        }
        else
        {
            int k = this.curblockDamage - this.initialDamage;
            float f1 = iblockstate1.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.world, this.delayedDestroyPos) * (float)(k + 1);
            int l = (int)(f1 * 10.0F);

            if (l != this.durabilityRemainingOnBlock)
            {
                this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.destroyPos, l);
                this.durabilityRemainingOnBlock = l;
            }
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:58,代码来源:PlayerInteractionManager.java

示例6: onBlockClicked

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * If not creative, it calls sendBlockBreakProgress until the block is broken first. tryHarvestBlock can also be the
 * result of this call.
 */
public void onBlockClicked(BlockPos pos, EnumFacing side)
{
    if (this.isCreative())
    {
        if (!this.theWorld.extinguishFire((EntityPlayer)null, pos, side))
        {
            this.tryHarvestBlock(pos);
        }
    }
    else
    {
        IBlockState iblockstate = this.theWorld.getBlockState(pos);
        Block block = iblockstate.getBlock();

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

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

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

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

        this.theWorld.extinguishFire((EntityPlayer)null, pos, side);
        this.initialDamage = this.curblockDamage;
        float f = 1.0F;

        if (iblockstate.getMaterial() != Material.AIR)
        {
            block.onBlockClicked(this.theWorld, pos, this.thisPlayerMP);
            f = iblockstate.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.world, pos);
        }

        if (iblockstate.getMaterial() != Material.AIR && f >= 1.0F)
        {
            this.tryHarvestBlock(pos);
        }
        else
        {
            this.isDestroyingBlock = true;
            this.destroyPos = pos;
            int i = (int)(f * 10.0F);
            this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), pos, i);
            this.durabilityRemainingOnBlock = i;
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:66,代码来源:PlayerInteractionManager.java

示例7: clickBlock

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Called when the player is hitting a block with an item.
 */
public boolean clickBlock(BlockPos loc, EnumFacing face)
{
    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(loc).getBlock()))
            {
                return false;
            }
        }
    }

    if (!this.mc.theWorld.getWorldBorder().contains(loc))
    {
        return false;
    }
    else
    {
        if (this.currentGameType.isCreative())
        {
            this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
            if (!net.minecraftforge.common.ForgeHooks.onLeftClickBlock(this.mc.thePlayer, loc, face, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(this.mc.thePlayer, getBlockReachDistance() + 1)).isCanceled())
            clickBlockCreative(this.mc, this, loc, face);
            this.blockHitDelay = 5;
        }
        else if (!this.isHittingBlock || !this.isHittingPosition(loc))
        {
            if (this.isHittingBlock)
            {
                this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.ABORT_DESTROY_BLOCK, this.currentBlock, face));
            }

            this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, loc, face));
            net.minecraftforge.event.entity.player.PlayerInteractEvent.LeftClickBlock event = net.minecraftforge.common.ForgeHooks.onLeftClickBlock(this.mc.thePlayer, loc, face, net.minecraftforge.common.ForgeHooks.rayTraceEyeHitVec(this.mc.thePlayer, getBlockReachDistance() + 1));

            IBlockState iblockstate = this.mc.theWorld.getBlockState(loc);
            boolean flag = iblockstate.getMaterial() != Material.AIR;

            if (flag && this.curBlockDamageMP == 0.0F)
            {
                if (event.getUseBlock() != net.minecraftforge.fml.common.eventhandler.Event.Result.DENY)
                iblockstate.getBlock().onBlockClicked(this.mc.theWorld, loc, this.mc.thePlayer);
            }
            if (event.getUseItem() == net.minecraftforge.fml.common.eventhandler.Event.Result.DENY) return true;
            if (flag && iblockstate.getPlayerRelativeBlockHardness(this.mc.thePlayer, this.mc.thePlayer.worldObj, loc) >= 1.0F)
            {
                this.onPlayerDestroyBlock(loc);
            }
            else
            {
                this.isHittingBlock = true;
                this.currentBlock = loc;
                this.currentItemHittingBlock = this.mc.thePlayer.getHeldItemMainhand();
                this.curBlockDamageMP = 0.0F;
                this.stepSoundTickCounter = 0.0F;
                this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
            }
        }

        return true;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:79,代码来源:PlayerControllerMP.java

示例8: onPlayerDamageBlock

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public boolean onPlayerDamageBlock(BlockPos posBlock, EnumFacing directionFacing)
{
    this.syncCurrentPlayItem();

    if (this.blockHitDelay > 0)
    {
        --this.blockHitDelay;
        return true;
    }
    else if (this.currentGameType.isCreative() && this.mc.theWorld.getWorldBorder().contains(posBlock))
    {
        this.blockHitDelay = 5;
        this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.START_DESTROY_BLOCK, posBlock, directionFacing));
        clickBlockCreative(this.mc, this, posBlock, directionFacing);
        return true;
    }
    else if (this.isHittingPosition(posBlock))
    {
        IBlockState iblockstate = this.mc.theWorld.getBlockState(posBlock);
        Block block = iblockstate.getBlock();

        if (iblockstate.getMaterial() == Material.AIR)
        {
            this.isHittingBlock = false;
            return false;
        }
        else
        {
            this.curBlockDamageMP += iblockstate.getPlayerRelativeBlockHardness(this.mc.thePlayer, this.mc.thePlayer.worldObj, posBlock);

            if (this.stepSoundTickCounter % 4.0F == 0.0F)
            {
                SoundType soundtype = block.getSoundType(iblockstate, mc.theWorld, posBlock, mc.thePlayer);
                this.mc.getSoundHandler().playSound(new PositionedSoundRecord(soundtype.getHitSound(), SoundCategory.NEUTRAL, (soundtype.getVolume() + 1.0F) / 8.0F, soundtype.getPitch() * 0.5F, posBlock));
            }

            ++this.stepSoundTickCounter;

            if (this.curBlockDamageMP >= 1.0F)
            {
                this.isHittingBlock = false;
                this.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.STOP_DESTROY_BLOCK, posBlock, directionFacing));
                this.onPlayerDestroyBlock(posBlock);
                this.curBlockDamageMP = 0.0F;
                this.stepSoundTickCounter = 0.0F;
                this.blockHitDelay = 5;
            }

            this.mc.theWorld.sendBlockBreakProgress(this.mc.thePlayer.getEntityId(), this.currentBlock, (int)(this.curBlockDamageMP * 10.0F) - 1);
            return true;
        }
    }
    else
    {
        return this.clickBlock(posBlock, directionFacing);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:58,代码来源:PlayerControllerMP.java

示例9: updateBlockRemoving

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public void updateBlockRemoving()
{
    ++this.curblockDamage;

    if (this.receivedFinishDiggingPacket)
    {
        int i = this.curblockDamage - this.initialBlockDamage;
        IBlockState iblockstate = this.theWorld.getBlockState(this.delayedDestroyPos);
        Block block = iblockstate.getBlock();

        if (block.isAir(iblockstate, theWorld, delayedDestroyPos))
        {
            this.receivedFinishDiggingPacket = false;
        }
        else
        {
            float f = iblockstate.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.worldObj, this.delayedDestroyPos) * (float)(i + 1);
            int j = (int)(f * 10.0F);

            if (j != this.durabilityRemainingOnBlock)
            {
                this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.delayedDestroyPos, j);
                this.durabilityRemainingOnBlock = j;
            }

            if (f >= 1.0F)
            {
                this.receivedFinishDiggingPacket = false;
                this.tryHarvestBlock(this.delayedDestroyPos);
            }
        }
    }
    else if (this.isDestroyingBlock)
    {
        IBlockState iblockstate1 = this.theWorld.getBlockState(this.destroyPos);
        Block block1 = iblockstate1.getBlock();

        if (block1.isAir(iblockstate1, theWorld, destroyPos))
        {
            this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.destroyPos, -1);
            this.durabilityRemainingOnBlock = -1;
            this.isDestroyingBlock = false;
        }
        else
        {
            int k = this.curblockDamage - this.initialDamage;
            float f1 = iblockstate1.getPlayerRelativeBlockHardness(this.thisPlayerMP, this.thisPlayerMP.worldObj, this.destroyPos) * (float)(k + 1); // Forge: Fix network break progress using wrong position
            int l = (int)(f1 * 10.0F);

            if (l != this.durabilityRemainingOnBlock)
            {
                this.theWorld.sendBlockBreakProgress(this.thisPlayerMP.getEntityId(), this.destroyPos, l);
                this.durabilityRemainingOnBlock = l;
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:58,代码来源:PlayerInteractionManager.java


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