5

So me and my friend are creating a Mario-like game in Minecraft Bedrock Edition. We are struggling with trying to come up with code. What we need is so if the player is standing on a red mushroom it breaks the mushroom and gives the player an item. The problem is that we need to have both things happen at the exact same time (without a comparator delay too) so that you can pick up multiple mushrooms in a row without missing any.

We have tried

/execute @a ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air and then hooking it up to a give command using a comparator. Obviously it works but we cant have a delay between picking up the mushrooms.

We have also tried running two execute commands in repeating, one that gives you an item and one that destroys the mushroom. The problem is it creates a 50/50 of if it works or not.

Could someone help us out with this?

1
  • Does it need to give you an item, or can it just be the mushroom block's drop? I've got a neat, fast answer using a single command and loot tables, but I'm not sure whether it's valid.
    – wizzwizz4
    Commented Jul 30, 2020 at 13:24

2 Answers 2

4

There is a simple fix to this:

Have a Repeat command block set to Always Active, with this command:

/execute @a ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air

There is a house/pentagon-shaped object with dots on it, and it should be on top, and pointing to a chain command block.

The chain command block should have your command that gives the player a mushroom, set to Always Active, and Conditional. The Conditional statement is there for this reason:

If the Repeat command block detects a player on a mushroom, then they will give that player a mushroom. If not, then nothing happens. If the block was Unconditional, then players would have their inventories cluttered with mushrooms. I hope this helps.

Edit: Because we want to detect which player stepped on a mushroom, we need separate pairs of command blocks for each player, like so:

/execute fasterthanlight ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air /give fasterthanlight red_mushroom 1

For each player, set up a different pair of command blocks with these commands, and replace my username with your targeted player. For example, with two players, Alice and Bob, two pairs of blocks will be used:

/execute Alice ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air /give Alice red_mushroom 1

and

/execute Bob ~~~ detect ~~~ red_mushroom 0 fill ~~~ ~~~ air /give Bob red_mushroom 1

1
  • 1
    Hm, nice answer. This does get a bit verbose, though, but it could work for a minimal number of players.
    – One 2 Many
    Commented Jul 30, 2020 at 4:09
5

1.19.10+ Update

As of MCBE 1.19.10, the syntax of /execute has been changed to more closely resemble that of Java Edition. The new syntax takes effect if the "Upcoming Creator Features" experimental toggle is enabled.

Replacement commands for this system using the new syntax are here:

  1. execute as @a at @s if block ~ ~-1 ~ red_mushroom 0 run give @s mushroom
    
  2. execute as @a at @s if block ~ ~-1 ~ red_mushroom 0 run setblock ~ ~-1 ~ air
    

Here is an answer that works no matter how many players there are.

Place down an always active repeating command chain of 2 blocks.

Commands inside:

  1. Tell everyone with a red_mushroom under them to give themselves an item.

    execute @a ~ ~ ~ detect ~ ~-1 ~ red_mushroom 0 give @s mushroom
    
  2. Tell everyone with with a red_mushroom under them to set the block underneath them to air.

    execute @a ~ ~ ~ detect ~ ~-1 ~ red_mushroom 0 setblock ~ ~-1 ~ air
    
2
  • 1
    Can you elaborate on this as well?
    – WarpPrime
    Commented Jul 30, 2020 at 2:28
  • I am wondering why this tag method works.
    – WarpPrime
    Commented Jul 30, 2020 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.