本文整理汇总了Java中net.minecraft.block.Block.onBlockExploded方法的典型用法代码示例。如果您正苦于以下问题:Java Block.onBlockExploded方法的具体用法?Java Block.onBlockExploded怎么用?Java Block.onBlockExploded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.block.Block
的用法示例。
在下文中一共展示了Block.onBlockExploded方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: damageBlock
import net.minecraft.block.Block; //导入方法依赖的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;
}
示例2: doExplosionB
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Does the second part of the explosion (sound, particles, drop spawn)
*/
@Override
public void doExplosionB(boolean spawnParticles) {
this.world.playSound((EntityPlayer) null, this.explosionX, this.explosionY, this.explosionZ,
SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, this.getExplosivePlacedBy() instanceof EntityPlayer ? 4.0F : 1.0F,
(1.0F + (this.world.rand.nextFloat() - this.world.rand.nextFloat()) * 0.2F) * 0.7F);
if (this.explosionSize >= 2.0F && this.isSmoking)
this.world.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.explosionX, this.explosionY,
this.explosionZ, 1.0D, 0.0D, 0.0D, new int[0]);
else
this.world.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.explosionX, this.explosionY,
this.explosionZ, 1.0D, 0.0D, 0.0D, new int[0]);
if (this.isSmoking && TF2ConfigVars.destTerrain == 2)
for (BlockPos blockpos : this.affectedBlockPositions) {
IBlockState iblockstate = this.world.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (spawnParticles) {
double d0 = blockpos.getX() + this.world.rand.nextFloat();
double d1 = blockpos.getY() + this.world.rand.nextFloat();
double d2 = blockpos.getZ() + this.world.rand.nextFloat();
double d3 = d0 - this.explosionX;
double d4 = d1 - this.explosionY;
double d5 = d2 - this.explosionZ;
double d6 = MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
d3 = d3 / d6;
d4 = d4 / d6;
d5 = d5 / d6;
double d7 = 0.5D / (d6 / this.explosionSize + 0.1D);
d7 = d7 * (this.world.rand.nextFloat() * this.world.rand.nextFloat() + 0.3F);
d3 = d3 * d7;
d4 = d4 * d7;
d5 = d5 * d7;
this.world.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, (d0 + this.explosionX) / 2.0D,
(d1 + this.explosionY) / 2.0D, (d2 + this.explosionZ) / 2.0D, d3, d4, d5, new int[0]);
this.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5, new int[0]);
}
if (iblockstate.getMaterial() != Material.AIR) {
if (block.canDropFromExplosion(this))
block.dropBlockAsItemWithChance(this.world, blockpos, this.world.getBlockState(blockpos),
1.0F / this.explosionSize, 0);
block.onBlockExploded(this.world, blockpos, this);
}
}
if (this.isFlaming)
for (BlockPos blockpos1 : this.affectedBlockPositions)
if (this.world.getBlockState(blockpos1).getMaterial() == Material.AIR
&& this.world.getBlockState(blockpos1.down()).isFullBlock()
&& this.explosionRNG.nextInt(3) == 0)
this.world.setBlockState(blockpos1, Blocks.FIRE.getDefaultState());
}
示例3: doExplosionB
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Does the second part of the explosion (sound, particles, drop spawn)
*/
public void doExplosionB(boolean spawnParticles)
{
this.worldObj.playSound((EntityPlayer)null, this.explosionX, this.explosionY, this.explosionZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (this.worldObj.rand.nextFloat() - this.worldObj.rand.nextFloat()) * 0.2F) * 0.7F);
if (this.explosionSize >= 2.0F && this.isSmoking)
{
this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D, new int[0]);
}
else
{
this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, this.explosionX, this.explosionY, this.explosionZ, 1.0D, 0.0D, 0.0D, new int[0]);
}
if (this.isSmoking)
{
for (BlockPos blockpos : this.affectedBlockPositions)
{
IBlockState iblockstate = this.worldObj.getBlockState(blockpos);
Block block = iblockstate.getBlock();
if (spawnParticles)
{
double d0 = (double)((float)blockpos.getX() + this.worldObj.rand.nextFloat());
double d1 = (double)((float)blockpos.getY() + this.worldObj.rand.nextFloat());
double d2 = (double)((float)blockpos.getZ() + this.worldObj.rand.nextFloat());
double d3 = d0 - this.explosionX;
double d4 = d1 - this.explosionY;
double d5 = d2 - this.explosionZ;
double d6 = (double)MathHelper.sqrt_double(d3 * d3 + d4 * d4 + d5 * d5);
d3 = d3 / d6;
d4 = d4 / d6;
d5 = d5 / d6;
double d7 = 0.5D / (d6 / (double)this.explosionSize + 0.1D);
d7 = d7 * (double)(this.worldObj.rand.nextFloat() * this.worldObj.rand.nextFloat() + 0.3F);
d3 = d3 * d7;
d4 = d4 * d7;
d5 = d5 * d7;
this.worldObj.spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, (d0 + this.explosionX) / 2.0D, (d1 + this.explosionY) / 2.0D, (d2 + this.explosionZ) / 2.0D, d3, d4, d5, new int[0]);
this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, d3, d4, d5, new int[0]);
}
if (iblockstate.getMaterial() != Material.AIR)
{
if (block.canDropFromExplosion(this))
{
block.dropBlockAsItemWithChance(this.worldObj, blockpos, this.worldObj.getBlockState(blockpos), 1.0F / this.explosionSize, 0);
}
block.onBlockExploded(this.worldObj, blockpos, this);
}
}
}
if (this.isFlaming)
{
for (BlockPos blockpos1 : this.affectedBlockPositions)
{
if (this.worldObj.getBlockState(blockpos1).getMaterial() == Material.AIR && this.worldObj.getBlockState(blockpos1.down()).isFullBlock() && this.explosionRNG.nextInt(3) == 0)
{
this.worldObj.setBlockState(blockpos1, Blocks.FIRE.getDefaultState());
}
}
}
}