Doors accept an electric input now and add Dispensers

This commit is contained in:
IamPyu 2024-12-13 16:43:30 -06:00
parent 002b80207e
commit b8150d6961
5 changed files with 73 additions and 2 deletions

View File

@ -18,7 +18,9 @@ Notable Game Changes:
- Improved command system and added Command Blocks
- Added many new commands, while also improving some builtin Luanti ones.
- Redesign the electricity system using a system similar to [Age of Mending's](https://content.luanti.org/packages/Sumianvoice/pmb_core/) wiring system
- New electricity devices like the Dropper
- New electricity devices:
- Dropper
- Dispenser
Other Game Changes:

View File

@ -34,6 +34,10 @@ local function on_rightclick(pos, node, clicker)
}, {pos = pos})
end
local function electricity_input(pos, node, sender_pos)
on_rightclick(pos, node)
end
PyuTest.make_door = function(name, desc, craftitem, texture, groups, extra)
local e = extra or {}
@ -53,7 +57,8 @@ PyuTest.make_door = function(name, desc, craftitem, texture, groups, extra)
collision_box = PyuTest.DOOR_NODEBOX,
after_place_node = after_place_node,
on_rightclick = on_rightclick
on_rightclick = on_rightclick,
__on_electricity_input = electricity_input,
}, e))
local id_windowless = name .. "_windowless"

View File

@ -52,6 +52,14 @@ PyuTest.make_liquid_bucket = function(name, desc, source, color)
PyuTest.give_item_or_drop(ItemStack("pyutest_buckets:bucket"), placer:get_inventory(), "main", placer:get_pos())
core.set_node(pos, { name = source })
end,
__on_dispense = function (pos, itemstack)
itemstack:take_item()
-- TODO: Eject liquid
return itemstack
end
})
core.override_item(source, {

View File

@ -53,3 +53,59 @@ core.register_craft({
{"group:cobble", "pyutest_ores:zinc_ingot", "group:cobble"}
}
})
local function dispense_stack(pos, itemstack)
local name = itemstack:get_name()
local def = core.registered_items[name]
if def.__on_dispense then
itemstack = def.__on_dispense(pos, itemstack) or itemstack
else
local it = itemstack:take_item()
PyuTest.drop_item(pos, it)
end
return itemstack
end
PyuTest.make_electricity_device("pyutest_electricity:dispenser", "Dispenser", {
cracky = PyuTest.BLOCK_NORMAL
}, {"pyutest-dispenser.png"}, nil, {
on_construct = function (pos)
local meta = core.get_meta(pos)
local inventory = meta:get_inventory()
inventory:set_size("items", 3 * 3)
meta:set_string("formspec", dropper_formspec(pos))
end,
on_destruct = function(pos)
local drops = {}
PyuTest.get_inventory_drops(pos, "items", drops)
for _, v in pairs(drops) do
core.add_item(pos, v)
end
end,
_pyutest_blast_resistance = 3
}, function (pos, node, sender_pos)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
for i = 1, inv:get_size("items") do
local stack = inv:get_stack("items", i)
if stack:get_count() > 0 then
local it = dispense_stack(pos, stack)
inv:set_stack("items", i, stack)
break
end
end
end)
core.register_craft({
output = "pyutest_electricity:dispenser",
recipe = {
{"group:cobble", "group:cobble", "group:cobble"},
{"group:cobble", "pyutest_ores:copper_ingot", "group:cobble"},
{"group:cobble", "pyutest_ores:zinc_ingot", "group:cobble"}
}
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 200 B