本文整理汇总了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);
}
示例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);
}
示例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.
}
示例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
}