diff --git a/common.lua b/common.lua index d0c50e1..146206e 100644 --- a/common.lua +++ b/common.lua @@ -163,16 +163,18 @@ local function delay(...) return (function() return unpack(args) end) end -local function get_set_wrap(name) - return (function(self, value) +local function get_set_wrap(name, is_dynamic) + return (function(self) return self["_" .. name] - end), (function(self) - self["_" .. name] = type(value) == "table" - and table.copy(value) or value + end), (function(self, value) + if is_dynamic then + self["_" .. name] = type(value) == "table" + and table.copy(value) or value + end end) end -function pipeworks.create_fake_player(def) +function pipeworks.create_fake_player(def, is_dynamic) local wielded_item = ItemStack("") if def.inventory and def.wield_list then wielded_item = def.inventory:get_stack(def.wield_list, def.wield_index or 1) @@ -192,6 +194,15 @@ function pipeworks.create_fake_player(def) _wielded_item = wielded_item, -- Model and view + _eye_offset1 = vector.new(), + _eye_offset3 = vector.new(), + set_eye_offset = function(self, first, third) + self._eye_offset1 = table.copy(first) + self._eye_offset3 = table.copy(third) + end, + get_eye_offset = function(self, first, third) + return self._eye_offset1, self._eye_offset3 + end, get_look_dir = delay(def.look_dir or {x=0, y=0, z=1}), get_look_pitch = delay(def.look_pitch or 0), get_look_yaw = delay(def.look_yaw or 0), @@ -234,13 +245,14 @@ function pipeworks.create_fake_player(def) } local _trash -- Getter & setter functions - p.get_inventory_formspec, p.set_inventory_formspec = get_set_wrap("formspec") - p.get_breath, p.set_breath = get_set_wrap("breath") - p.get_hp, p.set_hp = get_set_wrap("hp") - p.get_pos, p.set_pos = get_set_wrap("pos") - _trash, p.move_to = get_set_wrap("pos") - p.get_wield_index, p.set_wield_index = get_set_wrap("wield_index") - p.get_properties, p.set_properties = get_set_wrap("properties") + p.get_inventory_formspec, p.set_inventory_formspec + = get_set_wrap("formspec", is_dynamic) + p.get_breath, p.set_breath = get_set_wrap("breath", is_dynamic) + p.get_hp, p.set_hp = get_set_wrap("hp", is_dynamic) + p.get_pos, p.set_pos = get_set_wrap("pos", is_dynamic) + _trash, p.move_to = get_set_wrap("pos", is_dynamic) + p.get_wield_index, p.set_wield_index = get_set_wrap("wield_index", true) + p.get_properties, p.set_properties = get_set_wrap("properties", is_dynamic) -- Backwards compatibilty p.getpos = p.get_pos @@ -255,7 +267,6 @@ function pipeworks.create_fake_player(def) -- get_player_velocity -- set_look_pitch -- set_look_yaw - -- set_breath -- set_physics_override -- get_physics_override -- hud_add