diff --git a/API.lua b/API.lua index 6f1ccc5..0fce9e0 100644 --- a/API.lua +++ b/API.lua @@ -71,18 +71,18 @@ end function spawners.add_effects(pos, radius) minetest.add_particlespawner({ amount = 32, - time = .5, + time = 2, minpos = vector.subtract(pos, radius / 2), maxpos = vector.add(pos, radius / 2), - minvel = {x=-1, y=-10, z=-1}, - maxvel = {x=1, y=10, z=1}, + minvel = {x=-0.5, y=-10, z=-0.5}, + maxvel = {x=0.5, y=10, z=0.5}, minacc = vector.new(), maxacc = vector.new(), minexptime = .5, - maxexptime = 1, - minsize = 2, + maxexptime = 2, + minsize = .5, maxsize = 8, - texture = "smoke_particle.png", + texture = "spawners_smoke_particle.png", }) end @@ -127,8 +127,8 @@ function spawners.start_spawning_ores(pos, ore_name, sound_custom, spawners_pos) }) minetest.set_node(pos, {name=ore_name}) - print("#1 spawing "..ore_name.." at "..minetest.pos_to_string(pos)) spawners.add_effects(pos, 1) + print("#1 spawing "..ore_name.." at "..minetest.pos_to_string(pos)) end end diff --git a/spawners_mobs.lua b/spawners_mobs.lua index 4b9961c..788c32e 100644 --- a/spawners_mobs.lua +++ b/spawners_mobs.lua @@ -50,8 +50,8 @@ function spawners.create(mob_name, mod_prefix, size, offset, mesh, texture, nigh name = "spawners_spawner_animated.png", animation = { type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, + aspect_w = 32, + aspect_h = 32, length = 2.0 }, } @@ -76,11 +76,11 @@ function spawners.create(mob_name, mod_prefix, size, offset, mesh, texture, nigh sunlight_propagates = true, tiles = { { - name = "spawners_spawner_off_animated.png", + name = "spawners_spawner_waiting_animated.png", animation = { type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, + aspect_w = 32, + aspect_h = 32, length = 2.0 }, } @@ -140,8 +140,8 @@ function spawners.create(mob_name, mod_prefix, size, offset, mesh, texture, nigh minetest.register_abm({ nodenames = {"spawners:"..mod_prefix.."_"..mob_name.."_spawner", "spawners:"..mod_prefix.."_"..mob_name.."_spawner_active", "spawners:"..mod_prefix.."_"..mob_name.."_spawner_overheat", "spawners:"..mod_prefix.."_"..mob_name.."_spawner_waiting"}, neighbors = {"air"}, - interval = 10, - chance = 2, + interval = 10.0, + chance = 5, action = function(pos, node, active_object_count, active_object_count_wider) local random_pos, waiting = spawners.check_node_status(pos, mob_name, night_only) diff --git a/spawners_ores.lua b/spawners_ores.lua index cda234d..0bd6222 100644 --- a/spawners_ores.lua +++ b/spawners_ores.lua @@ -1,3 +1,214 @@ +-- +-- Formspecs +-- + +local function active_formspec(fuel_percent, item_percent) + local formspec = + "size[8,8.5]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "list[current_name;fuel;3.5,1.5;1,1;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + "button_exit[5,1.5;2,1;exit;Save]".. + "listring[current_name;fuel]".. + "listring[current_player;main]".. + default.get_hotbar_bg(0, 4.25) + return formspec +end + +local inactive_formspec = + "size[8,8.5]".. + default.gui_bg.. + default.gui_bg_img.. + default.gui_slots.. + "list[current_name;fuel;3.5,1.5;1,1;]".. + "list[current_player;main;0,4.25;8,1;]".. + "list[current_player;main;0,5.5;8,3;8]".. + "button_exit[5,1.5;2,1;exit;Save]".. + "listring[current_name;fuel]".. + "listring[current_player;main]".. + default.get_hotbar_bg(0, 4.25) + +-- +-- Node callback functions that are the same for active and inactive furnace +-- + +function spawners.get_formspec(pos) + + -- Inizialize metadata + local meta = minetest.get_meta(pos) + + -- Inizialize inventory + local inv = meta:get_inventory() + for listname, size in pairs({ + fuel = 1, + }) do + if inv:get_size(listname) ~= size then + inv:set_size(listname, size) + end + end + + local fuellist = inv:get_list("fuel") + + -- + -- Cooking + -- + + -- Check if we have cookable content + -- local cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) + -- local cookable = true + + -- if cooked.time == 0 then + -- cookable = false + -- end + + -- Check if we have enough fuel to burn + -- if fuel_time < fuel_totaltime then + -- -- The furnace is currently active and has enough fuel + -- fuel_time = fuel_time + 1 + + -- -- If there is a cookable item then check if it is ready yet + -- if cookable then + -- src_time = src_time + 1 + -- if src_time >= cooked.time then + -- -- Place result in dst list if possible + -- if inv:room_for_item("dst", cooked.item) then + -- inv:add_item("dst", cooked.item) + -- inv:set_stack("src", 1, aftercooked.items[1]) + -- src_time = 0 + -- end + -- end + -- end + -- else + -- -- Furnace ran out of fuel + -- if cookable then + -- -- We need to get new fuel + -- local fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) + + -- if fuel.time == 0 then + -- -- No valid fuel in fuel list + -- fuel_totaltime = 0 + -- fuel_time = 0 + -- src_time = 0 + -- else + -- -- Take fuel from fuel list + -- inv:set_stack("fuel", 1, afterfuel.items[1]) + + -- fuel_totaltime = fuel.time + -- fuel_time = 0 + + -- end + -- else + -- -- We don't need to get new fuel since there is no cookable item + -- fuel_totaltime = 0 + -- fuel_time = 0 + -- src_time = 0 + -- end + -- end + + -- + -- Update formspec, infotext and node + -- + local formspec = inactive_formspec + -- local item_state = "" + -- local item_percent = 0 + -- if cookable then + -- item_percent = math.floor(src_time / cooked.time * 100) + -- item_state = item_percent .. "%" + -- else + -- if srclist[1]:is_empty() then + -- item_state = "Empty" + -- else + -- item_state = "Not cookable" + -- end + -- end + + -- local fuel_state = "Empty" + -- local active = "inactive " + -- if fuel_time <= fuel_totaltime and fuel_totaltime ~= 0 then + -- active = "active " + -- local fuel_percent = math.floor(fuel_time / fuel_totaltime * 100) + -- fuel_state = fuel_percent .. "%" + -- formspec = active_formspec(fuel_percent, item_percent) + -- -- swap_node(pos, "default:furnace_active") + -- else + -- if not fuellist[1]:is_empty() then + -- fuel_state = "0%" + -- end + -- -- swap_node(pos, "default:furnace") + -- end + + -- local infotext = "Furnace " .. active .. "(Item: " .. item_state .. "; Fuel: " .. fuel_state .. ")" + + -- + -- Set meta values + -- + -- meta:set_float("fuel_totaltime", fuel_totaltime) + -- meta:set_float("fuel_time", fuel_time) + -- meta:set_float("src_time", src_time) + meta:set_string("formspec", formspec) + -- meta:set_string("infotext", infotext) +end + +local function can_dig(pos, player) + local meta = minetest.get_meta(pos); + local inv = meta:get_inventory() + return inv:is_empty("fuel") +end + +local function allow_metadata_inventory_put(pos, listname, index, stack, player) + print("allow_metadata_inventory_put") + print("listname: "..listname) + print("stack name: "..stack:get_name()) + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local ingot = minetest.get_node_or_nil(pos).name + + ingot = string.split(ingot, ":") + ingot = string.split(ingot[2], "_") + + print("ingot 3: "..ingot[3]) + + if stack:get_name() == "default:"..ingot[3].."_ingot" then + if inv:is_empty("src") then + meta:set_string("infotext", "ore spawner is empty") + end + return stack:get_count() + else + return 0 + end +end + +local function allow_metadata_inventory_take(pos, listname, index, stack, player) + print("allow_metadata_inventory_take") + if minetest.is_protected(pos, player:get_player_name()) then + return 0 + end + return stack:get_count() +end + +local function on_receive_fields(pos, formname, fields, sender) + print("on_receive_fields") + + if minetest.is_protected(pos, sender:get_player_name()) then + return 0 + end + + for k, v in ipairs(fields) do + print("k: "..k) + print("v: "..v) + end +end + +-- +-- Ores creation +-- + function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_custom) -- dummy inside the spawner local dummy_ore_definition = { @@ -24,7 +235,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ self.timer = self.timer + dtime local n = minetest.get_node_or_nil(self.object:getpos()) if self.timer > 2 then - if n and n.name and n.name ~= "spawners:"..ore_name.."_spawner_active" and n.name ~= "spawners:"..ore_name.."_spawner_waiting" then + if n and n.name and n.name ~= "spawners:"..ore_name.."_spawner_active" and n.name ~= "spawners:"..ore_name.."_spawner_waiting" and n.name ~= "spawners:"..ore_name.."_spawner" then self.object:remove() end end @@ -44,11 +255,11 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ sunlight_propagates = true, tiles = { { - name = "spawners_spawner_animated_v2.png", + name = "spawners_spawner_animated.png", animation = { type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, + aspect_w = 32, + aspect_h = 32, length = 2.0 }, } @@ -56,13 +267,19 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ is_ground_content = true, groups = {cracky=1,level=2,igniter=1,not_in_creative_inventory=1}, drop = "spawners:"..ore_name.."_spawner", - on_construct = function(pos) - pos.y = pos.y + offset - minetest.add_entity(pos,"spawners:dummy_ore_"..ore_name) - end, + -- on_construct = function(pos) + -- pos.y = pos.y + offset + -- minetest.add_entity(pos,"spawners:dummy_ore_"..ore_name) + -- end, + + can_dig = can_dig, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_take = allow_metadata_inventory_take, + on_receive_fields = on_receive_fields, }) - -- node spawner waiting for light - everything is ok but too much light or not enough light + -- node spawner waiting - no stone around or no fuel minetest.register_node("spawners:"..ore_name.."_spawner_waiting", { description = ore_name.." spawner waiting", paramtype = "light", @@ -73,11 +290,11 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ sunlight_propagates = true, tiles = { { - name = "spawners_spawner_off_animated.png", + name = "spawners_spawner_waiting_animated.png", animation = { type = "vertical_frames", - aspect_w = 16, - aspect_h = 16, + aspect_w = 32, + aspect_h = 32, length = 2.0 }, } @@ -85,10 +302,16 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ is_ground_content = true, groups = {cracky=1,level=2,not_in_creative_inventory=1}, drop = "spawners:"..ore_name.."_spawner", - on_construct = function(pos) - pos.y = pos.y + offset - minetest.add_entity(pos,"spawners:dummy_ore_"..ore_name) - end, + -- on_construct = function(pos) + -- spawners.get_formspec(pos) + -- pos.y = pos.y + offset + -- minetest.add_entity(pos,"spawners:dummy_ore_"..ore_name) + -- end, + can_dig = can_dig, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_take = allow_metadata_inventory_take, + on_receive_fields = on_receive_fields, }) -- node spawner inactive (default) @@ -105,19 +328,32 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ on_construct = function(pos) local waiting, found_node = spawners.check_node_status_ores(pos, ore_name, "default:stone") + spawners.get_formspec(pos) + if found_node then - minetest.set_node(pos, {name="spawners:"..ore_name.."_spawner_active"}) + minetest.swap_node(pos, {name="spawners:"..ore_name.."_spawner_active"}) elseif waiting then - minetest.set_node(pos, {name="spawners:"..ore_name.."_spawner_waiting"}) + minetest.swap_node(pos, {name="spawners:"..ore_name.."_spawner_waiting"}) else end + + pos.y = pos.y + offset + minetest.add_entity(pos,"spawners:dummy_ore_"..ore_name) end, + + can_dig = can_dig, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_take = allow_metadata_inventory_take, + on_receive_fields = on_receive_fields, }) - -- abm + -- + -- ABM + -- minetest.register_abm({ nodenames = {"spawners:"..ore_name.."_spawner", "spawners:"..ore_name.."_spawner_active", "spawners:"..ore_name.."_spawner_waiting"}, - interval = 5, + interval = 5.0, chance = 5, action = function(pos, node, active_object_count, active_object_count_wider) @@ -128,7 +364,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ if found_node then -- make sure the right node status is shown if node.name ~= "spawners:"..ore_name.."_spawner_active" then - minetest.set_node(pos, {name="spawners:"..ore_name.."_spawner"}) + minetest.swap_node(pos, {name="spawners:"..ore_name.."_spawner"}) end -- enough place to spawn more ores @@ -137,7 +373,7 @@ function spawners.create_ore(ore_name, mod_prefix, size, offset, texture, sound_ else -- waiting status if node.name ~= "spawners:"..ore_name.."_spawner_waiting" then - minetest.set_node(pos, {name="spawners:"..ore_name.."_spawner_waiting"}) + minetest.swap_node(pos, {name="spawners:"..ore_name.."_spawner_waiting"}) end end @@ -149,10 +385,13 @@ end -- default:stone_with_gold spawners.create_ore("stone_with_gold", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "tnt_ignite") +-- default:stone_with_coal spawners.create_ore("stone_with_coal", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "tnt_ignite") +-- default:stone_with_iron spawners.create_ore("stone_with_iron", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "tnt_ignite") +-- default:stone_with_copper spawners.create_ore("stone_with_copper", "", {x=.33,y=.33}, 0, {"default_stone.png^default_mineral_gold.png"}, "tnt_ignite") @@ -192,4 +431,3 @@ minetest.register_craft({ {"default:diamondblock", "xpanes:bar", "default:diamondblock"}, } }) - diff --git a/textures/spawners_smoke_particle.png b/textures/spawners_smoke_particle.png new file mode 100644 index 0000000..89d81c1 Binary files /dev/null and b/textures/spawners_smoke_particle.png differ diff --git a/textures/spawners_spawner.png b/textures/spawners_spawner.png index 06037b4..dd6803e 100644 Binary files a/textures/spawners_spawner.png and b/textures/spawners_spawner.png differ diff --git a/textures/spawners_spawner_animated.png b/textures/spawners_spawner_animated.png index 1f7e27a..cf0c2c3 100644 Binary files a/textures/spawners_spawner_animated.png and b/textures/spawners_spawner_animated.png differ diff --git a/textures/spawners_spawner_animated_v2.png b/textures/spawners_spawner_animated_v2.png deleted file mode 100644 index 2393f0c..0000000 Binary files a/textures/spawners_spawner_animated_v2.png and /dev/null differ diff --git a/textures/spawners_spawner_normal.png b/textures/spawners_spawner_normal.png index 16cdf59..b102aa7 100644 Binary files a/textures/spawners_spawner_normal.png and b/textures/spawners_spawner_normal.png differ diff --git a/textures/spawners_spawner_off_animated.png b/textures/spawners_spawner_off_animated.png deleted file mode 100644 index 9df39a7..0000000 Binary files a/textures/spawners_spawner_off_animated.png and /dev/null differ diff --git a/textures/spawners_spawner_waiting_animated.png b/textures/spawners_spawner_waiting_animated.png new file mode 100644 index 0000000..179f8c2 Binary files /dev/null and b/textures/spawners_spawner_waiting_animated.png differ