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