mirror of
https://github.com/mt-mods/pipeworks.git
synced 2024-09-27 06:40:36 +02:00
Fix setter issue, add dynamix/static option
This commit is contained in:
parent
0c5372ef16
commit
0cf4c7e7a5
35
common.lua
35
common.lua
|
@ -163,16 +163,18 @@ local function delay(...)
|
||||||
return (function() return unpack(args) end)
|
return (function() return unpack(args) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_set_wrap(name)
|
local function get_set_wrap(name, is_dynamic)
|
||||||
return (function(self, value)
|
return (function(self)
|
||||||
return self["_" .. name]
|
return self["_" .. name]
|
||||||
end), (function(self)
|
end), (function(self, value)
|
||||||
|
if is_dynamic then
|
||||||
self["_" .. name] = type(value) == "table"
|
self["_" .. name] = type(value) == "table"
|
||||||
and table.copy(value) or value
|
and table.copy(value) or value
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function pipeworks.create_fake_player(def)
|
function pipeworks.create_fake_player(def, is_dynamic)
|
||||||
local wielded_item = ItemStack("")
|
local wielded_item = ItemStack("")
|
||||||
if def.inventory and def.wield_list then
|
if def.inventory and def.wield_list then
|
||||||
wielded_item = def.inventory:get_stack(def.wield_list, def.wield_index or 1)
|
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,
|
_wielded_item = wielded_item,
|
||||||
|
|
||||||
-- Model and view
|
-- 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_dir = delay(def.look_dir or {x=0, y=0, z=1}),
|
||||||
get_look_pitch = delay(def.look_pitch or 0),
|
get_look_pitch = delay(def.look_pitch or 0),
|
||||||
get_look_yaw = delay(def.look_yaw or 0),
|
get_look_yaw = delay(def.look_yaw or 0),
|
||||||
|
@ -234,13 +245,14 @@ function pipeworks.create_fake_player(def)
|
||||||
}
|
}
|
||||||
local _trash
|
local _trash
|
||||||
-- Getter & setter functions
|
-- Getter & setter functions
|
||||||
p.get_inventory_formspec, p.set_inventory_formspec = get_set_wrap("formspec")
|
p.get_inventory_formspec, p.set_inventory_formspec
|
||||||
p.get_breath, p.set_breath = get_set_wrap("breath")
|
= get_set_wrap("formspec", is_dynamic)
|
||||||
p.get_hp, p.set_hp = get_set_wrap("hp")
|
p.get_breath, p.set_breath = get_set_wrap("breath", is_dynamic)
|
||||||
p.get_pos, p.set_pos = get_set_wrap("pos")
|
p.get_hp, p.set_hp = get_set_wrap("hp", is_dynamic)
|
||||||
_trash, p.move_to = get_set_wrap("pos")
|
p.get_pos, p.set_pos = get_set_wrap("pos", is_dynamic)
|
||||||
p.get_wield_index, p.set_wield_index = get_set_wrap("wield_index")
|
_trash, p.move_to = get_set_wrap("pos", is_dynamic)
|
||||||
p.get_properties, p.set_properties = get_set_wrap("properties")
|
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
|
-- Backwards compatibilty
|
||||||
p.getpos = p.get_pos
|
p.getpos = p.get_pos
|
||||||
|
@ -255,7 +267,6 @@ function pipeworks.create_fake_player(def)
|
||||||
-- get_player_velocity
|
-- get_player_velocity
|
||||||
-- set_look_pitch
|
-- set_look_pitch
|
||||||
-- set_look_yaw
|
-- set_look_yaw
|
||||||
-- set_breath
|
|
||||||
-- set_physics_override
|
-- set_physics_override
|
||||||
-- get_physics_override
|
-- get_physics_override
|
||||||
-- hud_add
|
-- hud_add
|
||||||
|
|
Loading…
Reference in New Issue
Block a user