From adfcfe08416d9a242015db1936b0dd6047e9d4ae Mon Sep 17 00:00:00 2001 From: number Zero Date: Mon, 1 Jun 2015 21:21:42 +0300 Subject: [PATCH] Detector rail added Neated the code --- detector.lua | 73 ++++++++++++++++++++++ init.lua | 12 ++++ textures/carts_rail_crossing_dtc.png | Bin 0 -> 621 bytes textures/carts_rail_crossing_dtc_on.png | Bin 0 -> 654 bytes textures/carts_rail_curved_dtc.png | Bin 0 -> 578 bytes textures/carts_rail_curved_dtc_on.png | Bin 0 -> 575 bytes textures/carts_rail_dtc.png | Bin 0 -> 542 bytes textures/carts_rail_dtc_on.png | Bin 0 -> 559 bytes textures/carts_rail_t_junction_dtc.png | Bin 0 -> 607 bytes textures/carts_rail_t_junction_dtc_on.png | Bin 0 -> 621 bytes 10 files changed, 85 insertions(+) create mode 100644 detector.lua create mode 100644 textures/carts_rail_crossing_dtc.png create mode 100644 textures/carts_rail_crossing_dtc_on.png create mode 100644 textures/carts_rail_curved_dtc.png create mode 100644 textures/carts_rail_curved_dtc_on.png create mode 100644 textures/carts_rail_dtc.png create mode 100644 textures/carts_rail_dtc_on.png create mode 100644 textures/carts_rail_t_junction_dtc.png create mode 100644 textures/carts_rail_t_junction_dtc_on.png diff --git a/detector.lua b/detector.lua new file mode 100644 index 0000000..c4f675e --- /dev/null +++ b/detector.lua @@ -0,0 +1,73 @@ +local mesecons_rules = mesecon.rules.flat + +function boost_cart:turnoff_detector_rail(pos) + local node = minetest.get_node(pos) + if minetest.get_item_group(node.name, "detector_rail") == 1 then + if node.name=="boost_cart:detectorrail_on" then --has not been dug + minetest.swap_node(pos, {name = "boost_cart:detectorrail", param2=node.param2}) + end + mesecon.receptor_off(pos, mesecon_rules) + end +end + +function boost_cart:signal_detector_rail(pos) + local node = minetest.get_node(pos) + if minetest.get_item_group(node.name, "detector_rail") ~= 1 then + return + end + minetest.log("action", "Signaling detector at " .. vector.tostr(pos)) + if node.name == "boost_cart:detectorrail" then + minetest.swap_node(pos, {name = "boost_cart:detectorrail_on", param2=node.param2}) + end + mesecon.receptor_on(pos, mesecon_rules) + minetest.after(0.5, boost_cart.turnoff_detector_rail, boost_cart, pos) +end + +minetest.register_node("boost_cart:detectorrail", { + description = "Detector rail", + drawtype = "raillike", + tiles = {"carts_rail_dtc.png", "carts_rail_curved_dtc.png", "carts_rail_t_junction_dtc.png", "carts_rail_crossing_dtc.png"}, + inventory_image = "carts_rail_dtc.png", + wield_image = "carts_rail_dtc.png", + paramtype = "light", + sunlight_propagates = true, + is_ground_content = true, + walkable = false, + selection_box = { + type = "fixed", + fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, + }, + groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1, detector_rail = 1}, + + mesecons = {receptor = {state = "off", rules = mesecons_rules }}, +}) + +minetest.register_node("boost_cart:detectorrail_on", { + description = "Detector rail ON (you hacker you)", + drawtype = "raillike", + tiles = {"carts_rail_dtc_on.png", "carts_rail_curved_dtc_on.png", "carts_rail_t_junction_dtc_on.png", "carts_rail_crossing_dtc_on.png"}, + inventory_image = "carts_rail_dtc_on.png", + wield_image = "carts_rail_dtc_on.png", + paramtype = "light", + sunlight_propagates = true, + is_ground_content = true, + walkable = false, + selection_box = { + type = "fixed", + -- but how to specify the dimensions for curved and sideways rails? + fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2}, + }, + groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1, detector_rail = 1, not_in_creative_inventory = 1}, + drop = "boost_cart:detectorrail", + + mesecons = {receptor = {state = "on", rules = mesecons_rules }}, +}) + +minetest.register_craft({ + output = "boost_cart:detectorrail 6", + recipe = { + {"default:steel_ingot", "mesecon:mesecon", "default:steel_ingot"}, + {"default:steel_ingot", "group:stick", "default:steel_ingot"}, + {"default:steel_ingot", "mesecon:mesecon", "default:steel_ingot"}, + }, +}) diff --git a/init.lua b/init.lua index 78c3483..e3d50bc 100644 --- a/init.lua +++ b/init.lua @@ -13,9 +13,17 @@ function vector.floor(v) } end +function vector.tostr(v) + return string.format("{%.3f; %.3f; %.3f}", v.x, v.y, v.z) +end + dofile(boost_cart.modpath.."/functions.lua") dofile(boost_cart.modpath.."/rails.lua") +if mesecon then + dofile(boost_cart.modpath.."/detector.lua") +end + boost_cart.cart = { physical = false, collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, @@ -224,6 +232,10 @@ function boost_cart.cart:on_step(dtime) new_acc = vector.multiply(dir, acc) end + if mesecon then + boost_cart:signal_detector_rail(vector.floor(pos)) + end + self.object:setacceleration(new_acc) self.old_pos = vector.new(pos) self.old_dir = vector.new(dir) diff --git a/textures/carts_rail_crossing_dtc.png b/textures/carts_rail_crossing_dtc.png new file mode 100644 index 0000000000000000000000000000000000000000..cf04f0ff73fa8a2f11620d9d25302dc7c795c685 GIT binary patch literal 621 zcmV-z0+RiSP)0YxPcbKi?pk!b40QxFsnO468{7f}O6D3PKq1;LXL$w?5a z^(6!7lxk^qUm}%OL`s`vGafek65B-t2Ohk6-#6dPoA(9)17H+O z1x}_CEHtotwtfi>oJ=LSSSm=40uQ?s5A)!tW!z)GLzrzU;&(0C4p|giXX=2B=9_a@*tFT+%JyZZ-Vz~3h)BREG(ZWywObkako8HU8;4ZAz zZ9F`(PX^w~L|6)xzjk_H%vzXVs6q7+-hDRlV`&*?brA%>6pNBKH(zrq5E^m%l_`ON zw-y>UV`a_8pkBqm8xw1d7PbdAA@iY=Xiygr8u5RBBytABvD;(gID78QUjsZi8>ew7 z9^&igd*#GsPKNl=l|$?`jjC6c?3AExKbIGj%L78A4cGk*{$BxbSS``T00000NkvXX Hu0mjfX+911 literal 0 HcmV?d00001 diff --git a/textures/carts_rail_crossing_dtc_on.png b/textures/carts_rail_crossing_dtc_on.png new file mode 100644 index 0000000000000000000000000000000000000000..b6f5b87e5da983cadcbfaae3272ff87d347758ac GIT binary patch literal 654 zcmV;90&)F`P)aN7U!C&$Ji-P-8E-aD9v&Lu`Oz0#eOHgOc^_Td!T{Wg+BkBk zk;^q7xES-$-P1+KR3`uyrHOi)cbSe47Fua zqUEp+3ozQ}68{yu)YsRM%@w$pahSrv-Zn7};@{VE5S>XeJ2#KDN)h>zYC%|DDKKD9)8CwAWp$06wVUxf)(;x6>xiagMC}l oe_U6k>%fGr0uvyb`scZS0Ch#+fZHTH^8f$<07*qoM6N<$f{;8RI{*Lx literal 0 HcmV?d00001 diff --git a/textures/carts_rail_curved_dtc.png b/textures/carts_rail_curved_dtc.png new file mode 100644 index 0000000000000000000000000000000000000000..8117c27a92edcb03681101eea2468cfebc35b8f6 GIT binary patch literal 578 zcmV-I0=@l-P)T2Y6N*5{bA0%Hzu(Wp^ZZ~Z>*mEn zGCOiaN_(#D7<^kd2%eiJb_&}>{jWH-FfRa+aI~ziwkvEl+G0y+3C4rFB$3>*-#RK8bY6KxBpfAB`+-+y zkK1B^>yJOH&18yj=&)2Yh%L;Em7MsIVd?u%W`+V~t6SeR$>s~y39P#NbXk2(q)DcJ z5giW7A8bV~Cx36DG`$pi^t4a38jYrXbzHvlRsn>%TEyG9yGSr`UYE(yy zX%i!zVRrPWtm=rF6FhELG39EvPfiX#BodBtrtJ$xCQm^M^iI7gBMf!5$o{<^YTX(y z*ILU*u<)DBI3Bl?jZ~Hs0WX=YJnkANJ(I81s*cJ%=P)}v~N{2d1C`Cn+YOnd<%j04E|82BIUV4rXzwh_^d3c^5{Li{Id_ZO< z4oi8@wiAOdn`wLl_lcgwG*SO5jxH?-KsXes=&PLyJMf{Q=+5|>De6^uI$1@~Szle<9ixjnnC(ixp} zCd_|7o;8b`(XkO0pPc1jciZ1T)8qM%CZSS@)uKRi1JJX-l{0r@Y8yo~w>R^d-2(ss N002ovPDHLkV1l%W`95dMe;1u5bdrEhxe%Jsh8_r3Q$@6&K@FEq52gWvHyAHF>2!#U8*-2AKz zj||Cr7s6k%-h~X049VR5Y{nRXmv;xUgQsV^d3eD{tI?zazOSj)5)vysuEbDv+{CS3 zxpHq&8GxDBMK1NZL9n&MR;58(p#`m>kq9;gt>I9?WZNvSegAX4f4zd{KVtwUZ=cE< zX9jy1Pf|H{G>@kgK{@7N-VoI-ljR61j(c&ZUj|3tI0qlUlxS}jeE3`Y)@E z4RJ%LCn=s*kayhTO0b_COpo?ujnB`WVB(^dYGldznvNrRib06qqIvSu!nWfc-8?B* z$CjLfg_RA?pK*h=VhQ7EYITdJU?cDeV@r|orq^z!KUNxU+b3Z literal 0 HcmV?d00001 diff --git a/textures/carts_rail_dtc_on.png b/textures/carts_rail_dtc_on.png new file mode 100644 index 0000000000000000000000000000000000000000..e81dbe1bee83389e3236d08506b2728bd2a25eb0 GIT binary patch literal 559 zcmV+~0?_@5P) zK~y-)&62@OR8bVhfA_xU8>fLRC|uM+=nt^0grZ%oqD3I)I$A|w5W3LStP;!?1{O%+ zBHOtT3Ijn}6m2x4g@zO|TH@0g8&Mzg-psr2xOmfz7H(?eSzYdTzK?T$9H`gy%#?I? zb%^8<4k*bZon0L=Ju_u{T!6O&SM0}=Vk^&kTxoPQiGb&6_9`*45e9xlHf*f-g4}*I zr(A&79}3)TPX)iYO>w8j@mvF1LoF6e0$M{;&b0yaOB;WW_pd8x{+`yN4Lh+`oE$kZ7u9x4W-587Y=6Hyd~zk40i(k!YV6jY>8nUzq|YQf@8g&IVJP`YrVh6LOgl(=Xi8&O<{ zXf_Iy42sr`lH!X9f#Sjk6hpJI3MC7zGzRL6K4@Yxxh|$N(^TuGp3Q}G&-u^!|NmZC ziQITr4Gx7=Nk_3xlyubKP)Oy*vu=$B@chaFH}UXrH|b-VYSknS1wNl-ak)<2QrwxZ z!lGSw`@&vz>S|tS08d|i?}UwYtJ;fRxbg*W7J(3|u5PfD)@I zqzsc}A;b1*#MECRWY%nCi z{gFNw@!hSgO(7a476?(&Q6(Lfj`yeshq~QHGv2FQ5#LUIA$ZWfNEs%(YIz=ApCEG1 zAZFP4EX>l{B3Z6BXls#7{#anC tVj+ZJsbayFE&%RcI?d>dvS6d%`8WRK@(dl8G*$or002ovPDHLkV1ft(5KsUB literal 0 HcmV?d00001 diff --git a/textures/carts_rail_t_junction_dtc_on.png b/textures/carts_rail_t_junction_dtc_on.png new file mode 100644 index 0000000000000000000000000000000000000000..9fda111b95284cbc6e210c3e6de9f9cd87a4e251 GIT binary patch literal 621 zcmV-z0+RiSP))a=%7fUE}bf^1}r+MP=kXIn$8*$5JXVokb)3IC@950 zLxz_GLE}>dpY-<@7(YE4y;9X zG9!aSK9MNG79mk&aL6aw$&6ED06ZT#>Ll)#dPsx~X*D!80hdejbEQhv5=Q3B4%odb zhve+doH78Oy!^-+kNr?AeW&!J!fy9=w1!Gmuxg++w7U%lVDG>+vIB@}rVuxijCH3` zQPjro*S{S%lk4)v#zKGI2c-Yn7z_nCIqhu#Jct}#CtM=jCwtmmwDn(g8ppcRO#|SW ztDn=uuWb!x3t#AHLXVqCf~V}W-gqImk8N7P4!bTlQ~Z---Nvmf-ONVKKZXW)IP7r{ zUmVNW6hZ;~c^?u*B#I=$y>jPskJFe8_lYCo+nG;zkJ}G%Gs*r+j)_}u2wpPrn>0k+ z39l9p*cyB&He9&400000NkvXX Hu0mjf@sSL= literal 0 HcmV?d00001