net.minecraft.world.World.getLootTableManager()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(84)

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

World.getLootTableManager介绍

暂无

代码示例

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

List<ItemStack> stacks = world.getLootTableManager().getLootTableFromLocation(lootTable).generateLootForPools(rand, new LootContext.Builder((WorldServer) world).build());
if (stacks.isEmpty())
  return;

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

@Override
public @Nonnull LootTableManager getLootTableManager() {
 return wrapped.getLootTableManager();
}

代码示例来源:origin: amadornes/MCMultiPart

@Override
public LootTableManager getLootTableManager() {
  return getActualWorld().getLootTableManager();
}

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

private boolean lootTableExists(World world, ResourceLocation lootTableName) {
  return world.getLootTableManager().getLootTableFromLocation(lootTableName) != null;
}

代码示例来源:origin: Alex-the-666/Ice_and_Fire

public void fillWithLoot(@Nullable EntityPlayer player) {
  if (this.lootTable != null && this.world != null && this.world.getLootTableManager() != null) {
    LootTable loottable = this.world.getLootTableManager().getLootTableFromLocation(this.lootTable);
    this.lootTable = null;
    Random random;
    if (this.lootTableSeed == 0L) {
      random = new Random();
    } else {
      random = new Random(this.lootTableSeed);
    }
    LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world);
    if (player != null) {
      lootcontext$builder.withLuck(player.getLuck()).withPlayer(player); // Forge: add player to LootContext
    }
    loottable.fillInventory(this, random, lootcontext$builder.build());
  }
}

代码示例来源:origin: ldtteam/minecolonies

/**
 * Return some random loot of a defined lootTable.
 *
 * @param lootTable the lootTable.
 * @return the ItemStack of the loot.
 */
private ItemStack getLootForLootTable(final ResourceLocation lootTable)
{
  final LootContext.Builder lootContextBuilder = new LootContext.Builder((WorldServer) CompatibilityUtils.getWorld(this));
  return CompatibilityUtils.getWorld(this).getLootTableManager()
       .getLootTableFromLocation(lootTable)
       .generateLootForPools(this.rand, lootContextBuilder.build()).stream().findFirst().orElse(null);
}

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

@Override
public void safeUpdate() {
  Pair<Chunk, Integer> pair = randSourceBlock();
  int src = pair.getRight();
  if (getSteamShare() > src) {
    decrSteam(src);
    if (world.rand.nextInt((int) (300.0F / src)) == 0 && !world.isRemote) {
      Chunk loc = pair.getLeft();
      LootContext lootContext = new LootContext.Builder((WorldServer) world).build();
      List<ItemStack> fishes = world.getLootTableManager().getLootTableFromLocation(
       LootTableList.GAMEPLAY_FISHING_FISH).generateLootForPools(world.rand, lootContext);
      ItemStack output = fishes.get(world.rand.nextInt(fishes.size()));
      ItemStack smeltingResult = FurnaceRecipes.instance().getSmeltingResult(output);
      if (smeltingResult != null) {
        output = smeltingResult;
      }
      dropItem(output, loc.x + 0.5F, pos.getY() + 1.0F, loc.z + 0.5F);
    }
  }
  super.safeUpdate();
}

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

@Override
public @Nonnull EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side,
  float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {
 if (world.isRemote || System.getProperty("INDEV") == null || !player.isCreative()) {
  return EnumActionResult.PASS;
 }
 TileEntity te = world.getTileEntity(pos);
 if (te instanceof TileEntityChest) {
  TileEntityChest chest = (TileEntityChest) te;
  chest.clear();
  LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world);
  lootcontext$builder.withLuck(player.getLuck());
  LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_SIMPLE_DUNGEON);
  // LootTable loottable = world.getLootTableManager().getLootTableFromLocation(LootTableList.CHESTS_IGLOO_CHEST);
  loottable.fillInventory(chest, world.rand, lootcontext$builder.build());
  return EnumActionResult.PASS;
 } else {
  IBlockState blockState = world.getBlockState(pos);
  int meta = blockState.getBlock().getMetaFromState(blockState);
  player.sendMessage(new TextComponentString(blockState + " (" + meta + ")"));
 }
 return EnumActionResult.PASS;
}

代码示例来源:origin: Silentine/GrimoireOfGaia

private static List<ItemStack> getLoot(World world, @Nullable EntityPlayer player, boolean entityWasRecentlyHit, ResourceLocation lootTableName) {
  LootContext.Builder builder = new LootContext.Builder((WorldServer) world);
  LootTable lootTable = world.getLootTableManager().getLootTableFromLocation(lootTableName);
  if (entityWasRecentlyHit && player != null) {
    builder.withLuck(player.getLuck()).withPlayer(player);
  }
  return lootTable.generateLootForPools(world.rand, builder.build());
}

代码示例来源:origin: Alex-the-666/Ice_and_Fire

public ItemStack getItemFromLootTable() {
  LootTable loottable = this.world.getLootTableManager().getLootTableFromLocation(getDeadLootTable());
  LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer) this.world)).withLootedEntity(this).withDamageSource(DamageSource.GENERIC);
  if (this.attackingPlayer != null) {
    lootcontext$builder = lootcontext$builder.withPlayer(this.attackingPlayer).withLuck(this.attackingPlayer.getLuck());
  }
  List<ItemStack> loot = loottable.generateLootForPools(this.rand, lootcontext$builder.build());
  if (loot.isEmpty()) {
    return ItemStack.EMPTY;
  } else {
    return loot.get(0);
  }
}

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

public static ItemStack getStack(World world, EntityPlayer player, ResourceLocation lootTable) {
    long lootTableSeed = world.rand.nextLong();
    LootTable loottable = world.getLootTableManager().getLootTableFromLocation(lootTable);
    Random random;

    if (lootTableSeed == 0L) {
      random = new Random();
    } else {
      random = new Random(lootTableSeed);
    }

    LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer)world);

    if (player != null) {
      lootcontext$builder.withLuck(player.getLuck());
    }

    loottable.fillInventory(INVENTORY, random, lootcontext$builder.build());
    ItemStack result = INVENTORY.getStackInSlot(0);
    if (result != null) result = result.copy();
    INVENTORY.setInventorySlotContents(0, null);
    return  result;
  }
}

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

public void fillWithLoot(EntityPlayer player){
    if(this.lootTable != null && !this.world.isRemote && this.world instanceof WorldServer){
      LootTable table = this.world.getLootTableManager().getLootTableFromLocation(this.lootTable);
      this.lootTable = null;

      LootContext.Builder builder = new LootContext.Builder((WorldServer)this.world);
      if(player != null){
        builder.withLuck(player.getLuck());
      }
      AwfulUtil.fillInventory(table, this.inv, world.rand, builder.build());
    }
  }
}

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

public static void generateLootFor(World world,
    @Nullable EntityPlayer player, IItemHandler inventory, Random rng, ResourceLocation lootTableName, int rolls) {
  LootContext.Builder builder = new LootContext.Builder((WorldServer) world);
  LootTable lootTable = world.getLootTableManager().getLootTableFromLocation(lootTableName);
  if (player != null) {
    builder.withLuck(player.getLuck()).withPlayer(player);
  }
  LootContext lootContext = builder.build();
  NonNullList<ItemStack> loot = NonNullList.create();
  for (int i = 0; i < rolls; i++) {
    mergeItemStacks(loot, toNonNullList(lootTable.generateLootForPools(rng, lootContext)));
  }
  List<Integer> randomSlots = getEmptySlotsRandomized(inventory, rng);
  shuffleItems(loot, randomSlots.size(), rng);
  for (ItemStack itemstack : loot) {
    if (randomSlots.isEmpty()) {
      AncientWarfareCore.LOG.warn("Tried to over-fill a container");
      return;
    }
    if (!itemstack.isEmpty()) {
      inventory.insertItem(randomSlots.remove(randomSlots.size() - 1), itemstack, false);
    }
  }
}

代码示例来源:origin: Silentine/GrimoireOfGaia

/**
 * Our Method to drop a random item from an entire Loot Table
 */
public void dropRandomLootFromLootTable(ResourceLocation dungeonLoot, boolean wasRecentlyHit, int lootingModifier, DamageSource source) {
  long LootTableSeed = 0;
  int maxCount = 0;
  int currentCount = 0;
  Random Randomize = new Random();
  int roll = 0;
  // Things for Looting enchant calculations
  LootTable loottable = world.getLootTableManager().getLootTableFromLocation(dungeonLoot);
  LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer) world)).withLootedEntity(this).withDamageSource(source);
  if (wasRecentlyHit && attackingPlayer != null) {
    lootcontext$builder = lootcontext$builder.withPlayer(attackingPlayer).withLuck(attackingPlayer.getLuck());
  }
  // Here we count the amount of pools are in the Loot Table Array
  for (ItemStack itemstack : loottable.generateLootForPools(LootTableSeed == 0L ? rand : new Random(LootTableSeed), lootcontext$builder.build())) {
    maxCount++;
  }
  // Our Roll dependent on the amount of pools we counted
  roll = Randomize.nextInt(maxCount);
  for (ItemStack itemstack : loottable.generateLootForPools(LootTableSeed == 0L ? rand : new Random(LootTableSeed), lootcontext$builder.build())) {
    // Check if our current iteration matches our roll
    if (currentCount == roll) {
      entityDropItem(itemstack, 0.0F);
    }
    currentCount++; // Incrementing the current Iteration
  }
}

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

public static List<ItemStack> getLoot(ResourceLocation loot, World world, EntityPlayer player, float luck) {
  LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world);
  lootcontext$builder.withLuck(player.getLuck() + luck);
  lootcontext$builder.withPlayer(player);
  return world.getLootTableManager().getLootTableFromLocation(loot).generateLootForPools(world.rand, lootcontext$builder.build());
}

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

LootTable loottable = entity.world.getLootTableManager().getLootTableFromLocation(resourcelocation);
LootContext.Builder builder = (new LootContext.Builder((WorldServer) entity.world)).withLootedEntity(entity).withDamageSource(source);

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

@Override
protected void dropLoot(boolean wasRecentlyHit, int lootingModifier, @Nullable DamageSource damageSource) {
  super.dropLoot(wasRecentlyHit, lootingModifier, damageSource);
  // Also drop loot from inner entity!
  EntityLivingBase innerEntity = getInnerEntity();
  if (innerEntity instanceof EntityLiving && damageSource != DamageSource.OUT_OF_WORLD) {
    ResourceLocation deathLootTable = ObfuscationHelpers.getLootTable((EntityLiving) innerEntity);
    if (deathLootTable != null) {
      LootTable loottable = getEntityWorld().getLootTableManager().getLootTableFromLocation(deathLootTable);
      LootContext.Builder lootcontext$builder = (new LootContext.Builder((WorldServer) getEntityWorld()))
          .withLootedEntity(innerEntity)
          .withDamageSource(DamageSource.GENERIC);
      if (wasRecentlyHit && this.attackingPlayer != null) {
        lootcontext$builder = lootcontext$builder.withPlayer(this.attackingPlayer).withLuck(this.attackingPlayer.getLuck());
      }
      for (ItemStack itemstack : loottable.generateLootForPools(getEntityWorld().rand, lootcontext$builder.build())) {
        this.entityDropItem(itemstack, 0.0F);
      }
    }
  }
}

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

@Override
  @SuppressWarnings("ConstantConditions")
  public void newDay(World world, BlockPos pos, IBlockState state) {
    TileTrap trap = (TileTrap) world.getTileEntity(pos);
    if (trap.stack != null && FishingAPI.INSTANCE.isBait(trap.stack)) {
      if (trap.isSurroundedByWater(world, pos)) {
        LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) world);
        lootcontext$builder.withLootedEntity(FakePlayerHelper.getFakePlayerWithPosition((WorldServer) world, pos));
        if (FishingHelper.isWater(world, pos.down())) lootcontext$builder.withLuck(1F);
        for (ItemStack itemstack : world.getLootTableManager().getLootTableFromLocation(trap.getLootTable()).generateLootForPools(world.rand, lootcontext$builder.build())) {
          trap.baited = false;
          trap.stack = itemstack.copy();
        }
        trap.saveAndRefresh();
      }
    }
  }
};

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

@Override
public void updateEntity(){
  super.updateEntity();
  if(!this.world.isRemote){
    if(!this.isRedstonePowered){
      if(this.world.getBlockState(this.pos.down()).getMaterial() == Material.WATER){
        if(this.timeUntilNextDrop > 0){
          this.timeUntilNextDrop--;
          if(this.timeUntilNextDrop <= 0){
            LootContext.Builder builder = new LootContext.Builder((WorldServer)this.world);
            List<ItemStack> fishables = this.world.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(this.world.rand, builder.build());
            for(ItemStack fishable : fishables){
              ItemStack leftover = this.storeInContainer(fishable);
              if(StackUtil.isValid(leftover)){
                EntityItem item = new EntityItem(this.world, this.pos.getX()+0.5, this.pos.getY()+0.5, this.pos.getZ()+0.5, leftover.copy());
                item.lifespan = 2000;
                this.world.spawnEntity(item);
              }
            }
          }
        }
        else{
          int time = 15000;
          this.timeUntilNextDrop = time+this.world.rand.nextInt(time/2);
        }
      }
    }
  }
}

代码示例来源:origin: joshiejack/Mariculture

@SubscribeEvent
  public void onKillChicken(LivingDeathEvent event) {
    if (Debug.CHICKEN_FISHING > 0) {
      EntityPlayer angler = event.getSource().getEntity() instanceof EntityPlayer ? (EntityPlayer) event.getSource().getEntity() : null;
      if (angler != null && !angler.worldObj.isRemote && event.getEntityLiving() instanceof EntityChicken) {
        for (int i = 0; i < Debug.CHICKEN_FISHING; i++) {
          LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) angler.worldObj);
          lootcontext$builder.withLuck((float) EnchantmentHelper.getLuckOfSeaModifier(angler) + angler.getLuck());
          lootcontext$builder.withPlayer(angler); //Added by Mariculture
          lootcontext$builder.withLootedEntity(event.getEntityLiving()); //Added by Mariculture

          for (ItemStack itemstack : angler.worldObj.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING).generateLootForPools(this.rand, lootcontext$builder.build())) {
            EntityItem entityitem = new EntityItem(angler.worldObj, event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, itemstack);
            double d0 = angler.posX - event.getEntityLiving().posX;
            double d1 = angler.posY - event.getEntityLiving().posY;
            double d2 = angler.posZ - event.getEntityLiving().posZ;
            double d3 = (double) MathHelper.sqrt_double(d0 * d0 + d1 * d1 + d2 * d2);
            double d4 = 0.1D;
            entityitem.motionX = d0 * d4;
            entityitem.motionY = d1 * d4 + (double) MathHelper.sqrt_double(d3) * 0.08D;
            entityitem.motionZ = d2 * d4;
            angler.worldObj.spawnEntityInWorld(entityitem);
            angler.worldObj.spawnEntityInWorld(new EntityXPOrb(angler.worldObj, angler.posX, angler.posY + 0.5D, angler.posZ + 0.5D, this.rand.nextInt(6) + 1));
          }
        }
      }
    }
  }
}

相关文章

微信公众号

最新文章

更多

World类方法