-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Artisan Benches: Fuel Device: add inv sizes,
:init()
, :is_empty()
…
- Loading branch information
Showing
3 changed files
with
60 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 25 additions & 32 deletions
57
mods/lord/Core/fuel_device/src/fuel_device/node/definition/common.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,41 @@ | ||
|
||
--- @generic GenericForm: fuel_device.node.Form | ||
--- @param device_name string | ||
--- @param form GenericForm | ||
--- @param size_of {fuel:number,src:number,dst:number} | ||
local function get_on_construct_function(device_name, form, size_of) | ||
--- @generic GenericDevice: fuel_device.Device | ||
--- @param Device fuel_device.Device | ||
--- @return fun(pos:Position) | ||
local function get_on_construct_function(Device) | ||
return function(pos) | ||
local meta = minetest.get_meta(pos) | ||
meta:set_string('formspec', form.get_spec('inactive')) | ||
meta:set_string('infotext', device_name) | ||
local inv = meta:get_inventory() | ||
inv:set_size('fuel', size_of.fuel or 1) | ||
inv:set_size('src', size_of.src or 1) | ||
inv:set_size('dst', size_of.dst or 1) | ||
Device:new(pos):init() | ||
end | ||
end | ||
|
||
--- @generic GenericDevice: fuel_device.Device | ||
--- @param Device fuel_device.Device | ||
--- @return fun(pos:Position,player:Player) | ||
local function get_can_dig_function(Device) | ||
--- @param pos Position | ||
--- @param player Player | ||
return function(pos, player) | ||
if Device:new(pos):is_empty() then | ||
return true | ||
end | ||
return false | ||
end | ||
end | ||
|
||
local common_definition = { | ||
paramtype2 = 'facedir', | ||
is_ground_content = false, | ||
can_dig = function(pos,player) | ||
local meta = minetest.get_meta(pos); | ||
local inv = meta:get_inventory() | ||
if not inv:is_empty('fuel') then | ||
return false | ||
elseif not inv:is_empty('dst') then | ||
return false | ||
elseif not inv:is_empty('src') then | ||
return false | ||
end | ||
return true | ||
end, | ||
} | ||
|
||
|
||
return { | ||
--- @generic GenericForm: fuel_device.node.Form | ||
--- @param device_name string | ||
--- @param inactive_node_name string | ||
--- @param form GenericForm | ||
--- @param size_of {fuel:number,src:number,dst:number}|nil | ||
get = function(device_name, inactive_node_name, form, size_of) | ||
--- @generic GenericDevice: fuel_device.Device | ||
--- @param Device GenericDevice | ||
get = function(Device) | ||
return table.merge(common_definition, { | ||
drop = inactive_node_name, | ||
on_construct = get_on_construct_function(device_name, form, size_of or {}) | ||
drop = Device.node_name.inactive, | ||
on_construct = get_on_construct_function(Device), | ||
can_dig = get_can_dig_function(Device), | ||
}) | ||
end | ||
} |