Skip to content

Commit

Permalink
add oil lamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Elkien3 committed Dec 12, 2022
1 parent 211985d commit 2761dd3
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 5 deletions.
8 changes: 6 additions & 2 deletions mods/nolight/handheld.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ minetest.register_globalstep(function(dtime)
local wielded_item = player:get_wielded_item()
if check_for_flashlight(player) then
beamlight.beams[player:get_player_name()] = {player = player, length = 3}
elseif wielded_item:get_name() == "nolight:lantern_active" then
elseif wielded_item:get_name() == "nolight:lantern_active" or wielded_item:get_name() == "nolight:oil_lamp_active" then
beamlight.beams[player:get_player_name()] = {player = player}
local meta = wielded_item:get_meta()
local fuel_time = meta:get_float("fuel_time")
Expand All @@ -47,7 +47,11 @@ minetest.register_globalstep(function(dtime)
local fuelitem = ItemStack(meta:get_string("stack"))
local afterfuel
fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = {fuelitem}})
fuel.time = fuel.time*50
if wielded_item:get_name() == "nolight:oil_lamp_active" then
fuel.time = fuel.time*40
else
fuel.time = fuel.time*50
end
if fuel.time == 0 then
-- No valid fuel in fuel list
fuel_totaltime = 0
Expand Down
134 changes: 131 additions & 3 deletions mods/nolight/lantern.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ local function swap_node(pos, name)
end

local function lantern_node_timer(pos, elapsed)
local name = string.gsub(minetest.get_node(pos).name, "_active", "")
--
-- Initialize metadata
--
Expand Down Expand Up @@ -147,15 +148,15 @@ local function lantern_node_timer(pos, elapsed)
local fuel_percent = 100 - math.floor(fuel_time / fuel_totaltime * 100)
fuel_state = S("@1%", fuel_percent)
formspec = get_lantern_active_formspec(fuel_percent, 0)
swap_node(pos, "nolight:lantern_active")
swap_node(pos, name.."_active")
-- make sure timer restarts automatically
result = true
else
if fuellist and not fuellist[1]:is_empty() then
fuel_state = S("@1%", 0)
end
formspec = get_lantern_inactive_formspec()
swap_node(pos, "nolight:lantern")
swap_node(pos, name)
-- stop timer on the inactive furnace
minetest.get_node_timer(pos):stop()
end
Expand Down Expand Up @@ -184,6 +185,7 @@ end
-- Node definitions
--

--LANTERN
minetest.register_node("nolight:lantern", {
description = S("Lantern"),
drawtype = "plantlike",
Expand Down Expand Up @@ -284,10 +286,136 @@ minetest.register_node("nolight:lantern_active", {
allow_metadata_inventory_take = allow_metadata_inventory_take,
})

--OIL LAMP
if minetest.get_modpath("basic_materials") then
local oil_lamp_allow_put = function(pos, listname, index, stack, player)
if stack:get_name() == "basic_materials:oil_extract" then
return allow_metadata_inventory_put(pos, listname, index, stack, player)
else
return 0
end
end
minetest.register_node("nolight:oil_lamp", {
description = S("Oil Lamp"),
drawtype = "plantlike",
inventory_image = "nolight_oil_lamp_inv.png",
wield_image = "nolight_oil_lamp_inv.png",
paramtype2 = "wallmounted",
walkable = true,
groups = {attached_node=1, oddly_breakable_by_hand=3},
tiles = {"nolight_oil_lamp.png"},
selection_box = xdecor.pixelbox(16, {{4, 0, 4, 8, 16, 8}}),
legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),

can_dig = can_dig,

on_timer = lantern_node_timer,

on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
lantern_node_timer(pos, 0)
end,

on_metadata_inventory_move = function(pos)
minetest.get_node_timer(pos):start(1.0)
end,
on_metadata_inventory_put = function(pos)
-- start timer function, it will sort out whether furnace can burn or not.
minetest.get_node_timer(pos):start(1.0)
end,
on_blast = function(pos)
local drops = {}
default.get_inventory_drops(pos, "fuel", drops)
drops[#drops+1] = "nolight:oil_lamp"
minetest.remove_node(pos)
return drops
end,

--[[after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = itemstack:get_meta()
local nodemeta = minetest.get_meta(pos)
nodemeta:set_float("fuel_time", meta:get_float("fuel_time"))
nodemeta:set_float("fuel_totaltime", meta:get_float("fuel_totaltime"))
local inv = nodemeta:get_inventory()
inv:set_stack('fuel', 1, meta:get_string("stack"))
lantern_node_timer(pos, 0)
minetest.get_node_timer(pos):start(1.0)
end,--]]

allow_metadata_inventory_put = oil_lamp_allow_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
})

minetest.register_node("nolight:oil_lamp_active", {
description = S("Oil Lamp"),
light_source = 13,
drawtype = "plantlike",
inventory_image = "nolight_oil_lamp_inv_active.png",
wield_image = "nolight_oil_lamp_inv_active.png",
paramtype2 = "wallmounted",
walkable = true,
groups = {attached_node=1, not_in_creative_inventory = 1, oddly_breakable_by_hand=3},
tiles = {{name = "nolight_oil_lamp_active.png", animation = {type="vertical_frames", length=1.5}}},
selection_box = xdecor.pixelbox(16, {{4, 0, 4, 8, 16, 8}}),
legacy_facedir_simple = true,
is_ground_content = false,
sounds = default.node_sound_stone_defaults(),
on_timer = lantern_node_timer,
--drop = "nolight:lantern",
stack_max = 1,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size('fuel', 1)
end,
--[[on_dig = function(pos, node, digger)
local nodemeta = minetest.get_meta(pos)
minetest.chat_send_all(dump(nodemeta:to_table()))
end,--]]
--can_dig = can_dig,
after_place_node = function(pos, placer, itemstack, pointed_thing)
local meta = itemstack:get_meta()
local nodemeta = minetest.get_meta(pos)
nodemeta:set_float("fuel_time", meta:get_float("fuel_time"))
nodemeta:set_float("fuel_totaltime", meta:get_float("fuel_totaltime"))
local inv = nodemeta:get_inventory()
inv:set_stack('fuel', 1, meta:get_string("stack"))
minetest.get_node_timer(pos):set(1,1)
end,

allow_metadata_inventory_put = oil_lamp_allow_put,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_take = allow_metadata_inventory_take,
})
minetest.register_craftitem("nolight:oil_lamp_unfired", {
description = "Unfired Oil Lamp",
inventory_image = "nolight_oil_lamp_unfired.png",
stack_max = 1
})
minetest.register_craft({
output = "nolight:oil_lamp_unfired",
recipe = {
{"", "", "farming:string"},
{"default:clay_lump", "farming:string", "default:clay_lump"},
{"", "default:clay_lump", ""},
}
})
minetest.register_craft({
output = "nolight:oil_lamp",
recipe = "nolight:oil_lamp_unfired",
type = "cooking",
})
end

local func = minetest.handle_node_drops
minetest.handle_node_drops = function(pos, drops, digger)
for index, name in pairs(drops) do
if name == "nolight:lantern_active" then
if name == "nolight:lantern_active" or name == "nolight:oil_lamp_active" then
drops[index] = ItemStack(name)
local meta = drops[index]:get_meta()
local nodemeta = minetest.get_meta(pos)
Expand Down
Binary file added mods/nolight/textures/nolight_oil_lamp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/nolight/textures/nolight_oil_lamp_active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/nolight/textures/nolight_oil_lamp_inv.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mods/nolight/textures/nolight_oil_lamp_unfired.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2761dd3

Please sign in to comment.