forked from MineClone5/MineClone5
Overhaul separation of swimming and flying for ease of use with writing mobs api
This commit is contained in:
parent
5365dec19a
commit
061602d9d4
|
@ -311,6 +311,8 @@ function mobs:register_mob(name, def)
|
||||||
wandering = true,
|
wandering = true,
|
||||||
current_animation = "",
|
current_animation = "",
|
||||||
gravity = GRAVITY,
|
gravity = GRAVITY,
|
||||||
|
swim = def.swim,
|
||||||
|
swim_in = def.swim_in or {mobs_mc.items.water_source, "mcl_core:water_flowing", mobs_mc.items.river_water_source},
|
||||||
--set_animation = mobs.set_animation,
|
--set_animation = mobs.set_animation,
|
||||||
--end j4i stuff
|
--end j4i stuff
|
||||||
|
|
||||||
|
|
|
@ -173,26 +173,24 @@ end
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
______ _ _ _______ _ _
|
_____ _
|
||||||
| ___| | (_) / / ___| (_) (_)
|
/ ___| (_)
|
||||||
| |_ | |_ _ _ _ __ __ _ / /\ `--.__ ___ _ __ ___ _ __ ___ _ _ __ __ _
|
\ `--.__ ___ _ __ ___
|
||||||
| _| | | | | | | '_ \ / _` | / / `--. \ \ /\ / / | '_ ` _ \| '_ ` _ \| | '_ \ / _` |
|
`--. \ \ /\ / / | '_ ` _ \
|
||||||
| | | | |_| | | | | | (_| |/ / /\__/ /\ V V /| | | | | | | | | | | | | | | | (_| |
|
/\__/ /\ V V /| | | | | | |
|
||||||
\_| |_|\__, |_|_| |_|\__, /_/ \____/ \_/\_/ |_|_| |_| |_|_| |_| |_|_|_| |_|\__, |
|
\____/ \_/\_/ |_|_| |_| |_|
|
||||||
__/ | __/ | __/ |
|
|
||||||
|___/ |___/ |___/
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- state switching logic (stand, walk, run, attacks)
|
-- state switching logic (stand, walk, run, attacks)
|
||||||
local fly_state_list_wandering = {"stand", "fly"}
|
local swim_state_list_wandering = {"stand", "swim"}
|
||||||
|
|
||||||
local fly_state_switch = function(self, dtime)
|
local swim_state_switch = function(self, dtime)
|
||||||
self.state_timer = self.state_timer - dtime
|
self.state_timer = self.state_timer - dtime
|
||||||
if self.wandering and self.state_timer <= 0 then
|
if self.wandering and self.state_timer <= 0 then
|
||||||
self.state_timer = math.random(4,10) + math.random()
|
self.state_timer = math.random(4,10) + math.random()
|
||||||
self.state = fly_state_list_wandering[math.random(1,#fly_state_list_wandering)]
|
self.state = swim_state_list_wandering[math.random(1,#swim_state_list_wandering)]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -203,13 +201,13 @@ local flop = function(self,dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
--this is to swap the built in engine acceleration modifier
|
--this is to swap the built in engine acceleration modifier
|
||||||
local fly_physics_swapper = function(self,inside_fly_node)
|
local swim_physics_swapper = function(self,inside_swim_node)
|
||||||
|
|
||||||
--should be flying, gravity is applied, switch to floating
|
--should be swimming, gravity is applied, switch to floating
|
||||||
if inside_fly_node and self.object:get_acceleration().y ~= 0 then
|
if inside_swim_node and self.object:get_acceleration().y ~= 0 then
|
||||||
self.object:set_acceleration(vector_new(0,0,0))
|
self.object:set_acceleration(vector_new(0,0,0))
|
||||||
--not be flying, gravity isn't applied, switch to falling
|
--not be swim, gravity isn't applied, switch to falling
|
||||||
elseif not inside_fly_node and self.object:get_acceleration().y == 0 then
|
elseif not inside_swim_node and self.object:get_acceleration().y == 0 then
|
||||||
self.pitch = 0
|
self.pitch = 0
|
||||||
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
||||||
end
|
end
|
||||||
|
@ -218,27 +216,27 @@ end
|
||||||
|
|
||||||
local random_pitch_multiplier = {-1,1}
|
local random_pitch_multiplier = {-1,1}
|
||||||
-- states are executed here
|
-- states are executed here
|
||||||
local fly_state_execution = function(self,dtime)
|
local swim_state_execution = function(self,dtime)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
pos.y = pos.y + self.object:get_properties().collisionbox[5]
|
pos.y = pos.y + self.object:get_properties().collisionbox[5]
|
||||||
local current_node = minetest_get_node(pos).name
|
local current_node = minetest_get_node(pos).name
|
||||||
local inside_fly_node = false
|
local inside_swim_node = false
|
||||||
|
|
||||||
--quick scan everything to see if inside fly node
|
--quick scan everything to see if inside swim node
|
||||||
for _,id in pairs(self.fly_in) do
|
for _,id in pairs(self.swim_in) do
|
||||||
if id == current_node then
|
if id == current_node then
|
||||||
inside_fly_node = true
|
inside_swim_node = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--turn gravity on or off
|
--turn gravity on or off
|
||||||
fly_physics_swapper(self,inside_fly_node)
|
swim_physics_swapper(self,inside_swim_node)
|
||||||
|
|
||||||
--fly properly if inside fly node
|
--swim properly if inside swim node
|
||||||
if inside_fly_node then
|
if inside_swim_node then
|
||||||
|
|
||||||
if self.state == "stand" then
|
if self.state == "stand" then
|
||||||
|
|
||||||
|
@ -250,9 +248,9 @@ local fly_state_execution = function(self,dtime)
|
||||||
|
|
||||||
--print("standing")
|
--print("standing")
|
||||||
|
|
||||||
mobs.set_fly_velocity(self,0)
|
mobs.set_swim_velocity(self,0)
|
||||||
|
|
||||||
elseif self.state == "fly" then
|
elseif self.state == "swim" then
|
||||||
|
|
||||||
self.walk_timer = self.walk_timer - dtime
|
self.walk_timer = self.walk_timer - dtime
|
||||||
|
|
||||||
|
@ -270,9 +268,9 @@ local fly_state_execution = function(self,dtime)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
mobs.set_fly_velocity(self,self.walk_velocity)
|
mobs.set_swim_velocity(self,self.walk_velocity)
|
||||||
end
|
end
|
||||||
--flop around if not inside fly node
|
--flop around if not inside swim node
|
||||||
else
|
else
|
||||||
--print("flopping")
|
--print("flopping")
|
||||||
flop(self,dtime)
|
flop(self,dtime)
|
||||||
|
@ -304,10 +302,10 @@ mobs.mob_step = function(self, dtime)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--swimming/flying
|
--swimming
|
||||||
if self.fly then
|
if self.swim then
|
||||||
fly_state_switch(self, dtime)
|
swim_state_switch(self, dtime)
|
||||||
fly_state_execution(self, dtime)
|
swim_state_execution(self, dtime)
|
||||||
--regular mobs that walk around
|
--regular mobs that walk around
|
||||||
else
|
else
|
||||||
land_state_switch(self, dtime)
|
land_state_switch(self, dtime)
|
||||||
|
|
|
@ -11,6 +11,17 @@ local vector_multiply = vector.multiply
|
||||||
|
|
||||||
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
_ _
|
||||||
|
| | | |
|
||||||
|
| | __ _ _ __ __| |
|
||||||
|
| | / _` | '_ \ / _` |
|
||||||
|
| |___| (_| | | | | (_| |
|
||||||
|
\_____/\__,_|_| |_|\__,_|
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
||||||
-- move mob in facing direction
|
-- move mob in facing direction
|
||||||
--this has been modified to be internal
|
--this has been modified to be internal
|
||||||
--internal = lua (self.yaw)
|
--internal = lua (self.yaw)
|
||||||
|
@ -71,6 +82,22 @@ mobs.jump = function(self, velocity)
|
||||||
self.object:add_velocity(vector_new(0,velocity,0))
|
self.object:add_velocity(vector_new(0,velocity,0))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--[[
|
||||||
|
_____ _
|
||||||
|
/ ___| (_)
|
||||||
|
\ `--.__ ___ _ __ ___
|
||||||
|
`--. \ \ /\ / / | '_ ` _ \
|
||||||
|
/\__/ /\ V V /| | | | | | |
|
||||||
|
\____/ \_/\_/ |_|_| |_| |_|
|
||||||
|
]]--
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--make mobs flop
|
--make mobs flop
|
||||||
mobs.flop = function(self, velocity)
|
mobs.flop = function(self, velocity)
|
||||||
|
|
||||||
|
@ -106,7 +133,7 @@ end
|
||||||
--this has been modified to be internal
|
--this has been modified to be internal
|
||||||
--internal = lua (self.yaw)
|
--internal = lua (self.yaw)
|
||||||
--engine = c++ (self.object:get_yaw())
|
--engine = c++ (self.object:get_yaw())
|
||||||
mobs.set_fly_velocity = function(self, v)
|
mobs.set_swim_velocity = function(self, v)
|
||||||
|
|
||||||
local yaw = (self.yaw or 0)
|
local yaw = (self.yaw or 0)
|
||||||
local pitch = (self.pitch or 0)
|
local pitch = (self.pitch or 0)
|
||||||
|
|
|
@ -48,8 +48,7 @@ mobs:register_mob("mobs_mc:squid", {
|
||||||
},
|
},
|
||||||
visual_size = {x=3, y=3},
|
visual_size = {x=3, y=3},
|
||||||
makes_footstep_sound = false,
|
makes_footstep_sound = false,
|
||||||
fly = true,
|
swim = true,
|
||||||
fly_in = { mobs_mc.items.water_source, "mcl_core:water_flowing", mobs_mc.items.river_water_source },
|
|
||||||
breathes_in_water = true,
|
breathes_in_water = true,
|
||||||
jump = false,
|
jump = false,
|
||||||
view_range = 16,
|
view_range = 16,
|
||||||
|
|
Loading…
Reference in New Issue