block that changes to another when stepped on

Started by mjiau on

Topic category: Help with modding (Java Edition)

Last seen on 12:49, 14. Apr 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
block that changes to another when stepped on

I want to make a block that changes into another block when stepped on, and then a third block when stepped on again. The problem is that if I just simply make a procedure to change the block into the next one when stepped on on the first two blocks, it immeadeatly turns into the third block. I want the player to have to step off the block and back on for it to change again.

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You'll need to add an…
Tue, 04/09/2024 - 18:57

You'll need to add an additional nbt logic tag to the block that tracks if a player is currently on it. (Making sure to use the 'replace block, keep NBT data' function.) Essentially:

  • For all three blocks, if there's no player directly above them when ticked, (in 1 block box centered at x + 0.5, y+0.6, z + 0.5), set the tag back to false.
  • When a player steps on block 1, change it to block 2, and change the nbt tag to true. 
  • When a player steps on block 2, if the nbt tag is false, change it to block 3 and set the nbt tag to true again.
Last seen on 12:49, 14. Apr 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
great, but how exactly do I…
Wed, 04/10/2024 - 17:11

great, but how exactly do I add an nbt tag?

Last seen on 12:49, 14. Apr 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
ok well I was able to put…
Wed, 04/10/2024 - 18:12

ok well I was able to put something together although it doesn't work, here's all my code
 

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Did you enable block entity…
Wed, 04/10/2024 - 19:57

Did you enable block entity for your custom block?

Last seen on 12:49, 14. Apr 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yes I did
Fri, 04/12/2024 - 10:08

yes I did

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Okay, the code should look…
Fri, 04/12/2024 - 10:57

Okay, the code should look something like this. The top section is for when the block is stepped on, the bottom section needs to be run on the block's update tick. The tag can be whatever you want to name it, as long as it's consistent:

Is this at all helpful? If this looks more or less like what you've got, I'd recommend double checking everything's linked properly, update tick's enabled, maybe reloading the gradle project if it looks like something's just bugged.

Last seen on 12:49, 14. Apr 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I copied your code pretty…
Fri, 04/12/2024 - 12:18

I copied your code pretty much exactly but it still doesn't work. When I step on the first block its quickly cycles through all the blocks and then turns into the second block and if I step on it again nothing happens. If I step on the second block (one that I placed myself) it turns into block three, just like it should.

I don't know If I've done the variable nbt whatever stuff correctly, that's probably the issue.
Right now I've got a variable called "snowpuzzle" with variable type "logic" and variable scope "GLOBAL_MAP" and initial value "false", I have no idea if that is correct or not.

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Ah. That may be the issue-…
Sat, 04/13/2024 - 12:12

Ah. That may be the issue- global map variables are true for the entire world, and would thus affect all the blocks. You need something that's specific to each block.

If NBT states really aren't working, you could technically make five distinct blocks instead of three. (Block 1, untriggered; Block 1 triggered; Block 2 untriggered, Block 2 triggered, and Block 3.) When a player steps on a block, change it to the triggered variant. When there's no longer a player on top of the block, change it to the next untriggered variant. Probably needlessly complicated, but I guess you'd get to make two additional textures if ya wanted.

Last seen on 12:49, 14. Apr 2024
Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
ok well, after messing…
Sun, 04/14/2024 - 12:30

ok well, after messing around for a while with variables and I've deduced that they're completely broken.

For whatever reason, absolutely randomly, they've changed to a different type of variable? I didn't change them?

If I change them back my mod doesn't compile anymore and everything breaks.

I give up...

Last seen on 13:54, 28. Apr 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
If the mod doesn't compile…
Sun, 04/14/2024 - 16:24

If the mod doesn't compile when you change the variables, that means somewhere you've got a procedure that's trying to reference the old variable. (If you change a logic variable to a number variable, but don't change the procedure, the procedure will try to reference a number variable as if it were logic, which causes a compilation error.) If you click the red links in the error message, it should direct you to which procedures are still using the old one. 

If you still want to give it a try, it might also be worth testing this in another workspace? Then you might be able to get some indication if the code itself is wrong, or if your workspace is corrupted.