From f08e23469f50c8b6aa332021a32ecf9384d55677 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 14 Feb 2017 02:15:51 +0100 Subject: [PATCH] Allow dropper to be facing up- or downwards --- mods/redstone/mcl_dropper/init.lua | 120 +++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 34 deletions(-) diff --git a/mods/redstone/mcl_dropper/init.lua b/mods/redstone/mcl_dropper/init.lua index e09d4a3592..fb86a603d2 100644 --- a/mods/redstone/mcl_dropper/init.lua +++ b/mods/redstone/mcl_dropper/init.lua @@ -1,29 +1,33 @@ -minetest.register_node("mcl_dropper:dropper", { - description = "Dropper", - 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" - }, - groups = {cracky=2,container=2}, +--[[ This mod registers 3 nodes: +- One node for the horizontal-facing dropper (mcl_dropper:dropper) +- One node for the upwards-facing droppers (mcl_dropper:dropper_up) +- One node for the downwards-facing droppers (mcl_dropper:dropper_down) + +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 +are so many weird tables below. +]] + +local setup_dropper = function(pos) + local form = "size[9,8.75]".. + "background[-0.19,-0.25;9.41,9.49;crafting_inventory_9_slots.png]".. + mcl_core.inventory_header.. + "image[3,-0.2;5,0.75;mcl_dropper_fnt_dropper.png]".. + "list[current_player;main;0,4.5;9,3;9]".. + "list[current_player;main;0,7.74;9,1;]".. + "list[current_name;main;3,0.5;3,3;]".. + "listring[current_name;main]".. + "listring[current_player;main]" + local meta = minetest.get_meta(pos) + meta:set_string("formspec", form) + local inv = meta:get_inventory() + inv:set_size("main", 9) +end + +-- Shared core definition table +local dropperdef = { is_ground_content = false, - paramtype2 = "facedir", sounds = mcl_sounds.node_sound_stone_defaults(), - after_place_node = function(pos) - local form = "size[9,8.75]".. - "background[-0.19,-0.25;9.41,9.49;crafting_inventory_9_slots.png]".. - mcl_core.inventory_header.. - "image[3,-0.2;5,0.75;mcl_dropper_fnt_dropper.png]".. - "list[current_player;main;0,4.5;9,3;9]".. - "list[current_player;main;0,7.74;9,1;]".. - "list[current_name;main;3,0.5;3,3;]".. - "listring[current_name;main]".. - "listring[current_player;main]" - local meta = minetest.get_meta(pos) - meta:set_string("formspec", form) - local inv = meta:get_inventory() - inv:set_size("main", 9) - end, after_dig_node = function(pos, oldnode, oldmetadata, digger) local meta = minetest.get_meta(pos) local meta2 = meta @@ -43,7 +47,14 @@ minetest.register_node("mcl_dropper:dropper", { action_on = function (pos, node) local meta = minetest.get_meta(pos) 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) -- Do not drop into solid nodes, unless they are containers local dropnodedef = minetest.registered_nodes[dropnode.name] @@ -75,13 +86,54 @@ minetest.register_node("mcl_dropper:dropper", { end end }} -}) +} -minetest.register_craft({ - output = 'mcl_dropper:dropper', - recipe = { - {"mcl_core:cobble", "mcl_core:cobble", "mcl_core:cobble",}, - {"mcl_core:cobble", "", "mcl_core:cobble",}, - {"mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble",}, - } -}) +-- Horizontal dropper + +local horizontal_def = table.copy(dropperdef) +horizontal_def.description = "Dropper" +horizontal_def.after_place_node = function(pos, placer, itemstack, pointed_thing) + 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)