Chapter 5. Movement

Most entities in Minecraft—such as creepers, pigs, and zombies—move in the game. But they don’t have the capability to jump or get damaged when they fall. Also, none of the entities except spiders can climb up walls, and spiders can climb only up to three blocks high. In this chapter, you’ll learn how to change all this by modding the movement of the player.

First, you will make the player jump much higher; then you will add a parachute so that the player can avoid fall damage. Finally, you will make a mod that lets snow golems and iron golems climb up walls to reach hostile mobs that they can kill.

Super Jump

A Minecraft player can normally jump up to 1.252 blocks. This is typically done to jump over a block or get out of a cave. But what if you were to jump over a cliff that is much higher or a cave that is much deeper? This mod will give you the ability to jump much higher and reach new heights.

First, make a new class and call it SuperJump. Register it in the main file to activate the mod. The event handler method code that needs to be added to this class is shown in Example 5-1.

Example 5-1. Super jump method code
@SubscribeEvent
public void makeJumpHigher(LivingJumpEvent event){ 1
	if (!(event.entity instanceof EntityPlayer)) { 2
		return;
	}

	event.entity.motionY ...

Get Minecraft Modding with Forge now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.