Whats wrong with this custom blocks loot table? Its supposed to choose drop by testing for silk touch, but non-enchanted pick drops both options

[BACK]
Whats wrong with this custom blocks loot table? Its supposed to choose drop by testing for silk touch, but non-enchanted pick drops both options
Posted On: March 13, 2024

I have a custom block that is supposed to be only obtainable using a Silk Touch pickaxe. If mined with a pickaxe without Silk Touch, it should drop end stone instead, and if mined with the wrong tool, it should drop nothing.


Instead, it drops the correct loot only when a Silk Touch pickaxe is used. When a regular pickaxe is used, it drops both itself and an end stone block; when mined with the wrong tool, the same thing happens.


From the official documentation, "Applying a condition to a pool allows you execute the entire pool based on the conditions defined." In my custom block's loot table, each pool has its own (mutually exclusive) condition, so I'm not sure what's causing multiple drops (which would imply matching both or possibly all 3 conditions, which should be impossible).


Here is the loot table .json file:.


{.


"pools": [.


// Give rhizome block if mined using a Silk Touch pickaxe.


{.


"condition": "query.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_pickaxe') && query.has_silk_touch",.


"rolls": 1,.


"entries": [.


{.


"type": "item",.


"name": "end:rhizome".


}.


].


},.


// Give end stone if mined with a pickaxe without Silk Touch.


{.


"condition": "query.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_pickaxe') && !query.has_silk_touch",.


"rolls": 1,.


"entries": [.


{.


"type": "item",.


"name": "minecraft:end_stone".


}.


].


},.


// Drop nothing if mined with anything other than a pickaxe.


{.


"condition": "!query.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_pickaxe')",.


"rolls": 1,.


"entries": [.


{.


"type": "empty".


}.


].


}.


].


}.


Rearranging the three pools does not change the result. So, it doesn't matter whether the "has silk touch" condition comes first or third: it's still the only one that works as intended.


I also tested swapping out the condition strings with condition arrays of the following form:.


"conditions": [.


{.


"condition": "same molang queries here".


}.


].


but the same problem was still happening.


Question from user Quack E. Duck at gaming.stackexchange.com.


Answer:

Here is a different way of accomplishing the same thing, without using conditions in the loot table:.


Loot table for the block: (set to a single, empty entry).


{.


"pools": [.


// A placeholder; the actual drop will be determined in main.js.


{.


"rolls": 1,.


"entries": [.


{.


"type": "empty".


}.


].


}.


].


}.


Script file (main.js; uses @minecraft/server version 1.10.0-beta): -- This is where we'll test for use of silk touch pickaxe vs. unenchanted pickaxe vs. no pickaxe.


import { world, system, ItemStack, ItemComponentTypes } from "@minecraft/server".


// For use inside the .playerBreakBlock event listener, for getting the broken block's former coordinates.


// Properties will be player names (type String); values will be Block objects.


var lastBlockHitByPlayer = {};.


world.afterEvents.entityHitBlock.subscribe(event => {.


// Keep a record of the last block the player hit.


if (event.damagingEntity.typeId === "minecraft:player") {.


lastBlockHitByPlayer[event.damagingEntity.name] = event.hitBlock;.


}.


});.


world.afterEvents.playerBreakBlock.subscribe(event => {.


if (event.brokenBlockPermutation.type.id === "end:rhizome") {.


const stack = event.itemStackAfterBreak;.


const player = event.player;.


// Block will drop rhizome if mined with a silk touch pickaxe (this happens automatically).


if (stack !== undefined && stack.typeId.includes("_pickaxe") && !stack.getComponent(ItemComponentTypes.Enchantable).hasEnchantment("silk_touch")) {.


// Drop regular end stone if the block is mined with a non-silk-touch pickaxe.


(async () => {.


// For .playerBreakBlock, there's no direct way to access the block's coordinates (because it isn't there anymore?). Instead, the coordinates.


// of the block that has just been broken should be the same as those of the most recent block which the player hit (since hitting the block - left click - is a prerequisite to breaking it).


await player.dimension.spawnItem(new ItemStack("minecraft:end_stone"), {x: lastBlockHitByPlayer[player.name].x, y: lastBlockHitByPlayer[player.name].y, z: lastBlockHitByPlayer[player.name].z});.


})();.


} // Otherwise, drop nothing.


}.


});.


With this method, the custom block drops the correct loot for each case.


Answer from user Quack E. Duck at gaming.stackexchange.com.


[BACK]
Whats wrong with this custom blocks loot table? Its supposed to choose drop by testing for silk touch, but non-enchanted pick drops both options
Posted On: March 13, 2024

I have a custom block that is supposed to be only obtainable using a Silk Touch pickaxe. If mined with a pickaxe without Silk Touch, it should drop end stone instead, and if mined with the wrong tool, it should drop nothing.


Instead, it drops the correct loot only when a Silk Touch pickaxe is used. When a regular pickaxe is used, it drops both itself and an end stone block; when mined with the wrong tool, the same thing happens.


From the official documentation, "Applying a condition to a pool allows you execute the entire pool based on the conditions defined." In my custom block's loot table, each pool has its own (mutually exclusive) condition, so I'm not sure what's causing multiple drops (which would imply matching both or possibly all 3 conditions, which should be impossible).


Here is the loot table .json file:.


{.


"pools": [.


// Give rhizome block if mined using a Silk Touch pickaxe.


{.


"condition": "query.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_pickaxe') && query.has_silk_touch",.


"rolls": 1,.


"entries": [.


{.


"type": "item",.


"name": "end:rhizome".


}.


].


},.


// Give end stone if mined with a pickaxe without Silk Touch.


{.


"condition": "query.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_pickaxe') && !query.has_silk_touch",.


"rolls": 1,.


"entries": [.


{.


"type": "item",.


"name": "minecraft:end_stone".


}.


].


},.


// Drop nothing if mined with anything other than a pickaxe.


{.


"condition": "!query.equipped_item_any_tag('slot.weapon.mainhand', 'minecraft:is_pickaxe')",.


"rolls": 1,.


"entries": [.


{.


"type": "empty".


}.


].


}.


].


}.


Rearranging the three pools does not change the result. So, it doesn't matter whether the "has silk touch" condition comes first or third: it's still the only one that works as intended.


I also tested swapping out the condition strings with condition arrays of the following form:.


"conditions": [.


{.


"condition": "same molang queries here".


}.


].


but the same problem was still happening.


Question from user Quack E. Duck at gaming.stackexchange.com.


Answer:

Here is a different way of accomplishing the same thing, without using conditions in the loot table:.


Loot table for the block: (set to a single, empty entry).


{.


"pools": [.


// A placeholder; the actual drop will be determined in main.js.


{.


"rolls": 1,.


"entries": [.


{.


"type": "empty".


}.


].


}.


].


}.


Script file (main.js; uses @minecraft/server version 1.10.0-beta): -- This is where we'll test for use of silk touch pickaxe vs. unenchanted pickaxe vs. no pickaxe.


import { world, system, ItemStack, ItemComponentTypes } from "@minecraft/server".


// For use inside the .playerBreakBlock event listener, for getting the broken block's former coordinates.


// Properties will be player names (type String); values will be Block objects.


var lastBlockHitByPlayer = {};.


world.afterEvents.entityHitBlock.subscribe(event => {.


// Keep a record of the last block the player hit.


if (event.damagingEntity.typeId === "minecraft:player") {.


lastBlockHitByPlayer[event.damagingEntity.name] = event.hitBlock;.


}.


});.


world.afterEvents.playerBreakBlock.subscribe(event => {.


if (event.brokenBlockPermutation.type.id === "end:rhizome") {.


const stack = event.itemStackAfterBreak;.


const player = event.player;.


// Block will drop rhizome if mined with a silk touch pickaxe (this happens automatically).


if (stack !== undefined && stack.typeId.includes("_pickaxe") && !stack.getComponent(ItemComponentTypes.Enchantable).hasEnchantment("silk_touch")) {.


// Drop regular end stone if the block is mined with a non-silk-touch pickaxe.


(async () => {.


// For .playerBreakBlock, there's no direct way to access the block's coordinates (because it isn't there anymore?). Instead, the coordinates.


// of the block that has just been broken should be the same as those of the most recent block which the player hit (since hitting the block - left click - is a prerequisite to breaking it).


await player.dimension.spawnItem(new ItemStack("minecraft:end_stone"), {x: lastBlockHitByPlayer[player.name].x, y: lastBlockHitByPlayer[player.name].y, z: lastBlockHitByPlayer[player.name].z});.


})();.


} // Otherwise, drop nothing.


}.


});.


With this method, the custom block drops the correct loot for each case.


Answer from user Quack E. Duck at gaming.stackexchange.com.


[BACK]

Is there a way to share vision with opponent in Starcraft 2? Is there a way to share vision with opponent in Starcraft 2?

Posted On: June 25, 2023
There are times that I would like to be able to share vision with my opponents when playing Starcraft 2. This was possible in the original Starcraft, but I can't find a way in Starcraft 2. Situ...[More]


BG3 trophy list is a bit... BG3 trophy list is a bit...

Posted On: September 26, 2023
Hostile. I don't mind trophies for playing the game badly that take a few minutes to unlock or which can be done in the context of a throwaway save. But Jack of all Trades? Who in their right m...[More]


What happens if you dont found a religion? What happens if you dont found a religion?

Posted On: March 18, 2024
Suppose the other civilizations have founded all the religions that could be founded in that map (that never happened to me, but I'm curious, but not curious enough to spend a night doing an experimen...[More]


Level 40 Is it Possible Hogwarts Legacy? Level 40 Is it Possible Hogwarts Legacy?

Posted On: August 17, 2023
I have a few questions regarding Level 40. 1) Is it worth the effort? 2) I am level 35 on my first play through and am about at the point of boredom starting my 2nd playthrough (dark path this t...[More]


In Professor Layton are there multiple solutions to Alchemists Lair 08? In Professor Layton are there multiple solutions to Alchemists Lair 08?

Posted On: March 13, 2023
In Professor Layton and the Miracle Mask, are there multiple solutions to the Alchemist's Lair 08 downloadable puzzle? I find that the four flasks in the bottom right corner should be able to b...[More]


How do I survive the vampire attack during the Bloodchill Manor quest? How do I survive the vampire attack during the Bloodchill Manor quest?

Posted On: January 23, 2023
I've tried several times to live and not contract Sanguinare Vampiris (although, I've only been using Lifeblood, my dwarven warhammer enchanted with the health-point-steal and not the Flames s...[More]


Does losing to Natsai in the first Charms class matter? Does losing to Natsai in the first Charms class matter?

Posted On: August 11, 2023
Does losing against her make any difference. Also did you win or lose against her your first time? Question from user Kronik95 at HogwartsLegacyGaming at reddit. Answer: I lost to her on m...[More]


What Pokemon characteristics are immutable as of gen 9 games? What Pokemon characteristics are immutable as of gen 9 games?

Posted On: February 6, 2023
I'm picking up Pokemon games with Violet and learning about every additions made to the game since gen 2, I'm having a hard time figuring out what are the Pokemon characteristics you can't change thro...[More]


Can I install an old DirectX version without affecting the latest version? Can I install an old DirectX version without affecting the latest version?

Posted On: May 25, 2023
I'm attempting to run RetroArch for an old game , but it requires DirectX 9.0c. Will installing DirectX 9.0c overwrite or delete the current version I have installed (v12)? If so, can I subsequ...[More]


Should I not have won a culture victory by now in Civilization 6? Should I not have won a culture victory by now in Civilization 6?

Posted On: April 8, 2023
I've been playing Civilization 6 as Tomyris for a while and thought I was comfortably winning a culture victory, but. the game seems to want to keep going without giving me the option to acce...[More]