#Custom loot table when breaking spawner

1 messages · Page 1 of 1 (latest)

tall crypt
#

Hi, I've been making a custom datapack, which (including other things) allows me to craft spawners and spawn eggs using netherrite.

I want to be able to break and collect the spawners so I can move them around (because they're quite expensive to make). Getting the spawners to drop was pretty easy, but I'm having trouble with getting it to drop the spawn egg that was used on it. Is this possible? If not, another alternative could be to make it drop the netherrite needed to craft the spawn egg, but then you would have to somehow check if the spawner has already been activated with a spawn egg, and I'm not sure how I would do that.

Any help would be appreciated!

dark whaleBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1735935027:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

forest adder
#

I'm not 100% this will work, but in theory, in your loot table you can make an entry forbeach spawn egg, and as a condition on each of those entries, do a location check and add a predicate to them check the NBT of the block, so you can make it drop a pig spawn egg only if it has the NBT of a pig spawner

#

The issue is that it's possible this won't work if the block is considered gone when the loot table gets called

tall crypt
#

what would the nbt be for a pig spawner?

#

or what would I put in the nbt spot

forest adder
#

But it's probably gonna be something like {SpawnData:{id:"minecraft:pig"}}

Note that I completely made that up, just to illustrate what kind of info you're looking for

tall crypt
#

i used data get block and got this but it doesnt seem to work

forest adder
#

You need to put it in {}

tall crypt
#

it is, it was just formatted weirdly lol

#

but it doesnt work

forest adder
#

Ah I see. Well, to confirm my theory, try calling the loot table while the block is still there using the /loot command, and see if the issue is just that the block is gone before the loot table is called, and so it can't check the NBT

tall crypt
#

it works with the /loot command

forest adder
#

So yeah, unfortunately this won't be a viable method for mining it

#

Oh you know what, I think you can use a copy_components function on the item entry

#

Though I don't have hands-on experiencing using that. I think you can just include block_entity_data, but I'm not really sure

tall crypt
#

I already tried it since the chest loot table preset had it but it didnt work, though I didnt add anything to the "include" section since the chest preset didnt have anything there

forest adder
#

Well try it with the include

#

Cause things like Shulker Boxes do use that, though they specify different components

tall crypt
#

it doesn't seem work with that either

forest adder
#

Unfortunate

#

In that case seems like the only way to get the behavior you want will be to summon a marker at each spawner's position that stores what mob type it has, and make that drop the corresponding loot table and kill itself if the mob spawner gets removed

tall crypt
#

hmmm

#

I have no idea how I would do that

tall crypt
tall crypt
forest adder
#

We'd run into the same problem

#

A spawner that has had a spawn egg used on it is practically indistinguishable from a spawner that hasn't, at least without checking NBT, which you can't do in the loot table

tall crypt
#

ah

tall crypt
forest adder
#

Not like a lot, the biggest thing is just spawning the markers without duplicating.

Rough rundown of the process:

  1. Periodically scan the area around every player for spawner blocks, check if those positions already have a marker entity there, and if they don't, spawn one there.
  2. As and at each marker, periodically (probably not every tick, so as not to eat performance) check the data of the block and set their score depending on the mob NBT it has
  3. As and at each marker, check every tick if there is a spawner block there, and if not, drop a loot table that uses the marker's score as a condition for each item entry to drop the correct and corresponding mob type, and then kill the marker.
#

This will require a tick function, and a load function that creates the scoreboard objective and starts at least one scheduled function

#

Plus a couple more than will branch off from each

tall crypt
#

I already have a tick and load function

#

Im still a beginner with datapacks so Im not sure how I should do this

stark wave
#

something you gotta know is as @a at @s i didnt know it when i started

#

just fyi

forest adder
#

Or if you have a specific question, you can ask that

#

But so far you've only asked a broad question, so I've given a broad answer

tall crypt
#

yeah that makes sense. I'll close this post since the original question has basically been resolved. I'll make a new post if something new comes up, but thank you for the help regardless!! 🙏🙏