Search in sources :

Example 1 with LootTables

use of net.minecraft.world.level.storage.loot.LootTables in project Denizen-For-Bukkit by DenizenScript.

the class FishingHelperImpl method getRandomReward.

public ItemStack getRandomReward(FishingHook hook, ResourceLocation key) {
    ServerLevel worldServer = (ServerLevel) hook.level;
    LootContext.Builder playerFishEvent2 = new LootContext.Builder(worldServer);
    LootTables registry = ((ServerLevel) hook.level).getServer().getLootTables();
    // registry.getLootTable(key).getLootContextParameterSet()
    LootContext info = playerFishEvent2.withOptionalParameter(LootContextParams.ORIGIN, new Vec3(hook.getX(), hook.getY(), hook.getZ())).withOptionalParameter(LootContextParams.TOOL, new ItemStack(Items.FISHING_ROD)).create(LootContextParamSets.FISHING);
    List<ItemStack> itemStacks = registry.get(key).getRandomItems(info);
    return itemStacks.get(worldServer.random.nextInt(itemStacks.size()));
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LootContext(net.minecraft.world.level.storage.loot.LootContext) BuiltInLootTables(net.minecraft.world.level.storage.loot.BuiltInLootTables) LootTables(net.minecraft.world.level.storage.loot.LootTables) Vec3(net.minecraft.world.phys.Vec3) CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with LootTables

use of net.minecraft.world.level.storage.loot.LootTables in project Denizen-For-Bukkit by DenizenScript.

the class FishingHelperImpl method getRandomReward.

public ItemStack getRandomReward(FishingHook hook, ResourceLocation key) {
    ServerLevel worldServer = (ServerLevel) hook.level;
    LootContext.Builder playerFishEvent2 = new LootContext.Builder(worldServer);
    LootTables registry = ((ServerLevel) hook.level).getServer().getLootTables();
    // registry.getLootTable(key).getLootContextParameterSet()
    LootContext info = playerFishEvent2.withOptionalParameter(LootContextParams.ORIGIN, new Vec3(hook.getX(), hook.getY(), hook.getZ())).withOptionalParameter(LootContextParams.TOOL, new ItemStack(Items.FISHING_ROD)).create(LootContextParamSets.FISHING);
    List<ItemStack> itemStacks = registry.get(key).getRandomItems(info);
    return itemStacks.get(worldServer.random.nextInt(itemStacks.size()));
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) LootContext(net.minecraft.world.level.storage.loot.LootContext) BuiltInLootTables(net.minecraft.world.level.storage.loot.BuiltInLootTables) LootTables(net.minecraft.world.level.storage.loot.LootTables) Vec3(net.minecraft.world.phys.Vec3) ItemStack(net.minecraft.world.item.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)2 ItemStack (net.minecraft.world.item.ItemStack)2 BuiltInLootTables (net.minecraft.world.level.storage.loot.BuiltInLootTables)2 LootContext (net.minecraft.world.level.storage.loot.LootContext)2 LootTables (net.minecraft.world.level.storage.loot.LootTables)2 Vec3 (net.minecraft.world.phys.Vec3)2 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)1