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 Hogwarts Legacy on Hard Difficulty really that difficult? Is Hogwarts Legacy on Hard Difficulty really that difficult?

Posted On: May 26, 2023
I finished downloading the game the other day and I haven’t had time to really start it. I like a bit of a challenge but I don’t want anything too crazy. Question from user Interesting-...[More]


Maximizing unarmed damage in skyrim Maximizing unarmed damage in skyrim

Posted On: February 15, 2023
It's been nearly a decade since this was asked, and by now it's hard to find an installation of Skyrim without at least the DLCs. There's no guarantee that Khajit are the strongest unarmed...[More]


Whats the max limit for each currency? Whats the max limit for each currency?

Posted On: April 10, 2024
The game has six currencies. I just found out the "R" currency caps at 50,000. What about the others?Question from user BlueRaja - Danny Pflughoeft at gaming.stackexchange.com.Answer: Requisition sli...[More]


Are Cheats in GTA5 official feature or is it some hack spread by developers - users? Are Cheats in GTA5 official feature or is it some hack spread by developers - users?

Posted On: November 30, 2023
When you press ` (backtick) key in GTA5, you can enter cheat codes like BUZZOFF. Now I was wondering is this official feature? I find it a bit strange because on GTA5 official site and in their Man...[More]


How well does the Nintendo Switch perform in terms of graphics compared to the Xbox One and PlayStation 4? How well does the Nintendo Switch perform in terms of graphics compared to the Xbox One and PlayStation 4?

Posted On: February 28, 2023
I'm interested in playing Hogwarts Legacy on Nintendo Switch. Since the Switch is a mobile console, I'm a little concerned the game's graphics might not as good as on the XBOX or PlaySt...[More]


Why do Pokemon sometimes have dark stripes in Pokemon Go? Why do Pokemon sometimes have dark stripes in Pokemon Go?

Posted On: February 5, 2023
Occasionally I'll face a Charizard or Venusaur in GBL that has dark striping like this:.How do they get those markings, or what is the significance of them?Question from user Lysander at gaming.stacke...[More]


In Farmville, Can I make friends with people who arent my social media friends? In Farmville, Can I make friends with people who arent my social media friends?

Posted On: May 25, 2023
I want friends! Friends seem awesome! I have a couple through people I know on Facebook, but not a lot of people I know are playing this game. Can I make friends any other way than connecting my socia...[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 save the Distressed Patient in Baldurs Gate 3? How do I save the Distressed Patient in Baldurs Gate 3?

Posted On: August 9, 2023
I completed combat with Malus Thorm (The Surgeon), and there's a Distressed Patient still locked into the Surgical Bed. He is still alive, but he has the condition "In Surgery" which say...[More]


How to farm large amount of studs in Lego Star Wars The Force Awakens How to farm large amount of studs in Lego Star Wars The Force Awakens

Posted On: March 25, 2023
I have been playing through Lego Star Wars: The Force Awakens. Once you get to the end of the game most of the characters are unlocked but you need to actually "buy" them in order to use ...[More]