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

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

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

Block.spawnAsEntity介绍

暂无

代码示例

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

private void finishChoppingTree() {
  BlockPos target = new BlockPos(player);
  drops.stream().forEach(i -> spawnAsEntity(world, target, i));
  MinecraftForge.EVENT_BUS.unregister(this);
}

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

continue;
if(world.rand.nextFloat() <= chance)
  Block.spawnAsEntity(world, dropCoord, stack_);

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

@Override
public void transformHook(ItemStack stack, IBlockState state, BlockPos pos, IAtomicReconstructor tile) {
  for(Map.Entry<Enchantment,Integer> e : EnchantmentHelper.getEnchantments(stack).entrySet()) {
    ItemStack book = new ItemStack(Items.ENCHANTED_BOOK);
    Map<Enchantment, Integer> ench = ImmutableMap.of(e.getKey(), e.getValue());
    EnchantmentHelper.setEnchantments(ench, book);
    Block.spawnAsEntity(tile.getWorldObject(), pos, book);
  }
}

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

private void harvestBlock(BlockPos position) {
  IBlockState state = world.getBlockState(position);
  Block block = state.getBlock();
  if (ThumperModule.dropItem) {
    Map<EnumFacing, ThumperAdjacentBehaviorModifier> modifiers = getAllAdjacentBehaviorModifiers();
    List<ItemStack> drops = block.getDrops(world, position, state, 0);
    for (Map.Entry<EnumFacing, ThumperAdjacentBehaviorModifier> entry : modifiers.entrySet()) {
      entry.getValue().dropItems(this, drops, state, modifiers.values(), entry.getKey());
    }
    // Default Thumper behavior.
    for (ItemStack drop : drops) {
      Block.spawnAsEntity(world, position, drop);
    }
  }
  world.setBlockToAir(position);
}

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

public final void dropAllCovers() {
  for(EnumFacing coverSide : EnumFacing.VALUES) {
    CoverBehavior coverBehavior = coverBehaviors[coverSide.getIndex()];
    if(coverBehavior == null) continue;
    List<ItemStack> drops = coverBehavior.getDrops();
    for (ItemStack dropStack : drops) {
      Block.spawnAsEntity(getWorld(), getPos(), dropStack);
    }
  }
}

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

@Override
public void onRemoved() {
  NonNullList<ItemStack> drops = NonNullList.create();
  MetaTileEntity.clearInventory(drops, filterTypeInventory);
  for(ItemStack itemStack : drops) {
    Block.spawnAsEntity(coverHolder.getWorld(), coverHolder.getPos(), itemStack);
  }
}

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

@Override
public void onRemoved() {
  NonNullList<ItemStack> drops = NonNullList.create();
  MetaTileEntity.clearInventory(drops, filterTypeInventory);
  for(ItemStack itemStack : drops) {
    Block.spawnAsEntity(coverHolder.getWorld(), coverHolder.getPos(), itemStack);
  }
}

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

public final void dropAllCovers() {
  for(EnumFacing coverSide : EnumFacing.VALUES) {
    CoverBehavior coverBehavior = coverBehaviors[coverSide.getIndex()];
    if(coverBehavior == null) continue;
    List<ItemStack> drops = coverBehavior.getDrops();
    for (ItemStack dropStack : drops) {
      Block.spawnAsEntity(getWorld(), getPos(), dropStack);
    }
  }
}
public boolean canPlaceCoverOnSide(EnumFacing side) {

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

public void setInventorySlotContents(int slot, @Nonnull ItemStack contents) {
 inventory[slot] = contents.copy();
 if (inventory[slot].getCount() > getInventoryStackLimit(slot)) {
  inventory[slot].setCount(getInventoryStackLimit(slot));
  contents.shrink(getInventoryStackLimit(slot));
  Block.spawnAsEntity(world, pos, contents);
 }
 markDirty();
}

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

/** Called to smash this block
 * @param player    the player smashing the block
 * @param world     the world
 * @param pos       the location of the block
 * @param state     the blocks state
 * @param tier      the tier of the tool used
 * @return return true if something was smashed*/
default boolean smashBlock(EntityPlayer player, World world, BlockPos pos, IBlockState state, ToolTier tier) {
  ToolTier required = getRequiredTier(state);
  if (required != null && tier.isGreaterThanOrEqualTo(required)) {
    float luck = tier.ordinal() * 0.25F;
    List<ItemStack> drops = getDrops(player, world, pos, state, luck);
    world.setBlockToAir(pos); //Clear out the block
    if (drops.size() > 0) {
      if (!world.isRemote) {
        for (ItemStack drop: drops) {
          spawnAsEntity(world, pos, drop);
        }
      }
      return true;
    }
  }
  return false;
}

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

@Override
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
  if(metaTileEntity != null) {
    NonNullList<ItemStack> inventoryContents = NonNullList.create();
    metaTileEntity.clearMachineInventory(inventoryContents);
    for(ItemStack itemStack : inventoryContents) {
      Block.spawnAsEntity(worldIn, pos, itemStack);
    }
    metaTileEntity.dropAllCovers();
    metaTileEntity.onRemoval();
  }
  super.breakBlock(worldIn, pos, state);
}

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

@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos position, EntityLivingBase entityLiving) {
  if (entityLiving instanceof EntityPlayer) {
    EntityPlayer player = (EntityPlayer) entityLiving;
    if (canUse(stack) && canBeDamaged()) {
      if (canLevel(stack, state)) ToolHelper.levelTool(stack);
      ArrayList<ItemStack> drops = new ArrayList<>();
      for (BlockPos pos : getBlocks(worldIn, position, player, stack)) {
        if (canUse(stack) && canBeDamaged()) {
          ToolHelper.performTask(player, stack, this);
          ToolHelper.collectDrops(worldIn, pos, worldIn.getBlockState(pos), player, drops);
          worldIn.setBlockToAir(pos); //No particles
        } else break; //Exist since we can't damage anymore
      }
      drops.stream().forEach(item -> spawnAsEntity(worldIn, new BlockPos(player), item));
    }
    return true;
  } else return false;
}

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

public final boolean removeCover(EnumFacing side) {
  Preconditions.checkNotNull(side, "side");
  CoverBehavior coverBehavior = getCoverAtSide(side);
  if (coverBehavior == null) {
    return false;
  }
  List<ItemStack> drops = coverBehavior.getDrops();
  coverBehavior.onRemoved();
  this.coverBehaviors[side.getIndex()] = null;
  for (ItemStack dropStack : drops) {
    Block.spawnAsEntity(getWorld(), getPos(), dropStack);
  }
  writeCustomData(2, buffer -> buffer.writeByte(side.getIndex()));
  holder.notifyBlockUpdate();
  holder.markAsDirty();
  return true;
}

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

@Override
public void handleExtraItem(@Nonnull ItemStack stack, @Nullable BlockPos drop) {
 InsertCallback insertCallback = new InsertCallback(stack);
 if (drop != null && Prep.isValid(stack)) {
  insertCallback.apply(mapBlockPosToSeedSlot(drop));
 }
 if (Prep.isValid(stack)) {
  FarmSlots.SEEDS.apply(insertCallback);
 }
 if (Prep.isValid(stack)) {
  FarmSlots.OUTPUTS.apply(insertCallback);
 }
 if (drop != null && Prep.isValid(stack)) {
  if (FarmConfig.useOutputQueue.get()) {
   owner.enQueueOverflow(stack.copy());
  } else {
   Block.spawnAsEntity(getWorld(), drop, stack.copy());
  }
  stack.setCount(0);
 }
}

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

Block.spawnAsEntity(world, pos, itemStack);

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

public final boolean removeCover(EnumFacing side) {
  Preconditions.checkNotNull(side, "side");
  CoverBehavior coverBehavior = getCoverAtSide(side);
  if(coverBehavior == null) {
    return false;
  }
  List<ItemStack> drops = coverBehavior.getDrops();
  coverBehavior.onRemoved();
  this.coverBehaviors[side.getIndex()] = null;
  for(ItemStack dropStack : drops) {
    Block.spawnAsEntity(getWorld(), getPos(), dropStack);
  }
  writeCustomData(-6, buffer -> buffer.writeByte(side.getIndex()));
  if(getHolder() != null) {
    getHolder().notifyBlockUpdate();
    getHolder().markDirty();
  }
  return true;
}

代码示例来源: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: SleepyTrousers/EnderIO

TileEntity blockTileEntity = source.getBlockTileEntity();
if (!(blockTileEntity instanceof TileEntityDispenser) || ((TileEntityDispenser) blockTileEntity).addItemStack(secondaryResult) < 0) {
 Block.spawnAsEntity(source.getWorld(), source.getBlockPos().offset(enumfacing), secondaryResult);

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

@Override
public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, BlockPos blockPos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  ItemStack stack = player.getHeldItem(hand);
  if (player.canPlayerEdit(blockPos, facing, stack) && !world.isAirBlock(blockPos)) {
    IBlockState blockState = world.getBlockState(blockPos);
    if (blockState.getBlock() == Blocks.GRASS || blockState.getBlock() == Blocks.DIRT) {
      if (blockState.getBlock() == Blocks.GRASS && player.isSneaking()) {
        if(GTUtility.doDamageItem(stack, this.cost, false)) {
          if (world.rand.nextInt(3) == 0) {
            ItemStack grassSeed = ForgeHooks.getGrassSeed(world.rand, 0);
            Block.spawnAsEntity(world, blockPos.up(), grassSeed);
          }
          world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
          world.setBlockState(blockPos, Blocks.DIRT.getDefaultState()
              .withProperty(BlockDirt.VARIANT, BlockDirt.DirtType.COARSE_DIRT));
          return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
        }
      } else if (blockState.getBlock() == Blocks.GRASS
        || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.DIRT
        || blockState.getValue(BlockDirt.VARIANT) == BlockDirt.DirtType.COARSE_DIRT) {
        if (GTUtility.doDamageItem(stack, this.cost, false)) {
          world.playSound(null, blockPos, SoundEvents.ITEM_HOE_TILL, SoundCategory.PLAYERS, 1.0F, 1.0F);
          world.setBlockState(blockPos, Blocks.FARMLAND.getDefaultState());
          return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
        }
      }
    }
  }
  return ActionResult.newResult(EnumActionResult.FAIL, stack);
}

代码示例来源:origin: squeek502/VeganOption

Block.spawnAsEntity(event.getWorld(), event.getPos().down(), drop);

相关文章

Block类方法