本文整理汇总了Java中net.minecraft.block.Block.getBlockHardness方法的典型用法代码示例。如果您正苦于以下问题:Java Block.getBlockHardness方法的具体用法?Java Block.getBlockHardness怎么用?Java Block.getBlockHardness使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.block.Block
的用法示例。
在下文中一共展示了Block.getBlockHardness方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBlockDestroyed
import net.minecraft.block.Block; //导入方法依赖的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, Block blockIn, BlockPos pos, EntityLivingBase playerIn)
{
if ((double)blockIn.getBlockHardness(worldIn, pos) != 0.0D)
{
stack.damageItem(2, playerIn);
}
return true;
}
示例2: onBlockDestroyed
import net.minecraft.block.Block; //导入方法依赖的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, Block blockIn, BlockPos pos, EntityLivingBase playerIn)
{
if ((double)blockIn.getBlockHardness(worldIn, pos) != 0.0D)
{
stack.damageItem(1, playerIn);
}
return true;
}
示例3: 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);
}
示例4: breakBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public void breakBlock(EnumFacing facing) {
BlockPos newPos = pos.offset(facing, 1);
IBlockState state = this.world.getBlockState(newPos);
Block block = state.getBlock();
if (!block.isAir(state, this.world, newPos) && block.getBlockHardness(state, this.world, newPos) >= 0
&& !(block instanceof BlockDynamicLiquid) && !(block instanceof BlockStaticLiquid)) {
// Creates a fake player which will berak the block
EntityPlayer player = new EntityPlayer(world, new GameProfile(null, "BlockBreaker")) {
@Override
public boolean isSpectator() {
return true;
}
@Override
public boolean isCreative() {
return false;
}
};
List<ItemStack> drops = new ArrayList<ItemStack>();
boolean customDrops = false;
if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) {
ItemStack enchantedBook = this.handler.getStackInSlot(9);
Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedBook);
if (enchantments.containsKey(Enchantments.FORTUNE)) {
int fortune = enchantments.get(Enchantments.FORTUNE);
drops.add(new ItemStack(block.getItemDropped(state, this.random, fortune),
block.quantityDroppedWithBonus(fortune, this.random), block.damageDropped(state)));
customDrops = true;
}
if (enchantments.containsKey(Enchantments.SILK_TOUCH)
&& block.canSilkHarvest(world, newPos, state, player)) {
// HARD FIX FOR LAPIS
if (block == Blocks.LAPIS_ORE)
drops.add(new ItemStack(block, 1));
else
drops.add(new ItemStack(block, 1, block.damageDropped(state)));
customDrops = true;
}
}
if (!customDrops)
drops = block.getDrops(world, newPos, state, 0);
for (ItemStack stack : drops) {
Utils.addStackToInventory(this.handler, 9, stack, false);
}
if (!Utils.isInventoryFull(this.handler, 9)) {
this.world.playEvent(2001, pos, Block.getStateId(state));
this.world.playSound(null, pos, block.getSoundType(state, world, newPos, player).getBreakSound(),
SoundCategory.BLOCKS, 1, 1);
this.world.setBlockToAir(newPos);
if (block == Blocks.ICE)
this.world.setBlockState(newPos, Blocks.FLOWING_WATER.getDefaultState());
}
}
}
示例5: getBlockHardness
import net.minecraft.block.Block; //导入方法依赖的package包/类
@Deprecated
public static float getBlockHardness(Block block) {
//return (Float)getValue(fBlockHardness, block);
return block.getBlockHardness(null, null, null);
}
示例6: 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.
}