Search in sources :

Example 1 with LootTable

use of net.minecraft.loot.LootTable in project Bookshelf by Darkhax-Minecraft.

the class ModifierConvert method doApply.

@Override
protected List<ItemStack> doApply(List<ItemStack> loot, LootContext ctx) {
    final List<ItemStack> outputs = NonNullList.create();
    final LootTable table = ctx.getLevel().getServer().getLootTables().get(this.tableName);
    for (final ItemStack item : loot) {
        if (MathsUtils.tryPercentage(this.chance)) {
            outputs.addAll(table.getRandomItems(ctx));
        } else {
            outputs.add(item);
        }
    }
    return outputs;
}
Also used : LootTable(net.minecraft.loot.LootTable) ItemStack(net.minecraft.item.ItemStack)

Example 2 with LootTable

use of net.minecraft.loot.LootTable in project Bookshelf by Darkhax-Minecraft.

the class ModifierSilkTouch method doApply.

@Nonnull
@Override
public List<ItemStack> doApply(List<ItemStack> loot, LootContext context) {
    final ItemStack tool = context.getParamOrNull(LootParameters.TOOL);
    if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) == 0) {
        final ItemStack fakeTool = tool.copy();
        fakeTool.enchant(Enchantments.SILK_TOUCH, 1);
        final LootContext.Builder builder = new LootContext.Builder(context);
        builder.withParameter(LootParameters.TOOL, fakeTool);
        final LootContext fakeContext = builder.create(LootParameterSets.BLOCK);
        final LootTable table = context.getLevel().getServer().getLootTables().get(context.getParamOrNull(LootParameters.BLOCK_STATE).getBlock().getLootTable());
        return table.getRandomItems(fakeContext);
    }
    return loot;
}
Also used : LootTable(net.minecraft.loot.LootTable) LootContext(net.minecraft.loot.LootContext) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2 LootTable (net.minecraft.loot.LootTable)2 Nonnull (javax.annotation.Nonnull)1 LootContext (net.minecraft.loot.LootContext)1