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 00000000..dbeb78ea --- /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 00000000..c791b3f2 --- /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!ia0vp^3Lwk@BpAX3RW*PVOS+@4BLl<6e(pbstRTr`k04(L zhAK4%hK3dfhF?ITh8GMBr3MTPuM!v-tY$DUh!@P+6=(yLU`q0KcVYP7-hXC4kjGx) z>Fdh=kcp4U)acPh#vY)2gQtsQh{b8w3+KCHLPd@~T<2E$@E6xP73Y&@j&tQ21XUU;n>PEPU(2xgX#E zzT5xfZfnHy?G^L*@0TiE^Ocq|{x8xzJJ>(QCiHmBRZV%RsohpNGkwpoV8VjQHdJ z)4%T$nY$pnM&|T--qnv!#s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3l^-f+qreRiQ{GU<`?E%nt2^Dm)HEy zyecbt@RYYyoB!qC=U6|t9WZ6#)mZy;k5T@K#Ew@!iTk}B6l5GHb803(T`1|Yx3!?F z-_RhQB|Fdh=kcp4U)acPh#vY)2j;D)bh{b8&iRZl^JBS>A?tkJ^cbr%fch^N7iO8l)a!apR5d7as3d7f=~QsZ=*TviH1E#)2^I#ZL`<{Wmg;GXZ;t|1$Pp!^6<;i+;8WERTF)rRZAXP<5LB z$i@W)vP?yHii|%#zApLl?Eh=sj1C@)9XXgnJL@cz?*1$*Wtii3*wH~VChWB!ga6eU z4({^fjBgbbmZ~zmu+83DxnR-G*A~0aUQ$~!#VdIJmw5|z-4I%Es$DK9I$_^U!G0l? z+?KB!n*Dcmzv{JPzj?{(knFRs*4JVkgpS|#xGxuV;M|=Xri!Lc3?=hR|8A0wzFPc& z$vY~++V!PB(|(ON8!8fvwZmTS|9$uFTK`{j%XZhYaXIhUa(Hu8?&|#Z{|p_A7@pp; zdshHVimD~95hW>!C8<`)MX5lF!N|bST-U%z*U%)yz{twf*viyE+rZGuz`*FS_C^#9 cx%nxXX_dG&IPaUx3)H~i>FVdQ&MBb@03`ry{{R30 literal 0 HcmV?d00001 diff --git a/mods/redstone/mcl_dispensers/textures/mcl_dispensers_dispenser_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!ia0vp^3Lwk@BpAX3RW*PVOS+@4BLl<6e(pbstRTr`k04(L zhALGChK6PahM)g|^h*YYQUeBtR|yOZRx=nF#PcV`A9Vw&WlHjPcVYP7-hXC4kjGiz z5n0T@z%2~Ij105pNB{-dOFVsD*&j0TF_{`Y+Q`@g)O5hp#WBRf-*@swug4A|ZO;|I zWlh(O;+n?$ZINd7f*ag|-kY_&jPjyPrkEUZP}C4vHka?97Gtl;TApjO_r6&Cu3oFl zUZtf*{<(^A`i$J`SzD`Q%~yx4Q<&y^bL*O-%Jl2oBHx}Vy}Rx9OBtCPXT_fWFmdpU z-CkMoDr(KMthHObCbhU9l2C5(x@s%;PIUj?)(@-KZeg*1eDRjV+N}Ww4>ZmlzI|9W zZR=zgwUd_O*^7qljAB|GCa%R-C zc+U8vXsguw@Q9_NZAVttFPg&BBEa|~!H13W?o*?_WJbL}%LhsST6owVtMYJ^a-0s7 zk@lUt`)(Y6lZx{Kx5bB~#Fb5@IE6~S7fEwE|D3Yy@WTf+HhBT8OHElcOQ(NubKG2F zB=Y>ZN{L(55*HcoNB0GcL{|B!P41rN%T)Ej;@RDDKQdR&^pE0=uV8Sp@0 zk^9mMi>?TzXp|oQeRsl#Jqr>$Pe{myZoKRCWakuf^Ems{&ps~-IQ2a6%O@e%izoh_ z)3WX4Jo%LO`>)v(PfvO8KJjF+(Hq@sFYbCiOzhZGH{UEKJ=`wM>ip-KU5nIOgp1X8 zK5y)P7_d_N(NCTF2Al409twJ4tB+OaY{I_khx zut73b<;}K(`r_R$L%b}frU=Yjc);gpukN<3<((fiB`<5LKm0Z8*WnNUoixm6&oTd= zv;A(~Y}&gLrF^{=0v;$PBoxqq^M`~EGVT2oI|{NwNYkt4Kt zfAC~r@>VTzjVMV;EJ?LWE=mPb3`Pcq=DG$(x`rkp21Zt<##W{V+6IPJ1_nltwKt+@ c$jwj5OsmAL!Fk_gUZ4gBPgg&ebxsLQ00L=|l>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~C7n%{hPs!=V#5lYtaVx}&cn1H;CC?mvmFK)yn< zN02WALzNl>LqiJ#!!Mvv!wUw6QUeBtR|yOZRx=nF#0%!^3bX-AFqH)P1v4;|O+IS@ z;w5>zyDi{Ax2KC^NX4zUH=?bP0l+XkKH