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

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

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

Block.getDrops介绍

暂无

代码示例

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public static ItemStack[] getBlockDrops( final World w, final BlockPos pos )
{
  List<ItemStack> out = new ArrayList<>();
  final IBlockState state = w.getBlockState( pos );
  if( state != null )
  {
    out = state.getBlock().getDrops( w, pos, state, 0 );
  }
  if( out == null )
  {
    return new ItemStack[0];
  }
  return out.toArray( new ItemStack[out.size()] );
}

代码示例来源:origin: SlimeKnights/TinkersConstruct

private void explodeBlock(BlockPos pos) {
  IBlockState state = world.getBlockState(pos);
  Block block = state.getBlock();
  if(!world.isRemote && block.canDropFromExplosion(explosion)) {
   List<ItemStack> drops = block.getDrops(world, pos, state, 0);
   ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, 0, 1f, false, null);
   droppedItems.addAll(drops);
  }

  if(world instanceof WorldServer) {
   ((WorldServer) world).spawnParticle(EnumParticleTypes.EXPLOSION_NORMAL, true, pos.getX(), pos.getY(), pos.getZ(), 2, 0, 0, 0, 0d);
   ((WorldServer) world).spawnParticle(EnumParticleTypes.SMOKE_LARGE, true, pos.getX(), pos.getY(), pos.getZ(), 1, 0, 0, 0, 0d);
  }

  block.onBlockExploded(world, pos, explosion);
 }
}

代码示例来源:origin: SlimeKnights/TinkersConstruct

public GuiTinkerStation(World world, BlockPos pos, ContainerTinkerStation<?> container) {
 super(container);
 this.world = world;
 this.container = container;
 tinkerTabs = new GuiTinkerTabs(this, container);
 addModule(tinkerTabs);
 // add tab data
 if(container.hasCraftingStation) {
  for(Pair<BlockPos, IBlockState> pair : container.tinkerStationBlocks) {
   IBlockState state = pair.getRight();
   BlockPos blockPos = pair.getLeft();
   ItemStack stack = state.getBlock().getDrops(world, blockPos, state, 0).get(0);
   tinkerTabs.addTab(stack, blockPos);
  }
 }
 // preselect the correct tab
 for(int i = 0; i < tinkerTabs.tabData.size(); i++) {
  if(tinkerTabs.tabData.get(i).equals(pos)) {
   tinkerTabs.tabs.selected = i;
  }
 }
}

代码示例来源:origin: SlimeKnights/TinkersConstruct

state.getBlock().getDrops(drops, world, pos, state, fortune);
chance = ForgeEventFactory.fireBlockHarvesting(drops, world, pos, state, fortune, chance, false, player);

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

@Override
public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
 StartupCommon.methodCallLogger.enterMethod("BlockToolTest.getDrops",
     "{world}, " + pos + ", " + String.valueOf(state) + ", " + fortune);
 List<ItemStack> result = super.getDrops(world, pos, state, fortune);
 String resultString = "";
 for (ItemStack itemStack : result) {
  resultString += String.valueOf(itemStack) + "; ";
 }
 StartupCommon.methodCallLogger.exitMethod("BlockToolTest.getDrops", String.valueOf(result));
 return result;
}

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

if(!burst.isFake()) {
  NonNullList<ItemStack> items = NonNullList.create();
  block.getDrops(items, world, collidePos, world.getBlockState(collidePos), 0);
  float chance = net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(items, world, collidePos, state, 0, 1.0f, false, null);

代码示例来源:origin: ForestryMC/ForestryMC

public static List<ItemStack> getBlockDrops(World world, BlockPos posBlock) {
  IBlockState blockState = world.getBlockState(posBlock);
  return blockState.getBlock().getDrops(world, posBlock, blockState, 0);
}

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

@Override
public void getDrops(@Nonnull NonNullList<ItemStack> drops, @Nonnull IBlockAccess world, @Nonnull BlockPos pos, @Nonnull IBlockState state, int fortune) {
 NNList<ItemStack> drops2 = new NNList<>();
 super.getDrops(drops2, world, pos, state, fortune);
 for (ItemStack drop : drops2) {
  PaintUtil.setSourceBlock(NullHelper.notnullM(drop, "null stack from getDrops()"), getPaintSource(state, world, pos));
 }
 drops.addAll(drops2);
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

protected NonNullList<ItemStack> getDrops(World world, IBlockState state, BlockPos pos, int fortune) {
  //using deprecated getDrops here just because of pam's harvestcraft, change to proper one in the future
  return InventoryTools.toNonNullList(state.getBlock().getDrops(world, pos, state, fortune));
}

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

@Override
public int convertBlockDrops(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer harvester, List<ItemStack> drops, boolean recursive) {
  if (blockState.getBlock().isLeaves(blockState, world, blockPos)) {
    drops.clear(); //clear previous drops to avoid possible issues
    NonNullList<ItemStack> dropsNonNull = NonNullList.create();
    blockState.getBlock().getDrops(dropsNonNull, world, blockPos, blockState, 10);
    drops.addAll(dropsNonNull);
  }
  return 0;
}

代码示例来源:origin: Esteemed-Innovation/Esteemed-Innovation

@Override
  public void onPlayerHarvestDropsWithTool(BlockEvent.HarvestDropsEvent event, @Nonnull ItemStack toolStack, @Nonnull ItemStack thisUpgradeStack) {
    BlockPos pos = event.getPos();
    EntityPlayer player = event.getHarvester();
    World world = event.getWorld();
    IBlockState state = event.getState();
    Block block = state.getBlock();

    event.getDrops().clear();
    event.getDrops().addAll(block.getDrops(world, pos, state, EnchantmentUtility.getFortuneModifier(player) + 2));
  }
}

代码示例来源:origin: Ellpeck/ActuallyAdditions

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune){
  Block normal = state.getValue(TYPE).getNormalVersion();
  normal.getDrops(drops, world, pos, normal.getDefaultState().withProperty(BlockCrops.AGE, 7), fortune);
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

private boolean harvestBlock(BlockPos current) {
  IBlockState state = world.getBlockState(current);
  Block block = state.getBlock();
  NonNullList<ItemStack> stacks = NonNullList.create();
  block.getDrops(stacks, world, current, state, getFortune());
  if (!InventoryTools.insertItems(mainInventory, stacks, true).isEmpty()) {
    return false;
  }
  if (!BlockTools.breakBlockNoDrops(world, current, state)) {
    return false;
  }
  InventoryTools.insertOrDropItems(mainInventory, stacks, world, current);
  return true;
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

@Override
public boolean pick(World world, IBlockState state, BlockPos pos, int fortune, IItemHandler inventory) {
  NonNullList<ItemStack> drops = NonNullList.create();
  state.getBlock().getDrops(drops, world, pos, state, fortune);
  if (drops.isEmpty() || !InventoryTools.canInventoryHold(inventory, drops)) {
    return false;
  }
  BlockTools.breakBlock(world, pos, fortune, false);
  InventoryTools.insertOrDropItems(inventory, drops, world, pos);
  return true;
}

代码示例来源:origin: sinkillerj/ProjectE

public static List<ItemStack> getBlockDrops(World world, EntityPlayer player, IBlockState state, ItemStack stack, BlockPos pos)
{
  if (EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, stack) > 0 && state.getBlock().canSilkHarvest(world, pos, state, player))
  {
    return Lists.newArrayList(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)));
  }
  return state.getBlock().getDrops(world, pos, state, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, stack));
}

代码示例来源:origin: WayofTime/BloodMagic

private void placeInInventory(IBlockState choppedState, World world, BlockPos choppedPos, @Nullable IItemHandler inventory) {
    if (inventory == null)
      return;

    for (ItemStack stack : choppedState.getBlock().getDrops(world, choppedPos, world.getBlockState(choppedPos), 0)) {
      ItemStack remainder = ItemHandlerHelper.insertItem(inventory, stack, false);
      if (!remainder.isEmpty())
        world.spawnEntity(new EntityItem(world, choppedPos.getX() + 0.4, choppedPos.getY() + 2, choppedPos.getZ() + 0.4, remainder));
    }
  }
}

代码示例来源:origin: WayofTime/BloodMagic

@Override
public boolean harvest(World world, BlockPos pos, IBlockState state, List<ItemStack> drops) {
  IBlockState up = world.getBlockState(pos.up());
  if (up.getBlock() == state.getBlock()) {
    NonNullList<ItemStack> blockDrops = NonNullList.create();
    up.getBlock().getDrops(blockDrops, world, pos.up(), up, 0);
    drops.addAll(blockDrops);
    world.destroyBlock(pos.up(), false);
    return true;
  }
  return false;
}

代码示例来源:origin: ForestryMC/ForestryMC

@Override
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
  Block block = blockState.getBlock();
  NonNullList<ItemStack> harvest = NonNullList.create();
  block.getDrops(harvest, world, pos, blockState, 0);
  if (harvest.size() > 1) {
    harvest.remove(1); //AgriCraft returns cropsticks in 0, seeds in 1 in getDrops, removing since harvesting doesn't return them.
  }
  harvest.remove(0);
  IBlockState oldState = world.getBlockState(pos);
  BlockUtil.setBlockWithBreakSound(world, pos, block.getDefaultState(), oldState);
  return harvest;
}

代码示例来源:origin: raoulvdberge/refinedstorage

private void dropConflictingBlock(World world, BlockPos pos) {
  if (!network.getPosition().equals(pos)) {
    IBlockState state = world.getBlockState(pos);
    NonNullList<ItemStack> drops = NonNullList.create();
    state.getBlock().getDrops(drops, world, pos, state, 0);
    world.setBlockToAir(pos);
    for (ItemStack drop : drops) {
      InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), drop);
    }
  }
}

代码示例来源: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;
}

相关文章

Block类方法