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


Java IBlockState.getBlockHardness方法代码示例

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


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

示例1: delayForHardBlocks

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
@Override
public void delayForHardBlocks(BlockPos pos, Consumer<BlockPos> nextJob) {
    World world = entity.getEntityWorld();
    if (world.isAirBlock(pos)) {
        return;
    }
    IBlockState state = world.getBlockState(pos);
    if (!allowedToHarvest(state, world, pos, GeneralTools.getHarvester())) {
        return;
    }
    Block block = state.getBlock();
    if (block instanceof BlockLiquid) {
        nextJob.accept(pos);
    } else {
        float hardness = state.getBlockHardness(world, pos);
        if (hardness < Config.delayAtHardness) {
            nextJob.accept(pos);
        } else {
            delay((int) (hardness * Config.delayFactor), () -> nextJob.accept(pos));
        }
    }
}
 
开发者ID:McJty,项目名称:MeeCreeps,代码行数:23,代码来源:WorkerHelper.java

示例2: blockStrength

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public static float blockStrength(IBlockState state, EntityPlayer player, World world, BlockPos pos)
{
    float hardness = state.getBlockHardness(world, pos);
    if (hardness < 0.0F)
    {
        return 0.0F;
    }

    if (!canHarvestBlock(state.getBlock(), player, world, pos))
    {
        return player.getDigSpeed(state, pos) / hardness / 100F;
    }
    else
    {
        return player.getDigSpeed(state, pos) / hardness / 30F;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:18,代码来源:ForgeHooks.java

示例3: doBlockInteraction

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
@Override
protected boolean doBlockInteraction(BlockPos pos, double distToBlock) {
    PlayerInteractionManager manager = drone.getFakePlayer().interactionManager;
    if (!manager.isDestroyingBlock || !manager.receivedFinishDiggingPacket) { //is not destroying and is not acknowledged.
        IBlockState blockState = worldCache.getBlockState(pos);
        Block block = blockState.getBlock();
        if (!ignoreBlock(block) && isBlockValidForFilter(worldCache, drone, pos, widget)) {
            if (blockState.getBlockHardness(drone.world(), pos) < 0) {
                addToBlacklist(pos);
                drone.addDebugEntry("gui.progWidget.dig.debug.cantDigBlock", pos);
                drone.setDugBlock(null);
                return false;
            }
            manager.onBlockClicked(pos, EnumFacing.DOWN);
            manager.blockRemoving(pos);
            if (!manager.isDestroyingBlock) {
                addToBlacklist(pos);
                drone.addDebugEntry("gui.progWidget.dig.debug.cantDigBlock", pos);
                drone.setDugBlock(null);
                return false;
            }
            drone.setDugBlock(pos);
            return true;
        }
        drone.setDugBlock(null);
        return false;
    } else {
        return true;
    }
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:31,代码来源:DroneAIDig.java

示例4: onBlockDestroyed

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
	if (!(entityLiving instanceof EntityPlayer)) return super.onBlockDestroyed(stack, world, state, pos, entityLiving);
	EntityPlayer player = (EntityPlayer)entityLiving;
	
       if (!world.isRemote && state.getBlockHardness(world, pos) != 0) {
           stack.damageItem(1, player);
           
           ArrayList<BlockPos> crushGroup = new ArrayList<>();
           
           //check and break anything nearby of equal or lower hardness
           for(int z=-1; z<=1; z++) {
           	for(int y=-1; y<=1; y++) {
           		for(int x=-1; x<=1; x++) {
           			if (x==0 && y==0 && z==0) continue;
           			BlockPos crushLocation = pos.add(x, y, z);
           			IBlockState toCrush = world.getBlockState(crushLocation);
           			
           			if (toCrush.getBlockHardness(world, crushLocation) <= state.getBlockHardness(world, pos)) {
           				if (!BLACKLIST.contains(toCrush.getBlock())) {
            				crushGroup.add(crushLocation);
            				stack.damageItem(1, entityLiving);
           				}
           			}
           		}
           	}
           }
           
           for(BlockPos cur : crushGroup) {
           	if (player instanceof EntityPlayerMP) { //Should be true any time we reach this part of the code
   				ToolHelper.auxHarvestBlock(world, cur, (EntityPlayerMP)player);
   			}
           }
       }
       
       return true;
   }
 
开发者ID:elytra,项目名称:Thermionics,代码行数:38,代码来源:ItemHammer.java

示例5: onBlockDestroyed

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
 */
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
{
    if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
    {
        stack.damageItem(2, entityLiving);
    }

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

示例6: onBlockDestroyed

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
 */
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
{
    if (!worldIn.isRemote && (double)state.getBlockHardness(worldIn, pos) != 0.0D)
    {
        stack.damageItem(1, entityLiving);
    }

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

示例7: getPlayerRelativeBlockHardness

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
@Deprecated

    /**
     * Get the hardness of this Block relative to the ability of the given player
     */
    public float getPlayerRelativeBlockHardness(IBlockState state, EntityPlayer player, World worldIn, BlockPos pos)
    {
        float f = state.getBlockHardness(worldIn, pos);
        return f < 0.0F ? 0.0F : (!player.canHarvestBlock(state) ? player.getDigSpeed(state) / f / 100.0F : player.getDigSpeed(state) / f / 30.0F);
    }
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:11,代码来源:Block.java

示例8: getHardness

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public static float getHardness(IBlockState block, World world) {
	if (block.getBlock() == Blocks.COBBLESTONE){
		
		return 2.1f;
	}
	if (block.getBlockHardness(world, new BlockPos(0, 0, 0)) == 0)
		return 0;
	return Math.min((block.getMaterial().isToolNotRequired() ? block.getBlockHardness(world, new BlockPos(0, 0, 0))
			: block.getBlockHardness(world, new BlockPos(0, 0, 0)) * 1.9f) / 1.55f + 0.65f, 50f);
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:11,代码来源:BlockLauncher.java

示例9: onBlockDestroyed

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
 */
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
{
    if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
    {
        stack.damageItem(1, entityLiving);
    }

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

示例10: auxHarvestBlock

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Destroys and tries to harvest a block with the currently active tool, except that instead of calling
 * onBlockDestroyed, it calls onBlockAuxDestroyed on the tool, preventing infinite loops.
 */
public static boolean auxHarvestBlock(World world, BlockPos pos, EntityPlayerMP player) {
	if (world.isRemote) return false; //Shouldn't even be possible if we have an EntityPlayerMP!
	
	GameType gameType = player.interactionManager.getGameType();
	
	int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, gameType, player, pos);
       if (exp == -1) {
           return false;
       } else {
           IBlockState iblockstate = world.getBlockState(pos);
           if (iblockstate.getBlockHardness(world, pos)<0) return false;
           TileEntity tileentity = world.getTileEntity(pos);
           Block block = iblockstate.getBlock();

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

               world.playEvent(player, 2001, pos, Block.getStateId(iblockstate));
               boolean removed = false;

               if (gameType==GameType.CREATIVE) {
                   removed = removeBlock(world, pos, player, false);
                   player.connection.sendPacket(new SPacketBlockChange(world, pos));
               } else {
                   ItemStack itemstack1 = player.getHeldItemMainhand();
                   ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
                   boolean canHarvest = iblockstate.getBlock().canHarvestBlock(world, pos, player);

                   if (!itemstack1.isEmpty()) {
                   //    itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
                    if (itemstack1.getItem() instanceof IAuxDestroyBlock) {
                    	((IAuxDestroyBlock)itemstack1.getItem()).onBlockAuxDestroyed(world, iblockstate, pos, player);
                    }
                   }
                   
                   removed = removeBlock(world, pos, player, canHarvest);
                   if (removed && canHarvest) {
                       iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
                   }
               }

               // Drop experience
               if (gameType!=GameType.CREATIVE && removed && exp > 0) {
                   iblockstate.getBlock().dropXpOnBlockBreak(world, pos, exp);
               }
               return removed;
           }
       }
}
 
开发者ID:elytra,项目名称:Thermionics,代码行数:58,代码来源:ToolHelper.java

示例11: canPush

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Checks if the piston can push the given BlockState.
 */
public static boolean canPush(IBlockState blockStateIn, World worldIn, BlockPos pos, EnumFacing facing, boolean destroyBlocks)
{
    Block block = blockStateIn.getBlock();

    if (block == Blocks.OBSIDIAN)
    {
        return false;
    }
    else if (!worldIn.getWorldBorder().contains(pos))
    {
        return false;
    }
    else if (pos.getY() >= 0 && (facing != EnumFacing.DOWN || pos.getY() != 0))
    {
        if (pos.getY() <= worldIn.getHeight() - 1 && (facing != EnumFacing.UP || pos.getY() != worldIn.getHeight() - 1))
        {
            if (block != Blocks.PISTON && block != Blocks.STICKY_PISTON)
            {
                if (blockStateIn.getBlockHardness(worldIn, pos) == -1.0F)
                {
                    return false;
                }

                if (blockStateIn.getMobilityFlag() == EnumPushReaction.BLOCK)
                {
                    return false;
                }

                if (blockStateIn.getMobilityFlag() == EnumPushReaction.DESTROY)
                {
                    return destroyBlocks;
                }
            }
            else if (((Boolean)blockStateIn.getValue(EXTENDED)).booleanValue())
            {
                return false;
            }

            return !block.hasTileEntity();
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:54,代码来源:BlockPistonBase.java

示例12: damageBlock

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public static float damageBlock(BlockPos pos, EntityLivingBase living, World world, float damage) {
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	if (block.isAir(state, world, pos) || state.getMaterial() == Material.WATER || state.getMaterial() == Material.LAVA || state.getBlockHardness(world, pos) < 0)
		return damage;

	DestroyBlockEntry finalEntry = null;
	int entryId = 0;
	int emptyId = -1;
	for (int i = 0; i < BlockEventBus.destroyProgress.size(); i++) {
		DestroyBlockEntry entry = BlockEventBus.destroyProgress.get(i);
		if (emptyId == -1 && entry == null)
			emptyId = i;
		if (entry != null && entry.world == world && entry.pos.equals(pos)) {
			finalEntry = entry;
			entryId = i;
			break;
		}
	}
	if (finalEntry == null) {
		finalEntry = new DestroyBlockEntry(pos, world);
		if (emptyId != -1) {
			 BlockEventBus.destroyProgress.set(emptyId, finalEntry);
			entryId = emptyId;
		} else {
			 BlockEventBus.destroyProgress.add(finalEntry);
			entryId =  BlockEventBus.destroyProgress.size() - 1;
		}

	}

	/*if (block instanceof BlockChest) {
		((TileEntityChest) world.getTileEntity(pos)).setLootTable(LootTableList.CHESTS_NETHER_BRIDGE, living.getRNG().nextLong());
	}*/
	float hardness = BlockLauncher.getHardness(state, world);

	finalEntry.curDamage += damage;

	if (living != null)
		world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, (int) ((finalEntry.curDamage / hardness) * 10));

	if (finalEntry.curDamage >= hardness) {
		if (living != null && living instanceof EntityPlayer)
			block.harvestBlock(world, (EntityPlayer) living, pos, state, null, ItemStack.EMPTY);
		else {
			block.dropBlockAsItem(world, pos, state, 0);
		}
		BlockEventBus.destroyProgress.remove(finalEntry);

		boolean flag = (living == null || !(living instanceof EntityPlayer) && world.isAirBlock(pos)) || block.removedByPlayer(state, world, pos, (EntityPlayer) living, true);

		if (flag) {
			if (living != null) {
				world.playEvent(2001, pos, Block.getStateId(state));
				world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, -1);
			}
			block.onBlockDestroyedByPlayer(world, pos, state);

		}
		return finalEntry.curDamage - hardness;
	}
	return 0;
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:64,代码来源:BlockLauncher.java

示例13: damageBlock

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public static float damageBlock(BlockPos pos, EntityLivingBase living, World world, ItemStack stack, int critical, float damage, Vec3d forwardVec, Explosion explosion) {
	IBlockState state = world.getBlockState(pos);
	Block block = state.getBlock();
	if (block.isAir(state, world, pos) || TF2ConfigVars.destTerrain == 0 || state.getBlockHardness(world, pos) < 0 ||
			(!(living instanceof EntityPlayer) && !world.getGameRules().getBoolean("mobGriefing")) || (living instanceof EntityPlayer && !world.isBlockModifiable((EntityPlayer) living, pos)))
		return 0;

	DestroyBlockEntry finalEntry = null;
	int entryId = 0;
	int emptyId = -1;
	for (int i = 0; i < TF2EventsCommon.destroyProgress.size(); i++) {
		DestroyBlockEntry entry = TF2EventsCommon.destroyProgress.get(i);
		if (emptyId == -1 && entry == null)
			emptyId = i;
		if (entry != null && entry.world == world && entry.pos.equals(pos)) {
			finalEntry = entry;
			entryId = i;
			break;
		}
	}
	if (finalEntry == null) {
		finalEntry = new DestroyBlockEntry(pos, world);
		if (emptyId != -1) {
			TF2EventsCommon.destroyProgress.set(emptyId, finalEntry);
			entryId = emptyId;
		} else {
			TF2EventsCommon.destroyProgress.add(finalEntry);
			entryId = TF2EventsCommon.destroyProgress.size() - 1;
		}

	}

	/*if (block instanceof BlockChest) {
		((TileEntityChest) world.getTileEntity(pos)).setLootTable(LootTableList.CHESTS_NETHER_BRIDGE, living.getRNG().nextLong());
	}*/
	float hardness = TF2Util.getHardness(state, world, pos);

	if (!stack.isEmpty() && stack.getItem() instanceof ItemSniperRifle && hardness > 100)
		damage *= 3;
	finalEntry.curDamage += damage;

	if (living != null)
		world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, (int) ((finalEntry.curDamage / hardness) * 10));

	if (finalEntry.curDamage >= hardness) {
		if (living != null && living instanceof EntityPlayer)
			block.harvestBlock(world, (EntityPlayer) living, pos, state, null, stack);
		else {
			block.dropBlockAsItem(world, pos, state, 0);
			block.onBlockExploded(world, pos, explosion);
		}
		TF2EventsCommon.destroyProgress.remove(finalEntry);

		boolean flag = (living == null || !(living instanceof EntityPlayer) && world.isAirBlock(pos)) || block.removedByPlayer(state, world, pos, (EntityPlayer) living, true);

		if (flag) {
			if (living != null) {
				world.playEvent(2001, pos, Block.getStateId(state));
				world.sendBlockBreakProgress(Math.min(Integer.MAX_VALUE, 0xFFFF + entryId), pos, -1);
			}
			block.onBlockDestroyedByPlayer(world, pos, state);

			if (forwardVec != null) {
				RayTraceResult trace = world.rayTraceBlocks(living.getPositionVector().addVector(0, living.getEyeHeight(), 0), forwardVec, false, true, false);
				if (trace != null)
					damageBlock(trace.getBlockPos(), living, world, stack, critical, finalEntry.curDamage - hardness, forwardVec, explosion);
			}
		}
		return finalEntry.curDamage - hardness;
	}
	return 0;
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:73,代码来源:TF2Util.java

示例14: getHardness

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
public static float getHardness(IBlockState state, World world, BlockPos pos) {
	return state.getBlockHardness(world, pos) * (!state.getMaterial().isToolNotRequired() && !(state.getBlock() instanceof BlockStone) ? 12f : 5.5f);
}
 
开发者ID:rafradek,项目名称:Mods,代码行数:4,代码来源:TF2Util.java

示例15: canPush

import net.minecraft.block.state.IBlockState; //导入方法依赖的package包/类
/**
 * Checks if the piston can push the given BlockState.
 */
public static boolean canPush(IBlockState blockStateIn, World worldIn, BlockPos pos, EnumFacing facing, boolean destroyBlocks)
{
    Block block = blockStateIn.getBlock();

    if (block == Blocks.OBSIDIAN)
    {
        return false;
    }
    else if (!worldIn.getWorldBorder().contains(pos))
    {
        return false;
    }
    else if (pos.getY() >= 0 && (facing != EnumFacing.DOWN || pos.getY() != 0))
    {
        if (pos.getY() <= worldIn.getHeight() - 1 && (facing != EnumFacing.UP || pos.getY() != worldIn.getHeight() - 1))
        {
            if (block != Blocks.PISTON && block != Blocks.STICKY_PISTON)
            {
                if (blockStateIn.getBlockHardness(worldIn, pos) == -1.0F)
                {
                    return false;
                }

                if (blockStateIn.getMobilityFlag() == EnumPushReaction.BLOCK)
                {
                    return false;
                }

                if (blockStateIn.getMobilityFlag() == EnumPushReaction.DESTROY)
                {
                    return destroyBlocks;
                }
            }
            else if (((Boolean)blockStateIn.getValue(EXTENDED)).booleanValue())
            {
                return false;
            }

            return !block.hasTileEntity(blockStateIn);
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:54,代码来源:BlockPistonBase.java


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