From b030c21febbd101981197087364e7ffeb3697e92 Mon Sep 17 00:00:00 2001 From: Misael Roman Date: Sat, 29 Sep 2012 19:20:51 -0500 Subject: [PATCH] added spell and node Added the alohomora spell, that is used to open a special door. This door can only be used with this spell. --- harrytest/init.lua | 203 +++++++++++++++++++++++++- harrytest/textures/mdoor_wood.png | Bin 0 -> 166 bytes harrytest/textures/mdoor_wood_a.png | Bin 0 -> 245 bytes harrytest/textures/mdoor_wood_a_r.png | Bin 0 -> 249 bytes harrytest/textures/mdoor_wood_b.png | Bin 0 -> 216 bytes harrytest/textures/mdoor_wood_b_r.png | Bin 0 -> 216 bytes htspells/init.lua | 17 ++- htspells/textures/key.png | Bin 0 -> 1511 bytes 8 files changed, 216 insertions(+), 4 deletions(-) create mode 100644 harrytest/textures/mdoor_wood.png create mode 100644 harrytest/textures/mdoor_wood_a.png create mode 100644 harrytest/textures/mdoor_wood_a_r.png create mode 100644 harrytest/textures/mdoor_wood_b.png create mode 100644 harrytest/textures/mdoor_wood_b_r.png create mode 100644 htspells/textures/key.png diff --git a/harrytest/init.lua b/harrytest/init.lua index 3c917bb..bc7ef90 100644 --- a/harrytest/init.lua +++ b/harrytest/init.lua @@ -4,11 +4,18 @@ --Licence: WTFPL --] +-------------------------------------------------------------------------------- + +local WALLMX = 3 +local WALLMZ = 5 +local WALLPX = 2 +local WALLPZ = 4 + +-------------------------------------------------------------------------------- + -- Items - ----1. Wand - minetest.register_tool("harrytest:wand", { description = "Magic Wand", inventory_image = "wand.png", @@ -21,4 +28,194 @@ minetest.register_tool("harrytest:wand", { choppy={times={[3]=0.70}, uses=40, maxlevel=0} } } -}) \ No newline at end of file +}) + +----2. Magic mdoor +minetest.register_alias('mdoor', 'harrytest:mdoor_wood') +minetest.register_alias('mdoor_wood', 'harrytest:mdoor_wood') + +minetest.register_node( 'harrytest:mdoor_wood', { + description = 'Magic door', + drawtype = 'signlike', + tiles = { 'mdoor_wood.png' }, + inventory_image = 'mdoor_wood.png', + wield_image = 'mdoor_wood.png', + paramtype2 = 'wallmounted', + selection_box = { type = 'wallmounted' }, + groups = { choppy=2, dig_immediate=2 }, +}) + +minetest.register_craft({ + type = 'fuel', + recipe = 'harrytest:mdoor_wood', + burntime = 30, +}) + +minetest.register_node( 'harrytest:mdoor_wood_a_c', { + Description = 'Top Closed Magic door', + drawtype = 'signlike', + tiles = { 'mdoor_wood_a.png' }, + inventory_image = 'mdoor_wood_a.png', + paramtype = 'light', + paramtype2 = 'wallmounted', + walkable = true, + selection_box = { type = "wallmounted", }, + groups = { choppy=2, dig_immediate=2 }, + legacy_wallmounted = true, + drop = 'harrytest:mdoor_wood', +}) + +minetest.register_node( 'harrytest:mdoor_wood_b_c', { + Description = 'Bottom Closed Magic door', + drawtype = 'signlike', + tiles = { 'mdoor_wood_b.png' }, + inventory_image = 'mdoor_wood_b.png', + paramtype = 'light', + paramtype2 = 'wallmounted', + walkable = true, + selection_box = { type = "wallmounted", }, + groups = { choppy=2, dig_immediate=2 }, + legacy_wallmounted = true, + drop = 'harrytest:mdoor_wood', +}) + +minetest.register_node( 'harrytest:mdoor_wood_a_o', { + Description = 'Top Open Magic door', + drawtype = 'signlike', + tiles = { 'mdoor_wood_a_r.png' }, + inventory_image = 'mdoor_wood_a_r.png', + paramtype = 'light', + paramtype2 = 'wallmounted', + walkable = false, + selection_box = { type = "wallmounted", }, + groups = { choppy=2, dig_immediate=2 }, + legacy_wallmounted = true, + drop = 'harrytest:mdoor_wood', +}) + +minetest.register_node( 'harrytest:mdoor_wood_b_o', { + Description = 'Bottom Open Magic door', + drawtype = 'signlike', + tiles = { 'mdoor_wood_b_r.png' }, + inventory_image = 'mdoor_wood_b_r.png', + paramtype = 'light', + paramtype2 = 'wallmounted', + walkable = false, + selection_box = { type = "wallmounted", }, + groups = { choppy=2, dig_immediate=2 }, + legacy_wallmounted = true, + drop = 'harrytest:mdoor_wood', +}) + +-------------------------------------------------------------------------------- + +local round = function( n ) + if n >= 0 then + return math.floor( n + 0.5 ) + else + return math.ceil( n - 0.5 ) + end +end + +local on_mdoor_placed = function( pos, node, placer ) + if node.name ~= 'harrytest:mdoor_wood' then return end + + local upos = { x = pos.x, y = pos.y - 1, z = pos.z } + local apos = { x = pos.x, y = pos.y + 1, z = pos.z } + local und = minetest.env:get_node( upos ) + local abv = minetest.env:get_node( apos ) + + local dir = placer:get_look_dir() + + if round( dir.x ) == 1 then + newparam = WALLMX + elseif round( dir.x ) == -1 then + newparam = WALLPX + elseif round( dir.z ) == 1 then + newparam = WALLMZ + elseif round( dir.z ) == -1 then + newparam = WALLPZ + end + + if und.name == 'air' then + minetest.env:add_node( pos, { name = 'harrytest:mdoor_wood_a_c', param2 = newparam } ) + minetest.env:add_node( upos, { name = 'harrytest:mdoor_wood_b_c', param2 = newparam } ) + elseif abv.name == 'air' then + minetest.env:add_node( pos, { name = 'harrytest:mdoor_wood_b_c', param2 = newparam } ) + minetest.env:add_node( apos, { name = 'harrytest:mdoor_wood_a_c', param2 = newparam } ) + else + minetest.env:remove_node( pos ) + placer:get_inventory():add_item( "main", 'harrytest:mdoor_wood' ) + minetest.chat_send_player( placer:get_player_name(), 'not enough space' ) + end +end + +local on_mdoor_punched = function( pos, node, puncher ) +local tool = puncher:get_wielded_item():get_name() + if tool and tool == "htspells:alohomora" then + if string.find( node.name, 'harrytest:mdoor_wood' ) == nil then return end + + local upos = { x = pos.x, y = pos.y - 1, z = pos.z } + local apos = { x = pos.x, y = pos.y + 1, z = pos.z } + + if string.find( node.name, '_c', -2 ) ~= nil then + if node.param2 == WALLPX then + newparam = WALLMZ + elseif node.param2 == WALLMZ then + newparam = WALLMX + elseif node.param2 == WALLMX then + newparam = WALLPZ + elseif node.param2 == WALLPZ then + newparam = WALLPX + end + elseif string.find( node.name, '_o', -2 ) ~= nil then + if node.param2 == WALLMZ then + newparam = WALLPX + elseif node.param2 == WALLMX then + newparam = WALLMZ + elseif node.param2 == WALLPZ then + newparam = WALLMX + elseif node.param2 == WALLPX then + newparam = WALLPZ + end + end + + + if ( node.name == 'harrytest:mdoor_wood_a_c' ) then + minetest.env:add_node( pos, { name = 'harrytest:mdoor_wood_a_o', param2 = newparam } ) + minetest.env:add_node( upos, { name = 'harrytest:mdoor_wood_b_o', param2 = newparam } ) + + elseif ( node.name == 'harrytest:mdoor_wood_b_c' ) then + minetest.env:add_node( pos, { name = 'harrytest:mdoor_wood_b_o', param2 = newparam } ) + minetest.env:add_node( apos, { name = 'harrytest:mdoor_wood_a_o', param2 = newparam } ) + + elseif ( node.name == 'harrytest:mdoor_wood_a_o' ) then + minetest.env:add_node( pos, { name = 'harrytest:mdoor_wood_a_c', param2 = newparam } ) + minetest.env:add_node( upos, { name = 'harrytest:mdoor_wood_b_c', param2 = newparam } ) + + elseif ( node.name == 'harrytest:mdoor_wood_b_o' ) then + minetest.env:add_node( pos, { name = 'harrytest:mdoor_wood_b_c', param2 = newparam } ) + minetest.env:add_node( apos, { name = 'harrytest:mdoor_wood_a_c', param2 = newparam } ) + + end +end +end + +local on_mdoor_digged = function( pos, node, digger ) + local upos = { x = pos.x, y = pos.y - 1, z = pos.z } + local apos = { x = pos.x, y = pos.y + 1, z = pos.z } + + if ( node.name == 'harrytest:mdoor_wood_a_c' ) or ( node.name == 'harrytest:mdoor_wood_a_o' ) then + minetest.env:remove_node( upos ) + elseif ( node.name == 'harrytest:mdoor_wood_b_c' ) or ( node.name == 'harrytest:mdoor_wood_b_o' ) then + minetest.env:remove_node( apos ) + end +end + +-------------------------------------------------------------------------------- + +minetest.register_on_placenode( on_mdoor_placed ) +minetest.register_on_punchnode( on_mdoor_punched ) +minetest.register_on_dignode( on_mdoor_digged ) + +-------------------------------------------------------------------------------- \ No newline at end of file diff --git a/harrytest/textures/mdoor_wood.png b/harrytest/textures/mdoor_wood.png new file mode 100644 index 0000000000000000000000000000000000000000..120fc982f7aeb151b2c014678b205072b2b20907 GIT binary patch literal 166 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|5QL70(Y)*K0-AbW|YuPgfjuc1+R`+j4k&)&>S|H<$BB)9s< z;_m`x!pyA+4|o$Cze}6B{#Yb+wBd00z2wjq-x?FK3_V`5-7w{YP&x2Xl_00vK2KbLh*2~7ZsCsTp| literal 0 HcmV?d00001 diff --git a/harrytest/textures/mdoor_wood_a_r.png b/harrytest/textures/mdoor_wood_a_r.png new file mode 100644 index 0000000000000000000000000000000000000000..9315b75ad9fe9039ca407cbfc40ed4ec33ccd3b7 GIT binary patch literal 249 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgf)~NowNM&_oXE`KAXVwWT~s5UPGhs_Wj06pS_uv{*&MLNpAIz z#oqm_dMHx`u@dw}(Or&=Cxtu6{1-oD!M<&(uQL70(Y)*K0-AbW|YuPgf^OLM`TEF?z;>R92T`0_Q>Tl$W;A>*WVAeJ-+#~800;~x yaJZTB@bT)LDD-S%tIQ1aI3v8YamEyOc7}sBqJ8paLODP?7(8A5T-G@yGywoZbUldx literal 0 HcmV?d00001 diff --git a/harrytest/textures/mdoor_wood_b_r.png b/harrytest/textures/mdoor_wood_b_r.png new file mode 100644 index 0000000000000000000000000000000000000000..9c53aa410599bb156bc5df9b25c42a2a72dc7809 GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|*pj^6T^Rm@ z;DWu&Cj&(|3p^r=85p>QL70(Y)*K0-AbW|YuPgfc-mj#PnPRIHZt82`Ti~3Uk?B!Ylp0*+7m{3+ootz+WN)WnQ(*-(AUCxn zQK2F?C$HG5!d3}vt`(3C64qBz04piUwpD^SD#ABF!8yMuRl!uxKsVXI%s|1+P|wiV z#N6CmN5ROz&_Lh7NZ-&%*U;R`*vQJjKmiJrfVLH-q*(>IxIyg#@@$ndN=gc>^!3Zj z%k|2Q_413-^$jg8EkR}&8R-I5=oVMzl_XZ^<`pZ$OmImpPAEg{v+u2}(t{7puX=A(aKG z`a!A1`K3k4z=%sz23b{L$o& z6x?nx#i>^x=oo!av?4__ObD2EKuma|1#;lYJ~a=R){B6NdSklaYX%0USWg$nkcwMV zf@3{G97X<}J9D@6`utqq+d|&SCqpN z9-LN=;L^}lTXOh!Vr*^6`W)$s?()frsq6Gq{(qHQJzLE4!KbH}Zx*p3)Kz-^W}Xk>Ra#6Za&1y#j|X77lXHLi)=J&$9m^E3q-@r%uk%2=Jvv^ zf7kJa%`(|KpMz#jJh!!l(@wLrYM;7vd)j2Hdxa;n_*)I@Hn_@|`L^WW4S#-F=*(_? z)mzuuT%K<9TfK7;%fyPN^_GkJ+m|J#SuFVHbs$K8%KC*}mt#+cEpJY%3+)yVx7XHt zGe2m7hseL54G}h`rK!6$3qH=;I{*4X`I>sC8+yC%uCTkHwEl>%$W7Ip+$qm_8jGgg zKbXh=agG?<_9xGNMeSU_)zfT`RKRZYT!optSweL-PuBkYOJ43^M)nl-a