本文整理汇总了Java中net.minecraft.block.Block.onBlockDestroyedByPlayer方法的典型用法代码示例。如果您正苦于以下问题:Java Block.onBlockDestroyedByPlayer方法的具体用法?Java Block.onBlockDestroyedByPlayer怎么用?Java Block.onBlockDestroyedByPlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.block.Block
的用法示例。
在下文中一共展示了Block.onBlockDestroyedByPlayer方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: onPlayerDestroyBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
/**
* Called when a player completes the destruction of a block
*/
public boolean onPlayerDestroyBlock(BlockPos pos, EnumFacing side)
{
if (this.currentGameType.isAdventure())
{
if (this.currentGameType == WorldSettings.GameType.SPECTATOR)
{
return false;
}
if (!this.mc.thePlayer.isAllowEdit())
{
Block block = this.mc.theWorld.getBlockState(pos).getBlock();
ItemStack itemstack = this.mc.thePlayer.getCurrentEquippedItem();
if (itemstack == null)
{
return false;
}
if (!itemstack.canDestroy(block))
{
return false;
}
}
}
if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItem() != null && this.mc.thePlayer.getHeldItem().getItem() instanceof ItemSword)
{
return false;
}
else
{
World world = this.mc.theWorld;
IBlockState iblockstate = world.getBlockState(pos);
Block block1 = iblockstate.getBlock();
if (block1.getMaterial() == Material.air)
{
return false;
}
else
{
world.playAuxSFX(2001, pos, Block.getStateId(iblockstate));
boolean flag = world.setBlockToAir(pos);
if (flag)
{
block1.onBlockDestroyedByPlayer(world, pos, iblockstate);
}
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
if (!this.currentGameType.isCreative())
{
ItemStack itemstack1 = this.mc.thePlayer.getCurrentEquippedItem();
if (itemstack1 != null)
{
itemstack1.onBlockDestroyed(world, block1, pos, this.mc.thePlayer);
if (itemstack1.stackSize == 0)
{
this.mc.thePlayer.destroyCurrentEquippedItem();
}
}
}
return flag;
}
}
}
示例3: 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;
}
示例4: 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;
}
示例5: onPlayerDestroyBlock
import net.minecraft.block.Block; //导入方法依赖的package包/类
public boolean onPlayerDestroyBlock(BlockPos pos)
{
if (this.currentGameType.isAdventure())
{
if (this.currentGameType == GameType.SPECTATOR)
{
return false;
}
if (!this.mc.thePlayer.isAllowEdit())
{
ItemStack itemstack = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack == null)
{
return false;
}
if (!itemstack.canDestroy(this.mc.theWorld.getBlockState(pos).getBlock()))
{
return false;
}
}
}
ItemStack stack = mc.thePlayer.getHeldItemMainhand();
if (stack != null && stack.getItem() != null && stack.getItem().onBlockStartBreak(stack, pos, mc.thePlayer))
{
return false;
}
if (this.currentGameType.isCreative() && this.mc.thePlayer.getHeldItemMainhand() != null && this.mc.thePlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
{
return false;
}
else
{
World world = this.mc.theWorld;
IBlockState iblockstate = world.getBlockState(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !this.mc.thePlayer.canUseCommandBlock())
{
return false;
}
else if (iblockstate.getMaterial() == Material.AIR)
{
return false;
}
else
{
world.playEvent(2001, pos, Block.getStateId(iblockstate));
this.currentBlock = new BlockPos(this.currentBlock.getX(), -1, this.currentBlock.getZ());
if (!this.currentGameType.isCreative())
{
ItemStack itemstack1 = this.mc.thePlayer.getHeldItemMainhand();
if (itemstack1 != null)
{
itemstack1.onBlockDestroyed(world, iblockstate, pos, this.mc.thePlayer);
if (itemstack1.stackSize <= 0)
{
net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(this.mc.thePlayer, itemstack1, EnumHand.MAIN_HAND);
this.mc.thePlayer.setHeldItem(EnumHand.MAIN_HAND, (ItemStack)null);
}
}
}
boolean flag = block.removedByPlayer(iblockstate, world, pos, mc.thePlayer, false);
if (flag)
{
block.onBlockDestroyedByPlayer(world, pos, iblockstate);
}
return flag;
}
}
}