From b92a220e49eca5e10a06892bf45fc03483e1eee6 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 14 Feb 2017 03:23:06 +0100 Subject: [PATCH] Add basic dispensers (don't dispense most stuff) --- mods/redstone/mcl_dispensers/depends.txt | 6 + mods/redstone/mcl_dispensers/init.lua | 177 ++++++++++++++++++ .../textures/dispenser_front_horizontal.png | Bin 0 -> 888 bytes .../textures/dispenser_front_vertical.png | Bin 0 -> 980 bytes ..._dispensers_dispenser_front_horizontal.png | Bin 0 -> 868 bytes ...cl_dispensers_dispenser_front_vertical.png | Bin 0 -> 973 bytes .../textures/mcl_dispensers_fnt_dispenser.png | Bin 0 -> 513 bytes 7 files changed, 183 insertions(+) create mode 100644 mods/redstone/mcl_dispensers/depends.txt create mode 100644 mods/redstone/mcl_dispensers/init.lua create mode 100644 mods/redstone/mcl_dispensers/textures/dispenser_front_horizontal.png create mode 100644 mods/redstone/mcl_dispensers/textures/dispenser_front_vertical.png create mode 100644 mods/redstone/mcl_dispensers/textures/mcl_dispensers_dispenser_front_horizontal.png create mode 100644 mods/redstone/mcl_dispensers/textures/mcl_dispensers_dispenser_front_vertical.png create mode 100644 mods/redstone/mcl_dispensers/textures/mcl_dispensers_fnt_dispenser.png diff --git a/mods/redstone/mcl_dispensers/depends.txt b/mods/redstone/mcl_dispensers/depends.txt new file mode 100644 index 000000000..dbeb78ea8 --- /dev/null +++ b/mods/redstone/mcl_dispensers/depends.txt @@ -0,0 +1,6 @@ +mesecons +mcl_core +mcl_sounds +mcl_fire +mcl_tnt +mcl_heads diff --git a/mods/redstone/mcl_dispensers/init.lua b/mods/redstone/mcl_dispensers/init.lua new file mode 100644 index 000000000..c791b3f2c --- /dev/null +++ b/mods/redstone/mcl_dispensers/init.lua @@ -0,0 +1,177 @@ +--[[ This mod registers 3 nodes: +- One node for the horizontal-facing dispensers (mcl_dispensers:dispenser) +- One node for the upwards-facing dispensers (mcl_dispenser:dispenser_up) +- One node for the downwards-facing dispensers (mcl_dispenser:dispenser_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. +]] + +-- For after_place_node +local setup_dispenser = function(pos) + -- Set formspec and inventory + 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_dispensers_fnt_dispenser.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 dispenserdef = { + is_ground_content = false, + sounds = mcl_sounds.node_sound_stone_defaults(), + after_dig_node = function(pos, oldnode, oldmetadata, digger) + local meta = minetest.get_meta(pos) + local meta2 = meta + meta:from_table(oldmetadata) + local inv = meta:get_inventory() + for i=1, inv:get_size("main") do + local stack = inv:get_stack("main", i) + if not stack:is_empty() then + local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + minetest.add_item(p, stack) + end + end + meta:from_table(meta2:to_table()) + end, + mesecons = {effector = { + -- Dispense random item when triggered + action_on = function (pos, node) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + local droppos + if node.name == "mcl_dispensers:dispenser" then + droppos = vector.subtract(pos, minetest.facedir_to_dir(node.param2)) + elseif node.name == "mcl_dispensers:dispenser_up" then + droppos = {x=pos.x, y=pos.y+1, z=pos.z} + elseif node.name == "mcl_dispensers:dispenser_down" then + droppos = {x=pos.x, y=pos.y-1, z=pos.z} + end + local dropnode = minetest.get_node(droppos) + -- Do not dispense into solid nodes + local dropnodedef = minetest.registered_nodes[dropnode.name] + if dropnodedef.walkable then + return + end + local stacks = {} + for i=1,inv:get_size("main") do + local stack = inv:get_stack("main", i) + if not stack:is_empty() then + table.insert(stacks, {stack = stack, stackpos = i}) + end + end + if #stacks >= 1 then + local r = math.random(1, #stacks) + local stack = stacks[r].stack + local dropitem = ItemStack(stack:get_name()) + local stack_id = stacks[r].stackpos + local iname = stack:get_name() + local igroups = minetest.registered_items[iname].groups + + --[===[ Dispense item ]===] + if iname == "mcl_fire:flint_and_steel" then + -- Ignite air or fire + if dropnode.name == "air" then + minetest.add_node(droppos, {name="mcl_fire:basic_flame"}) + if not minetest.setting_getbool("creative_mode") then + stack:add_wear(65535/65) -- 65 uses + end + elseif dropnode.name == "mcl_tnt:tnt" then + tnt.ignite(droppos) + if not minetest.setting_getbool("creative_mode") then + stack:add_wear(65535/65) -- 65 uses + end + end + + inv:set_stack("main", stack_id, stack) + elseif igroups.head or igroups.shulker_box or iname == "mcl_farming:pumpkin_face" then + -- Place head, shulker box, or pumpkin + if dropnodedef.buildable_to then + minetest.set_node(droppos, {name = iname, param2 = node.param2}) + stack:take_item() + inv:set_stack("main", stack_id, stack) + end + + -- TODO: Many other dispenser actions + else + -- Drop item + minetest.add_item(droppos, dropitem) + + stack:take_item() + inv:set_stack("main", stack_id, stack) + end + end + end + }} +} + +-- Horizontal dispenser + +local horizontal_def = table.copy(dispenserdef) +horizontal_def.description = "Dispenser" +horizontal_def.after_place_node = function(pos, placer, itemstack, pointed_thing) + setup_dispenser(pos) + + -- When placed up and down, convert node to up/down dispenser + if pointed_thing.above.y < pointed_thing.under.y then + minetest.swap_node(pos, {name = "mcl_dispensers:dispenser_down"}) + elseif pointed_thing.above.y > pointed_thing.under.y then + minetest.swap_node(pos, {name = "mcl_dispensers:dispenser_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_dispensers_dispenser_front_horizontal.png" +} +horizontal_def.paramtype2 = "facedir" +horizontal_def.groups = {cracky=2,container=2} + +minetest.register_node("mcl_dispensers:dispenser", horizontal_def) + +-- Down dispenser +local down_def = table.copy(dispenserdef) +down_def.description = "Downwards-Facing Dispenser" +down_def.after_place_node = setup_dispenser +down_def.tiles = { + "default_furnace_top.png", "mcl_dispensers_dispenser_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_dispensers:dispenser" +minetest.register_node("mcl_dispensers:dispenser_down", down_def) + +-- Up dispenser +-- The up dispenser is almost identical to the down dispenser , it only differs in textures +up_def = table.copy(down_def) +up_def.description = "Upwards-Facing Dispenser" +up_def.tiles = { + "mcl_dispensers_dispenser_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_dispensers:dispenser_up", up_def) + + + +minetest.register_craft({ + output = 'mcl_dispensers:dispenser', + recipe = { + {"mcl_core:cobble", "mcl_core:cobble", "mcl_core:cobble",}, + {"mcl_core:cobble", "mcl_throwing:bow", "mcl_core:cobble",}, + {"mcl_core:cobble", "mesecons:redstone", "mcl_core:cobble",}, + } +}) diff --git a/mods/redstone/mcl_dispensers/textures/dispenser_front_horizontal.png b/mods/redstone/mcl_dispensers/textures/dispenser_front_horizontal.png new file mode 100644 index 0000000000000000000000000000000000000000..1931211097cee8faa5bbf3a236b99a5246ab3038 GIT binary patch literal 888 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4h9AWhA=@@4F(1VmUKs7M+SzC{oH>NSwWJ? z9znhg3{`3j3=J&|48Ir{7#dzMFq9fFFuY1&V6d9Oz#v{QXIG#N0|Nt7lDE4H!~gdF zGy54B7}!fZeO=ifGVw8)8a>*`*u%iU)Zppj7-DhS^}_kCm{5_U57+z8jkXN+Z8bCR z)$QY?B7 z6$PX|?=eeX|24Y${o3<7omsOoc`T+UT&!C9qU`9?rL4Z`Pq$97DzN+VanrX&*Vq5= z6ARzEaPG(Vzwh?{xZ4`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enser_front_vertical.png b/mods/redstone/mcl_dispensers/textures/mcl_dispensers_dispenser_front_vertical.png new file mode 100644 index 0000000000000000000000000000000000000000..3b70c265e5136d90f5cb5d5f5828f22b835863de GIT binary patch literal 973 zcmeAS@N?(olHy`uVBq!ia0y~yU{C;I4h9AWhA=@@4F(1VmUKs7M+SzC{oH>NSwWJ? z9znhg3{|QO3=Pc;3_t%fFf_bmU???UV0e|lz+g3lfk8ZfQv6Xj1_lPEByV>YhX3vT zXZABNFmM)lL>4nJa0`PlBg3pY5)2Fs>?NMQuIvw)_?S$M9&KdoVPIf7;OXKRV&U&Q z`J&fj2a&etir=!P>qc=+RCKz{86-3>V0^`Qqi^}E9)0c;b{?I{E^_p#(DRtQC~8nUZCZJq<<|u zY>!oWI7&HA2g*qM&fR@Cj=xF8d4b#FLsH_(rc#_jCEtsrIh}t_S$6p0gBqK>0M@0Z zESja$Ke#z=E-?~${#>QRt!jyjjQ6Aa0!AXM{M06QPxED}`e5;4X6820PfdV@b1rXvwYY?GGmFH*3oT-+%gp|q{j#6ye4+uT)ie3B%T`S0 z`Oiv~YqnGz%WBHrerlE3j>=l!%lh(>EfM(zy4imCgiN}q|c0UYQsr~4uPJM$-_csp(y|C3svlLt2{|h($ literal 0 HcmV?d00001 diff --git a/mods/redstone/mcl_dispensers/textures/mcl_dispensers_fnt_dispenser.png b/mods/redstone/mcl_dispensers/textures/mcl_dispensers_fnt_dispenser.png new file mode 100644 index 0000000000000000000000000000000000000000..9e46ca3015ca05860e126b33d2f268506e2d2933 GIT binary patch literal 513 zcmeAS@N?(olHy`uVBq!ia0y~yU~Fe#U@+%kU|?W4bmC?*0|Ns~x}&cn1H;CC?mvmF z3=9kk$sR$z3=CCj3=9n|3=F>*7#JE}Fff!FFfhDIU|_JC!N4G1FlSew4FdxMQ%R6t zFatx`&D=#FHXOBbh~2^Z`XIAqg#tUjYIeqJm;C;~*^9r#CX2jF|2-uz+RXpkZti4T zko1!W3(r{fd=uW-_Ga$Cx25mv%>HN0dsCCR1|-!eW8?GM`S;p?JKxRSzUrLx*?9Kk zwDTJzt~Ik4eQ@BDTlUpas{Z)*Uoo}m^Ka(c$iVD$J$3){M%``S@7@2M;xpyzUaRwu zBKYM_fLwH=PWH!y|9@jQ$k|M2W-kJJW9uG9o?4xw2e!_-$iTp$TH+c}l9E`GYL#4+ znpl#`U}Ruuu4`bVYiJT;U}R-vWMyKhZD43+V6aw0z!615ZhlH;S|vh*afqRXm4T&| Xks(CG