From 36319afbbef29e58d5b136f2ad8113ee524a53de Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 28 Aug 2017 16:59:10 +0200 Subject: [PATCH] Basic powered rails implementation --- mods/ENTITIES/mcl_minecarts/functions.lua | 10 --- mods/ENTITIES/mcl_minecarts/init.lua | 26 +++--- mods/ENTITIES/mcl_minecarts/rails.lua | 79 ++++++++++++++---- .../textures/carts_rail_crossing_pwr.png | Bin 562 -> 263 bytes .../textures/carts_rail_curved_pwr.png | Bin 459 -> 223 bytes .../mcl_minecarts/textures/carts_rail_pwr.png | Bin 276 -> 256 bytes .../textures/carts_rail_t_junction_pwr.png | Bin 596 -> 258 bytes .../textures/default_rail_crossing.png | Bin 542 -> 247 bytes .../textures/default_rail_t_junction.png | Bin 576 -> 238 bytes ...minecarts_rail_golden_crossing_powered.png | Bin 0 -> 263 bytes ...l_minecarts_rail_golden_curved_powered.png | Bin 0 -> 223 bytes .../mcl_minecarts_rail_golden_powered.png | Bin 0 -> 257 bytes ...necarts_rail_golden_t_junction_powered.png | Bin 0 -> 254 bytes .../mcl_minecarts/textures/rail_detector.png | Bin 300 -> 283 bytes .../textures/rail_detector_powered.png | Bin 299 -> 277 bytes .../textures/rail_golden_powered.png | Bin 281 -> 0 bytes 16 files changed, 78 insertions(+), 37 deletions(-) create mode 100644 mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_crossing_powered.png create mode 100644 mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_curved_powered.png create mode 100644 mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_powered.png create mode 100644 mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_t_junction_powered.png delete mode 100644 mods/ENTITIES/mcl_minecarts/textures/rail_golden_powered.png diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index 1a298841e..42cdecd12 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -138,13 +138,3 @@ function mcl_minecarts:get_rail_direction(pos_, dir, ctrl, old_switch, railtype) return {x=0, y=0, z=0} end -function mcl_minecarts:boost_rail(pos, amount) - minetest.get_meta(pos):set_string("cart_acceleration", tostring(amount)) - for _,obj_ in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do - if not obj_:is_player() and - obj_:get_luaentity() and - obj_:get_luaentity().name == "mcl_minecarts:minecart" then - obj_:get_luaentity():on_punch() - end - end -end diff --git a/mods/ENTITIES/mcl_minecarts/init.lua b/mods/ENTITIES/mcl_minecarts/init.lua index 23a95e725..5333613b3 100644 --- a/mods/ENTITIES/mcl_minecarts/init.lua +++ b/mods/ENTITIES/mcl_minecarts/init.lua @@ -31,6 +31,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) _start_pos = nil, -- Used to calculate distance for “On A Rail” achievement _old_dir = {x=0, y=0, z=0}, _old_pos = nil, + _old_vel = {x=0, y=0, z=0}, _old_switch = 0, _railtype = nil, } @@ -128,6 +129,18 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) ctrl = player:get_player_control() end end + + -- Stop cart if velocity vector flips + if self._old_vel and self._old_vel.y == 0 and + (self._old_vel.x * vel.x < 0 or self._old_vel.z * vel.z < 0) then + self._old_vel = {x = 0, y = 0, z = 0} + self._old_pos = pos + self.object:setvelocity(vector.new()) + self.object:setacceleration(vector.new()) + return + end + self._old_vel = vector.new(vel) + if self._old_pos then local diff = vector.subtract(self._old_pos, pos) for _,v in ipairs({"x","y","z"}) do @@ -187,17 +200,9 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) -- Slow down or speed up local acc = dir.y * -1.8 - local speed_mod = tonumber(minetest.get_meta(pos):get_string("cart_acceleration")) + local speed_mod = minetest.registered_nodes[minetest.get_node(pos).name]._rail_acceleration if speed_mod and speed_mod ~= 0 then - if speed_mod > 0 then - for _,v in ipairs({"x","y","z"}) do - if math.abs(vel[v]) >= max_vel then - speed_mod = 0 - break - end - end - end - acc = acc + (speed_mod * 8) + acc = acc + speed_mod else acc = acc - 0.4 end @@ -214,6 +219,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick) for _,v in ipairs({"x","y","z"}) do if math.abs(vel[v]) > max_vel then vel[v] = mcl_minecarts:get_sign(vel[v]) * max_vel + new_acc[v] = 0 update.vel = true end end diff --git a/mods/ENTITIES/mcl_minecarts/rails.lua b/mods/ENTITIES/mcl_minecarts/rails.lua index f68a738c9..fb2a97b12 100644 --- a/mods/ENTITIES/mcl_minecarts/rails.lua +++ b/mods/ENTITIES/mcl_minecarts/rails.lua @@ -33,11 +33,26 @@ minetest.register_craft({ } }) --- Rail to speed up -minetest.register_node("mcl_minecarts:golden_rail", { +-- Function that get the input/output rules of the powered rails +local get_input_rules = function() + return { + {x = -1, y = 0, z = 0}, + {x = 1, y = 0, z = 0}, + {x = 0, y = 0, z = -1}, + {x = 0, y = 0, z = 1}, + } +end + +local get_output_rules = function() + return {} +end + +-- Powered rail + +local powered_rail_template = { description = "Powered Rail", - _doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Powered rails will accelerate moving minecarts, up to a maximum speed.", - _doc_items_usagehelp = railuse, + _doc_items_longdesc = "Rails can be used to build transport tracks for minecarts. Powered rails are able to accelerate and brake minecarts.", + _doc_items_usagehelp = railuse .. "\n" .. "Without redstone power, the rail will brake minecarts. To make this rail accelerate minecarts, power it with redstone power.", drawtype = "raillike", tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"}, inventory_image = "carts_rail_pwr.png", @@ -47,31 +62,61 @@ minetest.register_node("mcl_minecarts:golden_rail", { 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 = {handy=1,pickaxey=1, attached_node = 1, rail = 1, connect_to_raillike = 1, dig_by_water = 1,destroy_by_lava_flow=1, transport = 1}, - - after_place_node = function(pos, placer, itemstack) - if not mesecon then - minetest.get_meta(pos):set_string("cart_acceleration", "0.5") - end - end, + sounds = mcl_sounds.node_sound_metal_defaults(), mesecons = { effector = { action_on = function(pos, node) - mcl_minecarts:boost_rail(pos, 0.5) - end, - - action_off = function(pos, node) - minetest.get_meta(pos):set_string("cart_acceleration", "0") + minetest.swap_node(pos, {name = "mcl_minecarts:golden_rail_on", param2 = node.param2 }) + mesecon:receptor_on(pos, get_input_rules()) end, }, + receptor = { + state = mesecon.state.off, + rules = get_output_rules, + }, }, + + _rail_acceleration = -3, _mcl_blast_resistance = 3.5, _mcl_hardness = 0.7, -}) +} +minetest.register_node("mcl_minecarts:golden_rail", powered_rail_template) + + +-- Powered rail (activated by redstone) +local powered_rail_on = table.copy(powered_rail_template) +powered_rail_on.description = nil +powered_rail_on._doc_items_create_entry = false +powered_rail_on._doc_items_longdesc = nil +powered_rail_on._doc_items_usagehelp = nil +powered_rail_on.tiles = {"mcl_minecarts_rail_golden_powered.png", "mcl_minecarts_rail_golden_curved_powered.png", "mcl_minecarts_rail_golden_t_junction_powered.png", "mcl_minecarts_rail_golden_crossing_powered.png"} +powered_rail_on.inventory_image = "mcl_minecarts_rail_golden_powered.png" +powered_rail_on.wield_image = "mcl_minecarts_rail_golden_powered.png" +powered_rail_on.groups.not_in_creative_inventory = 1 +powered_rail_on.groups.transport = nil +powered_rail_on.mesecons = { + effector = { + action_off = function(pos, node) + minetest.swap_node(pos, {name = "mcl_minecarts:golden_rail", param2 = node.param2 }) + mesecon:receptor_off(pos, get_input_rules()) + end, + }, + receptor = { + state = mesecon.state.on, + rules = get_output_rules, + } +} +powered_rail_on._rail_acceleration = 4 + +minetest.register_node("mcl_minecarts:golden_rail_on", powered_rail_on) + +if minetest.get_modpath("doc") then + doc.add_entry_alias("nodes", "mcl_minecarts:golden_rail", "nodes", "mcl_minecarts:golden_rail_on") +end minetest.register_craft({ output = "mcl_minecarts:golden_rail 6", diff --git a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_crossing_pwr.png b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_crossing_pwr.png index 9ea9335d6a39d0271c1290e45c80a18465e7187a..df8f6bfbe1b4c15053b372090b787ae39fb459f7 100644 GIT binary patch delta 247 zcmVhMOv#?DKT)*+H+=2w{Wrp1Iw(~yLYcDZeZZB z+AFy5wqgSVyV2TJt8T3~Mg;O>npSvTr4cwoi9n8lsU^CnN%*Z?lN2X|U$$6_hLI^C z%5je4(2e?|1~Xon)gRx{_N$g{8a{lz#;wc8`JMcuR7{PC13|&6R4Uo{VvIvC&~}`; z1uf9{J?Qn-h2tyjc^*Tj)aKOU44>g&eWBWwHzp1j6qgXux#00000NkvXXu0mjf!c+#s diff --git a/mods/ENTITIES/mcl_minecarts/textures/carts_rail_curved_pwr.png b/mods/ENTITIES/mcl_minecarts/textures/carts_rail_curved_pwr.png index a9ab6eeb42b79cbd432a7cd134821fd4bff02d6e..d557a358ae9e4ebd23c98f5f840fed43d0a7ba5e 100644 GIT binary patch delta 207 zcmX@je4lZGL_G^L0|Ud`yN`l^lx~1eh%1oxk&&?w67ux)G&MD~wYAmJ(Mj^Q?#%L2 zR#q+yb9r?zsV3fMUS-0S<)&^aJEVXb7)yfuf*Bm1-ADs+5`#+c0-T4^Jkk4lAJtqCOfvx zI(P5;xe8Hc=E>?OT3$LZD?5HVJx5aFj6+XIv4-+b5r)VO!kYY+$rpi^F?hQAxvXlx6wv7p%W{7M{*d^7ZHnYb^lIIkeW~d49(;(ho2(raNZm z93nzd6za>n#h$x;0lzOEVy#6)SgFnRRJ|9_&MP7;&Q368Tn{JemxA(=y#?xnZFHY`GVh%7gXFklB z%ElI_DCgM7e3FN!#?3M_^LCJ=#E;&J9$r2MNghWV9vUA zF)qxp8}I-C00DGTPE!Ct=GbNc004qXL_t&-(`}F23PUjn1ii(hCT;)!Z@bz;;n01E zFqmYPh*;cL_-5)w=t9Mq>ZCJYQ$aS!nT0004WQchCHN17?8mcsJ-u@Wabg9Sgb$-K@GfC@O_w zrygPhp>zo}Uf(tL!aFGKIi$I^s8s!?2k-y?zwiHj--84AzJH&3o|ke0JkLvg-_PoD z!$Ta${0|I(2e)sepVoUQrI@N$xLm#POX2sP;{EzAVHjeXCQ?cOMgS~f0zCkFea+L? zUucwVY)fDXla=lsaU3J1L~D)Knkb462Xw*+(=-9FEkUCU7t3b`FRpI_pp-%g0f6he zT&s*SGq-5u0DtD+em10(2qAd3@XoL;kS?7kuAO<2XiZO`~jM36on@hi+#zYf6%YV>Y(7 zw>fHO6h#CKyoL9tjwO3C@$kHZ1~0x2c+v#025!B1vs V*M`pOj;jCw002ovPDHLkV1lza5*Ppg diff --git a/mods/ENTITIES/mcl_minecarts/textures/default_rail_crossing.png b/mods/ENTITIES/mcl_minecarts/textures/default_rail_crossing.png index 22556d38ddb3ff5b81f190bd4aec172548317641..409f14b8231d43f464edae502910b9305ea47591 100644 GIT binary patch delta 231 zcmbQo@||&lL_G^L0|Ud`yN`l^lwyESh%1ox^z_ux(Xq9)t%>(Z^0w~G@-sCxRaRCm z40D-RnZU;S;1N&}V@Z%-FoVOh8)-mJi>HfYNCjhZfT5jUQtoYl9)omts{OjP18_l zUYoS+_Ntk$_;}WcIxd{J>J+0xY@TM`yi>vwR#T>!%$hP~iUdn*Z(|t;H&gEXR|h07 fonR<+Q)XsxpP``9x^}r0&_N8Iu6{1-oD!M0vr)T) zND7q@iK}iBmfO8eb!&4oNiOR7SHu72y*KZl|G_DOAjo~+&wn`wzVGKj5a@eFbx4u~ zfJgW5Wz4 z#x^CUG#Euw-hU5bHmf!OmSvG9#R@TwcF*P-{wY4n_bE%2<>CEy= z^0uB=nUMYI>uI1O#*!evU^>MGbjm=7nL+=Y W#Dx8OtbKs)VDNPHb6Mw<&;$U8x=h>v delta 563 zcmV-30?hsH0l);17=H)`0000V^Z#K00004VQb$4nuFf3k0005{NklSfAUG7krD-Q0 zfk@YX!gUUe5W>cg}YX>_BUswSQWzj04c=bTX}V9#`N$ zQQZ4bO8qrhYn>Tmu-3Ax!U4E(>3p{KVT(A9>9y;Wl*^G)fv@8q0IYxhjHw;LM9^kzVGbzDkAjSb?!ZS;p}xmDMi2Eccxqr z5wzBswH6Vf+bmO3E=#wrPT1?ZF8kVOttF0QeBXCwYZb=19{N zkzYf-{otunuN|h_EHeyEPU3mq{t85d!C;X0eDnSjXMes~B{VU^&`c?C0PbABn5}GV zW343&L#|yo^~XheJNm-vD5244FjLrM>Deo%2=LK-!L}TwR4RC$$4p^!@|gY=p67Aq_#wuk_z5OE-xZhtZR7v|002ovPDHLkV1i(u B8595j diff --git a/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_crossing_powered.png b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_crossing_powered.png new file mode 100644 index 0000000000000000000000000000000000000000..81526029d480d777a968fa401fc3c46df4475b30 GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPHF3h)VW1=60Lo;o@@wzjr4@jgl3 z)&)#V)0vq&v;0g=O_i0E3&ULIRVG|nZhH5lP&`mIV@Z%-FoVOh8)-mJx2KC^NCjhZ zfQG_?VFgHPp`SLyL`P? zUc!S7x3qVB*p|f1y!+y<(A9ZsbrKScKZ(Xvq^B}5AJ>^MWf?QGcErXahJfkr$GP&K z^75>nGG&XHrlzJL2bVPSTLCeaTl=oAwMtQBz9Pvj$?$+#=ljB?fhIs_F?hQAxvXbJY5_^ zDj1U;SbMkv+BU5=oRP-o=gl1S=B(c312uY+Gw%p+Zf6x}%ls8-XQ14Z{?>LwkGk_` zn+=kjJaZ;Hw#_L*%WIxs6cemXrzQsRt5Pe`$b@=pCcmj*hLZZDE*; zsi~>5vhuvjgw8C#ns}ciZ|f_|O~xP|&n8VOH~hjwudzO=gsL#UHORndpGv5n>W-nSLGV#$HGyRQ`f!lUit>3ZxgtNy&k7Y|URMXz~ z76z1bO)TtTlz#SDPU7%`nS8|@AAfkho0}`sDgERQb9vf)o>rhc7(8A5T-G@yGywqc CQ(Acd literal 0 HcmV?d00001 diff --git a/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_t_junction_powered.png b/mods/ENTITIES/mcl_minecarts/textures/mcl_minecarts_rail_golden_t_junction_powered.png new file mode 100644 index 0000000000000000000000000000000000000000..6a4af02094c9c0bc4faa0ad357879e720e1cd23b GIT binary patch literal 254 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPHF4e$wZ1=60Lo;o@@wzjr~VJ@bo zrpn67^C}ZMv;1n}eUiMbUmZ*;U}Boi%zS0JX-hg!2~Y!LNswPKgTu2MX+TcBr;B4q z1!Ho8KoSF!tAbgRQN*D;r%y{avr1YV7So-Xv0}-Q1F6rhO3YevgCXRM(yT3xGaDP- zI}A@0IvX)Fub;T#+86ef4uZ*HOw(&?moX(o633LjBr>mdKI;Vst07Su5LI3~& literal 0 HcmV?d00001 diff --git a/mods/ENTITIES/mcl_minecarts/textures/rail_detector.png b/mods/ENTITIES/mcl_minecarts/textures/rail_detector.png index d4548bc21dcd9f7aa4d627a0626888caf20fa502..88eef9f6de762c4223252ff674c4350833c92f4e 100644 GIT binary patch delta 255 zcmVmH?1H%dq)&IZs(w?Wq1{(kb!7CDgf1qGY#du@7;<-412dPrcS><8` zF>u8d^Q;w&3R>@djMt%4Gy2lj^$oU?=V&DTb<18d#u&Z70gB*Q*Y!9d1&o#3Bbw18 z5>%C(v&ijH37n=Dtx$wwpSN%kE5!}+1$JTyUm&GC!2@LQ1ez;6XW9S&002ovPDHLk FV1k}bV!{9b delta 256 zcmV+b0ssD+0;~d%Bnkm@Qb$4nuFf3kks%a+aaKe%H8mq6Bc6F+iE2)KUrb_4JA{FP zj*N(RbaQK9S#54=I1&;}92_PL3{62gSx!fsOsnPq0004WQchCH0}&d2uf{$=g8ju|}u<#o&K|SCOFkJ*l!m!=P00000NkvXXu0mjf(b{E} delta 272 zcmV+r0q_2m0;>X$B!2;OQb$4nuFf3k0000&P)t-s|Ns9s1-C~Qt8f4==;+2FDi)xXn8-5L+HR+yLm}&E(F8ZX-zI>_0v|CE W1UKGzd1(Lu00{s|MNUMnLSTX&T5Vkb diff --git a/mods/ENTITIES/mcl_minecarts/textures/rail_golden_powered.png b/mods/ENTITIES/mcl_minecarts/textures/rail_golden_powered.png deleted file mode 100644 index 9d7b9d58a006e57ec97403a0ea422857951607b7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 281 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6T`Z5GB1G~%K)DcS6@df zPft%B9UWU++rlsxQ&UrAW#xI537uJfHSs=4-qu%^o4z`j1QcxI<;`GXn$FBzz{F%| zs3+Og&IB^CB*-tA!Qt7BG$5zZ)5S4F;&N_(B;R2J4%VAKyxVr&`M;@lg3HuJ`}mc6 z8Teg}IHkAje!+XApgLq(Cz}J0zbCiNA+`yxw9`^K&(BJ{dAv(E>gmZ%9g@GdnOCe{ zGd+A;Ka>2?j#Xjq%u?6;RC%8r&^LU@7$A33ZYCT5S!W)p7o0Pq?myc8xbFHd`wy(o XEtspNkCYw)I)=g1)z4*}Q$iB}Gv8md