Use node groups to determine swimming & burning
This commit is contained in:
parent
43d076dec8
commit
f631d43e55
@ -2,6 +2,7 @@
|
|||||||
v1.2-cmer
|
v1.2-cmer
|
||||||
---------
|
---------
|
||||||
- fixed nil error when clearing entity's nametag on death
|
- fixed nil error when clearing entity's nametag on death
|
||||||
|
- uses node groups to determine swimming & burning instead of depending on `default`
|
||||||
|
|
||||||
v1.1-cmer
|
v1.1-cmer
|
||||||
---------
|
---------
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
-- Localizations
|
-- Localizations
|
||||||
local rnd = math.random
|
local rnd = math.random
|
||||||
|
|
||||||
local translate_name = dofile(cmer.modpath .. "/misc_functions.lua")
|
local translate_name, is_water_node, is_burning_node = dofile(cmer.modpath .. "/misc_functions.lua")
|
||||||
|
|
||||||
|
|
||||||
local function knockback(selfOrObject, dir, old_dir, strengh)
|
local function knockback(selfOrObject, dir, old_dir, strengh)
|
||||||
@ -703,31 +703,28 @@ cmer.on_step = function(self, dtime)
|
|||||||
--swim
|
--swim
|
||||||
if self.can_swim and self.swimtimer > 0.8 and self.last_node then
|
if self.can_swim and self.swimtimer > 0.8 and self.last_node then
|
||||||
self.swimtimer = 0
|
self.swimtimer = 0
|
||||||
local name = self.last_node.name
|
if is_water_node(self.last_node) then
|
||||||
if name then
|
self.air_cnt = 0
|
||||||
if name == "default:water_source" then
|
local vel = me:get_velocity()
|
||||||
self.air_cnt = 0
|
update_velocity(me, {x=vel.x, y=0.9, z=vel.z}, 1)
|
||||||
local vel = me:get_velocity()
|
me:set_acceleration({x=0, y=-1.2, z=0})
|
||||||
update_velocity(me, {x=vel.x, y=0.9, z=vel.z}, 1)
|
self.in_water = true
|
||||||
me:set_acceleration({x=0, y=-1.2, z=0})
|
-- play swimming sounds
|
||||||
self.in_water = true
|
if def.sounds and def.sounds.swim then
|
||||||
-- play swimming sounds
|
local swim_snd = def.sounds.swim
|
||||||
if def.sounds and def.sounds.swim then
|
core.sound_play(swim_snd.name, {
|
||||||
local swim_snd = def.sounds.swim
|
pos = current_pos,
|
||||||
core.sound_play(swim_snd.name, {
|
gain = swim_snd.gain or 1,
|
||||||
pos = current_pos,
|
max_hear_distance = swim_snd.distance or 10,
|
||||||
gain = swim_snd.gain or 1,
|
})
|
||||||
max_hear_distance = swim_snd.distance or 10,
|
end
|
||||||
})
|
spawnParticles(current_pos, vel, "bubble.png")
|
||||||
end
|
else
|
||||||
spawnParticles(current_pos, vel, "bubble.png")
|
self.air_cnt = self.air_cnt + 1
|
||||||
else
|
if self.in_water == true and self.air_cnt > 5 then
|
||||||
self.air_cnt = self.air_cnt + 1
|
self.in_water = false
|
||||||
if self.in_water == true and self.air_cnt > 5 then
|
if not self.can_fly then
|
||||||
self.in_water = false
|
me:set_acceleration({x=0, y=-15, z=0})
|
||||||
if not self.can_fly then
|
|
||||||
me:set_acceleration({x=0, y=-15, z=0})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -736,13 +733,10 @@ cmer.on_step = function(self, dtime)
|
|||||||
-- Add damage when drowning or in lava
|
-- Add damage when drowning or in lava
|
||||||
if self.env_damage and self.envtimer > 1 and self.last_node then
|
if self.env_damage and self.envtimer > 1 and self.last_node then
|
||||||
self.envtimer = 0
|
self.envtimer = 0
|
||||||
local name = self.last_node.name
|
if not self.can_swim and is_water_node(self.last_node) then
|
||||||
if not self.can_swim and name == "default:water_source" then
|
|
||||||
changeHP(self, -1)
|
changeHP(self, -1)
|
||||||
elseif self.can_burn then
|
elseif self.can_burn and is_burning_node(self.last_node) then
|
||||||
if name == "fire:basic_flame" or name == "default:lava_source" then
|
changeHP(self, -4)
|
||||||
changeHP(self, -4)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- add damage when light is too bright or too dark
|
-- add damage when light is too bright or too dark
|
||||||
|
@ -8,4 +8,18 @@ local function translate_name(name)
|
|||||||
return name
|
return name
|
||||||
end
|
end
|
||||||
|
|
||||||
return translate_name
|
local function is_water_node(node)
|
||||||
|
if type(node) == "table" and node.groups ~= nil and (node.groups.liquid or node.groups.water) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function is_burning_node(node)
|
||||||
|
if type(node) == "table" and node.groups ~= nil and (node.groups.igniter or node.groups.fire or node.groups.lava) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return translate_name, is_water_node, is_burning_node
|
||||||
|
1
mod.conf
1
mod.conf
@ -2,5 +2,4 @@ name = cmer
|
|||||||
title = Creatures Revived
|
title = Creatures Revived
|
||||||
description = An API for creating mobs.
|
description = An API for creating mobs.
|
||||||
version = 1.1
|
version = 1.1
|
||||||
depends = default
|
|
||||||
optional_depends = creatures, asm_spawneggs
|
optional_depends = creatures, asm_spawneggs
|
||||||
|
Loading…
x
Reference in New Issue
Block a user