Search in sources :

Example 1 with LootContext

use of net.minecraft.loot.LootContext 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

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