當前位置: 首頁>>代碼示例>>Java>>正文


Java Blocks.tnt方法代碼示例

本文整理匯總了Java中net.minecraft.init.Blocks.tnt方法的典型用法代碼示例。如果您正苦於以下問題:Java Blocks.tnt方法的具體用法?Java Blocks.tnt怎麽用?Java Blocks.tnt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.init.Blocks的用法示例。


在下文中一共展示了Blocks.tnt方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: catchOnFire

import net.minecraft.init.Blocks; //導入方法依賴的package包/類
private void catchOnFire(World worldIn, BlockPos pos, int chance, Random random, int age)
{
    int i = this.getFlammability(worldIn.getBlockState(pos).getBlock());

    if (random.nextInt(chance) < i)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);

        if (random.nextInt(age + 10) < 5 && !worldIn.canLightningStrike(pos))
        {
            int j = age + random.nextInt(5) / 4;

            if (j > 15)
            {
                j = 15;
            }

            worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(j)), 3);
        }
        else
        {
            worldIn.setBlockToAir(pos);
        }

        if (iblockstate.getBlock() == Blocks.tnt)
        {
            Blocks.tnt.onBlockDestroyedByPlayer(worldIn, pos, iblockstate.withProperty(BlockTNT.EXPLODE, Boolean.valueOf(true)));
        }
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:31,代碼來源:BlockFire.java

示例2: onImpact

import net.minecraft.init.Blocks; //導入方法依賴的package包/類
@Override
public void onImpact(MovingObjectPosition target)	// Server-side
{
	if (target.entityHit != null) 	// Hit a entity
   	{
		// Damage
		target.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.shootingEntity), (float)this.damage);
		target.entityHit.hurtResistantTime = 0; // No immunity frames
		
		// Knockback
           double f3 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
           if (f3 > 0.0F) 
           {
           	target.entityHit.addVelocity(
       			this.motionX * (double)this.knockbackStrength * 0.6000000238418579D / (double)f3, 
       			0.1D, 
       			this.motionZ * (double)this.knockbackStrength * 0.6000000238418579D / (double)f3
           	);
           }
           
		// Effect
		if ( !(target.entityHit instanceof EntityEnderman) ) { target.entityHit.setFire(this.fireDuration); } 
		
		this.setDead();	
		
	}
	else 	// Hit a block
	{ 
		Block block = this.worldObj.getBlock(target.blockX, target.blockY, target.blockZ);
		
		// Glass breaking, once
		if (Helper.tryBlockBreak(this.worldObj, this, target, 1) && this.targetsHit < 1) { this.targetsHit += 1; }
		else { this.setDead(); }	// else, either we didn't break that block or we already hit one entity
           
		// Let's ignite TNT explicitly here.
		if (block == Blocks.tnt)
		{
			this.worldObj.setBlockToAir(target.blockX, target.blockY, target.blockZ); // setBlockToAir
              
			EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(this.worldObj, 
               		(double)((float)target.blockX + 0.5F), 
               		(double)((float)target.blockY + 0.5F), 
               		(double)((float)target.blockZ + 0.5F), 
               		this.shootingEntity);									

               this.worldObj.spawnEntityInWorld(entitytntprimed);			// This is TNT, so begone with that block and replace it with primed TNT
               
               this.worldObj.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F);
		}
		// else, block is not TNT
	} 
	
	if (!this.isInWater()) // Only explode if we're not in water
	{																			
		boolean griefing = true;	// Allowed by default
		
		if (this.shootingEntity instanceof EntityPlayer)
		{
			griefing = this.dmgTerrain;	// It's up to player settings to allow/forbid this
		}
		else
		{
			griefing = this.worldObj.getGameRules().getGameRuleBooleanValue("mobGriefing");	// Are we allowed to break things?
		}
		
		this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, (float) this.explosionSize, griefing); 	
		// 4.0F is TNT, false is for "not flaming"
		// Editchevsky: Actually, false is double-used for "don't damage terrain"
	}
}
 
開發者ID:Domochevsky,項目名稱:minecraft-quiverbow,代碼行數:71,代碼來源:SmallRocket.java


注:本文中的net.minecraft.init.Blocks.tnt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。