Forcefield mod help
I am going to make a forcefield mod where undigable block (forcefield block) is placed around about 6 blocks from forcefield generator block when it has coal in it and takes a coal away every 10 times forcefield block is hit, every 10 seconds, or if any block is missing, and destroys all forcefield block when there is no more coal. I am stuck on part detecting if coal is in the forcefield generator and there will be way more help needed afterwards.
init.lua:
init.lua:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_node("forcefield:forcefield", {
tiles = {"forcefield_forcefield.png"},
drawtype = glasslike,
sunlight_propagates = true,
walkable = true,
diggable = false,
on_punch = function(pos, node, puncher)
pos = position
a = "a" + "1"
end,
})
default.forcefield_formspec =
"size[8,9]"..
"list[current_name;coal;1,1;6,3;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("forcefield:fmaker", {
description = "Forcefield Generator",
tiles = {"forcefield_sides.png","forcefield_sides.png","forcefield_front.png","forcefield_sides.png","forcefield_sides.png","forcefield_sides.png"},
groups = {snappy=2, choppy=2},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", default.forcefield_formspec)
meta:set_string("infotext", "forcefield generator")
local inv = meta:get_inventory()
inv:set_size("coal", 18)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("coal", 18) then
return false
end
return true
end,
})
minetest.register_abm({
nodenames = {"forcefield:fmaker"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local fuel = inv:get_list("coal")
if fuel == "default:coal_lump" then
srcstack = inv:get_stack("coal", 1)
srcstack:take_item("default:coal_lump")
inv:set_stack("coal", 1, srcstack)
else
print("there was no coal")
end
end,
})
minetest.register_craft({
output = 'forcefield:fmaker',
recipe = {
{'default:mese', 'default:mese', 'default:mese'},
{'default:mese', 'default:furnace', 'default:mese'},
{'default:mese', 'default:mese', 'default:mese'},
}
})
