added minitest
|
@ -0,0 +1,16 @@
|
|||
===Minicraft - a game for MINETEST-C55===
|
||||
by PilzAdam
|
||||
|
||||
Introduction:
|
||||
This game tries to copy some elements of the Minecraft gameplay.
|
||||
|
||||
How to install:
|
||||
Unzip the folder and copy it to the game/ folder in your Minetest directory. Then create a new world and choose Minitest as game.
|
||||
|
||||
License:
|
||||
The most textures are from Jordach.
|
||||
All mods have a README.txt; read these for license and authors.
|
||||
Mods without a README.txt are from me (PilzAdam) and under the WTFPL (all parts).
|
||||
|
||||
See also:
|
||||
http://minetest.net/
|
|
@ -0,0 +1 @@
|
|||
name = MiniTest
|
|
@ -0,0 +1,8 @@
|
|||
Animated-Fluids
|
||||
===============
|
||||
|
||||
A mod for minetest
|
||||
|
||||
extract the zip to ~/.minetest/mods/minetest/
|
||||
|
||||
rename khonkhortisan-animatedfluids-a73caea to animatedfluids
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,13 @@
|
|||
fluids = {'water', 'lava'}
|
||||
for fluid=1,#fluids do
|
||||
name = fluids[fluid]
|
||||
fluid = minetest.registered_nodes['default:'..name..'_flowing']
|
||||
tile = {name='default_'..name..'_animated.png', animation={type='vertical_frames', aspect_w=16, aspect_h=16, length=fluid.viscosity}}
|
||||
fluid.tiles = {tile}
|
||||
tile1 = tile
|
||||
tile2 = tile
|
||||
tile1.backface_culling=false
|
||||
tile2.backface_culling=true
|
||||
fluid.special_tiles = {tile1,tile2}
|
||||
minetest.register_node(':default:'..name..'_flowing', fluid)
|
||||
end
|
After Width: | Height: | Size: 934 B |
After Width: | Height: | Size: 510 B |
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 1.5 KiB |
|
@ -0,0 +1,14 @@
|
|||
This simple mod uses a bit of code cobbled together from the default
|
||||
torches and from the recently-introduced animated lava to create proper,
|
||||
animated torches. All existing torches (wall, ceiling, floor) will be
|
||||
displayed with the new animated texture, but no nodes are being
|
||||
replaced. Inventory/wield image uses the stock torch image already
|
||||
supplied with Minetest.
|
||||
|
||||
Textures by me (derived from a rendered torch and an actual burning
|
||||
flame).
|
||||
|
||||
This mod requires a build or git pull of Minetest dated June 17, 2012 or
|
||||
later.
|
||||
|
||||
License: GPL for the code, WTFPL for the textures.
|
|
@ -0,0 +1,4 @@
|
|||
Code copied from minetest's stock code by celeron55 et.al, modifications
|
||||
and all textures by Vanessa Ezekowitz.
|
||||
|
||||
Licenses: For the lua code, GPL. For all images and everything else, WTFPL.
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,33 @@
|
|||
-- Animated torches, based on the static torches and animated lava code
|
||||
-- from Minetest; modifications by Vanessa Ezekowitz 2012-06-17
|
||||
--
|
||||
-- License: LGPL
|
||||
|
||||
minetest.register_node(":default:torch", {
|
||||
description = "Torch",
|
||||
drawtype = "torchlike",
|
||||
tiles = {
|
||||
|
||||
-- "default_torch_on_floor.png", "default_torch_on_ceiling.png", "default_torch.png"
|
||||
|
||||
{name="default_torch_on_floor_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}},
|
||||
{name="default_torch_on_ceiling_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}},
|
||||
{name="default_torch_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=3.0}}
|
||||
|
||||
},
|
||||
inventory_image = "default_torch_on_floor.png",
|
||||
wield_image = "default_torch_on_floor.png",
|
||||
paramtype = "light",
|
||||
paramtype2 = "wallmounted",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
light_source = LIGHT_MAX-1,
|
||||
selection_box = {
|
||||
type = "wallmounted",
|
||||
wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
|
||||
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
|
||||
wall_side = {-0.5, -0.3, -0.1, -0.5+0.3, 0.3, 0.1},
|
||||
},
|
||||
groups = {choppy=2,dig_immediate=3,flammable=1},
|
||||
sounds = default.node_sound_defaults(),
|
||||
})
|
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 282 B |
After Width: | Height: | Size: 1.3 KiB |
|
@ -0,0 +1,48 @@
|
|||
===BEDS MOD for MINETEST-C55===
|
||||
by PilzAdam
|
||||
|
||||
Introduction:
|
||||
This mods brings beds to Minetest. You can use them to sleep at night
|
||||
to prevent attacks by evil mobs.
|
||||
|
||||
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
|
||||
|
||||
How to use the mod:
|
||||
Craft a bed like this:
|
||||
red wool blue wool blue wool
|
||||
stick stick
|
||||
(Theres no "normal" way to get wool so you can use the commands
|
||||
"/giveme wool:red" and "/giveme wool:blue 2")
|
||||
After placing it anywhere you can go to sleep with a leftklick with your
|
||||
hand on the bed. If it is night a chatmessage wishs you "Good night" and
|
||||
you sleep until the next morning. To go outside the bed it is recommended
|
||||
to hit the bed again with a leftklick (it also works if you just go away
|
||||
but its not so safe).
|
||||
|
||||
License:
|
||||
Sourcecode: WTFPL (see below)
|
||||
Graphics: WTFPL (see below)
|
||||
|
||||
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.
|
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
wool
|
|
@ -0,0 +1,211 @@
|
|||
local player_ges = 0
|
||||
local player_in_bed = 0
|
||||
|
||||
minetest.register_node("beds:bed_bottom", {
|
||||
description = "Bed",
|
||||
drawtype = "nodebox",
|
||||
tiles = {"beds_bed_top_bottom.png", "default_wood.png", "beds_bed_side.png", "beds_bed_side.png", "beds_bed_side.png", "beds_bed_side.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
-- bed
|
||||
{-0.5, 0.0, -0.5, 0.5, 0.3, 0.5},
|
||||
|
||||
-- stützen
|
||||
{-0.5, -0.5, -0.5, -0.4, 0.0, -0.4},
|
||||
{0.4, 0.0, -0.4, 0.5, -0.5, -0.5},
|
||||
}
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.5, -0.5, -0.5, 0.5, 0.3, 1.5},
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
on_construct = function(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local param2 = node.param2
|
||||
if param2 == 0 then
|
||||
node.name = "beds:bed_top"
|
||||
pos.z = pos.z+1
|
||||
minetest.env:set_node(pos, node)
|
||||
elseif param2 == 1 then
|
||||
node.name = "beds:bed_top"
|
||||
pos.x = pos.x+1
|
||||
minetest.env:set_node(pos, node)
|
||||
elseif param2 == 2 then
|
||||
node.name = "beds:bed_top"
|
||||
pos.z = pos.z-1
|
||||
minetest.env:set_node(pos, node)
|
||||
elseif param2 == 3 then
|
||||
node.name = "beds:bed_top"
|
||||
pos.x = pos.x-1
|
||||
minetest.env:set_node(pos, node)
|
||||
end
|
||||
end,
|
||||
|
||||
on_destruct = function(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local param2 = node.param2
|
||||
if param2 == 0 then
|
||||
pos.z = pos.z+1
|
||||
minetest.env:remove_node(pos)
|
||||
elseif param2 == 1 then
|
||||
pos.x = pos.x+1
|
||||
minetest.env:remove_node(pos)
|
||||
elseif param2 == 2 then
|
||||
pos.z = pos.z-1
|
||||
minetest.env:remove_node(pos)
|
||||
elseif param2 == 3 then
|
||||
pos.x = pos.x-1
|
||||
minetest.env:remove_node(pos)
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(pos, node, puncher)
|
||||
if not puncher:is_player() then
|
||||
return
|
||||
end
|
||||
if puncher:get_wielded_item():get_name() == "" then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local param2 = node.param2
|
||||
if param2 == 0 then
|
||||
pos.z = pos.z+1
|
||||
elseif param2 == 1 then
|
||||
pos.x = pos.x+1
|
||||
elseif param2 == 2 then
|
||||
pos.z = pos.z-1
|
||||
elseif param2 == 3 then
|
||||
pos.x = pos.x-1
|
||||
end
|
||||
if puncher:get_player_name() == meta:get_string("player") then
|
||||
if param2 == 0 then
|
||||
pos.x = pos.x-1
|
||||
elseif param2 == 1 then
|
||||
pos.z = pos.z+1
|
||||
elseif param2 == 2 then
|
||||
pos.x = pos.x+1
|
||||
elseif param2 == 3 then
|
||||
pos.z = pos.z-1
|
||||
end
|
||||
pos.y = pos.y-0.5
|
||||
puncher:setpos(pos)
|
||||
meta:set_string("player", "")
|
||||
player_in_bed = player_in_bed-1
|
||||
elseif meta:get_string("player") == "" then
|
||||
pos.y = pos.y-0.5
|
||||
puncher:setpos(pos)
|
||||
meta:set_string("player", puncher:get_player_name())
|
||||
player_in_bed = player_in_bed+1
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("beds:bed_top", {
|
||||
drawtype = "nodebox",
|
||||
tiles = {"beds_bed_top_top.png", "default_wood.png", "beds_bed_side_top_r.png", "beds_bed_side_top_l.png", "default_wood.png", "beds_bed_side.png"},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
-- bed
|
||||
{-0.5, 0.0, -0.5, 0.5, 0.3, 0.5},
|
||||
|
||||
-- stützen
|
||||
{-0.4, 0.0, 0.4, -0.5, -0.5, 0.5},
|
||||
{0.5, -0.5, 0.5, 0.4, 0.0, 0.4},
|
||||
}
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{0, 0, 0, 0, 0, 0},
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_alias("beds:bed", "beds:bed_bottom")
|
||||
|
||||
minetest.register_craft({
|
||||
output = "beds:bed",
|
||||
recipe = {
|
||||
{"wool:red", "wool:blue", "wool:blue", },
|
||||
{"default:stick", "", "default:stick", }
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_on_joinplayer(function(pl)
|
||||
player_ges = player_ges+1
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(pl)
|
||||
player_ges = player_ges-1
|
||||
end)
|
||||
|
||||
local timer = 0
|
||||
local wait = false
|
||||
minetest.register_globalstep(function(dtime)
|
||||
if timer<10 then
|
||||
timer = timer+dtime
|
||||
end
|
||||
timer = 0
|
||||
|
||||
if player_ges == player_in_bed and player_ges ~= 0 then
|
||||
if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.805 then
|
||||
if not wait then
|
||||
minetest.chat_send_all("Good night!!!")
|
||||
minetest.after(2, function()
|
||||
minetest.env:set_timeofday(0.23)
|
||||
wait = false
|
||||
end)
|
||||
wait = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"beds:bed_bottom"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("player") ~= "" then
|
||||
local param2 = node.param2
|
||||
if param2 == 0 then
|
||||
pos.z = pos.z+1
|
||||
elseif param2 == 1 then
|
||||
pos.x = pos.x+1
|
||||
elseif param2 == 2 then
|
||||
pos.z = pos.z-1
|
||||
elseif param2 == 3 then
|
||||
pos.x = pos.x-1
|
||||
end
|
||||
local player = minetest.env:get_player_by_name(meta:get_string("player"))
|
||||
if player == nil then
|
||||
meta:set_string("player", "")
|
||||
player_in_bed = player_in_bed-1
|
||||
return
|
||||
end
|
||||
local player_pos = player:getpos()
|
||||
player_pos.x = math.floor(0.5+player_pos.x)
|
||||
player_pos.y = math.floor(0.5+player_pos.y)
|
||||
player_pos.z = math.floor(0.5+player_pos.z)
|
||||
if pos.x ~= player_pos.x or pos.y ~= player_pos.y or pos.z ~= player_pos.z then
|
||||
meta:set_string("player", "")
|
||||
player_in_bed = player_in_bed-1
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
After Width: | Height: | Size: 536 B |
After Width: | Height: | Size: 500 B |
After Width: | Height: | Size: 502 B |
After Width: | Height: | Size: 539 B |
After Width: | Height: | Size: 605 B |
|
@ -0,0 +1,26 @@
|
|||
Minetest 0.4 mod: bucket
|
||||
=========================
|
||||
|
||||
License of source code:
|
||||
-----------------------
|
||||
Copyright (C) 2011-2012 Kahrl <kahrl@gmx.net>
|
||||
Copyright (C) 2011-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
|
||||
License of media (textures and sounds)
|
||||
--------------------------------------
|
||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
Authors of media files
|
||||
-----------------------
|
||||
Everything not listed in here:
|
||||
Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
default
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
-- Minetest 0.4 mod: bucket
|
||||
-- See README.txt for licensing and other information.
|
||||
|
||||
minetest.register_alias("bucket", "bucket:bucket_empty")
|
||||
minetest.register_alias("bucket_water", "bucket:bucket_water")
|
||||
minetest.register_alias("bucket_lava", "bucket:bucket_lava")
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'bucket:bucket_empty 1',
|
||||
recipe = {
|
||||
{'default:steel_ingot', '', 'default:steel_ingot'},
|
||||
{'', 'default:steel_ingot', ''},
|
||||
}
|
||||
})
|
||||
|
||||
bucket = {}
|
||||
bucket.liquids = {}
|
||||
|
||||
-- Register a new liquid
|
||||
-- source = name of the source node
|
||||
-- flowing = name of the flowing node
|
||||
-- itemname = name of the new bucket item (or nil if liquid is not takeable)
|
||||
-- inventory_image = texture of the new bucket item (ignored if itemname == nil)
|
||||
-- This function can be called from any mod (that depends on bucket).
|
||||
function bucket.register_liquid(source, flowing, itemname, inventory_image)
|
||||
bucket.liquids[source] = {
|
||||
source = source,
|
||||
flowing = flowing,
|
||||
itemname = itemname,
|
||||
}
|
||||
bucket.liquids[flowing] = bucket.liquids[source]
|
||||
|
||||
if itemname ~= nil then
|
||||
minetest.register_craftitem(itemname, {
|
||||
inventory_image = inventory_image,
|
||||
stack_max = 1,
|
||||
liquids_pointable = true,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
-- Must be pointing to node
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
-- Check if pointing to a liquid
|
||||
n = minetest.env:get_node(pointed_thing.under)
|
||||
if bucket.liquids[n.name] == nil then
|
||||
-- Not a liquid
|
||||
minetest.env:add_node(pointed_thing.above, {name=source})
|
||||
elseif n.name ~= source then
|
||||
-- It's a liquid
|
||||
minetest.env:add_node(pointed_thing.under, {name=source})
|
||||
end
|
||||
return {name="bucket:bucket_empty"}
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_craftitem("bucket:bucket_empty", {
|
||||
description = "Emtpy bucket",
|
||||
inventory_image = "bucket.png",
|
||||
stack_max = 1,
|
||||
liquids_pointable = true,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
-- Must be pointing to node
|
||||
if pointed_thing.type ~= "node" then
|
||||
return
|
||||
end
|
||||
-- Check if pointing to a liquid source
|
||||
n = minetest.env:get_node(pointed_thing.under)
|
||||
liquiddef = bucket.liquids[n.name]
|
||||
if liquiddef ~= nil and liquiddef.source == n.name and liquiddef.itemname ~= nil then
|
||||
minetest.env:add_node(pointed_thing.under, {name="air"})
|
||||
return {name=liquiddef.itemname}
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
bucket.register_liquid(
|
||||
"default:water_source",
|
||||
"default:water_flowing",
|
||||
"bucket:bucket_water",
|
||||
"bucket_water.png"
|
||||
)
|
||||
|
||||
bucket.register_liquid(
|
||||
"default:lava_source",
|
||||
"default:lava_flowing",
|
||||
"bucket:bucket_lava",
|
||||
"bucket_lava.png"
|
||||
)
|
||||
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "bucket:bucket_lava",
|
||||
burntime = 60,
|
||||
})
|
After Width: | Height: | Size: 353 B |
After Width: | Height: | Size: 482 B |
After Width: | Height: | Size: 440 B |
|
@ -0,0 +1,55 @@
|
|||
===CARTS MOD for MINETEST-C55===
|
||||
by PilzAdam
|
||||
|
||||
Version 29
|
||||
|
||||
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...).
|
||||
|
||||
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
|
||||
|
||||
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.
|
|
@ -0,0 +1,43 @@
|
|||
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'}
|
||||
}
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,17 @@
|
|||
local APPROXIMATION = 0.8
|
||||
|
||||
equals = function(num1, num2)
|
||||
if math.abs(num1-num2) <= APPROXIMATION then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
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
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,807 @@
|
|||
--=========
|
||||
-- Maximum speed of the cart
|
||||
--=========
|
||||
local MAX_SPEED = 4.5
|
||||
--=========
|
||||
-- Transport the player like a normal item
|
||||
-- Note: This is extremly laggy <- FIXME
|
||||
--=========
|
||||
TRANSPORT_PLAYER = true
|
||||
--=========
|
||||
-- The name of the Soundfile
|
||||
--=========
|
||||
SOUND_FILES = {
|
||||
{"carts_curved_rails", 2},
|
||||
{"carts_railway_crossover", 2},
|
||||
{"carts_straight_rails", 1},
|
||||
}
|
||||
|
||||
--=========
|
||||
-- The sound gain
|
||||
SOUND_GAIN = 0.8
|
||||
--=========
|
||||
|
||||
--=========
|
||||
-- Raillike nodes
|
||||
--=========
|
||||
RAILS = {"default:rail", "carts:meseconrail_off", "carts:meseconrail_on", "carts:meseconrail_stop_off", "carts:meseconrail_stop_on"}
|
||||
|
||||
local cart = {
|
||||
physical = true,
|
||||
collisionbox = {-0.425, -0.425, -0.425, 0.425, 0.425, 0.425},
|
||||
visual = "cube",
|
||||
textures = {"carts_cart_top.png", "carts_cart_bottom.png", "carts_cart_side.png", "carts_cart_side.png", "carts_cart_side.png", "carts_cart_side.png"},
|
||||
visual_size = {x=.85, y=.85, z=0.85},
|
||||
--Variables
|
||||
fahren = false, -- true when the cart drives
|
||||
fallen = false, -- true when the cart drives downhill
|
||||
bremsen = false, -- true when the cart brakes
|
||||
dir = nil, -- direction of the cart
|
||||
old_dir = nil, -- saves the direction when the cart stops
|
||||
items = {}, -- list with transported items
|
||||
weiche = {x=nil, y=nil, z=nil}, -- saves the position of the railroad switch (to prevent double direction changes)
|
||||
sound_handler = nil, -- soundhandler
|
||||
}
|
||||
|
||||
-- Returns the current speed of the cart
|
||||
function cart:get_speed()
|
||||
if self.dir == "x+" then
|
||||
return self.object:getvelocity().x
|
||||
elseif self.dir == "x-" then
|
||||
return -1*self.object:getvelocity().x
|
||||
elseif self.dir == "z+" then
|
||||
return self.object:getvelocity().z
|
||||
elseif self.dir == "z-" then
|
||||
return -1*self.object:getvelocity().z
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
-- Sets the current speed of the cart
|
||||
function cart:set_speed(speed)
|
||||
local newsp = {x=0, y=0, z=0}
|
||||
if self.dir == "x+" then
|
||||
newsp.x = speed
|
||||
elseif self.dir == "x-" then
|
||||
newsp.x = -1*speed
|
||||
elseif self.dir == "z+" then
|
||||
newsp.z = speed
|
||||
elseif self.dir == "z-" then
|
||||
newsp.z = -1*speed
|
||||
end
|
||||
self.object:setvelocity(newsp)
|
||||
end
|
||||
|
||||
-- Sets the acceleration of the cart
|
||||
function cart:set_acceleration(staerke)
|
||||
if self.dir == "x+" then
|
||||
self.object:setacceleration({x=staerke, y=-10, z=0})
|
||||
elseif self.dir == "x-" then
|
||||
self.object:setacceleration({x=-staerke, y=-10, z=0})
|
||||
elseif self.dir == "z+" then
|
||||
self.object:setacceleration({x=0, y=-10, z=staerke})
|
||||
elseif self.dir == "z-" then
|
||||
self.object:setacceleration({x=0, y=-10, z=-staerke})
|
||||
end
|
||||
end
|
||||
|
||||
-- Stops the cart
|
||||
function cart:stop()
|
||||
self.fahren = false
|
||||
self.bremsen = false
|
||||
self.items = {}
|
||||
self.fallen = false
|
||||
self.object:setacceleration({x = 0, y = -10, z = 0})
|
||||
self:set_speed(0)
|
||||
-- stop sound
|
||||
self:sound("stop")
|
||||
end
|
||||
|
||||
function cart:sound(arg)
|
||||
if arg == "stop" then
|
||||
if self.sound_handler ~= nil then
|
||||
minetest.sound_stop(self.sound_handler)
|
||||
self.sound_handler = nil
|
||||
end
|
||||
elseif arg == "continue" then
|
||||
if self.sound_handler == nil then
|
||||
return
|
||||
end
|
||||
minetest.sound_stop(self.sound_handler)
|
||||
local sound = SOUND_FILES[math.random(1, #SOUND_FILES)]
|
||||
self.sound_handler = minetest.sound_play(sound[1], {
|
||||
object = self.object,
|
||||
gain = SOUND_GAIN,
|
||||
})
|
||||
minetest.after(sound[2], function()
|
||||
self:sound("continue")
|
||||
end)
|
||||
elseif arg == "start" then
|
||||
local sound = SOUND_FILES[math.random(1, #SOUND_FILES)]
|
||||
self.sound_handler = minetest.sound_play(sound[1], {
|
||||
object = self.object,
|
||||
gain = SOUND_GAIN,
|
||||
})
|
||||
minetest.after(sound[2], function()
|
||||
self:sound("continue")
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns the direction the cart has to drive
|
||||
function cart:get_new_direction(pos)
|
||||
if pos == nil then
|
||||
pos = self.object:getpos()
|
||||
end
|
||||
if self.dir == nil then
|
||||
return nil
|
||||
end
|
||||
pos.x = math.floor(0.5+pos.x)
|
||||
pos.y = math.floor(0.5+pos.y)
|
||||
pos.z = math.floor(0.5+pos.z)
|
||||
if self.fallen then
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == rail then
|
||||
return "y-"
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.dir == "x+" then
|
||||
pos.x = pos.x+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
pos.x = pos.x-1
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("rail_direction") == "right" and not pos_equals(pos, self.weiche) then
|
||||
pos.z = pos.z+1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x, y=pos.y, z=pos.z-1}
|
||||
return "z+"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z-1
|
||||
elseif meta:get_string("rail_direction") == "left" and not pos_equals(pos, self.weiche) then
|
||||
pos.z = pos.z-1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x, y=pos.y, z=pos.z+1}
|
||||
return "z-"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z+1
|
||||
end
|
||||
|
||||
return "x+"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y-"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y+2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y+"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
pos.x = pos.x-1
|
||||
|
||||
local tmp = minetest.env:get_meta(pos):get_string("rail_direction")
|
||||
if tmp == "left" then
|
||||
pos.z = pos.z+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z+"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z-1
|
||||
elseif tmp == "right" then
|
||||
pos.z = pos.z-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z-"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z+1
|
||||
end
|
||||
|
||||
pos.z = pos.z-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z-"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z+2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z+"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z-1
|
||||
elseif self.dir == "x-" then
|
||||
pos.x = pos.x-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
pos.x = pos.x+1
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("rail_direction") == "left" and not pos_equals(pos, self.weiche) then
|
||||
pos.z = pos.z+1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x, y=pos.y, z=pos.z-1}
|
||||
return "z+"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z-1
|
||||
elseif meta:get_string("rail_direction") == "right" and not pos_equals(pos, self.weiche) then
|
||||
pos.z = pos.z-1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x, y=pos.y, z=pos.z+1}
|
||||
return "z-"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z+1
|
||||
end
|
||||
|
||||
return "x-"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y-"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y+2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y+"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
pos.x = pos.x+1
|
||||
|
||||
local tmp = minetest.env:get_meta(pos):get_string("rail_direction")
|
||||
if tmp == "left" then
|
||||
pos.z = pos.z-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z-"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z+1
|
||||
elseif tmp == "right" then
|
||||
pos.z = pos.z+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z+"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z-1
|
||||
end
|
||||
|
||||
pos.z = pos.z+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z+"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z-2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "z-"
|
||||
end
|
||||
end
|
||||
pos.z = pos.z+1
|
||||
elseif self.dir == "z+" then
|
||||
pos.z = pos.z+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
pos.z = pos.z-1
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("rail_direction") == "left" and not pos_equals(pos, self.weiche) then
|
||||
pos.x = pos.x+1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x-1, y=pos.y, z=pos.z}
|
||||
return "x+"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x-1
|
||||
elseif meta:get_string("rail_direction") == "right" and not pos_equals(pos, self.weiche) then
|
||||
pos.x = pos.x-1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x+1, y=pos.y, z=pos.z}
|
||||
return "x-"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x+1
|
||||
end
|
||||
|
||||
return "z+"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y-"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y+2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y+"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
pos.z = pos.z-1
|
||||
|
||||
local tmp = minetest.env:get_meta(pos):get_string("rail_direction")
|
||||
if tmp == "left" then
|
||||
pos.x = pos.x-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x-"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x+1
|
||||
elseif tmp == "right" then
|
||||
pos.x = pos.x+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x+"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x-1
|
||||
end
|
||||
|
||||
pos.x = pos.x+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x+"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x-2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x-"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x+1
|
||||
elseif self.dir == "z-" then
|
||||
pos.z = pos.z-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
pos.z = pos.z+1
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if meta:get_string("rail_direction") == "right" and not pos_equals(pos, self.weiche) then
|
||||
pos.x = pos.x+1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x-1, y=pos.y, z=pos.z}
|
||||
return "x+"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x-1
|
||||
elseif meta:get_string("rail_direction") == "left" and not pos_equals(pos, self.weiche) then
|
||||
pos.x = pos.x-1
|
||||
for i,rail1 in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail1 then
|
||||
self.weiche = {x=pos.x+1, y=pos.y, z=pos.z}
|
||||
return "x-"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x+1
|
||||
end
|
||||
|
||||
return "z-"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y-"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y+2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "y+"
|
||||
end
|
||||
end
|
||||
pos.y = pos.y-1
|
||||
pos.z = pos.z+1
|
||||
|
||||
local tmp = minetest.env:get_meta(pos):get_string("rail_direction")
|
||||
if tmp == "left" then
|
||||
pos.x = pos.x+1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x+"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x-1
|
||||
elseif tmp == "right" then
|
||||
pos.x = pos.x-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x-"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x+1
|
||||
end
|
||||
|
||||
pos.x = pos.x-1
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x-"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x+2
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
return "x+"
|
||||
end
|
||||
end
|
||||
pos.x = pos.x-1
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- This method does several things.
|
||||
function cart:on_step(dtime)
|
||||
-- if the cart dont drives set gravity and return
|
||||
if not self.fahren then
|
||||
self.object:setacceleration({x=0, y=-10, z=0})
|
||||
return
|
||||
end
|
||||
|
||||
local newdir = self:get_new_direction()
|
||||
if newdir == nil and not self.fallen then
|
||||
-- end of rail
|
||||
-- chek if the cart derailed
|
||||
local pos = self.object:getpos()
|
||||
if self.dir == "x+" then
|
||||
pos.x = pos.x-1
|
||||
elseif self.dir == "x-" then
|
||||
pos.x = pos.x+1
|
||||
elseif self.dir == "z+" then
|
||||
pos.z = pos.z-1
|
||||
elseif self.dir == "z-" then
|
||||
pos.z = pos.z+1
|
||||
end
|
||||
local checkdir = self:get_new_direction(pos)
|
||||
if checkdir ~= self.dir and checkdir ~= nil then
|
||||
self.object:setpos(pos)
|
||||
self.dir = checkdir
|
||||
self.old_dir = checkdir
|
||||
-- change direction
|
||||
local speed = self:get_speed()
|
||||
self:set_speed(speed)
|
||||
else
|
||||
-- stop
|
||||
self:stop()
|
||||
local pos = self.object:getpos()
|
||||
pos.x = math.floor(0.5+pos.x)
|
||||
pos.z = math.floor(0.5+pos.z)
|
||||
self.object:setpos(pos)
|
||||
end
|
||||
elseif newdir == "y+" then
|
||||
-- uphill
|
||||
self.fallen = false
|
||||
local vel = self.object:getvelocity()
|
||||
vel.y = MAX_SPEED
|
||||
self.object:setvelocity(vel)
|
||||
elseif newdir == "y-" then
|
||||
-- downhill
|
||||
local vel = self.object:getvelocity()
|
||||
vel.y = -2*MAX_SPEED
|
||||
self.object:setvelocity(vel)
|
||||
self.fallen = true
|
||||
elseif newdir ~= self.dir then
|
||||
-- curve
|
||||
self.fallen = false
|
||||
local pos = self.object:getpos()
|
||||
-- wait until the cart is nearly on the cornernode
|
||||
if equals(pos.x, math.floor(0.5+pos.x)) and equals(pos.y, math.floor(0.5+pos.y)) and equals(pos.z, math.floor(0.5+pos.z)) then
|
||||
-- "jump" exacly on the cornernode
|
||||
pos.x = math.floor(0.5+pos.x)
|
||||
pos.z = math.floor(0.5+pos.z)
|
||||
self.object:setpos(pos)
|
||||
-- change direction
|
||||
local speed = self:get_speed()
|
||||
self.dir = newdir
|
||||
self.old_dir = newdir
|
||||
self:set_speed(speed)
|
||||
end
|
||||
end
|
||||
|
||||
-- control speed and acceleration
|
||||
if self.bremsen then
|
||||
if not equals(self:get_speed(), 0) then
|
||||
-- if the cart is still driving -> brake
|
||||
self:set_acceleration(-10)
|
||||
else
|
||||
-- if the cart stand still -> stop
|
||||
self:stop()
|
||||
end
|
||||
else
|
||||
if self.fahren and self:get_speed() < MAX_SPEED then
|
||||
-- if the cart is too slow -> accelerate
|
||||
self:set_acceleration(10)
|
||||
else
|
||||
self:set_acceleration(0)
|
||||
end
|
||||
end
|
||||
|
||||
-- move items
|
||||
for i,item in ipairs(self.items) do
|
||||
if item:is_player() then
|
||||
-- if the item is a player move him 0.5 blocks lowlier
|
||||
local pos = self.object:getpos()
|
||||
pos.y = pos.y-0.5
|
||||
item:setpos(pos)
|
||||
else
|
||||
item:setpos(self.object:getpos())
|
||||
end
|
||||
end
|
||||
|
||||
-- if the cart isnt on a railroad switch reset the variable
|
||||
local pos_tmp = self.object:getpos()
|
||||
pos_tmp.x = math.floor(0.5+pos_tmp.x)
|
||||
pos_tmp.y = math.floor(0.5+pos_tmp.y)
|
||||
pos_tmp.z = math.floor(0.5+pos_tmp.z)
|
||||
if not pos_equals(pos_tmp, self.weiche) then
|
||||
self.weiche = {x=nil, y=nil, z=nil}
|
||||
end
|
||||
|
||||
-- search for chests
|
||||
for d=-1,1 do
|
||||
local pos = {x=self.object:getpos().x+d, y=self.object:getpos().y, z=self.object:getpos().z}
|
||||
local name1 = minetest.env:get_node(pos).name
|
||||
pos = {x=self.object:getpos().x, y=self.object:getpos().y, z=self.object:getpos().z+d}
|
||||
local name2 = minetest.env:get_node(pos).name
|
||||
if name1 == "carts:chest" then
|
||||
pos = {x=self.object:getpos().x+d, y=self.object:getpos().y, z=self.object:getpos().z}
|
||||
elseif name2 == "carts:chest" then
|
||||
pos = {x=self.object:getpos().x, y=self.object:getpos().y, z=self.object:getpos().z+d}
|
||||
else
|
||||
name1 = nil
|
||||
end
|
||||
if name1 ~= nil then
|
||||
pos.x = math.floor(0.5+pos.x)
|
||||
pos.y = math.floor(0.5+pos.y)
|
||||
pos.z = math.floor(0.5+pos.z)
|
||||
local inv = minetest.env:get_meta(pos):get_inventory()
|
||||
-- drop items
|
||||
local items_tmp = {}
|
||||
local inv = minetest.env:get_meta(pos):get_inventory()
|
||||
for i,item in ipairs(self.items) do
|
||||
if not item:is_player() and item:get_luaentity().itemstring ~= nil and item:get_luaentity().itemstring ~= "" and inv:room_for_item("in", ItemStack(item:get_luaentity().itemstring)) then
|
||||
if item:get_luaentity().pickup == nil or not pos_equals(pos, item:get_luaentity().pickup) then
|
||||
inv:add_item("in", ItemStack(item:get_luaentity().itemstring))
|
||||
item:remove()
|
||||
else
|
||||
table.insert(items_tmp, item)
|
||||
end
|
||||
else
|
||||
table.insert(items_tmp, item)
|
||||
end
|
||||
end
|
||||
self.items = items_tmp
|
||||
|
||||
--pick up items
|
||||
for i=1,inv:get_size("out") do
|
||||
local stack = inv:get_stack("out", i)
|
||||
if not stack:is_empty() then
|
||||
local item = minetest.env:add_entity(self.object:getpos(), "__builtin:item")
|
||||
item:get_luaentity():set_item(stack:get_name().." "..stack:get_count())
|
||||
item:get_luaentity().pickup = pos
|
||||
table.insert(self.items, item)
|
||||
inv:remove_item("out", stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- mesecons functions
|
||||
if minetest.get_modpath("mesecons") ~= nil then
|
||||
local pos = self.object:getpos()
|
||||
pos.x = math.floor(0.5+pos.x)
|
||||
pos.y = math.floor(0.5+pos.y)
|
||||
pos.z = math.floor(0.5+pos.z)
|
||||
local name = minetest.env:get_node(pos).name
|
||||
if name == "carts:meseconrail_off" then
|
||||
minetest.env:set_node(pos, {name="carts:meseconrail_on"})
|
||||
if mesecon ~= nil then
|
||||
mesecon:receptor_on(pos)
|
||||
end
|
||||
end
|
||||
|
||||
if name == "carts:meseconrail_stop_on" then
|
||||
self:stop()
|
||||
local pos = self.object:getpos()
|
||||
pos.x = math.floor(0.5+pos.x)
|
||||
pos.z = math.floor(0.5+pos.z)
|
||||
self.object:setpos(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- rightclick starts/stops the cart
|
||||
function cart:on_rightclick(clicker)
|
||||
if self.fahren then
|
||||
self.bremsen = true
|
||||
else
|
||||
-- find out the direction
|
||||
local pos_cart = self.object:getpos()
|
||||
local pos_player = clicker:getpos()
|
||||
local res = {x=pos_cart.x-pos_player.x, z=pos_cart.z-pos_player.z}
|
||||
if math.abs(res.x) > math.abs(res.z) then
|
||||
if res.x < 0 then
|
||||
self.dir = "x-"
|
||||
self.old_dir = "x-"
|
||||
if self:get_new_direction() ~= "x-" then
|
||||
if res.z < 0 then
|
||||
self.dir = "z-"
|
||||
self.old_dir = "z-"
|
||||
else
|
||||
self.dir = "z+"
|
||||
self.old_dir = "z+"
|
||||
end
|
||||
if self:get_new_direction() ~= self.dir then
|
||||
self.dir = "x-"
|
||||
self.old_dir = "x-"
|
||||
end
|
||||
end
|
||||
else
|
||||
self.dir = "x+"
|
||||
self.old_dir = "x+"
|
||||
if self:get_new_direction() ~= "x+" then
|
||||
if res.z < 0 then
|
||||
self.dir = "z-"
|
||||
self.old_dir = "z-"
|
||||
else
|
||||
self.dir = "z+"
|
||||
self.old_dir = "z+"
|
||||
end
|
||||
if self:get_new_direction() ~= self.dir then
|
||||
self.dir = "x+"
|
||||
self.old_dir = "x+"
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
if res.z < 0 then
|
||||
self.dir = "z-"
|
||||
self.old_dir = "z-"
|
||||
if self:get_new_direction() ~= "z-" then
|
||||
if res.x < 0 then
|
||||
self.dir = "x-"
|
||||
self.old_dir = "x-"
|
||||
else
|
||||
self.dir = "x+"
|
||||
self.old_dir = "x+"
|
||||
end
|
||||
if self:get_new_direction() ~= self.dir then
|
||||
self.dir = "z-"
|
||||
self.old_dir = "z-"
|
||||
end
|
||||
end
|
||||
else
|
||||
self.dir = "z+"
|
||||
self.old_dir = "z+"
|
||||
if self:get_new_direction() ~= "z+" then
|
||||
if res.x < 0 then
|
||||
self.dir = "x-"
|
||||
self.old_dir = "x-"
|
||||
else
|
||||
self.dir = "x+"
|
||||
self.old_dir = "x+"
|
||||
end
|
||||
if self:get_new_direction() ~= self.dir then
|
||||
self.dir = "z+"
|
||||
self.old_dir = "z+"
|
||||
end
|
||||
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
|
||||
|
||||
-- remove the cart and place it in the inventory
|
||||
function cart:on_punch(hitter)
|
||||
-- stop sound
|
||||
self:sound("stop")
|
||||
self.object:remove()
|
||||
hitter:get_inventory():add_item("main", "carts:cart")
|
||||
end
|
||||
|
||||
-- save the probprties of the cart if unloaded
|
||||
function cart:get_staticdata()
|
||||
local str = tostring(self.fahren)
|
||||
str = str..","
|
||||
if self.fahren then
|
||||
str = str..self.dir
|
||||
end
|
||||
self.object:setvelocity({x=0, y=0, z=0})
|
||||
return str
|
||||
end
|
||||
|
||||
-- set gravity
|
||||
function cart:on_activate(staticdata)
|
||||
self.object:setacceleration({x = 0, y = -10, z = 0})
|
||||
self.items = {}
|
||||
if staticdata ~= nil then
|
||||
-- if the cart was unloaded
|
||||
if string.find(staticdata, ",") ~= nil then
|
||||
-- restore the probprties
|
||||
if string.sub(staticdata, 1, string.find(staticdata, ",")-1)=="true" then
|
||||
self.dir = string.sub(staticdata, string.find(staticdata, ",")+1)
|
||||
self.old_dir = dir
|
||||
self.fahren = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity("carts:cart", cart)
|
||||
|
||||
-- inventoryitem
|
||||
minetest.register_craftitem("carts:cart", {
|
||||
description = "Cart",
|
||||
image = minetest.inventorycube("carts_cart_top.png", "carts_cart_side.png", "carts_cart_side.png"),
|
||||
wield_image = "carts_cart_top.png",
|
||||
stack_max = 1,
|
||||
-- replace it with the object
|
||||
on_place = function(itemstack, placer, pointed)
|
||||
local pos = pointed.under
|
||||
local bool = false
|
||||
for i,rail in ipairs(RAILS) do
|
||||
if minetest.env:get_node(pos).name == rail then
|
||||
bool = true
|
||||
end
|
||||
end
|
||||
if not bool then
|
||||
pos = pointed.above
|
||||
end
|
||||
pos = {x = math.floor(0.5+pos.x), y = math.floor(0.5+pos.y), z = math.floor(0.5+pos.z)}
|
||||
minetest.env:add_entity(pos, "carts:cart")
|
||||
itemstack:take_item(1)
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = '"carts:cart" 1',
|
||||
recipe = {
|
||||
{'default:steel_ingot', '', 'default:steel_ingot'},
|
||||
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'}
|
||||
}
|
||||
})
|
||||
|
||||
dofile(minetest.get_modpath("carts").."/switches.lua")
|
||||
dofile(minetest.get_modpath("carts").."/mesecons.lua")
|
||||
dofile(minetest.get_modpath("carts").."/chest.lua")
|
||||
dofile(minetest.get_modpath("carts").."/functions.lua")
|
|
@ -0,0 +1,248 @@
|
|||
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
|
|
@ -0,0 +1,235 @@
|
|||
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', ''},
|
||||
}
|
||||
})
|
After Width: | Height: | Size: 154 B |
After Width: | Height: | Size: 192 B |
After Width: | Height: | Size: 223 B |
After Width: | Height: | Size: 641 B |
After Width: | Height: | Size: 619 B |
After Width: | Height: | Size: 584 B |
After Width: | Height: | Size: 594 B |
After Width: | Height: | Size: 556 B |
After Width: | Height: | Size: 560 B |
After Width: | Height: | Size: 603 B |
After Width: | Height: | Size: 607 B |
After Width: | Height: | Size: 591 B |
After Width: | Height: | Size: 588 B |
After Width: | Height: | Size: 549 B |
After Width: | Height: | Size: 550 B |
After Width: | Height: | Size: 612 B |
After Width: | Height: | Size: 609 B |
After Width: | Height: | Size: 622 B |
After Width: | Height: | Size: 623 B |
|
@ -0,0 +1,22 @@
|
|||
Minetest 0.4 mod: creative
|
||||
==========================
|
||||
|
||||
Implements creative mode.
|
||||
|
||||
Switch on by using the "creative_mode" setting.
|
||||
|
||||
Registered items that
|
||||
- have a description, and
|
||||
- do not have the group not_in_creative_inventory
|
||||
are added to the creative inventory.
|
||||
|
||||
License of source code and media files:
|
||||
---------------------------------------
|
||||
Copyright (C) 2012 Perttu Ahola (celeron55) <celeron55@gmail.com>
|
||||
|
||||
This program is free software. It comes without any warranty, to
|
||||
the extent permitted by applicable law. You can redistribute it
|
||||
and/or modify it under the terms of the Do What The Fuck You Want
|
||||
To Public License, Version 2, as published by Sam Hocevar. See
|
||||
http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
-- minetest/creative/init.lua
|
||||
|
||||
local creative_inventory = {}
|
||||
|
||||
-- Create detached creative inventory after loading all mods
|
||||
minetest.after(0, function()
|
||||
local inv = minetest.create_detached_inventory("creative", {
|
||||
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return -1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_take = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return -1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
end,
|
||||
on_take = function(inv, listname, index, stack, player)
|
||||
print(player:get_player_name().." takes item from creative inventory; listname="..dump(listname)..", index="..dump(index)..", stack="..dump(stack))
|
||||
if stack then
|
||||
print("stack:get_name()="..dump(stack:get_name())..", stack:get_count()="..dump(stack:get_count()))
|
||||
end
|
||||
end,
|
||||
})
|
||||
local creative_list = {}
|
||||
for name,def in pairs(minetest.registered_items) do
|
||||
if (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
|
||||
and def.description and def.description ~= "" then
|
||||
table.insert(creative_list, name)
|
||||
end
|
||||
end
|
||||
table.sort(creative_list)
|
||||
inv:set_size("main", #creative_list)
|
||||
for _,itemstring in ipairs(creative_list) do
|
||||
local stack = ItemStack(itemstring)
|
||||
-- Make a stack of the right number of items
|
||||
local stack2 = nil
|
||||
if stack:get_stack_max() == 1 then
|
||||
stack2 = ItemStack(stack:get_name())
|
||||
else
|
||||
-- Insert half full so that a taken stack can be put back
|
||||
stack2 = ItemStack(stack:get_name().." "..(stack:get_stack_max()/2))
|
||||
end
|
||||
inv:add_item("main", stack2)
|
||||
end
|
||||
creative_inventory.creative_inventory_size = #creative_list
|
||||
print("creative inventory size: "..dump(creative_inventory.creative_inventory_size))
|
||||
end)
|
||||
|
||||
creative_inventory.set_creative_formspec = function(player, start_i, pagenum)
|
||||
pagenum = math.floor(pagenum)
|
||||
local pagemax = math.floor((creative_inventory.creative_inventory_size-1) / (6*4) + 1)
|
||||
player:set_inventory_formspec("size[13,7.5]"..
|
||||
--"image[6,0.6;1,2;player.png]"..
|
||||
"list[current_player;main;5,3.5;8,4;]"..
|
||||
"list[current_player;craft;8,0;3,3;]"..
|
||||
"list[current_player;craftpreview;12,1;1,1;]"..
|
||||
"list[detached:creative;main;0.3,0.5;4,6;"..tostring(start_i).."]"..
|
||||
"label[2.0,6.55;"..tostring(pagenum).."/"..tostring(pagemax).."]"..
|
||||
"button[0.3,6.5;1.6,1;creative_prev;<<]"..
|
||||
"button[2.7,6.5;1.6,1;creative_next;>>]")
|
||||
end
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
-- If in creative mode, modify player's inventory forms
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
return
|
||||
end
|
||||
creative_inventory.set_creative_formspec(player, 0, 1)
|
||||
end)
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
if not minetest.setting_getbool("creative_mode") then
|
||||
return
|
||||
end
|
||||
-- Figure out current page from formspec
|
||||
local current_page = 0
|
||||
local formspec = player:get_inventory_formspec()
|
||||
local start_i = string.match(formspec, "list%[detached:creative;main;[%d.]+,[%d.]+;[%d.]+,[%d.]+;(%d+)%]")
|
||||
start_i = tonumber(start_i) or 0
|
||||
|
||||
if fields.creative_prev then
|
||||
start_i = start_i - 4*6
|
||||
end
|
||||
if fields.creative_next then
|
||||
start_i = start_i + 4*6
|
||||
end
|
||||
|
||||
if start_i < 0 then
|
||||
start_i = start_i + 4*6
|
||||
end
|
||||
if start_i >= creative_inventory.creative_inventory_size then
|
||||
start_i = start_i - 4*6
|
||||
end
|
||||
|
||||
if start_i < 0 or start_i >= creative_inventory.creative_inventory_size then
|
||||
start_i = 0
|
||||
end
|
||||
|
||||
creative_inventory.set_creative_formspec(player, start_i, start_i / (6*4) + 1)
|
||||
end)
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
minetest.register_on_dieplayer(function(player)
|
||||
local inv = player:get_inventory()
|
||||
local pos = player:getpos()
|
||||
for i,stack in ipairs(inv:get_list("main")) do
|
||||
local x = math.random(0, 9)/3
|
||||
local z = math.random(0, 9)/3
|
||||
pos.x = pos.x + x
|
||||
pos.z = pos.z + z
|
||||
minetest.env:add_item(pos, stack)
|
||||
stack:clear()
|
||||
inv:set_stack("main", i, stack)
|
||||
pos.x = pos.x - x
|
||||
pos.z = pos.z - z
|
||||
end
|
||||
end)
|
|
@ -0,0 +1,64 @@
|
|||
Minetest 0.4 mod: default
|
||||
==========================
|
||||
|
||||
License of source code:
|
||||
-----------------------
|
||||
Copyright (C) 2011-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
|
||||
License of media (textures and sounds)
|
||||
--------------------------------------
|
||||
Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
|
||||
http://creativecommons.org/licenses/by-sa/3.0/
|
||||
|
||||
Authors of media files
|
||||
-----------------------
|
||||
Everything not listed in here:
|
||||
Copyright (C) 2010-2012 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
Originating from work by kddekadenz/Dogers:
|
||||
default_grass_footstep.{1,2,3}.ogg
|
||||
default_dig_crumbly.{1,2}.ogg
|
||||
|
||||
Cisoun's WTFPL texture pack:
|
||||
default_chest_front.png
|
||||
default_chest_lock.png
|
||||
default_chest_side.png
|
||||
default_chest_top.png
|
||||
default_cobble.png
|
||||
default_dirt.png
|
||||
default_grass.png
|
||||
default_grass_side.png
|
||||
default_jungletree.png
|
||||
default_jungletree_top.png
|
||||
default_lava.png
|
||||
default_leaves.png
|
||||
default_mossycobble.png
|
||||
default_sand.png
|
||||
default_sapling.png
|
||||
default_sign_wall.png
|
||||
default_stone.png
|
||||
default_tool_mesepick.png
|
||||
default_tool_steelpick.png
|
||||
default_tool_steelshovel.png
|
||||
default_tool_steelsword.png
|
||||
default_tool_stonepick.png
|
||||
default_tool_stoneshovel.png
|
||||
default_tool_woodpick.png
|
||||
default_tool_woodshovel.png
|
||||
default_tree.png
|
||||
default_tree_top.png
|
||||
default_water.png
|
||||
|
||||
Originating from G4JC's Almost MC Texture Pack:
|
||||
default_wood.png
|
||||
default_torch.png
|
||||
default_torch_on_ceiling.png
|
||||
default_torch_on_floor.png
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
-- minetest/default/leafdecay.lua
|
||||
|
||||
-- To enable leaf decay for a node, add it to the "leafdecay" group.
|
||||
--
|
||||
-- The rating of the group determines how far from a node in the group "tree"
|
||||
-- the node can be without decaying.
|
||||
--
|
||||
-- If param2 of the node is ~= 0, the node will always be preserved. Thus, if
|
||||
-- the player places a node of that kind, you will want to set param2=1 or so.
|
||||
|
||||
default.leafdecay_trunk_cache = {}
|
||||
default.leafdecay_enable_cache = true
|
||||
-- Spread the load of finding trunks
|
||||
default.leafdecay_trunk_find_allow_accumulator = 0
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
local finds_per_second = 5000
|
||||
default.leafdecay_trunk_find_allow_accumulator =
|
||||
math.floor(dtime * finds_per_second)
|
||||
end)
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:leafdecay"},
|
||||
neighbors = {"air", "group:liquid"},
|
||||
-- A low interval and a high inverse chance spreads the load
|
||||
interval = 2,
|
||||
chance = 5,
|
||||
|
||||
action = function(p0, node, _, _)
|
||||
--print("leafdecay ABM at "..p0.x..", "..p0.y..", "..p0.z..")")
|
||||
local do_preserve = false
|
||||
local d = minetest.registered_nodes[node.name].groups.leafdecay
|
||||
if not d or d == 0 then
|
||||
--print("not groups.leafdecay")
|
||||
return
|
||||
end
|
||||
local n0 = minetest.env:get_node(p0)
|
||||
if n0.param2 ~= 0 then
|
||||
--print("param2 ~= 0")
|
||||
return
|
||||
end
|
||||
local p0_hash = nil
|
||||
if default.leafdecay_enable_cache then
|
||||
p0_hash = minetest.hash_node_position(p0)
|
||||
local trunkp = default.leafdecay_trunk_cache[p0_hash]
|
||||
if trunkp then
|
||||
local n = minetest.env:get_node(trunkp)
|
||||
local reg = minetest.registered_nodes[n.name]
|
||||
-- Assume ignore is a trunk, to make the thing work at the border of the active area
|
||||
if n.name == "ignore" or (reg.groups.tree and reg.groups.tree ~= 0) then
|
||||
--print("cached trunk still exists")
|
||||
return
|
||||
end
|
||||
--print("cached trunk is invalid")
|
||||
-- Cache is invalid
|
||||
table.remove(default.leafdecay_trunk_cache, p0_hash)
|
||||
end
|
||||
end
|
||||
if default.leafdecay_trunk_find_allow_accumulator <= 0 then
|
||||
return
|
||||
end
|
||||
default.leafdecay_trunk_find_allow_accumulator =
|
||||
default.leafdecay_trunk_find_allow_accumulator - 1
|
||||
-- Assume ignore is a trunk, to make the thing work at the border of the active area
|
||||
local p1 = minetest.env:find_node_near(p0, d, {"ignore", "group:tree"})
|
||||
if p1 then
|
||||
do_preserve = true
|
||||
if default.leafdecay_enable_cache then
|
||||
--print("caching trunk")
|
||||
-- Cache the trunk
|
||||
default.leafdecay_trunk_cache[p0_hash] = p1
|
||||
end
|
||||
end
|
||||
if not do_preserve then
|
||||
-- Drop stuff other than the node itself
|
||||
itemstacks = minetest.get_node_drops(n0.name)
|
||||
for _, itemname in ipairs(itemstacks) do
|
||||
if itemname ~= n0.name then
|
||||
local p_drop = {
|
||||
x = p0.x - 0.5 + math.random(),
|
||||
y = p0.y - 0.5 + math.random(),
|
||||
z = p0.z - 0.5 + math.random(),
|
||||
}
|
||||
minetest.env:add_item(p_drop, itemname)
|
||||
end
|
||||
end
|
||||
-- Remove node
|
||||
minetest.env:remove_node(p0)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
@ -0,0 +1,275 @@
|
|||
-- minetest/default/mapgen.lua
|
||||
|
||||
--
|
||||
-- Aliases for map generator outputs
|
||||
--
|
||||
|
||||
minetest.register_alias("mapgen_air", "air")
|
||||
minetest.register_alias("mapgen_stone", "default:stone")
|
||||
minetest.register_alias("mapgen_tree", "default:tree")
|
||||
minetest.register_alias("mapgen_leaves", "default:leaves")
|
||||
minetest.register_alias("mapgen_apple", "default:apple")
|
||||
minetest.register_alias("mapgen_water_source", "default:water_source")
|
||||
minetest.register_alias("mapgen_dirt", "default:dirt")
|
||||
minetest.register_alias("mapgen_sand", "default:sand")
|
||||
minetest.register_alias("mapgen_gravel", "default:gravel")
|
||||
minetest.register_alias("mapgen_clay", "default:clay")
|
||||
minetest.register_alias("mapgen_lava_source", "default:lava_source")
|
||||
minetest.register_alias("mapgen_cobble", "default:cobble")
|
||||
minetest.register_alias("mapgen_mossycobble", "default:mossycobble")
|
||||
minetest.register_alias("mapgen_dirt_with_grass", "default:dirt_with_grass")
|
||||
minetest.register_alias("mapgen_junglegrass", "default:junglegrass")
|
||||
minetest.register_alias("mapgen_stone_with_coal", "default:stone_with_coal")
|
||||
minetest.register_alias("mapgen_stone_with_iron", "default:stone_with_iron")
|
||||
minetest.register_alias("mapgen_mese", "default:mese")
|
||||
minetest.register_alias("mapgen_desert_sand", "default:desert_sand")
|
||||
minetest.register_alias("mapgen_desert_stone", "default:desert_stone")
|
||||
|
||||
--
|
||||
-- Ore generation
|
||||
--
|
||||
|
||||
local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, chunk_size, ore_per_chunk, height_min, height_max)
|
||||
if maxp.y < height_min or minp.y > height_max then
|
||||
return
|
||||
end
|
||||
local y_min = math.max(minp.y, height_min)
|
||||
local y_max = math.min(maxp.y, height_max)
|
||||
local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
|
||||
local pr = PseudoRandom(seed)
|
||||
local num_chunks = math.floor(chunks_per_volume * volume)
|
||||
local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
|
||||
--print("generate_ore num_chunks: "..dump(num_chunks))
|
||||
for i=1,num_chunks do
|
||||
local y0 = pr:next(y_min, y_max-chunk_size+1)
|
||||
if y0 >= height_min and y0 <= height_max then
|
||||
local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
|
||||
local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
|
||||
local p0 = {x=x0, y=y0, z=z0}
|
||||
for x1=0,chunk_size-1 do
|
||||
for y1=0,chunk_size-1 do
|
||||
for z1=0,chunk_size-1 do
|
||||
if pr:next(1,inverse_chance) == 1 then
|
||||
local x2 = x0+x1
|
||||
local y2 = y0+y1
|
||||
local z2 = z0+z1
|
||||
local p2 = {x=x2, y=y2, z=z2}
|
||||
if minetest.env:get_node(p2).name == wherein then
|
||||
minetest.env:set_node(p2, {name=name})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--print("generate_ore done")
|
||||
end
|
||||
|
||||
function default.make_papyrus(pos, size)
|
||||
for y=0,size-1 do
|
||||
local p = {x=pos.x, y=pos.y+y, z=pos.z}
|
||||
minetest.env:set_node(p, {name="default:papyrus"})
|
||||
end
|
||||
end
|
||||
|
||||
function default.make_cactus(pos, size)
|
||||
for y=0,size-1 do
|
||||
local p = {x=pos.x, y=pos.y+y, z=pos.z}
|
||||
minetest.env:set_node(p, {name="default:cactus"})
|
||||
end
|
||||
end
|
||||
|
||||
-- facedir: 0/1/2/3 (head node facedir value)
|
||||
-- length: length of rainbow tail
|
||||
function default.make_nyancat(pos, facedir, length)
|
||||
local tailvec = {x=0, y=0, z=0}
|
||||
if facedir == 0 then
|
||||
tailvec.z = 1
|
||||
elseif facedir == 1 then
|
||||
tailvec.x = 1
|
||||
elseif facedir == 2 then
|
||||
tailvec.z = -1
|
||||
elseif facedir == 3 then
|
||||
tailvec.x = -1
|
||||
else
|
||||
print("default.make_nyancat(): Invalid facedir: "+dump(facedir))
|
||||
facedir = 0
|
||||
tailvec.z = 1
|
||||
end
|
||||
local p = {x=pos.x, y=pos.y, z=pos.z}
|
||||
minetest.env:set_node(p, {name="default:nyancat", param2=facedir})
|
||||
for i=1,length do
|
||||
p.x = p.x + tailvec.x
|
||||
p.z = p.z + tailvec.z
|
||||
minetest.env:set_node(p, {name="default:nyancat_rainbow"})
|
||||
end
|
||||
end
|
||||
|
||||
function generate_nyancats(seed, minp, maxp)
|
||||
local height_min = -31000
|
||||
local height_max = -32
|
||||
if maxp.y < height_min or minp.y > height_max then
|
||||
return
|
||||
end
|
||||
local y_min = math.max(minp.y, height_min)
|
||||
local y_max = math.min(maxp.y, height_max)
|
||||
local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
|
||||
local pr = PseudoRandom(seed + 9324342)
|
||||
local max_num_nyancats = math.floor(volume / (16*16*16))
|
||||
for i=1,max_num_nyancats do
|
||||
if pr:next(0, 1000) == 0 then
|
||||
local x0 = pr:next(minp.x, maxp.x)
|
||||
local y0 = pr:next(minp.y, maxp.y)
|
||||
local z0 = pr:next(minp.z, maxp.z)
|
||||
local p0 = {x=x0, y=y0, z=z0}
|
||||
default.make_nyancat(p0, pr:next(0,3), pr:next(3,15))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
-- Generate regular ores
|
||||
generate_ore("default:stone_with_coal", "default:stone", minp, maxp, seed+0, 1/8/8/8, 3, 8, -31000, 64)
|
||||
generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+1, 1/12/12/12, 2, 3, -15, 2)
|
||||
generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+2, 1/9/9/9, 3, 5, -63, -16)
|
||||
generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+3, 1/7/7/7, 3, 5, -31000, -64)
|
||||
generate_ore("default:mese", "default:stone", minp, maxp, seed+4, 1/16/16/16, 2, 3, -127, -64)
|
||||
generate_ore("default:mese", "default:stone", minp, maxp, seed+5, 1/9/9/9, 3, 5, -31000,-128)
|
||||
|
||||
generate_ore("default:stone_with_coal", "default:stone", minp, maxp, seed+7, 1/24/24/24, 6,27, -31000, 0)
|
||||
generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+6, 1/24/24/24, 6,27, -31000, -64)
|
||||
|
||||
if maxp.y >= 2 and minp.y <= 0 then
|
||||
-- Generate clay
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 4
|
||||
local divs = (maxp.x-minp.x)/divlen+1;
|
||||
for divx=0+1,divs-1-1 do
|
||||
for divz=0+1,divs-1-1 do
|
||||
local cx = minp.x + math.floor((divx+0.5)*divlen)
|
||||
local cz = minp.z + math.floor((divz+0.5)*divlen)
|
||||
if minetest.env:get_node({x=cx,y=1,z=cz}).name == "default:water_source" and
|
||||
minetest.env:get_node({x=cx,y=0,z=cz}).name == "default:sand" then
|
||||
local is_shallow = true
|
||||
local num_water_around = 0
|
||||
if minetest.env:get_node({x=cx-divlen*2,y=1,z=cz+0}).name == "default:water_source" then
|
||||
num_water_around = num_water_around + 1 end
|
||||
if minetest.env:get_node({x=cx+divlen*2,y=1,z=cz+0}).name == "default:water_source" then
|
||||
num_water_around = num_water_around + 1 end
|
||||
if minetest.env:get_node({x=cx+0,y=1,z=cz-divlen*2}).name == "default:water_source" then
|
||||
num_water_around = num_water_around + 1 end
|
||||
if minetest.env:get_node({x=cx+0,y=1,z=cz+divlen*2}).name == "default:water_source" then
|
||||
num_water_around = num_water_around + 1 end
|
||||
if num_water_around >= 2 then
|
||||
is_shallow = false
|
||||
end
|
||||
if is_shallow then
|
||||
for x1=-divlen,divlen do
|
||||
for z1=-divlen,divlen do
|
||||
if minetest.env:get_node({x=cx+x1,y=0,z=cz+z1}).name == "default:sand" then
|
||||
minetest.env:set_node({x=cx+x1,y=0,z=cz+z1}, {name="default:clay"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Generate papyrus
|
||||
local perlin1 = minetest.env:get_perlin(354, 3, 0.7, 100)
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 8
|
||||
local divs = (maxp.x-minp.x)/divlen+1;
|
||||
for divx=0,divs-1 do
|
||||
for divz=0,divs-1 do
|
||||
local x0 = minp.x + math.floor((divx+0)*divlen)
|
||||
local z0 = minp.z + math.floor((divz+0)*divlen)
|
||||
local x1 = minp.x + math.floor((divx+1)*divlen)
|
||||
local z1 = minp.z + math.floor((divz+1)*divlen)
|
||||
-- Determine papyrus amount from perlin noise
|
||||
local papyrus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 45 - 20)
|
||||
-- Find random positions for papyrus based on this random
|
||||
local pr = PseudoRandom(seed+1)
|
||||
for i=0,papyrus_amount do
|
||||
local x = pr:next(x0, x1)
|
||||
local z = pr:next(z0, z1)
|
||||
if minetest.env:get_node({x=x,y=1,z=z}).name == "default:dirt_with_grass" and
|
||||
minetest.env:find_node_near({x=x,y=1,z=z}, 1, "default:water_source") then
|
||||
default.make_papyrus({x=x,y=2,z=z}, pr:next(2, 4))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Generate cactuses
|
||||
local perlin1 = minetest.env:get_perlin(230, 3, 0.6, 100)
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 16
|
||||
local divs = (maxp.x-minp.x)/divlen+1;
|
||||
for divx=0,divs-1 do
|
||||
for divz=0,divs-1 do
|
||||
local x0 = minp.x + math.floor((divx+0)*divlen)
|
||||
local z0 = minp.z + math.floor((divz+0)*divlen)
|
||||
local x1 = minp.x + math.floor((divx+1)*divlen)
|
||||
local z1 = minp.z + math.floor((divz+1)*divlen)
|
||||
-- Determine cactus amount from perlin noise
|
||||
local cactus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 6 - 3)
|
||||
-- Find random positions for cactus based on this random
|
||||
local pr = PseudoRandom(seed+1)
|
||||
for i=0,cactus_amount do
|
||||
local x = pr:next(x0, x1)
|
||||
local z = pr:next(z0, z1)
|
||||
-- Find ground level (0...15)
|
||||
local ground_y = nil
|
||||
for y=30,0,-1 do
|
||||
if minetest.env:get_node({x=x,y=y,z=z}).name ~= "air" then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
end
|
||||
-- If desert sand, make cactus
|
||||
if ground_y and minetest.env:get_node({x=x,y=ground_y,z=z}).name == "default:desert_sand" then
|
||||
default.make_cactus({x=x,y=ground_y+1,z=z}, pr:next(3, 4))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Generate dry shrubs
|
||||
local perlin1 = minetest.env:get_perlin(329, 3, 0.6, 100)
|
||||
-- Assume X and Z lengths are equal
|
||||
local divlen = 16
|
||||
local divs = (maxp.x-minp.x)/divlen+1;
|
||||
for divx=0,divs-1 do
|
||||
for divz=0,divs-1 do
|
||||
local x0 = minp.x + math.floor((divx+0)*divlen)
|
||||
local z0 = minp.z + math.floor((divz+0)*divlen)
|
||||
local x1 = minp.x + math.floor((divx+1)*divlen)
|
||||
local z1 = minp.z + math.floor((divz+1)*divlen)
|
||||
-- Determine cactus amount from perlin noise
|
||||
local cactus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 5 + 0)
|
||||
-- Find random positions for cactus based on this random
|
||||
local pr = PseudoRandom(seed+1)
|
||||
for i=0,cactus_amount do
|
||||
local x = pr:next(x0, x1)
|
||||
local z = pr:next(z0, z1)
|
||||
-- Find ground level (0...15)
|
||||
local ground_y = nil
|
||||
for y=30,0,-1 do
|
||||
if minetest.env:get_node({x=x,y=y,z=z}).name ~= "air" then
|
||||
ground_y = y
|
||||
break
|
||||
end
|
||||
end
|
||||
-- If desert sand, make cactus
|
||||
if ground_y and minetest.env:get_node({x=x,y=ground_y,z=z}).name == "default:desert_sand" then
|
||||
minetest.env:set_node({x=x,y=ground_y+1,z=z}, {name="default:dry_shrub"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Generate nyan cats
|
||||
generate_nyancats(seed, minp, maxp)
|
||||
end)
|
||||
|
After Width: | Height: | Size: 539 B |
After Width: | Height: | Size: 361 B |
After Width: | Height: | Size: 439 B |
After Width: | Height: | Size: 465 B |
After Width: | Height: | Size: 637 B |
After Width: | Height: | Size: 543 B |
After Width: | Height: | Size: 395 B |
After Width: | Height: | Size: 523 B |
After Width: | Height: | Size: 523 B |
After Width: | Height: | Size: 469 B |
After Width: | Height: | Size: 434 B |