1
0
Fork 0

Add in prototype jump-only mobs api

mineclone5
jordan4ibanez 2021-04-17 18:21:33 -04:00
parent db87b8e0a3
commit 719bb2a3c9
4 changed files with 167 additions and 4 deletions

View File

@ -314,7 +314,7 @@ function mobs:register_mob(name, def)
swim = def.swim, swim = def.swim,
swim_in = def.swim_in or {mobs_mc.items.water_source, "mcl_core:water_flowing", mobs_mc.items.river_water_source}, swim_in = def.swim_in or {mobs_mc.items.water_source, "mcl_core:water_flowing", mobs_mc.items.river_water_source},
pitch_switch = "static", pitch_switch = "static",
--set_animation = mobs.set_animation, jump_only = def.jump_only,
--end j4i stuff --end j4i stuff
-- MCL2 extensions -- MCL2 extensions

View File

@ -342,7 +342,7 @@ local fly_state_switch = function(self, dtime)
end end
--check if a mob needs to turn while flyming --check if a mob needs to turn while flying
local fly_turn_check = function(self,dtime) local fly_turn_check = function(self,dtime)
local pos = self.object:get_pos() local pos = self.object:get_pos()
@ -446,8 +446,115 @@ local fly_state_execution = function(self,dtime)
end end
--[[
___
|_ |
| |_ _ _ __ ___ _ __
| | | | | '_ ` _ \| '_ \
/\__/ / |_| | | | | | | |_) |
\____/ \__,_|_| |_| |_| .__/
| |
|_|
]]--
--check if a mob needs to turn while jumping
local jump_turn_check = function(self,dtime)
local pos = self.object:get_pos()
pos.y = pos.y + 0.1
local dir = minetest_yaw_to_dir(self.yaw)
local collisionbox = self.object:get_properties().collisionbox
local radius = collisionbox[4] + 0.5
vector_multiply(dir, radius)
local test_dir = vector.add(pos,dir)
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
return(green_flag_1)
end
-- state switching logic (stand, jump, run, attacks)
local jump_state_list_wandering = {"stand", "jump"}
local jump_state_switch = function(self, dtime)
self.state_timer = self.state_timer - dtime
if self.wandering and self.state_timer <= 0 then
self.state_timer = math.random(4,10) + math.random()
self.state = jump_state_list_wandering[math.random(1,#jump_state_list_wandering)]
end
end
-- states are executed here
local jump_state_execution = function(self,dtime)
local pos = self.object:get_pos()
local collisionbox = self.object:get_properties().collisionbox
--get the center of the mob
pos.y = pos.y + (collisionbox[2] + collisionbox[5] / 2)
local current_node = minetest_get_node(pos).name
local float_now = false
--recheck if in water or lava
if minetest_get_item_group(current_node, "water") ~= 0 or minetest_get_item_group(current_node, "lava") ~= 0 then
float_now = true
end
if self.state == "stand" then
--do animation
mobs.set_mob_animation(self, "stand")
--set the velocity of the mob
mobs.set_velocity(self,0)
elseif self.state == "jump" then
self.walk_timer = self.walk_timer - dtime
--reset the jump timer
if self.walk_timer <= 0 then
--re-randomize the jump timer
self.walk_timer = math.random(1,6) + math.random()
--set the mob into a random direction
self.yaw = (math_random() * (math.pi * 2))
end
--do animation
mobs.set_mob_animation(self, "walk")
--enable rotation locking
mobs.movement_rotation_lock(self)
--jumping mobs are more loosey goosey
if node_in_front_of == 1 then
quick_rotate(self,dtime)
end
--only move forward if path is clear
mobs.jump_move(self,self.walk_velocity)
elseif self.state == "run" then
print("run")
elseif self.state == "attack" then
print("attack")
end
if float_now then
mobs.float(self)
end
end
@ -470,8 +577,12 @@ mobs.mob_step = function(self, dtime)
return false return false
end end
--jump only (like slimes)
if self.jump_only then
jump_state_switch(self, dtime)
jump_state_execution(self, dtime)
--swimming --swimming
if self.swim then elseif self.swim then
swim_state_switch(self, dtime) swim_state_switch(self, dtime)
swim_state_execution(self, dtime) swim_state_execution(self, dtime)
--flying --flying

View File

@ -221,6 +221,54 @@ mobs.set_fly_velocity = function(self, v)
} }
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
end
--smooths out mobs a bit
if vector_length(new_velocity_addition) >= 0.0001 then
self.object:add_velocity(new_velocity_addition)
end
end
--[[
___
|_ |
| |_ _ _ __ ___ _ __
| | | | | '_ ` _ \| '_ \
/\__/ / |_| | | | | | | |_) |
\____/ \__,_|_| |_| |_| .__/
| |
|_|
]]--
--special mob jump movement
mobs.jump_move = function(self, velocity)
if self.object:get_velocity().y ~= 0 or not self.old_velocity or (self.old_velocity and self.old_velocity.y > 0) then
return
end
--make the mob stick for a split second
mobs.set_velocity(self,0)
--fallback velocity to allow modularity
jump_height = 8
local yaw = (self.yaw or 0)
local current_velocity = self.object:get_velocity()
local goal_velocity = {
x = (math_sin(yaw) * -velocity),
y = jump_height,
z = (math_cos(yaw) * velocity),
}
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity) local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then if vector_length(new_velocity_addition) > vector_length(goal_velocity) then

View File

@ -64,6 +64,7 @@ local slime_big = {
hp_max = 16, hp_max = 16,
xp_min = 4, xp_min = 4,
xp_max = 4, xp_max = 4,
rotate = 270,
collisionbox = {-1.02, -0.01, -1.02, 1.02, 2.03, 1.02}, collisionbox = {-1.02, -0.01, -1.02, 1.02, 2.03, 1.02},
visual_size = {x=12.5, y=12.5}, visual_size = {x=12.5, y=12.5},
textures = {{"mobs_mc_slime.png"}}, textures = {{"mobs_mc_slime.png"}},
@ -100,6 +101,7 @@ local slime_big = {
view_range = 16, view_range = 16,
attack_type = "dogfight", attack_type = "dogfight",
passive = false, passive = false,
jump_only = true,
jump = true, jump = true,
walk_velocity = 2.5, walk_velocity = 2.5,
run_velocity = 2.5, run_velocity = 2.5,
@ -311,6 +313,7 @@ local magma_cube_big = {
}, },
walk_velocity = 4, walk_velocity = 4,
run_velocity = 4, run_velocity = 4,
rotate = 270,
damage = 6, damage = 6,
reach = 3, reach = 3,
armor = 53, armor = 53,
@ -337,12 +340,13 @@ local magma_cube_big = {
}, },
water_damage = 0, water_damage = 0,
lava_damage = 0, lava_damage = 0,
fire_damage = 0, fire_damage = 0,
light_damage = 0, light_damage = 0,
fall_damage = 0, fall_damage = 0,
view_range = 16, view_range = 16,
attack_type = "dogfight", attack_type = "dogfight",
passive = false, passive = false,
jump_only = true,
jump = true, jump = true,
jump_height = 8, jump_height = 8,
walk_chance = 0, walk_chance = 0,