From 859679a59113875e431c1fd5869ee1893c883afa Mon Sep 17 00:00:00 2001 From: paramat Date: Sat, 28 Nov 2015 21:38:49 +0000 Subject: [PATCH] Add meseblock car. Recolour wheelhubs --- README.txt | 4 +- init.lua | 205 ++++++++++++++++++++++++++--- textures/mesecar_car1leftside.png | Bin 271 -> 270 bytes textures/mesecar_car1rightside.png | Bin 267 -> 267 bytes textures/mesecar_car2front.png | Bin 193 -> 194 bytes textures/mesecar_car2leftside.png | Bin 268 -> 268 bytes textures/mesecar_car2rightside.png | Bin 266 -> 267 bytes textures/mesecar_car3leftside.png | Bin 268 -> 263 bytes textures/mesecar_car3rightside.png | Bin 264 -> 260 bytes textures/mesecar_car4back.png | Bin 0 -> 202 bytes textures/mesecar_car4front.png | Bin 0 -> 212 bytes textures/mesecar_car4leftside.png | Bin 0 -> 255 bytes textures/mesecar_car4rightside.png | Bin 0 -> 252 bytes textures/mesecar_car4top.png | Bin 0 -> 173 bytes 14 files changed, 187 insertions(+), 22 deletions(-) create mode 100644 textures/mesecar_car4back.png create mode 100644 textures/mesecar_car4front.png create mode 100644 textures/mesecar_car4leftside.png create mode 100644 textures/mesecar_car4rightside.png create mode 100644 textures/mesecar_car4top.png diff --git a/README.txt b/README.txt index 37ffe79..df9de82 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -mesecar 0.3.3 by paramat -For latest stable Minetest and back to 0.4.10 +mesecar 0.4.0 by paramat +For Minetest 0.4.10 and later Depends default Licenses: code WTFPL, textures CC BY-SA diff --git a/init.lua b/init.lua index 0868852..e66f32d 100644 --- a/init.lua +++ b/init.lua @@ -1,21 +1,16 @@ --- mesecar 0.3.4 by paramat --- For latest stable Minetest and back to 0.4.10 --- Depends default --- Licenses: code WTFPL, textures CC-BY-SA - --- Oerkka, nyancar - local ACDC = 0.2 -- Acceleration / decelleration local MAXSP = 12 -- Maximum speed local TURNSP = 0.03 -- Maximum yaw speed local STEPH = 0.6 -- Stepheight, 0.6 = climb slabs, 1.1 = climb nodes + -- Functions local function is_ground(pos) return minetest.registered_nodes[minetest.get_node(pos).name].walkable end + local function get_sign(i) if i == 0 then return 0 @@ -24,24 +19,27 @@ local function get_sign(i) end end + local function get_velocity(v, yaw, y) local x = -math.sin(yaw) * v local z = math.cos(yaw) * v return {x=x, y=y, z=z} end + local function get_v(v) return math.sqrt(v.x ^ 2 + v.z ^ 2) end --- Car entity + +-- Car entity 1 local car1 = { physical = true, collide_with_objects = true, collisionbox = {-0.53, -0.75, -0.53, 0.53, 0.75, 0.53}, visual = "cube", - visual_size = {x=1.5, y=1.5}, + visual_size = {x = 1.5, y = 1.5}, textures = { -- top base rightside leftside front back "mesecar_car1top.png", "mesecar_carbase.png", @@ -57,6 +55,7 @@ local car1 = { removed = false, } + function car1:on_rightclick(clicker) if not clicker or not clicker:is_player() then return @@ -78,6 +77,7 @@ function car1:on_rightclick(clicker) end end + function car1.on_activate(self, staticdata, dtime_s) self.object:set_armor_groups({immortal = 1}) if staticdata then @@ -86,10 +86,12 @@ function car1.on_activate(self, staticdata, dtime_s) self.last_v = self.v end + function car1.get_staticdata(self) return tostring(self.v) end + function car1.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction) if self.driver then self.driver:set_detach() @@ -107,6 +109,7 @@ function car1.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d end end + function car1:on_step(dtime) self.v = get_v(self.object:getvelocity()) * get_sign(self.v) if self.driver then @@ -139,18 +142,19 @@ function car1:on_step(dtime) local s = get_sign(self.v) self.v = self.v - 0.03 * s if s ~= get_sign(self.v) then - self.object:setvelocity({x=0, y=0, z=0}) + self.object:setvelocity({x = 0, y = 0, z = 0}) self.v = 0 return end if absv > MAXSP then self.v = MAXSP * get_sign(self.v) end - self.object:setacceleration({x=0, y=-9.81, z=0}) + self.object:setacceleration({x = 0, y = -9.81, z = 0}) self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)) self.object:setpos(self.object:getpos()) end + -- Car entity 2 local car2 = { @@ -158,7 +162,7 @@ local car2 = { collide_with_objects = true, collisionbox = {-0.53, -0.75, -0.53, 0.53, 0.75, 0.53}, visual = "cube", - visual_size = {x=1.5, y=1.5}, + visual_size = {x = 1.5, y = 1.5}, textures = { -- top base rightside leftside front back "mesecar_car2top.png", "mesecar_carbase.png", @@ -174,6 +178,7 @@ local car2 = { removed = false, } + function car2:on_rightclick(clicker) if not clicker or not clicker:is_player() then return @@ -195,6 +200,7 @@ function car2:on_rightclick(clicker) end end + function car2.on_activate(self, staticdata, dtime_s) self.object:set_armor_groups({immortal = 1}) if staticdata then @@ -203,10 +209,12 @@ function car2.on_activate(self, staticdata, dtime_s) self.last_v = self.v end + function car2.get_staticdata(self) return tostring(self.v) end + function car2.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction) if self.driver then self.driver:set_detach() @@ -224,6 +232,7 @@ function car2.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d end end + function car2:on_step(dtime) self.v = get_v(self.object:getvelocity()) * get_sign(self.v) if self.driver then @@ -256,18 +265,19 @@ function car2:on_step(dtime) local s = get_sign(self.v) self.v = self.v - 0.03 * s if s ~= get_sign(self.v) then - self.object:setvelocity({x=0, y=0, z=0}) + self.object:setvelocity({x = 0, y = 0, z = 0}) self.v = 0 return end if absv > MAXSP then self.v = MAXSP * get_sign(self.v) end - self.object:setacceleration({x=0, y=-9.81, z=0}) + self.object:setacceleration({x = 0, y = -9.81, z = 0}) self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)) self.object:setpos(self.object:getpos()) end + -- Car entity 3 local car3 = { @@ -275,7 +285,7 @@ local car3 = { collide_with_objects = true, collisionbox = {-0.53, -0.75, -0.53, 0.53, 0.75, 0.53}, visual = "cube", - visual_size = {x=1.5, y=1.5}, + visual_size = {x = 1.5, y = 1.5}, textures = { -- top base rightside leftside front back "mesecar_car3top.png", "mesecar_carbase.png", @@ -291,6 +301,7 @@ local car3 = { removed = false, } + function car3:on_rightclick(clicker) if not clicker or not clicker:is_player() then return @@ -312,6 +323,7 @@ function car3:on_rightclick(clicker) end end + function car3.on_activate(self, staticdata, dtime_s) self.object:set_armor_groups({immortal = 1}) if staticdata then @@ -320,10 +332,12 @@ function car3.on_activate(self, staticdata, dtime_s) self.last_v = self.v end + function car3.get_staticdata(self) return tostring(self.v) end + function car3.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction) if self.driver then self.driver:set_detach() @@ -341,6 +355,7 @@ function car3.on_punch(self, puncher, time_from_last_punch, tool_capabilities, d end end + function car3:on_step(dtime) self.v = get_v(self.object:getvelocity()) * get_sign(self.v) if self.driver then @@ -373,23 +388,149 @@ function car3:on_step(dtime) local s = get_sign(self.v) self.v = self.v - 0.03 * s if s ~= get_sign(self.v) then - self.object:setvelocity({x=0, y=0, z=0}) + self.object:setvelocity({x = 0, y = 0, z = 0}) self.v = 0 return end if absv > MAXSP then self.v = MAXSP * get_sign(self.v) end - self.object:setacceleration({x=0, y=-9.81, z=0}) + self.object:setacceleration({x = 0, y = -9.81, z = 0}) self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)) self.object:setpos(self.object:getpos()) end + +-- Car entity 4 + +local car4 = { + physical = true, + collide_with_objects = true, + collisionbox = {-0.53, -0.75, -0.53, 0.53, 0.75, 0.53}, + visual = "cube", + visual_size = {x = 1.5, y = 1.5}, + textures = { -- top base rightside leftside front back + "mesecar_car4top.png", + "mesecar_carbase.png", + "mesecar_car4rightside.png", + "mesecar_car4leftside.png", + "mesecar_car4front.png", + "mesecar_car4back.png", + }, + stepheight = STEPH, + driver = nil, + v = 0, + last_v = 0, + removed = false, +} + + +function car4:on_rightclick(clicker) + if not clicker or not clicker:is_player() then + return + end + local name = clicker:get_player_name() + if self.driver and clicker == self.driver then + self.driver = nil + clicker:set_detach() + default.player_attached[name] = false + default.player_set_animation(clicker, "stand" , 30) + elseif not self.driver then + self.driver = clicker + clicker:set_attach(self.object, "", {x = 0, y = 3, z = -2}, {x = 0, y = 0, z = 0}) + default.player_attached[name] = true + minetest.after(0.2, function() + default.player_set_animation(clicker, "sit" , 30) + end) + self.object:setyaw(clicker:get_look_yaw() - math.pi / 2) + end +end + + +function car4.on_activate(self, staticdata, dtime_s) + self.object:set_armor_groups({immortal = 1}) + if staticdata then + self.v = tonumber(staticdata) + end + self.last_v = self.v +end + + +function car4.get_staticdata(self) + return tostring(self.v) +end + + +function car4.on_punch(self, puncher, time_from_last_punch, tool_capabilities, direction) + if self.driver then + self.driver:set_detach() + local name = self.driver:get_player_name() + default.player_attached[name] = false + default.player_set_animation(self.driver, "stand" , 30) + self.driver = nil + end + -- delay remove to ensure player is detached + minetest.after(0.1, function() + self.object:remove() + end) + if puncher and puncher:is_player() and not minetest.setting_getbool("creative_mode") then + puncher:get_inventory():add_item("main", "mesecar:mesecar4") + end +end + + +function car4:on_step(dtime) + self.v = get_v(self.object:getvelocity()) * get_sign(self.v) + if self.driver then + local ctrl = self.driver:get_player_control() + if ctrl.up then + self.v = self.v + ACDC + elseif ctrl.down then + self.v = self.v - ACDC + end + end + if self.v == 0 and self.object:getvelocity().y == 0 then + return + end + local absv = math.abs(self.v) + if self.driver then + local ctrl = self.driver:get_player_control() + local turn + local maxturn = (1 + dtime * 2) * TURNSP + if absv < 4 then + turn = maxturn * absv / 4 + else + turn = maxturn * (1 - (absv - 4) / 16) + end + if ctrl.left then + self.object:setyaw(self.object:getyaw() + turn) + elseif ctrl.right then + self.object:setyaw(self.object:getyaw() - turn) + end + end + local s = get_sign(self.v) + self.v = self.v - 0.03 * s + if s ~= get_sign(self.v) then + self.object:setvelocity({x = 0, y = 0, z = 0}) + self.v = 0 + return + end + if absv > MAXSP then + self.v = MAXSP * get_sign(self.v) + end + self.object:setacceleration({x = 0, y = -9.81, z = 0}) + self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y)) + self.object:setpos(self.object:getpos()) +end + + -- Register entities minetest.register_entity("mesecar:mesecar1", car1) minetest.register_entity("mesecar:mesecar2", car2) minetest.register_entity("mesecar:mesecar3", car3) +minetest.register_entity("mesecar:mesecar4", car4) + -- Items @@ -397,7 +538,7 @@ minetest.register_craftitem("mesecar:mesecar1", { description = "Mese Car 1", inventory_image = "mesecar_car1front.png", wield_image = "mesecar_car1front.png", - wield_scale = {x=2, y=2, z=2}, + wield_scale = {x = 2, y = 2, z = 2}, liquids_pointable = true, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then @@ -415,11 +556,12 @@ minetest.register_craftitem("mesecar:mesecar1", { end, }) + minetest.register_craftitem("mesecar:mesecar2", { description = "Mese Car 2", inventory_image = "mesecar_car2front.png", wield_image = "mesecar_car2front.png", - wield_scale = {x=2, y=2, z=2}, + wield_scale = {x = 2, y = 2, z = 2}, liquids_pointable = true, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then @@ -437,11 +579,12 @@ minetest.register_craftitem("mesecar:mesecar2", { end, }) + minetest.register_craftitem("mesecar:mesecar3", { description = "Mese Car 3", inventory_image = "mesecar_car3front.png", wield_image = "mesecar_car3front.png", - wield_scale = {x=2, y=2, z=2}, + wield_scale = {x = 2, y = 2, z = 2}, liquids_pointable = true, on_place = function(itemstack, placer, pointed_thing) if pointed_thing.type ~= "node" then @@ -459,3 +602,25 @@ minetest.register_craftitem("mesecar:mesecar3", { end, }) + +minetest.register_craftitem("mesecar:mesecar4", { + description = "Mese Car 4", + inventory_image = "mesecar_car4front.png", + wield_image = "mesecar_car4front.png", + wield_scale = {x = 2, y = 2, z = 2}, + liquids_pointable = true, + on_place = function(itemstack, placer, pointed_thing) + if pointed_thing.type ~= "node" then + return + end + if not is_ground(pointed_thing.under) then + return + end + pointed_thing.under.y = pointed_thing.under.y + 1.25 + minetest.add_entity(pointed_thing.under, "mesecar:mesecar4") + if not minetest.setting_getbool("creative_mode") then + itemstack:take_item() + end + return itemstack + end, +}) diff --git a/textures/mesecar_car1leftside.png b/textures/mesecar_car1leftside.png index 43ff8ebe706824831085945cc803a47c8ed89117..249d1dce55bde9ae629e27851b3643b188b8f6d0 100644 GIT binary patch delta 197 zcmV;$06PDV0*(TZQGeeH92E~4yS)hb0001+Nklj3uN_P6 z2mo4ZD5Xw~TxxSFLk@BE2Xaj82yrWY6(7#LQpSOFJ^h={;zBR{%YCI$uu26=gThU<*h zL^&Bph-gR9rp8x;=07*qoM6N<$g4Cx@ AB>(^b diff --git a/textures/mesecar_car1rightside.png b/textures/mesecar_car1rightside.png index 5fbb7ba5d72e90f5193f5031bd98b653e1926a97..d07f627aacf40004cfd99762fbd455911bb9d920 100644 GIT binary patch delta 74 zcmeBX>Sme{$aSAvMwCxKS7wdE#OP|%=7t7_KtH!|Zhq0ax;i!>PFbJG{Qu(BBwl7G bHU(yeS9`2}8NP8|%K!wPu6{1-oD!MSme{$aRlXh>?-CI=D4?Vsy3X;ZnEkMRR)AiOFfn75Pg@NIaRiw~hCYdw91g d4~Jv}55w(QcK4pjcNH=Kfv2mV%Q~loCIGnb8JGY7 diff --git a/textures/mesecar_car2front.png b/textures/mesecar_car2front.png index a991029256998558284e4e72cdc577abb18276bd..80db81ad1158adf85c6e9340225c20f82990ddf9 100644 GIT binary patch delta 118 zcmV-+0Ez#>0m1>0Q*RgnF*)SNFLM9@08dFoK~y-)?US(yz(5QGPa%VAjh`mt{1{G? z;z?ytswW5TBw-MeaSi_@% delta 117 zcmV-*0E+*@0l@)~Q*IRk9VAZNPJjRa08U9nK~y-)?US($z%UR3k0^t)hNsCm9^>6w zsbb;E%GH2g;*oI?ARr332stL8fM>xq>1A9l17P`+f7Ywfq8jf`|7#3+k4X!ku;+pS XY%&y;+-qcY00000NkvXXu0mjf6q+!w diff --git a/textures/mesecar_car2leftside.png b/textures/mesecar_car2leftside.png index e3d011ba09598e820af7383ca3470022955c5677..4a2f05dc536003489320e382821ddae2d3d4ae1a 100644 GIT binary patch delta 195 zcmV;!06hPU0*nHXQGeeH92F1({DRMl0001)Nkl|EOq=;iVhB%f;nNRce^tnTK2#?P+NC4SdONnGcc3|CZAcY6<0H!BJ9OM}6SR$oA&DYcC4&5OvHc}x0M6EU6djQscPZpbeL#3_) zAZphrd-@E{%ml(0Yia4|@&XgnsZL=z|DOR6kAB)OE&-f#2|O5M4m)nM4S-UL(Tt~_ xyv@pw(NCS=?Qs{y+rxY1>uhlb3oj|lz5t3^D`z4gfqwu1002ovPDHLkV1mq9PQ3sC diff --git a/textures/mesecar_car2rightside.png b/textures/mesecar_car2rightside.png index 3e0532583b3e12c18d304ac2f4561d3a522da031..4d9d86d72f18932c4b3c5087cf1a817ec85968eb 100644 GIT binary patch delta 194 zcmV;z06qVT0*eBWQGeeH92F2HS%`Y!0001(Nkl07*qoM6N<$f?ge0tN;K2 delta 193 zcmV;y06zbV0*V5VQGebE6b2S6f+9s@0001&NklFCk|6Vt6uVO`IA03;rqy~rG|0i1IY7&>DvJ07(afYzGPjJK|Q v)W**wABnIT-YR?g^&9zCoAqGjxk$7N239I-l~7Oi00000NkvXXu0mjfL5x!r diff --git a/textures/mesecar_car3leftside.png b/textures/mesecar_car3leftside.png index 1cf0b5c13f674251f661100091da56d168a9ac8d..cac450ea97d121aef77dc30572c8ee28fd4c0485 100644 GIT binary patch delta 190 zcmV;v073tZ0*3;SQGeeH92F4=1xy#!0001#NklsQV!RVe}bi zE)Mzt7K5FDvnO!hX|*__f5~9ouJ6^Xek`E|=L$e;Z39XvKQ|pMcLGQ$5o6qSWXql3 sgNPs^0Nk$6(EE6n>t?XxU4hSf0ZN-S^5yY&k^lez07*qoM6N<$f(K4gDF6Tf delta 195 zcmV;!06hPP0*nHXQGebE6#@_nC!{?B0001)Nkl257Tub5CFIhPpN%8%XKqY@v6XQy#P0iJQO=rVRirj002ovPDHLkV1n-=j zJoq?1Ko8=Z^#IM3MOl(kR3!x5u@3~|@p!WJ6SS(*1FfoC0Edxt{>leB@i&0bJI0Zl z!@hvYa2Md}89YyxnjF)g^kCgAyPdwc2ImVvYwb;xQVuIx?KA+8QXd96+Zi$E> pA^<$@bJ)8*t95&@^1B9~SO9>sHS$R0T8{t#002ovPDHLkV1lX>RGa_+ delta 191 zcmV;w06_nQ0*C^TQGebE6#@~{L%9GouzrId|GDL5TgwAuzhMCc#=sV7@) tyC&l>A_xHY+dJ&tp4GZNSomFoPt0wjJQOxkr;Gpq002ovPDHLkV1l|NQEvbM diff --git a/textures/mesecar_car4back.png b/textures/mesecar_car4back.png new file mode 100644 index 0000000000000000000000000000000000000000..52b628c221dc63ccdb93ff8d02e1105466fee65c GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=DinK$vl=HlH+5kiEpy*OmP~w~Q!ilE>BL6xez|7m89Z5lQKcbkZ<*nD^@c|&x~rQuw8o3iXpvyQb2j rTqNi5>%`1G#8|(fCF7pLVJ@kQZNgfwSx*}RtzhtU^>bP0l+XkKS{Fgm literal 0 HcmV?d00001 diff --git a/textures/mesecar_car4front.png b/textures/mesecar_car4front.png new file mode 100644 index 0000000000000000000000000000000000000000..717f860a818976a1c9c5debe897ad6a037581828 GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=DinK$vl=HlH+5kiEpy*OmP~w~Q#8hV{bD-9Vv4PZ!4!i_>=}`*Jk|aJ1MjcCKuC z7bE^5;_{*gp1CzUI@#`=?LUzrw1}~J-a#i}dBYA4rA0cY{`_MT+F{KQlxuW_cF BN9X_m literal 0 HcmV?d00001 diff --git a/textures/mesecar_car4leftside.png b/textures/mesecar_car4leftside.png new file mode 100644 index 0000000000000000000000000000000000000000..7110d5ba810ec5b7c9ebe8d1c537fac8fa4a2a79 GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~w~Q#4GQ%-dexOi~r;B5V#p$<`4Y>{*@VL%*QdnHW zEU$9?!-LBuC+;-=;Cg${IW=gyiK>$(Yxx>S1-tl5&%MQrd(NdV6=6Q}JU#JS-@@`= z`x!mnOS$i0{lFX{Q^xr0zV?gn3A@)l&YYJa#A(}b?H1paD0{yzcNi6(`*^+7J~_{N vpHQf4DC3TM;hm?|Ki|2~%*$WDj(y%5S>q%7BXs5g-NoSP>gTe~DWM4f%-LIV literal 0 HcmV?d00001 diff --git a/textures/mesecar_car4rightside.png b/textures/mesecar_car4rightside.png new file mode 100644 index 0000000000000000000000000000000000000000..75b9ccca632fc8f95252a175601b7175a6df9b99 GIT binary patch literal 252 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~w~Q#Kx=!1st3aVnPZ!4!i_>o>8*&{s;BlSrykKz+ zv%Jdn4-YPvoVe5cgX`rz=hUF-JDQbz4oWHubR6HVy6@?NE+e5;8Qw3_&;1PX=Q&o( z*m5y_PGa!~_6Xi;rqf@Ad#Vd^rrq_6mxw^dHo^O4?J;lWM$W_sPQ=p?5JYD@<);T3K0RV3nUnu|p literal 0 HcmV?d00001 diff --git a/textures/mesecar_car4top.png b/textures/mesecar_car4top.png new file mode 100644 index 0000000000000000000000000000000000000000..2b5197ae774fca832e97dd59a11807f4b267073c GIT binary patch literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|I14-?iy0XB zj({-ZRBb+KpdfpRr>`sfT^=bxIT_cM&>EnSy{C&~h{pNkKmX@9svKzYZki}~>c@Zi z*0U~qZVGHS5DaNdQ&(PDm!R~5okO~b!-8{Nhlc&1|NhzbJy{D}m>D{6h$y(|YQ6&+ O#o+1c=d#Wzp$PzIT{1lY literal 0 HcmV?d00001