Started by
Korra
on
Topic category: Help with Minecraft modding (Java Edition)
I'm trying to find methods to customize the loot drops from mobs when actively using a modded weapon. For example, implementing a feature similar to an auto-smelting pickaxe but for mobs, allowing for altered drops and potentially a percent chance for the specific item to drop alongside the usual vanilla loot table. Does anyone know the solution?
You can't really do this with a loot table, (you probably could actually, it would just be complicated), but you can do this very easily with procedures.
You'll want to first override the entity's loot table so it doesn't drop anything by default. (You can do this the same way you'd override any vanilla loot table; by making a loot table with an identical namespace; but just leave the table empty.)
Then, you can make a procedure that drops items when an entity dies. You'll want to use the 'when entity dies' global trigger, then check if the event/target entity is a subtype of the desired entity, (a pig, or ender dragon, or whatever entity's loot you're trying to modify). Then, make another if-else bracket inside, and check that the item in the main hand of the source entity, (the one who killed it), is your modded item. If it is, you'll use the special loot table, and if it isn't, you'll use something similar to the original version.
You can then make a sort-of bootleg loot table by adding a local number variable to your procedure, then setting it to a random integer 1-100. (Essentially, you can use this for percentages.) If the number is 1-10, you drop one thing, if it's 11-30 you drop a different thing, and so on and so forth. You'll need something that drops the original items, (for the case in which the entity dies without being killed by the modded item), and loot for your custom item, (in the case the killer uses the modded item.) If you want to make this a lot simpler, (but less like vanilla loot tables in terms of probability), you can use the 'do with 70% chance' procedure template, and just use 'repeat' functions to increase the number of rolls.