net.minecraft.block.Block.onBlockDestroyedByPlayer()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中net.minecraft.block.Block.onBlockDestroyedByPlayer()方法的一些代码示例,展示了Block.onBlockDestroyedByPlayer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Block.onBlockDestroyedByPlayer()方法的具体详情如下:
包路径:net.minecraft.block.Block
类名称:Block
方法名:onBlockDestroyedByPlayer

Block.onBlockDestroyedByPlayer介绍

暂无

代码示例

代码示例来源:origin: TheGreyGhost/MinecraftByExample

@Override
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {
 StartupCommon.methodCallLogger.enterMethod("BlockToolTest.onBlockDestroyedByPlayer",
     "{world}, " + pos + ", " + String.valueOf(state));
 super.onBlockDestroyedByPlayer(worldIn, pos, state);
 StartupCommon.methodCallLogger.exitMethod("BlockToolTest.onBlockDestroyedByPlayer", "");
 return;
}

代码示例来源:origin: OpenMods/OpenModsLib

private boolean removeBlock(EntityPlayer player, BlockPos pos, IBlockState state, boolean canHarvest) {
  final Block block = state.getBlock();
  final boolean result = block.removedByPlayer(state, worldObj, pos, player, canHarvest);
  if (result) block.onBlockDestroyedByPlayer(worldObj, pos, state);
  return result;
}

代码示例来源:origin: vadis365/TheErebus

@Override
public void onBlockDestroyedByPlayer(World world, BlockPos pos, IBlockState state) {
  if (!world.isRemote)
    if (world.rand.nextInt(5) == 0) {
      EntityWoodlouse entity = new EntityWoodlouse(world);
      entity.setLocationAndAngles(pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, 0.0F, 0.0F);
      world.spawnEntity(entity);
    }
  super.onBlockDestroyedByPlayer(world, pos, state);
}

代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition

@Override
public ArrayList<ItemStack> dismantleBlock(EntityPlayer player, World world, BlockPos pos, boolean returnDrops) {
  IBlockState blockState = world.getBlockState(pos);
  ItemStack blockItem = new ItemStack(getItemDropped(blockState, world.rand, 1));
  boolean flag = blockState.getBlock().removedByPlayer(blockState, world, pos, player, true);
  super.breakBlock(world, pos, blockState);
  if (flag) {
    blockState.getBlock().onBlockDestroyedByPlayer(world, pos, blockState);
  }
  if (!returnDrops) {
    dropBlockAsItem(world, pos, blockState, 0);
  } else {
    MOInventoryHelper.insertItemStackIntoInventory(player.inventory, blockItem, EnumFacing.DOWN);
  }
  ArrayList<ItemStack> list = new ArrayList<>();
  list.add(blockItem);
  return list;
}

代码示例来源:origin: TheGreyGhost/MinecraftByExample

@Override
  public void update() {
    if (!this.hasWorld()) return;  // prevent crash
    World world = this.getWorld();
    if (world.isRemote) return;   // don't bother doing anything on the client side.
    if (ticksLeftTillDisappear == INVALID_VALUE) return;  // do nothing until the time is valid
    --ticksLeftTillDisappear;
//        this.markDirty();            // if you update a tileentity variable on the server and this should be communicated to the client,
//                                                                         you need to markDirty() to force a resend.  In this case, the client doesn't need to know
    if (ticksLeftTillDisappear > 0) return;   // not ready yet

    Block [] blockChoices = {Blocks.DIAMOND_BLOCK, Blocks.OBSIDIAN, Blocks.AIR, Blocks.TNT, Blocks.YELLOW_FLOWER, Blocks.SAPLING, Blocks.WATER};
    Random random = new Random();
    Block chosenBlock = blockChoices[random.nextInt(blockChoices.length)];
   world.setBlockState(this.pos, chosenBlock.getDefaultState());
    if (chosenBlock == Blocks.TNT) {
      Blocks.TNT.onBlockDestroyedByPlayer(world, pos, Blocks.TNT.getDefaultState().withProperty(BlockTNT.EXPLODE, true));
      world.setBlockToAir(pos);
    } else if (chosenBlock == Blocks.SAPLING) {
      BlockSapling blockSapling = (BlockSapling)Blocks.SAPLING;
      blockSapling.generateTree(world, this.pos, blockSapling.getDefaultState(),random);
    }
  }

代码示例来源:origin: SleepyTrousers/EnderIO

if (exp != -1 && block.canHarvestBlock(world, target, player)) {
 if (block.removedByPlayer(blockstate, world, target, player, true)) {
  block.onBlockDestroyedByPlayer(world, target, blockstate);
  block.harvestBlock(world, player, target, blockstate, null, item);
  if (!gameType.isCreative() && exp > 0) {

代码示例来源:origin: GregTechCE/GregTech

private boolean tryBreakRailBlock(IBlockState blockState, World world, BlockPos blockPos, EntityPlayer player) {
  if (world.canMineBlockBody(player, blockPos) && blockState.getBlock().canHarvestBlock(world, blockPos, player)) {
    for (ItemStack drops : blockState.getBlock().getDrops(world, blockPos, blockState, 0)) {
      Block.spawnAsEntity(world, blockPos, drops);
    }
    blockState.getBlock().onBlockDestroyedByPlayer(world, blockPos, blockState);
    blockState.getBlock().onBlockHarvested(world, blockPos, blockState, player);
    blockState.getBlock().breakBlock(world, blockPos, blockState);
    world.setBlockToAir(blockPos);
    return true;
  }
  return false;
}

代码示例来源:origin: CoFH/CoFHCore

if (!world.isRemote) {
    if (block.removedByPlayer(state, world, pos, player, false)) {
      block.onBlockDestroyedByPlayer(world, pos, state);
  } else {
    if (block.removedByPlayer(state, world, pos, player, false)) {
      block.onBlockDestroyedByPlayer(world, pos, state);
    block.onBlockDestroyedByPlayer(world, pos, state);
    block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), player.getHeldItemMainhand());
    if (xpToDrop > 0) {
} else {
  if (block.removedByPlayer(state, world, pos, player, true)) {
    block.onBlockDestroyedByPlayer(world, pos, state);

代码示例来源:origin: MatterOverdrive/MatterOverdrive-Legacy-Edition

blockState.getBlock().onBlockDestroyedByPlayer(world, pos, blockState);

代码示例来源:origin: Vazkii/Quark

block.onBlockDestroyedByPlayer(world, pos, state.withProperty(BlockTNT.EXPLODE, Boolean.valueOf(true)));
world.setBlockToAir(pos);

代码示例来源:origin: CoFH/CoFHCore

block.onBlockDestroyedByPlayer(world, pos, state);
    if (!player.capabilities.isCreativeMode) {
      block.harvestBlock(world, player, pos, state, world.getTileEntity(pos), player.getHeldItemMainhand());
} else {
  if (block.removedByPlayer(state, world, pos, player, !player.capabilities.isCreativeMode)) {
    block.onBlockDestroyedByPlayer(world, pos, state);

代码示例来源:origin: CyclopsMC/EvilCraft

block.onBlockDestroyedByPlayer(world, pos, blockState);
  block.harvestBlock(world, player, pos, blockState, world.getTileEntity(pos), null);
  block.dropXpOnBlockBreak(world, pos, expToDrop);
block.onBlockDestroyedByPlayer(world, pos, blockState);

代码示例来源:origin: Vazkii/Psi

public static void removeBlockWithDrops(SpellContext context, EntityPlayer player, World world, ItemStack tool, BlockPos pos, boolean particles) {
  if(!world.isBlockLoaded(pos) || (context.positionBroken != null && pos.equals(context.positionBroken.getBlockPos())) || !world.isBlockModifiable(player, pos))
    return;
  if (tool.isEmpty())
    tool = PsiAPI.getPlayerCAD(player);
  IBlockState state = world.getBlockState(pos);
  Block block = state.getBlock();
  if(!world.isRemote && !block.isAir(state, world, pos) && !(block instanceof BlockLiquid) && !(block instanceof IFluidBlock) && state.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
    if(!canHarvestBlock(block, player, world, pos, tool))
      return;
    BreakEvent event = createBreakEvent(state, player, world, pos, tool);
    MinecraftForge.EVENT_BUS.post(event);
    if(!event.isCanceled()) {
      if(!player.capabilities.isCreativeMode) {
        TileEntity tile = world.getTileEntity(pos);
        if(block.removedByPlayer(state, world, pos, player, true)) {
          block.onBlockDestroyedByPlayer(world, pos, state);
          block.harvestBlock(world, player, pos, state, tile, tool);
        }
      } else world.setBlockToAir(pos);
    }
    if(particles)
      world.playEvent(2001, pos, Block.getStateId(state));
  }
}

代码示例来源:origin: PenguinSquad/Harvest-Festival

boolean flag = state.getBlock().removedByPlayer(state, worldIn, newPos, player, true);
if (flag) {
  state.getBlock().onBlockDestroyedByPlayer(worldIn, newPos, state);
  state.getBlock().harvestBlock(worldIn, player, newPos, state, worldIn.getTileEntity(newPos), stack);

相关文章

Block类方法