Completly rewrite the mod

master
PilzAdam 2012-12-04 18:44:51 +01:00
parent fb153cb8ac
commit 4997a3f3a1
29 changed files with 334 additions and 1406 deletions

View File

@ -1,53 +1,18 @@
===CARTS MOD for MINETEST-C55===
Minetest 0.4 mod: carts
=======================
by PilzAdam
Introduction:
This mod adds carts to minetest. There were rails for so long in minetest
but no carts so that they were useless. But this mod brings what many
players all over the world wanted for so long (I think so...).
License of source code:
-----------------------
WTFPL
How to install:
Unzip the archive an place it in minetest-base-directory/mods/minetest/
if you have a windows client or a linux run-in-place client. If you have
a linux system-wide instalation place it in ~/.minetest/mods/minetest/.
If you want to install this mod only in one world create the folder
worldmods/ in your worlddirectory.
For further information or help see:
http://wiki.minetest.com/wiki/Installing_Mods
License of media (textures and sounds):
---------------------------------------
CC-0
How to use the mod:
Read the first post at http://minetest.net/forum/viewtopic.php?id=2451
Configuration:
(all variables are in init.lua)
line 4: MAX_SPEED => the maximum speed of the cart
line 9: TRANSPORT_PLAYER => transport the player like a normal item
(this is very laggy NOT RECOMMENDED)
line 13: SOUND_FILES => a table with all soundfiles and there length. To
add your own files copy them into carts/sounds (only .ogg files
are supported) and add there name (without ".ogg") and there
lenght (in seconds) to the table.
line 21: SOUND_GAIN => the gain of the sound.
line 27: RAILS => blocks that are treated as rails.
License:
Sourcecode: WTFPL (see below)
Sound: WTFPL (provided from Ragnarok)
Graphics: CC0 (provided from kddekadenz)
See also:
http://minetest.net/
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
Authors of media files:
-----------------------
kddekadenz:
cart_bottom.png
cart_side.png
cart_top.png

16
box.lua
View File

@ -1,16 +0,0 @@
minetest.register_node("carts:cart_box", {
tiles = {"carts_cart_top.png", "carts_cart_bottom.png", "carts_cart_side.png", "carts_cart_side.png", "carts_cart_side.png", "carts_cart_side.png"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.45, -0.5, 0.5, 0.5, -0.5+1/16},
{-0.5, -0.45, -0.5, -0.5+1/16, 0.5, 0.5},
{0.5, -0.5, 0.5, -0.5, 0.5, 0.5-1/16},
{0.5, -0.5, 0.5, 0.5-1/16, 0.5, -0.5},
{-0.5, -0.5, -0.5, 0.5, -0.3, 0.5},
},
},
groups = {oddly_breakable_by_hand=3, not_in_creative_inventory=1},
})

View File

@ -1,43 +0,0 @@
minetest.register_node("carts:chest", {
description = "Railchest",
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png^default_rail.png", "default_chest_side.png^default_rail.png", "default_chest_side.png^default_rail.png", "default_chest_front.png"},
paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec",
"invsize[8,8;]"..
"label[0.5.0,0;In:]"..
"list[current_name;in;0.5,0.5;3,3;]"..
"label[4.5.0,0;Out:]"..
"list[current_name;out;4.5,0.5;3,3;]"..
"list[current_player;main;0,4;8,4;]")
meta:set_string("infotext", "Railchest")
local inv = meta:get_inventory()
inv:set_size("in", 3*3)
inv:set_size("out", 3*3)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
return (inv:is_empty("in") and inv:is_empty("out"))
end,
})
minetest.register_abm({
nodenames = {"carts:pickup_plate"},
interval = 0,
chance = 1,
action = function(pos)
minetest.env:remove_node(pos)
end
})
minetest.register_craft({
output = '"carts:chest" 1',
recipe = {
{'default:wood', 'default:wood', 'default:wood'},
{'default:wood', 'default:rail', 'default:wood'},
{'default:wood', 'default:wood', 'default:wood'}
}
})

View File

@ -1,17 +1,57 @@
local APPROXIMATION = 0.8
equals = function(num1, num2)
if math.abs(num1-num2) <= APPROXIMATION then
return true
--
-- Helper functions
--
cart_func = {}
function cart_func:get_sign(z)
if z == 0 then
return 0
else
return false
return z/math.abs(z)
end
end
pos_equals = function(pos1, pos2)
if pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z then
return true
-- Returns the velocity as a unit vector
-- The smaller part of the vector will be turned to 0
function cart_func:velocity_to_dir(v)
if math.abs(v.x) > math.abs(v.z) then
return {x=cart_func:get_sign(v.x), y=cart_func:get_sign(v.y), z=0}
else
return false
return {x=0, y=cart_func:get_sign(v.y), z=cart_func:get_sign(v.z)}
end
end
function cart_func:is_rail(p)
local nn = minetest.env:get_node(p).name
return nn == "default:rail" or
minetest.get_item_group(nn, "rail") ~= 0
end
function cart_func:is_int(z)
z = math.abs(z)
return math.abs(math.floor(z+0.5)-z) < 0.1
end
cart_func.v3 = {}
function cart_func.v3:add(v1, v2)
return {x=v1.x+v2.x, y=v1.y+v2.y, z=v1.z+v2.z}
end
function cart_func.v3:copy(v)
return {x=v.x, y=v.y, z=v.z}
end
function cart_func.v3:round(v)
return {
x = math.floor(v.x+0.5),
y = math.floor(v.y+0.5),
z = math.floor(v.z+0.5),
}
end
function cart_func.v3:equal(v1, v2)
return v1.x == v2.x and v1.y == v2.y and v1.z == v2.z
end

1077
init.lua

File diff suppressed because it is too large Load Diff

View File

@ -1,248 +0,0 @@
if minetest.get_modpath("mesecons") ~= nil then
minetest.after(0, function()
mesecon:register_on_signal_on(function(pos, node)
for i,rail in ipairs(RAILS) do
if node.name == rail then
local carts = minetest.env:get_objects_inside_radius(pos, 1)
for i,cart in ipairs(carts) do
if not cart:is_player() and cart:get_luaentity().name == "carts:cart" and not cart:get_luaentity().fahren then
local self = cart:get_luaentity()
-- find out the direction
local dir_table
if self.old_dir ~= nil then
dir_table = {self.old_dir, "x+", "x-", "z+", "z-"}
else
dir_table = {"x+", "x-", "z+", "z-"}
end
for i,dir in ipairs(dir_table) do
self.dir = dir
if self:get_new_direction() == self.dir then
break
end
end
-- detect items
local tmp = minetest.env:get_objects_inside_radius(self.object:getpos(), 1)
for i,item in ipairs(tmp) do
if not item:is_player() and item:get_luaentity().name ~= "carts:cart" then
table.insert(self.items, item)
elseif item:is_player() and TRANSPORT_PLAYER then
table.insert(self.items, item)
end
end
-- start sound
self:sound("start")
self.fahren = true
end
end
end
end
if node.name == "carts:switch_left" then
node.name = "carts:switch_right"
minetest.env:set_node(pos, node)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "right")
end
end
elseif node.name == "carts:switch_right" then
node.name = "carts:switch_left"
minetest.env:set_node(pos, node)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "left")
end
end
end
if node.name == "carts:meseconrail_stop_off" then
node.name = "carts:meseconrail_stop_on"
minetest.env:set_node(pos, node)
end
end)
mesecon:register_on_signal_off(function(pos, node)
if node.name == "carts:meseconrail_stop_on" then
node.name = "carts:meseconrail_stop_off"
minetest.env:set_node(pos, node)
local carts = minetest.env:get_objects_inside_radius(pos, 1)
for i,cart in ipairs(carts) do
if not cart:is_player() and cart:get_luaentity().name == "carts:cart" and not cart:get_luaentity().fahren then
local self = cart:get_luaentity()
-- find out the direction
if self.old_dir ~= nil then
self.dir = self.old_dir
else
for i,dir in ipairs({"x+", "x-", "z+", "z-"}) do
self.dir = dir
if self:get_new_direction() == self.dir then
break
end
end
end
-- detect items
local tmp = minetest.env:get_objects_inside_radius(self.object:getpos(), 1)
for i,item in ipairs(tmp) do
if not item:is_player() and item:get_luaentity().name ~= "carts:cart" then
table.insert(self.items, item)
elseif item:is_player() and TRANSPORT_PLAYER then
table.insert(self.items, item)
end
end
-- start sound
self:sound("start")
self.fahren = true
end
end
end
end)
end)
minetest.register_node("carts:meseconrail_off", {
description = "Meseconrail",
drawtype = "raillike",
tiles = {"carts_meseconrail_off.png", "carts_meseconrail_curved_off.png", "carts_meseconrail_t_junction_off.png", "carts_meseconrail_crossing_off.png",},
inventory_image = "carts_meseconrail_off.png",
wield_image = "carts_meseconrail_off.png",
paramtype = "light",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy=2,snappy=1,dig_immediate=2},
})
minetest.register_node("carts:meseconrail_on", {
drawtype = "raillike",
tiles = {"carts_meseconrail_on.png", "carts_meseconrail_curved_on.png", "carts_meseconrail_t_junction_on.png", "carts_meseconrail_crossing_on.png",},
paramtype = "light",
light_source = LIGHT_MAX-11,
drop = "carts:meseconrail_off",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy=2, snappy=1, dig_immediate=2, not_in_creative_inventory=1},
after_destruct = function(pos, oldnode)
if mesecon ~= nil then
mesecon:receptor_off(pos)
end
end,
})
minetest.register_alias("carts:meseconrail", "carts:meseconrail_off")
minetest.after(0, function()
mesecon:add_receptor_node("carts:meseconrail_on")
mesecon:add_receptor_node_off("carts:meseconrail_off")
end)
minetest.register_abm({
nodenames = {"carts:meseconrail_on"},
interval = 1.0,
chance = 1,
action = function(pos, node)
local tmp = minetest.env:get_objects_inside_radius(pos, 1)
local cart_is_there = false
for i,cart in ipairs(tmp) do
if not cart:is_player() and cart:get_luaentity().name == "carts:cart" then
cart_is_there = true
end
end
if not cart_is_there then
minetest.env:set_node(pos, {name="carts:meseconrail_off"})
if mesecon ~= nil then
mesecon:receptor_off(pos)
end
end
end
})
minetest.register_craft({
output = '"carts:meseconrail_off" 1',
recipe = {
{'default:rail', 'mesecons:mesecon_off', 'default:rail'},
{'default:rail', 'mesecons:mesecon_off', 'default:rail'},
{'default:rail', 'mesecons:mesecon_off', 'default:rail'},
}
})
minetest.register_node("carts:meseconrail_stop_off", {
description = "Meseconrail stop",
drawtype = "raillike",
tiles = {"carts_meseconrail_stop_off.png", "carts_meseconrail_stop_curved_off.png", "carts_meseconrail_stop_t_junction_off.png", "carts_meseconrail_stop_crossing_off.png",},
inventory_image = "carts_meseconrail_stop_off.png",
wield_image = "carts_meseconrail_stop_off.png",
paramtype = "light",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy=2,snappy=1,dig_immediate=2},
after_destruct = function(pos, oldnode)
if mesecon ~= nil then
mesecon:receptor_off(pos)
end
end,
})
minetest.register_node("carts:meseconrail_stop_on", {
drawtype = "raillike",
tiles = {"carts_meseconrail_stop_on.png", "carts_meseconrail_stop_curved_on.png", "carts_meseconrail_stop_t_junction_on.png", "carts_meseconrail_stop_crossing_on.png",},
paramtype = "light",
light_source = LIGHT_MAX-11,
drop = "carts:meseconrail_stop_off",
walkable = false,
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {bendy=2, snappy=1, dig_immediate=2, not_in_creative_inventory=1},
after_destruct = function(pos, oldnode)
if mesecon ~= nil then
mesecon:receptor_off(pos)
end
end,
})
minetest.register_alias("carts:meseconrail_stop", "carts:meseconrail_stop_off")
minetest.register_craft({
output = '"carts:meseconrail_stop_off" 1',
recipe = {
{'default:rail', 'mesecons:mesecon_off', 'default:rail'},
{'default:rail', '', 'default:rail'},
{'default:rail', 'mesecons:mesecon_off', 'default:rail'},
}
})
end

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,235 +0,0 @@
minetest.register_node("carts:switch_left", {
paramtype2 = "facedir",
tiles = {"default_wood.png"},
drop = "carts:switch_middle",
groups = {bendy=2, snappy=1, dig_immediate=2, not_in_creative_inventory=1},
on_punch = function(pos, node, puncher)
node.name = "carts:switch_middle"
minetest.env:set_node(pos, node)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "")
end
end
end,
on_destruct = function(pos)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "")
end
end
end,
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
-- shaft
{-0.05, -0.5, -0.45, 0.05, -0.4, -0.4},
{-0.1, -0.4, -0.45, 0, -0.3, -0.4},
{-0.15, -0.3, -0.45, -0.05, -0.2, -0.4},
{-0.2, -0.2, -0.45, -0.1, -0.1, -0.4},
{-0.25, -0.1, -0.45, -0.15, 0, -0.4},
{-0.3, 0, -0.45, -0.2, 0.1, -0.4},
-- head
{-0.45, 0.1, -0.5, -0.25, 0.3, -0.35},
},
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.35, -0.35},
}
},
walkable = false,
})
minetest.register_node("carts:switch_middle", {
description = "Switch",
paramtype2 = "facedir",
tiles = {"default_wood.png"},
groups = {bendy=2, snappy=1, dig_immediate=2},
on_punch = function(pos, node, puncher)
node.name = "carts:switch_right"
minetest.env:set_node(pos, node)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "right")
end
end
end,
on_construct = function(pos)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "")
end
end
end,
on_destruct = function(pos)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "")
end
end
end,
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
-- shaft
{-0.05, -0.5, -0.45, 0.05, 0.15, -0.4},
-- head
{-0.1, 0.15, -0.5, 0.1, 0.35, -0.35},
},
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.35, -0.35},
}
},
walkable = false,
})
minetest.register_node("carts:switch_right", {
paramtype2 = "facedir",
tiles = {"default_wood.png"},
groups = {bendy=2,snappy=1, dig_immediate=2, not_in_creative_inventory=1},
drop = "carts:switch_middle",
on_punch = function(pos, node, puncher)
node.name = "carts:switch_left"
minetest.env:set_node(pos, node)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "left")
end
end
end,
on_destruct = function(pos)
local par2 = minetest.env:get_node(pos).param2
if par2 == 0 then
pos.z = pos.z-1
elseif par2 == 1 then
pos.x = pos.x-1
elseif par2 == 2 then
pos.z = pos.z+1
elseif par2 == 3 then
pos.x = pos.x+1
end
for i,rail in ipairs(RAILS) do
if minetest.env:get_node(pos).name == rail then
local meta = minetest.env:get_meta(pos)
meta:set_string("rail_direction", "")
end
end
end,
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
-- shaft
{-0.05, -0.5, -0.45, 0.05, -0.4, -0.4},
{0, -0.4, -0.45, 0.1, -0.3, -0.4},
{0.05, -0.3, -0.45, 0.15, -0.2, -0.4},
{0.1, -0.2, -0.45, 0.2, -0.1, -0.4},
{0.15, -0.1, -0.45, 0.25, 0, -0.4},
{0.2, 0, -0.45, 0.3, 0.1, -0.4},
-- head
{0.25, 0.1, -0.5, 0.45, 0.3, -0.35},
},
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.35, -0.35},
}
},
walkable = false,
})
minetest.register_alias("carts:switch", "carts:switch_middle")
minetest.register_craft({
output = '"carts:switch_middle" 1',
recipe = {
{'', 'default:rail', ''},
{'default:rail', '', ''},
{'', 'default:rail', ''},
}
})

View File

Before

Width:  |  Height:  |  Size: 154 B

After

Width:  |  Height:  |  Size: 154 B

View File

Before

Width:  |  Height:  |  Size: 192 B

After

Width:  |  Height:  |  Size: 192 B

View File

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 641 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 619 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 560 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 603 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 591 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 550 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 609 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 622 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 623 B