Skip to content

How To Create A Mob

jordan4ibanez edited this page Jan 2, 2017 · 30 revisions

This mod is broken down into an easy to use API. Let's go through the steps.


The first step in making a mob using this mod is to create the table which houses all the mob's variables:

open_ai.register_mob("creeper",{})

As you can see you do not need to include the mod name, as it will automatically be set.


Second let's set some aesthetic variables:

The visual can be "cube"/"sprite"/"upright_sprite"/"mesh"/"wielditem", whatever you'd like. But we'll use mesh for this example.

visual = "mesh",

Where you define the mesh you created.

mesh = "creeper.b3d",

Where you define the textures.

textures = {"creeper.png"},

The animation table. You put the key frames of the animations you created for your mob here. For now there is only the walk_start and walk_end. The speed is the speed that the mesh plays at when the mob walks around.

animation = {
	speed_normal = 10,
	walk_start = 71,
	walk_end = 89,
},

For jump only mobs the animation table will look like this:

animation = {
	speed_normal = 60,
	stand_start = 10,
	stand_end = 50,
	jump_start = 70,
	jump_end = 95,
},

The direction the mob's mesh faces in. If your mob is facing sideways or backwards, try tweaking this setting in 90 degree intervals.

automatic_face_movement_dir = 90,

Whether or not the mob makes footstep sounds when moving around

makes_footstep_sound = true,

The scale of the mesh model. X is width, Y is height

visual_size = {x=2,y=2},

This is the color of the safari ball when it is captured.

ball_color = "0000ff",


Third, let's add some physical variables

The collisionbox of the mob, try to center your mob in it as best as you can for the best mob possible! Keep the width equal and negative in the first two, and positive in the last two.

collisionbox = {-width,-Y,-width,width,+Y,width},

collisionbox = {-0.4, -0.0, -0.4, 0.4, 1.0, 0.4},

If a mob collides with the terrain. Setting this to false is useful for ghosts or entities similar.

physical = true,

How high a mob jumps.

jump_height = 5,

If this is set the mob will jump around as it's main method of transportation.

jump_only = true

How much health a mob has.

health = 20,

The highest velocity a mob can hit a node in any direction before it takes damage.

hurt_velocity = 7,

The max velocity the mob can run.

max_velocity = 3,

This variable defines how fast a mob gets up to speed, slows down, and any matter of movement besides jumping. Keep this around the max_velocity speed for best result

acceleration = 3,

This defines how many seconds must pass before a mob can change states or direction

behavior_change_min = 3,

behavior_change_max = 5,

Whether the mob will float in water or sink to the bottom.

float = true,

What a mob drops when it dies

drops = "wool:white",


Fourth, the behavior variables


For debug purposes, the mob will pathfind to you if you're in the area if you're holding this item.

follow_item = "default:dry_grass_1",

If a mob can be leashed.

leash = true,

If a mob can ride in a cart.

rides_cart = true,

If a mob is hostile.

hostile = false,

The node that the mob will spawn on.

spawn_node = "default:dirt_with_grass",


Riding and Mob Chairs


Mobs that are rideable use special functions for riding and the mob chair. The chair can be a saddle, a sheet, an actual chair. When you create the model, make the mob chair it's own part of the texture map, so that you can reuse the texture with the chair part translucent. (The horse mob for an example) Alternatively the texture of the normal mob can be slightly modified so it looks like it has a sheet on it. Do whatever you think is best!

The Y eye offset of the player when they ride the mob.

eye_offset = 8,

How high the player model is in 3rd person view and to other players when riding the mob.

visual_offset = 16.5,

The pose the player is in when riding the mob, can be a single frame, as in the example here, or an animation from the default animation table.

player_pose = { x=194, y=194, },

If the mob can be ridden.

rideable = true,

If the mob can be tamed.

tameable = true,

The item you right click the mob with to tame.

tame_item = "farming:wheat",

How many times, min and max a player has to click to tame the mob with the item. Is randomized for each mob.

tame_click_min = 3,

tame_click_max = 10,

The chair that the player can put on the mob.

mob_chair = "open_ai:saddle",

The texture the mob uses once a player puts the mob chair on it.

chair_textures = {"equine2-saddle.png"},


Water Mobs


Water mobs require variables to be set so they function correctly.

If a mob is a water mob.

liquid_mob = true,

Set these three to false and there won't be any problems with your mob!

leash = false,

rides_cart = false,

hostile = false,

If a mob is a water mob then it will spawn inside of this node instead of on top of it

spawn_node = "default:water_source",


User Defined Functions


Users can define custom functions that the mob will execute.

Standard entity functions

on_step = function(self,dtime)

end,

on_activate = function(self, staticdata, dtime_s)

end,

on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)

end,

on_rightclick = function(self, clicker)

end,

Executed when the mob gets hurt.

on_hurt = function(self,hp_change)

end,

Executed when the mob jumps.

on_jump = function(self,dtime)

end,

on_die = function(self, puncher, time_from_last_punch, tool_capabilities, dir)

end,


Example


Here is a basic example of what your mob registration table should look like. This is the sheep.

open_ai.register_mob("sheep",{
	collisionbox = {-0.4, -0.0, -0.4, 0.4, 1.0, 0.4},
	physical = true,
	jump_height = 5,
	health = 20, 
	hurt_velocity = 7,
	--mob movement variables
	max_velocity = 3,
	acceleration = 3,
	behavior_change_min = 3, 
	behavior_change_max = 5, 
	float = true, 
	--mob aesthetic variables
	visual = "mesh",
	mesh = "sheeptest.b3d",
	textures = {"sheeptest.png"},
	animation = {
		speed_normal = 10,
		stand_start = 0,
		stand_end = 60,
		walk_start = 71,
		walk_end = 89,
	},
	automatic_face_movement_dir = 0,
	makes_footstep_sound = true, 
	visual_size = {x=2,y=2},
	--mob behavior variables
	follow_item = "default:dry_grass_1",
	leash       = true,
	rides_cart  = true,
	hostile     = false,
	spawn_node  = "default:dirt_with_grass",
	--safari ball variables
	ball_color = "0000ff",
	--what a mob drops on death
	drops = "wool:white",
	--user defined functions
	on_step = function(self,dtime)
		print(dtime)
	end,
	on_activate = function(self, staticdata, dtime_s)
		print("activating")
	end,
	on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
		print("hit")
	end,
	on_die = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
		print("poof")
	end,
	on_rightclick = function(self, clicker)
		print("right clicked")
	end,
	--when a mob gets hurt
	on_hurt = function(self,hp_change)
		print(hp_change)
	end,
	--when a mob jumps
	on_jump = function(self,dtime)
		print("user defined jump sheep!")
	end,

})