本文整理汇总了Java中net.minecraft.block.Block.dropBlockAsItem方法的典型用法代码示例。如果您正苦于以下问题:Java Block.dropBlockAsItem方法的具体用法?Java Block.dropBlockAsItem怎么用?Java Block.dropBlockAsItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.block.Block
的用法示例。
在下文中一共展示了Block.dropBlockAsItem方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: destroyBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Sets a block to air, but also plays the sound and particles and can spawn drops
*/
public boolean destroyBlock(BlockPos pos, boolean dropBlock)
{
IBlockState iblockstate = this.getBlockState(pos);
Block block = iblockstate.getBlock();
if (block.getMaterial() == Material.air)
{
return false;
}
else
{
this.playAuxSFX(2001, pos, Block.getStateId(iblockstate));
if (dropBlock)
{
block.dropBlockAsItem(this, pos, iblockstate, 0);
}
return this.setBlockState(pos, Blocks.air.getDefaultState(), 3);
}
}
示例2: destroyBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Sets a block to air, but also plays the sound and particles and can spawn drops
*/
public boolean destroyBlock(BlockPos pos, boolean dropBlock)
{
IBlockState iblockstate = this.getBlockState(pos);
Block block = iblockstate.getBlock();
if (iblockstate.getMaterial() == Material.AIR)
{
return false;
}
else
{
this.playEvent(2001, pos, Block.getStateId(iblockstate));
if (dropBlock)
{
block.dropBlockAsItem(this, pos, iblockstate, 0);
}
return this.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
}
示例3: destroyBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Sets a block to air, but also plays the sound and particles and can spawn drops
*/
public boolean destroyBlock(BlockPos pos, boolean dropBlock)
{
IBlockState iblockstate = this.getBlockState(pos);
Block block = iblockstate.getBlock();
if (block.isAir(iblockstate, this, pos))
{
return false;
}
else
{
this.playEvent(2001, pos, Block.getStateId(iblockstate));
if (dropBlock)
{
block.dropBlockAsItem(this, pos, iblockstate, 0);
}
return this.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
}
}
示例4: explodeBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
public float explodeBlock(World world, BlockPos pos, float power) {
if (world.isAirBlock(pos)) return power;
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block==Blocks.BEDROCK) return 0;
//Just delete fluids without examination or notification so their neighbors don't try to fill them in.
if (isFluid(block)) {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2 | 16);
return power;
}
float resistance = block.getExplosionResistance(world, pos, null, dummyExplosion);
if (resistance>power) return 0;
boolean drop = state.getBlock().canDropFromExplosion(dummyExplosion);
if (drop && world.rand.nextInt(1000)==5) {
block.dropBlockAsItem(world, pos, state, 0);
}
//block.onBlockExploded(world, pos, dummyExplosion); //Also calls onBlockDestroyedByExplosion
if (pos.getY()>4) {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2 | 16); //Observers are blinded by explosions or something
} else {
world.setBlockState(pos, Blocks.AIR.getDefaultState(), 2 | 16); //Don't know if the chest bug still exists, but if it does we'll be safe with this line.
world.setBlockState(pos, Blocks.OBSIDIAN.getDefaultState(), 2 | 16); //If we're that strong, glass the crater floor.
}
return power - (int)(resistance*RESISTANCE_SCALE);
}
示例5: 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.
}
示例6: damageBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
public static float damageBlock(BlockPos pos, EntityLivingBase living, World world, float damage) {
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block.isAir(state, world, pos) || state.getMaterial() == Material.WATER || state.getMaterial() == Material.LAVA || state.getBlockHardness(world, pos) < 0)
return damage;
DestroyBlockEntry finalEntry = null;
int entryId = 0;
int emptyId = -1;
for (int i = 0; i < BlockEventBus.destroyProgress.size(); i++) {
DestroyBlockEntry entry = BlockEventBus.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) {
BlockEventBus.destroyProgress.set(emptyId, finalEntry);
entryId = emptyId;
} else {
BlockEventBus.destroyProgress.add(finalEntry);
entryId = BlockEventBus.destroyProgress.size() - 1;
}
}
/*if (block instanceof BlockChest) {
((TileEntityChest) world.getTileEntity(pos)).setLootTable(LootTableList.CHESTS_NETHER_BRIDGE, living.getRNG().nextLong());
}*/
float hardness = BlockLauncher.getHardness(state, world);
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, ItemStack.EMPTY);
else {
block.dropBlockAsItem(world, pos, state, 0);
}
BlockEventBus.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);
}
return finalEntry.curDamage - hardness;
}
return 0;
}
示例7: 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;
}
示例8: displaceIfPossible
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Attempt to displace the block at (pos), return true if it was displaced.
*/
public boolean displaceIfPossible(World world, BlockPos pos)
{
if (world.isAirBlock(pos))
{
return true;
}
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
if (block == this)
{
return false;
}
if (displacements.containsKey(block))
{
if (displacements.get(block))
{
if (state.getBlock() != Blocks.SNOW_LAYER) //Forge: Vanilla has a 'bug' where snowballs don't drop like every other block. So special case because ewww...
block.dropBlockAsItem(world, pos, state, 0);
return true;
}
return false;
}
Material material = state.getMaterial();
if (material.blocksMovement() || material == Material.PORTAL)
{
return false;
}
int density = getDensity(world, pos);
if (density == Integer.MAX_VALUE)
{
block.dropBlockAsItem(world, pos, state, 0);
return true;
}
if (this.density > density)
{
return true;
}
else
{
return false;
}
}