adding ability for custom on_step/destroy functions in wagon definition
parent
8f4da0be77
commit
e046e1926d
51
wagons.lua
51
wagons.lua
|
@ -111,30 +111,42 @@ end
|
|||
|
||||
-- Remove the wagon
|
||||
function wagon:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
||||
if not puncher or not puncher:is_player() or puncher == self.driver then
|
||||
if not puncher or not puncher:is_player() or self.driver then
|
||||
return
|
||||
end
|
||||
|
||||
self.object:remove()
|
||||
if not self.initialized then return end
|
||||
if self.custom_may_destroy then
|
||||
if not self.custom_may_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if self.custom_on_destroy then
|
||||
self.custom_on_destroy(self, puncher, time_from_last_punch, tool_capabilities, direction)
|
||||
end
|
||||
|
||||
local inv = puncher:get_inventory()
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
if not inv:contains_item("main", self.name) then
|
||||
inv:add_item("main", self.name)
|
||||
end
|
||||
else
|
||||
self:destroy()
|
||||
|
||||
local inv = puncher:get_inventory()
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
if not inv:contains_item("main", self.name) then
|
||||
inv:add_item("main", self.name)
|
||||
end
|
||||
|
||||
table.remove(self:train().trainparts, self.pos_in_trainparts)
|
||||
advtrains.update_trainpart_properties(self.train_id)
|
||||
advtrains.wagon_save[self.unique_id]=nil
|
||||
if self.discouple then self.discouple.object:remove() end--will have no effect on unloaded objects
|
||||
return
|
||||
|
||||
|
||||
else
|
||||
inv:add_item("main", self.name)
|
||||
end
|
||||
end
|
||||
function wagon:destroy()
|
||||
self.object:remove()
|
||||
|
||||
if not self.initialized then return end
|
||||
|
||||
table.remove(self:train().trainparts, self.pos_in_trainparts)
|
||||
advtrains.update_trainpart_properties(self.train_id)
|
||||
advtrains.wagon_save[self.unique_id]=nil
|
||||
if self.discouple then self.discouple.object:remove() end--will have no effect on unloaded objects
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
function wagon:on_step(dtime)
|
||||
local t=os.clock()
|
||||
|
@ -170,6 +182,11 @@ function wagon:on_step(dtime)
|
|||
end
|
||||
end
|
||||
|
||||
--custom on_step function
|
||||
if self.custom_on_step then
|
||||
self.custom_on_step(self, dtime)
|
||||
end
|
||||
|
||||
--driver control
|
||||
if self.driver and self.is_locomotive then
|
||||
if self.driver:get_player_control_bits()~=self.old_player_control_bits then
|
||||
|
|
Loading…
Reference in New Issue