Use node groups to determine swimming & burning
This commit is contained in:
parent
43d076dec8
commit
f631d43e55
@ -2,6 +2,7 @@
|
||||
v1.2-cmer
|
||||
---------
|
||||
- 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
|
||||
---------
|
||||
|
@ -23,7 +23,7 @@
|
||||
-- Localizations
|
||||
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)
|
||||
@ -703,9 +703,7 @@ cmer.on_step = function(self, dtime)
|
||||
--swim
|
||||
if self.can_swim and self.swimtimer > 0.8 and self.last_node then
|
||||
self.swimtimer = 0
|
||||
local name = self.last_node.name
|
||||
if name then
|
||||
if name == "default:water_source" then
|
||||
if is_water_node(self.last_node) then
|
||||
self.air_cnt = 0
|
||||
local vel = me:get_velocity()
|
||||
update_velocity(me, {x=vel.x, y=0.9, z=vel.z}, 1)
|
||||
@ -731,19 +729,15 @@ cmer.on_step = function(self, dtime)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Add damage when drowning or in lava
|
||||
if self.env_damage and self.envtimer > 1 and self.last_node then
|
||||
self.envtimer = 0
|
||||
local name = self.last_node.name
|
||||
if not self.can_swim and name == "default:water_source" then
|
||||
if not self.can_swim and is_water_node(self.last_node) then
|
||||
changeHP(self, -1)
|
||||
elseif self.can_burn then
|
||||
if name == "fire:basic_flame" or name == "default:lava_source" then
|
||||
elseif self.can_burn and is_burning_node(self.last_node) then
|
||||
changeHP(self, -4)
|
||||
end
|
||||
end
|
||||
|
||||
-- add damage when light is too bright or too dark
|
||||
local tod = core.get_timeofday() * 24000
|
||||
|
@ -8,4 +8,18 @@ local function translate_name(name)
|
||||
return name
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user