Add Lava Furnace Fueler
This commit is contained in:
parent
71376c343b
commit
3ee6eca845
@ -18,3 +18,4 @@ dofile(path.."/crafting_supplier.lua")
|
||||
dofile(path.."/cobble_supplier.lua")
|
||||
dofile(path.."/synchronizer.lua")
|
||||
dofile(path.."/reservoir.lua")
|
||||
dofile(path.."/lava_furnace_fueler.lua")
|
||||
|
@ -20,16 +20,6 @@ local GUIDE_BTN = "guide"
|
||||
|
||||
local UPDATE_INTERVAL = 1.0
|
||||
|
||||
-- returns the lava cap in milibuckets
|
||||
local function get_lava_capacity(pos)
|
||||
local nodeName = minetest.get_node(pos).name
|
||||
local nodeDef = minetest.registered_nodes[nodeName]
|
||||
if not nodeDef or not nodeDef.logistica or not nodeDef.logistica.lava_capacity then
|
||||
return nil
|
||||
end
|
||||
return nodeDef.logistica.lava_capacity * 1000
|
||||
end
|
||||
|
||||
local function fill_lava_tank_from_fuel(pos, meta, inv)
|
||||
local itemstackName = inv:get_stack(INV_FUEL, 1):get_name()
|
||||
if itemstackName ~= BUCKET_LAVA and itemstackName ~= LAVA_UNIT then return end
|
||||
@ -39,7 +29,7 @@ local function fill_lava_tank_from_fuel(pos, meta, inv)
|
||||
returnStack = ItemStack(BUCKET_EMPTY)
|
||||
end
|
||||
local currLevel = meta:get_int(META_LAVA_IN_TANK)
|
||||
local cap = get_lava_capacity(pos)
|
||||
local cap = logistica.lava_furnace_get_lava_capacity(pos)
|
||||
if cap - currLevel < 1000 then return end
|
||||
currLevel = currLevel + 1000
|
||||
meta:set_int(META_LAVA_IN_TANK, currLevel)
|
||||
@ -149,7 +139,7 @@ end
|
||||
|
||||
local function common_formspec(pos, meta)
|
||||
local currLava = meta:get_int(META_LAVA_IN_TANK)
|
||||
local lavaCap = get_lava_capacity(pos) or 1
|
||||
local lavaCap = logistica.lava_furnace_get_lava_capacity(pos) or 1
|
||||
local lavaPercent = logistica.round(currLava / lavaCap * 100)
|
||||
return "formspec_version[4]"..
|
||||
"size[10.5,11]"..
|
||||
@ -365,7 +355,8 @@ function logistica.register_lava_furnace(desc, name, lavaCapacity, combinedTiles
|
||||
allow_metadata_inventory_take = lava_furnace_allow_metadata_inv_take,
|
||||
on_receive_fields = lava_furnace_receive_fields,
|
||||
logistica = {
|
||||
lava_capacity = lavaCapacity
|
||||
lava_capacity = lavaCapacity,
|
||||
lava_furnace = true,
|
||||
}
|
||||
}
|
||||
|
||||
|
172
api/lava_furnace_fueler.lua
Normal file
172
api/lava_furnace_fueler.lua
Normal file
@ -0,0 +1,172 @@
|
||||
|
||||
local S = logistica.TRANSLATOR
|
||||
|
||||
local ON_OFF_BUTTON = "on_off_btn"
|
||||
local FORMSPEC_NAME = "logistica_lvfurnfueler"
|
||||
local BTN_INC = "btninc"
|
||||
local BTN_DEC = "btndec"
|
||||
local META_TARGET_LAVA = "tarlava"
|
||||
local MAX_LAVA = 4000 -- not really related to lava furnace, but this is a refueler, so it should be fine
|
||||
|
||||
local forms = {}
|
||||
|
||||
local function get_lava_img(currLava, lavaPercent)
|
||||
local img = ""
|
||||
if lavaPercent > 0 then
|
||||
img = "image[4.1,1.6;1,3;logistica_lava_furnace_tank_bg.png^[lowpart:"..
|
||||
lavaPercent..":logistica_lava_furnace_tank.png]"
|
||||
else
|
||||
img = "image[4.1,1.6;1,3;logistica_lava_furnace_tank_bg.png]"
|
||||
end
|
||||
return img.."tooltip[4.1,1.6;1,3;"..S("Refuel if level below: ")..(currLava/1000)..S(" Buckets").."]"
|
||||
end
|
||||
|
||||
local function get_fueler_formspec(pos)
|
||||
local isOn = logistica.is_machine_on(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local currLava = meta:get_int(META_TARGET_LAVA)
|
||||
local lavaPercent = logistica.round(currLava / MAX_LAVA * 100)
|
||||
return "formspec_version[4]"..
|
||||
"size[8.0,5.5]"..
|
||||
logistica.ui.background_lava_furnace..
|
||||
"label[0.2,0.2;"..S("Lava Furnace Fueler: Refuels Lava Furnace").."]"..
|
||||
"label[0.2,0.6;"..S("from Reservoirs connected to Network").."]"..
|
||||
"label[2.0,1.3;"..S("Refuel when lava drops below:").."]"..
|
||||
"button[2.9,1.6;1,1;"..BTN_INC..";+]"..
|
||||
"button[2.9,3.6;1,1;"..BTN_DEC..";-]"..
|
||||
"label[3.7,4.9;"..(currLava/1000)..S(" Buckets").."]"..
|
||||
get_lava_img(currLava, lavaPercent)..
|
||||
logistica.ui.on_off_btn(isOn, 0.5, 1.3, ON_OFF_BUTTON, S("Enable"))
|
||||
end
|
||||
|
||||
local function change_target_lava(pos, change)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local currLevel = meta:get_int(META_TARGET_LAVA)
|
||||
local newLevel = logistica.clamp(currLevel + change * 200, 0, MAX_LAVA)
|
||||
meta:set_int(META_TARGET_LAVA, newLevel)
|
||||
end
|
||||
|
||||
local function show_fueler_formspec(playerName, pos)
|
||||
forms[playerName] = {position = pos}
|
||||
minetest.show_formspec(playerName, FORMSPEC_NAME, get_fueler_formspec(pos))
|
||||
end
|
||||
|
||||
-- callbacks
|
||||
|
||||
local function on_fueler_recieve_fields(player, formname, fields)
|
||||
if not player or not player:is_player() then return false end
|
||||
if formname ~= FORMSPEC_NAME then return false end
|
||||
local playerName = player:get_player_name()
|
||||
if not forms[playerName] then return false end
|
||||
local pos = forms[playerName].position
|
||||
if not pos then return false end
|
||||
if minetest.is_protected(pos, playerName) then return true end
|
||||
|
||||
if fields.quit then
|
||||
forms[playerName] = nil
|
||||
elseif fields[ON_OFF_BUTTON] then
|
||||
logistica.toggle_machine_on_off(pos)
|
||||
show_fueler_formspec(player:get_player_name(), pos)
|
||||
elseif fields[BTN_INC] then
|
||||
change_target_lava(pos, 1)
|
||||
show_fueler_formspec(player:get_player_name(), pos)
|
||||
elseif fields[BTN_DEC] then
|
||||
change_target_lava(pos, -1)
|
||||
show_fueler_formspec(player:get_player_name(), pos)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function on_fueler_punch(pos, node, puncher, pointed_thing)
|
||||
local targetPos = logistica.lava_furnace_fueler_target_pos(pos)
|
||||
if targetPos and puncher:is_player() and puncher:get_player_control().sneak then
|
||||
logistica.show_output_at(targetPos)
|
||||
end
|
||||
end
|
||||
|
||||
local function on_fueler_right_click(pos, node, clicker, itemstack, pointed_thing)
|
||||
if not clicker or not clicker:is_player() then return end
|
||||
if minetest.is_protected(pos, clicker:get_player_name()) then return end
|
||||
show_fueler_formspec(clicker:get_player_name(), pos)
|
||||
end
|
||||
|
||||
local function after_place_fueler(pos, placer, itemstack)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if placer and placer:is_player() then
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
end
|
||||
logistica.show_output_at(logistica.lava_furnace_fueler_target_pos(pos))
|
||||
logistica.set_node_tooltip_from_state(pos)
|
||||
logistica.on_lava_furnace_fueler_change(pos)
|
||||
end
|
||||
|
||||
----------------------------------------------------------------
|
||||
-- Minetest registration
|
||||
----------------------------------------------------------------
|
||||
|
||||
minetest.register_on_player_receive_fields(on_fueler_recieve_fields)
|
||||
|
||||
minetest.register_on_leaveplayer(function(objRef, timed_out)
|
||||
if objRef:is_player() then
|
||||
forms[objRef:get_player_name()] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
----------------------------------------------------------------
|
||||
-- Public Registration API
|
||||
----------------------------------------------------------------
|
||||
|
||||
function logistica.register_lava_furnace_fueler(description, name, tiles)
|
||||
local lname = string.lower(name:gsub(" ", "_"))
|
||||
local fuelerName = "logistica:"..lname
|
||||
logistica.misc_machines[fuelerName] = true
|
||||
local grps = {oddly_breakable_by_hand = 3, cracky = 3 }
|
||||
grps[logistica.TIER_ALL] = 1
|
||||
local def = {
|
||||
description = description,
|
||||
drawtype = "normal",
|
||||
tiles = tiles,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
groups = grps,
|
||||
drop = fuelerName,
|
||||
sounds = logistica.node_sound_metallic(),
|
||||
on_timer = logistica.on_timer_powered(logistica.lava_furnace_fueler_on_timer),
|
||||
after_place_node = function (pos, placer, itemstack)
|
||||
after_place_fueler(pos, placer, itemstack)
|
||||
end,
|
||||
after_dig_node = logistica.on_lava_furnace_fueler_change,
|
||||
on_punch = on_fueler_punch,
|
||||
on_rightclick = on_fueler_right_click,
|
||||
logistica = {
|
||||
on_connect_to_network = function(pos, networkId)
|
||||
logistica.lava_furnace_fueler_start_timer(pos)
|
||||
end,
|
||||
on_power = function(pos, isPoweredOn)
|
||||
if isPoweredOn then
|
||||
logistica.lava_furnace_fueler_start_timer(pos)
|
||||
end
|
||||
logistica.set_node_tooltip_from_state(pos, nil, isPoweredOn)
|
||||
end,
|
||||
}
|
||||
}
|
||||
|
||||
minetest.register_node(fuelerName, def)
|
||||
|
||||
local def_disabled = table.copy(def)
|
||||
local tiles_disabled = {}
|
||||
for k, v in pairs(def.tiles) do tiles_disabled[k] = v.."^logistica_disabled.png" end
|
||||
|
||||
def_disabled.tiles = tiles_disabled
|
||||
def_disabled.groups = { oddly_breakable_by_hand = 3, cracky = 3, choppy = 3, not_in_creative_inventory = 1 }
|
||||
def_disabled.on_construct = nil
|
||||
def_disabled.after_dig_node = nil
|
||||
def_disabled.on_punch = nil
|
||||
def_disabled.on_rightclick = nil
|
||||
def_disabled.on_timer = nil
|
||||
def_disabled.logistica = nil
|
||||
|
||||
minetest.register_node(fuelerName.."_disabled", def_disabled)
|
||||
|
||||
end
|
80
logic/lava_furnace_fueler.lua
Normal file
80
logic/lava_furnace_fueler.lua
Normal file
@ -0,0 +1,80 @@
|
||||
|
||||
local TIMER_DURATION = 1
|
||||
local META_TARGET_LAVA = "tarlava"
|
||||
local META_LAVA_IN_TANK = "lavam"
|
||||
|
||||
local EMPTY_BUCKET = "bucket:bucket_empty"
|
||||
local LAVA_LIQUID_NAME = "lava"
|
||||
|
||||
local function get_lava_furnace_lava_in_tank(meta)
|
||||
return meta:get_int(META_LAVA_IN_TANK)
|
||||
end
|
||||
|
||||
local function set_lava_furnace_lava_in_tank(meta, newLevel)
|
||||
meta:set_int(META_LAVA_IN_TANK, newLevel)
|
||||
end
|
||||
|
||||
local function get_min_lava(meta)
|
||||
return meta:get_int(META_TARGET_LAVA)
|
||||
end
|
||||
|
||||
--------------------------------
|
||||
-- public functions
|
||||
--------------------------------
|
||||
|
||||
-- returns the lava cap in milibuckets
|
||||
function logistica.lava_furnace_get_lava_capacity(pos)
|
||||
local nodeName = minetest.get_node(pos).name
|
||||
local nodeDef = minetest.registered_nodes[nodeName]
|
||||
if not nodeDef or not nodeDef.logistica or not nodeDef.logistica.lava_capacity then
|
||||
return nil
|
||||
end
|
||||
return nodeDef.logistica.lava_capacity * 1000
|
||||
end
|
||||
|
||||
function logistica.lava_furnace_fueler_start_timer(pos)
|
||||
logistica.start_node_timer(pos, TIMER_DURATION)
|
||||
end
|
||||
|
||||
-- returns the target position of the lava furnace
|
||||
function logistica.lava_furnace_fueler_target_pos(pos)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node then return nil end
|
||||
local target = vector.add(pos, logistica.get_rot_directions(node.param2).backward)
|
||||
if not minetest.get_node_or_nil(target) then return nil end
|
||||
return target
|
||||
end
|
||||
|
||||
function logistica.lava_furnace_fueler_on_timer(pos, elapsed)
|
||||
if not logistica.is_machine_on(pos) then return end
|
||||
if not logistica.get_network_or_nil(pos) then return true end
|
||||
|
||||
local targetPos = logistica.lava_furnace_fueler_target_pos(pos)
|
||||
local targetNode = minetest.get_node(targetPos)
|
||||
local targetDef = minetest.registered_nodes[targetNode.name]
|
||||
|
||||
if not targetDef
|
||||
or not targetDef.logistica
|
||||
or not targetDef.logistica.lava_furnace
|
||||
or not targetDef.logistica.lava_capacity
|
||||
then
|
||||
return true
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local targetMeta = minetest.get_meta(targetPos)
|
||||
|
||||
local minLava = get_min_lava(meta)
|
||||
local targetLavaCap = logistica.lava_furnace_get_lava_capacity(targetPos)
|
||||
local targetCurrLava = get_lava_furnace_lava_in_tank(targetMeta)
|
||||
local newTargetLava = targetCurrLava + 1000
|
||||
|
||||
if targetCurrLava < minLava and newTargetLava < targetLavaCap then
|
||||
local takenLiquid = logistica.use_bucket_for_liquid_in_network(pos, ItemStack(EMPTY_BUCKET), LAVA_LIQUID_NAME)
|
||||
if not takenLiquid then return true end
|
||||
set_lava_furnace_lava_in_tank(targetMeta, newTargetLava)
|
||||
logistica.start_node_timer(targetPos, 1)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
@ -19,3 +19,4 @@ dofile(path.."/autocrafting_logic.lua")
|
||||
dofile(path.."/crafting_supplier.lua")
|
||||
dofile(path.."/synchronizer.lua")
|
||||
dofile(path.."/reservoir.lua")
|
||||
dofile(path.."/lava_furnace_fueler.lua")
|
||||
|
@ -381,6 +381,12 @@ local RESERVOIR_OPS = {
|
||||
update_cache_node_removed = function(_) end,
|
||||
}
|
||||
|
||||
local LAVA_FURNACE_FUELER_OPS = {
|
||||
get_list = function(network) return network.misc end,
|
||||
update_cache_node_added = function(_) end,
|
||||
update_cache_node_removed = function(_) end,
|
||||
}
|
||||
|
||||
local function cable_can_extend_network_from(pos)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node then return false end
|
||||
@ -510,3 +516,7 @@ end
|
||||
function logistica.on_reservoir_change(pos, oldNode, oldMeta)
|
||||
on_node_change(pos, oldNode, oldMeta, RESERVOIR_OPS)
|
||||
end
|
||||
|
||||
function logistica.on_lava_furnace_fueler_change(pos, oldNode, oldMeta)
|
||||
on_node_change(pos, oldNode, oldMeta, LAVA_FURNACE_FUELER_OPS)
|
||||
end
|
||||
|
@ -159,6 +159,17 @@ logistica.register_lava_furnace("Lava Furnace", "lava_furnace", 4, {
|
||||
}
|
||||
})
|
||||
|
||||
-- Lava Furnace Fueler
|
||||
|
||||
logistica.register_lava_furnace_fueler("Lava Furnace Fueler", "lava_furnace_fueler", {
|
||||
"logistica_fueler_side.png^[transformR270",
|
||||
"logistica_fueler_side.png^[transformR90",
|
||||
"logistica_fueler_side.png^[transformR180",
|
||||
"logistica_fueler_side.png",
|
||||
"logistica_fueler_back.png",
|
||||
"logistica_fueler_front.png",
|
||||
})
|
||||
|
||||
--------------------------------
|
||||
-- Mass Storage
|
||||
--------------------------------
|
||||
|
BIN
textures/logistica_fueler_back.png
Normal file
BIN
textures/logistica_fueler_back.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
BIN
textures/logistica_fueler_front.png
Normal file
BIN
textures/logistica_fueler_front.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
textures/logistica_fueler_side.png
Normal file
BIN
textures/logistica_fueler_side.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
Loading…
x
Reference in New Issue
Block a user