Home

Minecraft Modding: How to Fix Bugs Related to Events

|
|  Updated:  
2016-03-26 07:31:10
Minecraft Basics For Dummies
Explore Book
Buy On Amazon

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

About This Article

This article is from the book: 

About the book author:

Sarah Guthals, PhD, co-founded an ed-tech company and now continues to build technology for kids to learn, create, and share safely online. She loves to teach teachers how to teach coding in the classroom.

Stephen Foster, PhD, is the CEO of ThoughtSTEM, a company that teaches computer science to kids across America.

Lindsey Handley, PhD, is the COO of ThoughtSTEM and has hundreds of hours of experience as a classroom instructor for Minecraft-based science and computer science classes.