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


Java Block.getHarvestLevel方法代码示例

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


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

示例1: canHarvestBlock

import net.minecraft.block.Block; //导入方法依赖的package包/类
public static boolean canHarvestBlock(Block block, EntityPlayer player, IBlockAccess world, BlockPos pos)
{
    IBlockState state = world.getBlockState(pos);
    state = state.getBlock().getActualState(state, world, pos);
    if (state.getMaterial().isToolNotRequired())
    {
        return true;
    }

    ItemStack stack = player.inventory.getCurrentItem();
    String tool = block.getHarvestTool(state);
    if (stack == null || tool == null)
    {
        return player.canHarvestBlock(state);
    }

    int toolLevel = stack.getItem().getHarvestLevel(stack, tool, player, state);
    if (toolLevel < 0)
    {
        return player.canHarvestBlock(state);
    }

    return toolLevel >= block.getHarvestLevel(state);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:25,代码来源:ForgeHooks.java

示例2: doMining

import net.minecraft.block.Block; //导入方法依赖的package包/类
void doMining(World world, EntityPlayerMP player, int x, int y, int z)	// Calling this 27 times, to blast mine a 3x3x3 area
{
	Block toBeBroken = world.getBlock(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);

	if (toBeBroken.getBlockHardness(world, x, y, z) == -1) { return; }	// Unbreakable

	if (toBeBroken.getHarvestLevel(meta) > 1) { return; }
	if (toBeBroken.getMaterial() == Material.water) { return; }
	if (toBeBroken.getMaterial() == Material.lava) { return; }
	if (toBeBroken.getMaterial() == Material.air) { return; }
	if (toBeBroken.getMaterial() == Material.portal) { return; }

	// Need to do checks here against invalid blocks
	if (toBeBroken == Blocks.water) { return; }
	if (toBeBroken == Blocks.flowing_water) { return; }
	if (toBeBroken == Blocks.lava) { return; }
	if (toBeBroken == Blocks.flowing_lava) { return; }
	if (toBeBroken == Blocks.obsidian) { return; }
	if (toBeBroken == Blocks.mob_spawner) { return; }

	// Crashing blocks: Redstone Lamp, Extended Piston
	// They're likely trying to drop things that cannot be dropped (active states of themselves)

	//WorldSettings.GameType gametype = WorldSettings.GameType.getByName("survival");
	WorldSettings.GameType gametype = world.getWorldInfo().getGameType();
	BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, gametype, player, x, y, z);

	if (event.isCanceled()) { return; }	// Not allowed to do this

	//toBeBroken.dropBlockAsItem(world, x, x, z, meta, 0);	// The last one is Fortune

	boolean removalSuccess = world.setBlockToAir(x, y, z);
	if (removalSuccess) { toBeBroken.onBlockDestroyedByPlayer(world, x, y, z, meta); }

	Item preBlockItem = toBeBroken.getItemDropped(meta, player.getRNG(), 0);

	if (preBlockItem == null) { return; }	// Item doesn't exist

	ItemStack blockItem = new ItemStack(preBlockItem);

	blockItem.setItemDamage(meta);

	EntityItem entityItem = new EntityItem(world, x, y + 0.5d, z, blockItem);
	entityItem.delayBeforeCanPickup = 10;

	world.spawnEntityInWorld(entityItem);
}
 
开发者ID:Domochevsky,项目名称:minecraft-quiverbow,代码行数:49,代码来源:PowderKnuckle_Mod.java

示例3: onImpact

import net.minecraft.block.Block; //导入方法依赖的package包/类
@Override
public void onImpact(MovingObjectPosition target)
{
	if (target.entityHit != null) 		// We hit a living thing!
   	{		
		// Damage
		target.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), (float)this.damage);
       }
	else	// Hit the terrain
   	{
   		Block block = this.worldObj.getBlock(target.blockX, target.blockY, target.blockZ);            
           int meta = this.worldObj.getBlockMetadata(target.blockX, target.blockY, target.blockZ);
           
           boolean breakThis = true;
           
           // Checking here against invalid blocks
       	if (block == Blocks.bedrock) { breakThis = false; }
       	else if (block == Blocks.water) { breakThis = false; }
       	else if (block == Blocks.flowing_water) { breakThis = false; }
       	else if (block == Blocks.lava) { breakThis = false; }
       	else if (block == Blocks.flowing_lava) { breakThis = false; }
       	else if (block == Blocks.obsidian) { breakThis = false; }
       	else if (block == Blocks.mob_spawner) { breakThis = false; }
       	
       	else if (block.getMaterial() == Material.water) { breakThis = false; }
       	else if (block.getMaterial() == Material.lava) { breakThis = false; }
       	else if (block.getMaterial() == Material.air) { breakThis = false; }
       	else if (block.getMaterial() == Material.portal) { breakThis = false; }
       	
       	else if (block.getHarvestLevel(meta) > 0) { breakThis = false; }
       	else if (block.getBlockHardness(this.worldObj, target.blockX, target.blockY, target.blockZ) > 3) { breakThis = false; }
       	
       	if (this.shootingEntity instanceof EntityPlayerMP)
       	{
       		WorldSettings.GameType gametype = this.worldObj.getWorldInfo().getGameType();
           	BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(this.worldObj, gametype, (EntityPlayerMP) this.shootingEntity, target.blockX, target.blockY, target.blockZ);
              
           	if (event.isCanceled()) { breakThis = false; }	// Not allowed to do this
       	}
           
           if (breakThis)	// Nothing preventing us from breaking this block!
           {            	
           	this.worldObj.setBlockToAir(target.blockX, target.blockY, target.blockZ);
           	block.dropBlockAsItem(this.worldObj, target.blockX, target.blockY, target.blockZ, meta, 0);
           }
   	}
	
	// SFX
	for (int i = 0; i < 4; ++i) { this.worldObj.spawnParticle("smoke", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D); }
	this.worldObj.playSoundAtEntity(this, Block.soundTypeGravel.getBreakSound(), 1.0F, 1.0F);
	
	this.setDead();	// Hit something, so begone.
}
 
开发者ID:Domochevsky,项目名称:minecraft-quiverbow,代码行数:54,代码来源:FlintDust.java

示例4: onImpact

import net.minecraft.block.Block; //导入方法依赖的package包/类
@Override
public void onImpact(MovingObjectPosition target)
{
	if (target.entityHit != null) 		// We hit a living thing!
   	{		
		// Damage
		target.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), (float)this.damage);
           target.entityHit.hurtResistantTime = 0;	// No immunity frames
           this.targetsHit += 1;					// Punched through one more entity
           
           // Bonus
           EntityLightningBolt bolt = new EntityLightningBolt(this.worldObj, target.entityHit.posX, target.entityHit.posY, target.entityHit.posZ);
           this.worldObj.addWeatherEffect(bolt);
       }
	else
	{
		// Let's blast through terrain on hit
		
		int x = target.blockX;
		int y = target.blockY;
		int z = target.blockZ;
		
		Block toBeBroken = this.worldObj.getBlock(x, y, z);
		int meta = this.worldObj.getBlockMetadata(x, y, z);
		
		boolean breakThis = true;
		
		if (toBeBroken.getHarvestLevel(meta) > 1) 
		{ 
			breakThis = false; 
			this.targetsHit += 1;	// Thicker materials
		}
		
		if (toBeBroken.getHarvestLevel(meta) > 2) 
		{ 
			breakThis = false; 
			this.targetsHit += 2;	// Even thicker materials
		}
		
		if (toBeBroken.getHarvestLevel(meta) > 3) 
		{ 
			breakThis = false; 
			this.targetsHit += 3;	// Super thick material
		}
		
    	if (toBeBroken.getMaterial() == Material.water) { breakThis = false; }
    	
    	if (toBeBroken == Blocks.water) { breakThis = false; }
    	if (toBeBroken == Blocks.flowing_water) { breakThis = false; }
    	
    	if (toBeBroken == Blocks.obsidian) 
    	{ 
    		breakThis = false; 
    		this.targetsHit += 2;	// Thicker materials
    	}
    	
    	if (toBeBroken == Blocks.iron_block) 
    	{ 
    		breakThis = false; 
    		this.targetsHit += 2;	// Thicker materials
    	}
    	
    	if (breakThis)	// Sorted out all blocks we don't want to break. Checking the rest now
    	{
    		// Glass breaking
        	Helper.tryBlockBreak(this.worldObj, this, target, 3);	// Very Strong
    	}
		
		this.targetsHit += 1;	// Punched through one more block, no matter if we managed to break it
	}
	
	// SFX
	NetHelper.sendParticleMessageToAllPlayers(this.worldObj, this.getEntityId(), (byte) 10, (byte) 2);
	this.worldObj.playSoundAtEntity(this, "ambient.weather.thunder", 0.7F, 0.5F);
	
	if (this.targetsHit > this.targetsHitMax) { this.setDead(); }	// Went through the maximum, so ending now
}
 
开发者ID:Domochevsky,项目名称:minecraft-quiverbow,代码行数:78,代码来源:RedLight.java


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