Minecraft Modding: How to Fix Bugs Related to Events - For Dummies

In Minecraft, you have no way to indicate that you no longer want to trigger events. To trigger an event means that Minecraft recognizes that the event has happened and then calls the function that was set up in the event call.

For example, this shows the SetupPlayer function, which has an event setup block in it. This event is triggered after two seconds, and then it teleports the player to the center of the arena.

image0.jpg

Because you don’t always want events to be triggered, testing your code can be difficult. For example, in Spleef you replace only the block below you with air if you’re walking on diamond blocks (the arena).

If you run the Spleef mod and play it and then decide to explore a cave instead, you start to fall through the ground. That’s because, as you can see below, every 1 second the removeBlockAfterStep function is called and the block below you is replaced with an air block.

image1.jpg

You can get an event to stop triggering, but you have to disconnect from the server and reconnect.

To avoid having to disconnect from the server every time you play a game of Spleef, you can add a simple conditional statement that checks to make sure that you’re walking on a diamond block before it changes it to an air block.

This shows the blocks you need to add to the removeBlock function to check the type of block you’re walking on.

image2.jpg