#Lootjs examples for mining blocks

9 messages · Page 1 of 1 (latest)

pure solar
#

Im wanting to change a pre existing block drop to drop something else when mined without silk touch, and then the block with silk touch

barren fieldBOT
#

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

ember jay
# pure solar Im wanting to change a pre existing block drop to drop something else when mined...
LootJS.modifiers(event => {

  const LootOre = [ 
      ['kubejs:debris_cluster','minecraft:netherite_scrap']
  ]

  LootOre.forEach(([ore,material]) => {
    const WhenFortune = LootEntry.of(material).applyOreBonus("minecraft:fortune")
                        .when(c => c.matchMainHand(ItemFilter.hasEnchantment("minecraft:fortune")))

    const WhenSilkTouch = LootEntry.of(ore)
                          .when(c => c.matchMainHand(ItemFilter.hasEnchantment("minecraft:silk_touch")))

    event.addBlockModifier(ore)
         .removeLoot(Ingredient.all)
         .addAlternativesLoot(WhenFortune,WhenSilkTouch,material)
  })

})
pure solar
ember jay
#

You can even skip the whole loop and just write this directly, replacing ore and material with the actual IDs:

LootJS.modifiers(event => {
  const WhenSilkTouch = LootEntry.of(ore)
                      .when(c => c.matchMainHand(ItemFilter.hasEnchantment("minecraft:silk_touch")))

  event.addBlockModifier(ore)
     .removeLoot(Ingredient.all)
     .addAlternativesLoot(WhenSilkTouch, material)
})

The most important part is the order inside .addAlternativesLoot(WhenSilkTouch, material). It executes from left to right, so if the first condition is met, it will always drop that first reward and ignore the rest.

bitter carbon
#

If this worked can you please close the ticket, thanks!

wary brookBOT
#

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue!
This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You should create a new post for unrelated issues.

pure solar