4

The idea

I'm attempting (via data pack) to use an interaction (tagged MobSpawner) to cycle through a "list" of different mobs when it's right-clicked, but only after having been right-clicked once prior (i.e, when all is said and done, I want the player to "unlock" it first before it cycles; I also have it set to a stupid delay, so mobs won't spawn beforehand).

My attempts to do this so far have involved two scoreboards (named UnlockedMob and MobOption for example purposes), and various checks in a function running every tick.

The attempts

The initial unlock check works as follows;

  • Unless UnlockMob is already set, if the interaction entity has any interaction data, modify the spawner's Delay from insanely long to a quick time.
    • execute as @e[type=interaction,tag=MobSpawner] unless score @s UnlockedMob matches 1 if data entity @s interaction run data modify block ~ ~ ~ Delay set value 10s
  • With the same checks, set MobOption for it to 1.
    • ...run scoreboard players set @s MobOption 1
  • With the same checks, set UnlockedMob to 1.
    • ...run scoreboard players set @s UnlockedMob 1
  • Remove the interaction data from the entity
    • execute as @e[type=minecraft:interaction,tag=MobSpawner] run data remove entity @s interaction

With UnlockedMob set to one, in theory, any further interactions with the entity should not trigger this section of code.

Then, I have code set for the following;

  • If the interaction entity has any interaction data, and MobOption is 1, modify the spawner's entity to be a Cow.
    • execute as @e[type=minecraft:interaction,tag=MobSpawner] if data entity @s interaction if score @s MobOption matches 1 run data modify block 10 1 10 SpawnData.entity.id set value "minecraft:cow"
  • With the same checks, set MobOption to 2.
    • ... run scoreboard players set @s MobOption 2
  • Remove the interaction data from the entity
    • execute as @e[type=minecraft:interaction,tag=MobSpawner] run data remove entity @s interaction

These commands are then basically copy-pasted, with if score @s MobOption matches and scoreboard players set @s MobOption increasing by one, until we hit the end of the "list" where I set it back to 1 again.

The problem

I have tried every conceivable fashion of modifying this to make it work; the furthest I got was without any form of "has unlocked" check and without removing the interaction data, where it immediately shot to the end of the list and remained unchanged no matter what I did.

Now, however, it remains unmoved and unchanged regardless of what I try. The interaction entity isn't even getting the MobOption or UnlockedMob scores, which I've tested standalone outside the data pack both via command blocks and via the chat, and have worked fine.

1 Answer 1

2

The issue was due to poor firing across the board.

Because it was trying to reset itself constantly and perform a stupid number of checks, it would eventually fail on a check and refuse to run.

The resolution itself was to modularize each section into its own functions; rather than the one massive function file for each check, I now have the main function file performing checks on unlocking and/or cycling, and separate function files handling the actual unlocking and cycling.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .