#Apply fortune or Silktouch to blocks when certain condition

4 messages · Page 1 of 1 (latest)

verbal marsh
#

So i what want to do is... apply fortune or silktouch to ore drops if the player has a certain effect. the effect part o manage to do one time but i deleted that code.
The problem is that i don't now how to just apply the fortune. i tried this code

LootJS.modifiers((event) => {
    //First loot entry with a condition. Will drop if the player has fortune.
    const stickWhenFortune = LootEntry.of("minecraft:stick")
        .applyOreBonus("minecraft:fortune")
        .when((c) => c.matchMainHand(ItemFilter.hasEnchantment("minecraft:fortune")));

    //Second loot entry with a condition. Will drop if the player has silk touch and the first entry doesn't match.

    const appleWhenSilkTouch = LootEntry.of("minecraft:apple").when((c) =>
        c.matchMainHand(ItemFilter.hasEnchantment("minecraft:silk_touch"))
    );

    //No conditions just an item, so this will always drop if the other two don't.
    const ironIngot = "minecraft:iron_ingot";

    event
        .addBlockLootModifier("minecraft:redstone_ore")
        .removeLoot(Ingredient.all)
        .addAlternativesLoot(stickWhenFortune, appleWhenSilkTouch, ironIngot);
});``` 
But the amount of stick dropped aren't consistent with a vanilla redstone ore + fortune. 
I thought about removing the ingredients and re-add them with my fortune condition, but... i know i can get the block loottable using 
```js
Block.getBlock().getLootTable()```
But the loottable is a resourceLocation and i don't know how to use this in LootEntry.
So how to apply fortune? can i copy the block drops, remove than re-add them?
valid horizonBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

rustic bolt
#

i dont know if this work in 1.20 but try

function customDropsOres(ore, drop) {
        const isFortune = LootEntry.of(drop).applyOreBonus('minecraft:fortune').when(item => item.matchMainHand(ItemFilter.hasEnchantment('minecraft:fortune')))
        const isSilktouch = LootEntry.of(ore).when(item => item.matchMainHand(ItemFilter.hasEnchantment('minecraft:silk_touch')))

        let customDrop = event.addBlockLootModifier(ore)
            .removeLoot(Ingredient.all)
            .addAlternativesLoot(isFortune, isSilktouch, drop)
    }
verbal marsh
#

So, on the left is your script with fortune 3, middle is no-script and no fortune and right is no-script with fortune 3. each stack is 10 blocks broken. i came across this problem when i was testing the other time, it doesn't work like fortune