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());
}
}
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());
}
}
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;
}
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;
}
}
}
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;
}
Aggregations