Search in sources :

Example 1 with LootTable

use of net.minecraft.world.storage.loot.LootTable in project MorePlanets by SteveKunG.

the class TileEntityTreasureChestMP method fillWithLoot.

protected void fillWithLoot(@Nullable EntityPlayer player) {
    if (this.lootTable != 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());
        }
        loottable.fillInventory(this, random, lootcontext$builder.build());
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) Random(java.util.Random) LootContext(net.minecraft.world.storage.loot.LootContext)

Example 2 with LootTable

use of net.minecraft.world.storage.loot.LootTable in project MorePlanets by SteveKunG.

the class TileEntityCrashedAlienProbe method fillWithLoot.

protected void fillWithLoot(@Nullable EntityPlayer player) {
    if (this.lootTable != 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());
        }
        loottable.fillInventory(this, random, lootcontext$builder.build());
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) Random(java.util.Random) LootContext(net.minecraft.world.storage.loot.LootContext)

Example 3 with LootTable

use of net.minecraft.world.storage.loot.LootTable in project MinecraftForge by MinecraftForge.

the class ForgeHooks method loadLootTable.

@Nullable
public static LootTable loadLootTable(Gson gson, ResourceLocation name, String data, boolean custom) {
    Deque<LootTableContext> que = lootContext.get();
    if (que == null) {
        que = Queues.newArrayDeque();
        lootContext.set(que);
    }
    LootTable ret = null;
    try {
        que.push(new LootTableContext(name, custom));
        ret = gson.fromJson(data, LootTable.class);
        que.pop();
    } catch (JsonParseException e) {
        que.pop();
        throw e;
    }
    if (!custom)
        ret = ForgeEventFactory.loadLootTable(name, ret);
    if (ret != null)
        ret.freeze();
    return ret;
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) JsonParseException(com.google.gson.JsonParseException) Nullable(javax.annotation.Nullable)

Example 4 with LootTable

use of net.minecraft.world.storage.loot.LootTable in project ImmersiveEngineering by BluSunrize.

the class TileEntityWoodenCrate method onGuiOpened.

@Override
public void onGuiOpened(EntityPlayer player, boolean clientside) {
    if (this.lootTable != null && !clientside) {
        LootTable loottable = this.worldObj.getLootTableManager().getLootTableFromLocation(this.lootTable);
        this.lootTable = null;
        Random random;
        LootContext.Builder contextBuilder = new LootContext.Builder((WorldServer) this.worldObj);
        if (player != null)
            contextBuilder.withLuck(player.getLuck());
        LootContext context = contextBuilder.build();
        Random rand = new Random();
        List<ItemStack> list = loottable.generateLootForPools(rand, context);
        List<Integer> listSlots = Lists.newArrayList();
        for (int i = 0; i < inventory.length; i++) if (inventory[i] == null)
            listSlots.add(Integer.valueOf(i));
        Collections.shuffle(listSlots, rand);
        if (listSlots.isEmpty())
            return;
        Utils.shuffleLootItems(list, listSlots.size(), rand);
        for (ItemStack itemstack : list) {
            int slot = listSlots.remove(listSlots.size() - 1).intValue();
            inventory[slot] = itemstack;
        }
    }
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) Random(java.util.Random) LootContext(net.minecraft.world.storage.loot.LootContext) ItemStack(net.minecraft.item.ItemStack) IComparatorOverride(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)

Example 5 with LootTable

use of net.minecraft.world.storage.loot.LootTable in project RecurrentComplex by Ivorforce.

the class VanillaItemCollection method getRandomItemStack.

@Override
public ItemStack getRandomItemStack(WorldServer server, Random random) {
    List<ItemStack> loot = null;
    try {
        LootTable loottable = server.getLootTableManager().getLootTableFromLocation(this.vanillaKey);
        loot = loottable.generateLootForPools(random, new LootContext.Builder(server).build());
        // TODO generate tile entities with loot? TileEntityLockedLoot
        return loot.size() > 0 ? loot.get(0) : null;
    } catch (Exception e) {
        RecurrentComplex.logger.error("Error generating vanilla loot", e);
    }
    return ItemStack.EMPTY;
}
Also used : LootTable(net.minecraft.world.storage.loot.LootTable) LootContext(net.minecraft.world.storage.loot.LootContext) ItemStack(net.minecraft.item.ItemStack)

Aggregations

LootTable (net.minecraft.world.storage.loot.LootTable)5 LootContext (net.minecraft.world.storage.loot.LootContext)4 Random (java.util.Random)3 ItemStack (net.minecraft.item.ItemStack)2 IComparatorOverride (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)1 JsonParseException (com.google.gson.JsonParseException)1 Nullable (javax.annotation.Nullable)1