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]

Would the companion talk to each other about Tav - Durge? Would the companion talk to each other about Tav - Durge?

Posted On: November 8, 2023
Specifically if you manage to romance nearly all of them, do they just sit around the campfire and talk to each other about it, like it's the Bachelor/Bachelorette - Faerun edition? Or do they ...[More]


Will switching fishing rods break my chain in Holocure Save The Fans? Will switching fishing rods break my chain in Holocure Save The Fans?

Posted On: September 26, 2023
When fishing at the Holo House, you catch extra bonus fish if you successfully catch multiple fish in a row. If I switch to a different fishing rod by talking to Bloop, will it break my fishing chain?...[More]


Why is Shadowheart so…. loved? Why is Shadowheart so…. loved?

Posted On: November 30, 2023
Hear me out, I’m not trying to shart (hehe) on her character or anything. I just kind of find her annoying? I think a lot of it might be due to the fact that she was overhyped to me before I pla...[More]


What types of kills are counted on Strange Flamethrowers? What types of kills are counted on Strange Flamethrowers?

Posted On: April 9, 2024
When playing Team Fortress 2, I noticed that my Strange Flare Gun had more than double the amount of kills my Strange Degreaser had (I started using both of them at about the same time). Even though I...[More]


Is there a way to fully load a turret in Factorio? Is there a way to fully load a turret in Factorio?

Posted On: March 18, 2023
For the defense of my factory I use Gun Turrets. I've got a belt with magazines running past them. However when there are a lot of biters/spitters coming the belt can't provide fast enough so ...[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]


Can the Japanese version be played in English? Can the Japanese version be played in English?

Posted On: February 1, 2023
Can the Japanese version of Pokémon Conquest be played in English (via a setting menu or something)? Or can that version of Pokémon Conquest only be played in the Japanese language?Question from...[More]


Whats the air intake parts air drag in Kerbal Space Program past 1.0? Whats the air intake parts air drag in Kerbal Space Program past 1.0?

Posted On: April 3, 2023
I've been considering increasing efficiency of my early launch stages by adding jet engines. I found an old thread discussing the idea, and one post struck me as "make-or-break" of my id...[More]


Fallout 4 wont launch after Xbox update Fallout 4 wont launch after Xbox update

Posted On: April 25, 2024
After the Xbox update on December 6th to version 10.0.25398.2917 I am unable to start Fallout 4 anymore. The loading screen is shown, but nothing else happens.As this is the only game I have installed...[More]


What does the Runescape Dismiss familiar button do when it is a pet? What does the Runescape Dismiss familiar button do when it is a pet?

Posted On: May 14, 2023
What happens when you click on the "Dismiss familiar" button when it's not a summon but a pet? By that I mean the rightmost button in: . Does the pet return to inventory? Does it go a...[More]