Allow dropper to be facing up- or downwards
This commit is contained in:
parent
73a22d3de1
commit
f08e23469f
|
@ -1,15 +1,14 @@
|
||||||
minetest.register_node("mcl_dropper:dropper", {
|
--[[ This mod registers 3 nodes:
|
||||||
description = "Dropper",
|
- One node for the horizontal-facing dropper (mcl_dropper:dropper)
|
||||||
tiles = {
|
- One node for the upwards-facing droppers (mcl_dropper:dropper_up)
|
||||||
"default_furnace_top.png", "default_furnace_bottom.png",
|
- One node for the downwards-facing droppers (mcl_dropper:dropper_down)
|
||||||
"default_furnace_side.png", "default_furnace_side.png",
|
|
||||||
"default_furnace_side.png", "mcl_dropper_dropper_front_horizontal.png"
|
3 node definitions are needed because of the way the textures are defined.
|
||||||
},
|
All node definitions share a lot of code, so this is the reason why there
|
||||||
groups = {cracky=2,container=2},
|
are so many weird tables below.
|
||||||
is_ground_content = false,
|
]]
|
||||||
paramtype2 = "facedir",
|
|
||||||
sounds = mcl_sounds.node_sound_stone_defaults(),
|
local setup_dropper = function(pos)
|
||||||
after_place_node = function(pos)
|
|
||||||
local form = "size[9,8.75]"..
|
local form = "size[9,8.75]"..
|
||||||
"background[-0.19,-0.25;9.41,9.49;crafting_inventory_9_slots.png]"..
|
"background[-0.19,-0.25;9.41,9.49;crafting_inventory_9_slots.png]"..
|
||||||
mcl_core.inventory_header..
|
mcl_core.inventory_header..
|
||||||
|
@ -23,7 +22,12 @@ minetest.register_node("mcl_dropper:dropper", {
|
||||||
meta:set_string("formspec", form)
|
meta:set_string("formspec", form)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("main", 9)
|
inv:set_size("main", 9)
|
||||||
end,
|
end
|
||||||
|
|
||||||
|
-- Shared core definition table
|
||||||
|
local dropperdef = {
|
||||||
|
is_ground_content = false,
|
||||||
|
sounds = mcl_sounds.node_sound_stone_defaults(),
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local meta2 = meta
|
local meta2 = meta
|
||||||
|
@ -43,7 +47,14 @@ minetest.register_node("mcl_dropper:dropper", {
|
||||||
action_on = function (pos, node)
|
action_on = function (pos, node)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local droppos = vector.subtract(pos, minetest.facedir_to_dir(node.param2))
|
local droppos
|
||||||
|
if node.name == "mcl_dropper:dropper" then
|
||||||
|
droppos = vector.subtract(pos, minetest.facedir_to_dir(node.param2))
|
||||||
|
elseif node.name == "mcl_dropper:dropper_up" then
|
||||||
|
droppos = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||||
|
elseif node.name == "mcl_dropper:dropper_down" then
|
||||||
|
droppos = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||||
|
end
|
||||||
local dropnode = minetest.get_node(droppos)
|
local dropnode = minetest.get_node(droppos)
|
||||||
-- Do not drop into solid nodes, unless they are containers
|
-- Do not drop into solid nodes, unless they are containers
|
||||||
local dropnodedef = minetest.registered_nodes[dropnode.name]
|
local dropnodedef = minetest.registered_nodes[dropnode.name]
|
||||||
|
@ -75,13 +86,54 @@ minetest.register_node("mcl_dropper:dropper", {
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}}
|
}}
|
||||||
})
|
}
|
||||||
|
|
||||||
minetest.register_craft({
|
-- Horizontal dropper
|
||||||
output = 'mcl_dropper:dropper',
|
|
||||||
recipe = {
|
local horizontal_def = table.copy(dropperdef)
|
||||||
{"mcl_core:cobble", "mcl_core:cobble", "mcl_core:cobble",},
|
horizontal_def.description = "Dropper"
|
||||||
{"mcl_core:cobble", "", "mcl_core:cobble",},
|
horizontal_def.after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||||
{"mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble",},
|
setup_dropper(pos)
|
||||||
}
|
|
||||||
})
|
-- When placed up and down, convert node to up/down dropper
|
||||||
|
if pointed_thing.above.y < pointed_thing.under.y then
|
||||||
|
minetest.swap_node(pos, {name = "mcl_dropper:dropper_down"})
|
||||||
|
elseif pointed_thing.above.y > pointed_thing.under.y then
|
||||||
|
minetest.swap_node(pos, {name = "mcl_dropper:dropper_up"})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Else, the normal facedir logic applies
|
||||||
|
end
|
||||||
|
horizontal_def.tiles = {
|
||||||
|
"default_furnace_top.png", "default_furnace_bottom.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png",
|
||||||
|
"default_furnace_side.png", "mcl_dropper_dropper_front_horizontal.png"
|
||||||
|
}
|
||||||
|
horizontal_def.paramtype2 = "facedir"
|
||||||
|
horizontal_def.groups = {cracky=2,container=2}
|
||||||
|
|
||||||
|
minetest.register_node("mcl_dropper:dropper", horizontal_def)
|
||||||
|
|
||||||
|
-- Down dropper
|
||||||
|
local down_def = table.copy(dropperdef)
|
||||||
|
down_def.description = "Downwards-Facing Dropper"
|
||||||
|
down_def.after_place_node = setup_dropper
|
||||||
|
down_def.tiles = {
|
||||||
|
"default_furnace_top.png", "mcl_dropper_dropper_front_vertical.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png"
|
||||||
|
}
|
||||||
|
down_def.groups = {cracky=2,container=2,not_in_creative_inventory=1}
|
||||||
|
down_def.drop = "mcl_dropper:dropper"
|
||||||
|
minetest.register_node("mcl_dropper:dropper_down", down_def)
|
||||||
|
|
||||||
|
-- Up dropper
|
||||||
|
-- The up dropper is almost identical to the down dropper, it only differs in textures
|
||||||
|
up_def = table.copy(down_def)
|
||||||
|
up_def.description = "Upwards-Facing Dropper"
|
||||||
|
up_def.tiles = {
|
||||||
|
"mcl_dropper_dropper_front_vertical.png", "default_furnace_bottom.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png",
|
||||||
|
"default_furnace_side.png", "default_furnace_side.png"
|
||||||
|
}
|
||||||
|
minetest.register_node("mcl_dropper:dropper_up", up_def)
|
||||||
|
|
Loading…
Reference in New Issue