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 any way I can give myself 360° vision in game? Is there any way I can give myself 360° vision in game?

Posted On: July 6, 2023
A key gameplay mechanic in Project Zomboid is that your character can only see what's in front of them, even though the game has an isometric perspective. Anything behind becomes shrouded. That...[More]


What games are similar to Hogwarts Legacy? What games are similar to Hogwarts Legacy?

Posted On: April 10, 2023
Looking for suggestions of what to play after I’m done with this game. Are there any games similar that would have you following a story while doing quests or battles? Question from user Harm...[More]


how to make dwarves happier in Dwarf Fortress? how to make dwarves happier in Dwarf Fortress?

Posted On: April 28, 2023
Most of my dwarves are not happy, and I don't know how to make them happier in general. So, how can I properly make at least the angrier of them less unhappy/more happy? I really want to pre...[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]


How do I get Marios hat back after pressing the Yellow Switch? How do I get Marios hat back after pressing the Yellow Switch?

Posted On: September 12, 2023
In the "abandoned" version 0.9 of B3313 (a ROM hack of Super Mario 64), I activated the Yellow Switch which caused Mario to lose his hat. Just like the original version of Super Mario 64, Ma...[More]


What happens to my boarding party if the enemy ship surrenders? What happens to my boarding party if the enemy ship surrenders?

Posted On: March 15, 2024
In Faster than Light, if I still have crew members on the enemy ship when they surrender: What happens to my boarding crew members if I accept the offer from the enemy ship?Question from user stack_ho...[More]


Why don't I love my Dragonborn as I did my Argonians? Why don't I love my Dragonborn as I did my Argonians?

Posted On: March 22, 2026
I can't pinpoint what it is, but I had a fantastic time playing lizard people in Morrowind, Oblivion and Skyrim. It felt different, fun and interesting. The racial traits didn't matter to me - I just ...[More]


Can you add a custom item to Minecraft Java using a resource pack? Can you add a custom item to Minecraft Java using a resource pack?

Posted On: May 18, 2023
I'm trying to add a custom item to Minecraft that players can use as a currency (e.g., a gold coin block). Can I do this with a resource pack, or do I need a full client-side mod? I haven't be...[More]


Stuck with the conjuration curse Stuck with the conjuration curse

Posted On: August 22, 2023
I have got 139/140 conjurations and I am missing the medium constructed decorations. All my collection chests are completed across the maps, I have checked the butterfly missions more than 5 times,...[More]


If I can only buy games as gifts on Steam and not as keys, where do 3rd party resellers get theirs? If I can only buy games as gifts on Steam and not as keys, where do 3rd party resellers get theirs?

Posted On: October 16, 2023
3rd party game key resellers like Kinguin or G2A sell game keys right? Supposedly the key sellers are just other users. I as a user as well cannot seem to buy keys from Steam though? I can only buy th...[More]