Added step height and max speed parameters. Bugfix floating above slabs. Resize car, collisionbox. New texture. Update crafting

This commit is contained in:
paramat 2014-09-02 05:21:47 +01:00
parent 8eaa3d8d64
commit 5ac3a9a67d
4 changed files with 49 additions and 53 deletions

View File

@ -1,4 +1,4 @@
mesecar 0.1.0 by paramat, a fork of Dan Duncombe's car mod mesecar 0.2.0 by paramat
For latest stable Minetest and back to 0.4.7 For latest stable Minetest and back to 0.4.9
Depends default Depends default wool dye
Licenses: code WTFPL, textures CC BY-SA Licenses: code WTFPL, textures CC BY-SA

View File

@ -1 +1,3 @@
default default
wool
dye

View File

@ -1,9 +1,18 @@
-- mesecar 0.1.0 by paramat, a fork of Dan Duncombe's car mod -- mesecar 0.2.0 by paramat, a fork of Dan Duncombe's car mod
-- For latest stable Minetest and back to 0.4.7 -- For latest stable Minetest and back to 0.4.9
-- Depends default -- Depends default wool dye
-- Licenses: code WTFPL, textures CC-BY-SA -- Licenses: code WTFPL, textures CC-BY-SA
local TURNS = 0.04 -- 0.04 -- Maximum turn speed. -- new in 0.2.0:
-- added step height and max speed parameters
-- bugfix floating above slabs
-- resize car, collisionbox
-- new texture
-- update crafting
local MAXSP = 8 -- Maxspeed in nodes per second
local TURNSP = 0.04 -- Maximum turn speed
local STEPH = 0.6 -- Stepheight, 0.6 = climb slabs, 1.1 = climb nodes
-- Functions -- Functions
@ -22,28 +31,28 @@ end
local function get_velocity(v, yaw, y) local function get_velocity(v, yaw, y)
local x = math.cos(yaw) * v local x = math.cos(yaw) * v
local z = math.sin(yaw) * v local z = math.sin(yaw) * v
return {x=x,y=y,z=z} return {x=x, y=y, z=z}
end end
local function get_v(v) local function get_v(v)
return math.sqrt(v.x ^ 2 + v.z ^ 2) return math.sqrt(v.x ^ 2 + v.z ^ 2)
end end
-- Cart entity -- Car entity
local boat = { local car = {
physical = true, physical = true,
collisionbox = {-0.6,0.75,-0.6, 0.6,0.75,0.6}, collisionbox = {-0.55, 0, -0.55, 0.55, 1.45, 0.55},
visual = "mesh", visual = "mesh",
visual_size = {x=1,y=1.6}, visual_size = {x=0.9, y=1.3},
mesh = "mesecar.x", mesh = "mesecar.x",
textures = {"mesecar_mesecar.png"}, textures = {"mesecar_mesecar.png"},
stepheight = STEPH,
driver = nil, driver = nil,
v = 0, v = 0,
} }
function boat:on_rightclick(clicker) function car:on_rightclick(clicker)
if not clicker or not clicker:is_player() then if not clicker or not clicker:is_player() then
return return
end end
@ -52,23 +61,23 @@ function boat:on_rightclick(clicker)
clicker:set_detach() clicker:set_detach()
elseif not self.driver then elseif not self.driver then
self.driver = clicker self.driver = clicker
clicker:set_attach(self.object, "", {x=0,y=5,z=0}, {x=0,y=0,z=0}) clicker:set_attach(self.object, "", {x=0, y=5, z=0}, {x=0, y=0, z=0})
self.object:setyaw(clicker:get_look_yaw()) self.object:setyaw(clicker:get_look_yaw())
end end
end end
function boat:on_activate(staticdata, dtime_s) function car:on_activate(staticdata, dtime_s)
self.object:set_armor_groups({immortal=1}) self.object:set_armor_groups({immortal=1})
if staticdata then if staticdata then
self.v = tonumber(staticdata) self.v = tonumber(staticdata)
end end
end end
function boat:get_staticdata() function car:get_staticdata()
return tostring(v) return tostring(v)
end end
function boat:on_punch(puncher, time_from_last_punch, tool_capabilities, direction) function car:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
self.object:remove() self.object:remove()
if puncher and puncher:is_player() then if puncher and puncher:is_player() then
puncher:get_inventory():add_item("main", "mesecar:mesecar") puncher:get_inventory():add_item("main", "mesecar:mesecar")
@ -77,7 +86,7 @@ end
-- On globalstep -- On globalstep
function boat:on_step(dtime) function car:on_step(dtime)
self.v = get_v(self.object:getvelocity()) * get_sign(self.v) self.v = get_v(self.object:getvelocity()) * get_sign(self.v)
local absv = math.abs(self.v) local absv = math.abs(self.v)
if self.driver then if self.driver then
@ -88,7 +97,7 @@ function boat:on_step(dtime)
self.v = self.v - 0.3 self.v = self.v - 0.3
end end
local turn local turn
local maxturn = (1 + dtime) * TURNS local maxturn = (1 + dtime) * TURNSP
if absv < 4 then if absv < 4 then
turn = maxturn * absv / 4 turn = maxturn * absv / 4
else else
@ -101,44 +110,27 @@ function boat:on_step(dtime)
end end
end end
local s = get_sign(self.v) local s = get_sign(self.v)
self.v = self.v - 0.02 * s -- decceleration self.v = self.v - 0.02 * s
if s ~= get_sign(self.v) then -- if decceleration reverses direction if s ~= get_sign(self.v) then
self.object:setvelocity({x=0,y=0,z=0}) -- stop self.object:setvelocity({x=0, y=0, z=0})
self.v = 0 self.v = 0
return return
end end
if absv > 8 then if absv > MAXSP then
self.v = 8 * get_sign(self.v) -- limit speed to ~20mph self.v = MAXSP * get_sign(self.v)
end
local p = self.object:getpos()
p.y = p.y - 0.5
if not is_ground(p) then
self.object:setacceleration({x=0,y=-9.81,z=0})
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), self.object:getvelocity().y))
else
p.y = p.y + 1
if is_ground(p) then
self.object:setacceleration({x=0,y=0,z=0})
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), 0))
local pos = self.object:getpos()
pos.y = math.floor(pos.y) + 1.5
self.object:setpos(pos)
else
self.object:setacceleration({x=0,y=0,z=0})
self.object:setvelocity(get_velocity(self.v, self.object:getyaw(), 0))
local pos = self.object:getpos()
pos.y = math.floor(pos.y) + 0.5
self.object:setpos(pos)
end
end 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 end
minetest.register_entity("mesecar:mesecar", boat) minetest.register_entity("mesecar:mesecar", car)
-- Items
minetest.register_craftitem("mesecar:mesecar", { minetest.register_craftitem("mesecar:mesecar", {
description = "Mese Car", description = "Mese Car",
inventory_image = "mesecar_mesecar.png", inventory_image = "mesecar_mesecar.png",
wield_scale = {x=2,y=2,z=1},
liquids_pointable = true, liquids_pointable = true,
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
@ -148,7 +140,7 @@ minetest.register_craftitem("mesecar:mesecar", {
if not is_ground(pointed_thing.under) then if not is_ground(pointed_thing.under) then
return return
end end
pointed_thing.under.y = pointed_thing.under.y + 2 pointed_thing.under.y = pointed_thing.under.y + 1
minetest.add_entity(pointed_thing.under, "mesecar:mesecar") minetest.add_entity(pointed_thing.under, "mesecar:mesecar")
itemstack:take_item() itemstack:take_item()
return itemstack return itemstack
@ -167,6 +159,8 @@ minetest.register_craftitem("mesecar:battery", {
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1},
}) })
-- Crafting
minetest.register_craft({ minetest.register_craft({
output = "mesecar:motor", output = "mesecar:motor",
recipe = { recipe = {
@ -181,15 +175,15 @@ minetest.register_craft({
recipe = { recipe = {
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"default:steel_ingot", "default:mese_block", "default:copper_ingot"}, {"default:steel_ingot", "default:mese_block", "default:copper_ingot"},
{"default:copper_ingot", "default:steel_ingot", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
}, },
}) })
minetest.register_craft({ minetest.register_craft({
output = "mesecar:mesecar", output = "mesecar:mesecar",
recipe = { recipe = {
{"wool:black", "wool:orange", "default:glass"}, {"dye:yellow", "wool:black", "default:glass"},
{"mesecar:battery", "default:copper_ingot", "mesecar:motor"}, {"mesecar:battery", "default:copper_ingot", "mesecar:motor"},
{"default:steelblock", "default:steelblock", "default:steelblock"}, {"default:steelblock", "default:steelblock", "default:steelblock"},
}, },
}) })

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB