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