First push
|
@ -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,103 @@
|
|||
-- 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 buildable node
|
||||
n = minetest.env:get_node(pointed_thing.under)
|
||||
if minetest.registered_nodes[n.name].buildable_to then
|
||||
-- buildable; replace the node
|
||||
minetest.env:add_node(pointed_thing.under, {name=source})
|
||||
else
|
||||
-- not buildable to; place the liquid above
|
||||
-- check if the node above can be replaced
|
||||
n = minetest.env:get_node(pointed_thing.above)
|
||||
if minetest.registered_nodes[n.name].buildable_to then
|
||||
minetest.env:add_node(pointed_thing.above,{name=source})
|
||||
else
|
||||
-- do not remove the bucket with the liquid
|
||||
return
|
||||
end
|
||||
end
|
||||
return {name="bucket:bucket_empty"}
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_craftitem("bucket:bucket_empty", {
|
||||
description = "Empty 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: 329 B |
After Width: | Height: | Size: 363 B |
After Width: | Height: | Size: 369 B |
|
@ -0,0 +1 @@
|
|||
default
|
|
@ -0,0 +1,130 @@
|
|||
--disable the crafting and shrink inventory size
|
||||
local no_craft = {}
|
||||
|
||||
no_craft.set_creative_formspec = function(player)
|
||||
player:set_inventory_formspec("size[3,3]"..
|
||||
"list[current_player;main;0,0;3,3;]")
|
||||
player:get_inventory():set_size("main", 3*3) --NotNick's contribution
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if not minetest.setting_getbool("creative_mode") == false then
|
||||
return
|
||||
end
|
||||
no_craft.set_creative_formspec(player, 0, 1)
|
||||
end)
|
||||
|
||||
minetest.register_on_dignode(function(pos, newnode, placer, oldnode)
|
||||
if placer:get_inventory():get_stack("main", 4):get_name() ~= "" then
|
||||
print(newnode.name)
|
||||
end
|
||||
end)
|
||||
|
||||
--oddly breakable by hand is no longer allowed
|
||||
minetest.register_item(":", {
|
||||
type = "none",
|
||||
wield_image = "wieldhand.png",
|
||||
wield_scale = {x=1,y=1,z=2.5},
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 0.9,
|
||||
max_drop_level = 0,
|
||||
groupcaps = {
|
||||
fleshy = {times={[2]=0.75, [3]=0.6}, uses=0, maxlevel=1},
|
||||
crumbly = {times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1},
|
||||
snappy = {times={[3]=0.40}, uses=0, maxlevel=1},
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
--craft node in which you can craft items automatically.
|
||||
function autocraft(inventory)
|
||||
local recipe=inventory:get_list("recipe")
|
||||
local result
|
||||
local new
|
||||
for i=1,9 do
|
||||
recipe[i]=ItemStack({name=recipe[i]:get_name(),count=1})
|
||||
end
|
||||
result,new=minetest.get_craft_result({method="normal",width=3,items=recipe})
|
||||
local input=inventory:get_list("input")
|
||||
if result.item:is_empty() then return end
|
||||
result=result.item
|
||||
local to_use={}
|
||||
for _,item in ipairs(recipe) do
|
||||
if item~=nil and not item:is_empty() then
|
||||
if to_use[item:get_name()]==nil then
|
||||
to_use[item:get_name()]=1
|
||||
else
|
||||
to_use[item:get_name()]=to_use[item:get_name()]+1
|
||||
end
|
||||
end
|
||||
end
|
||||
local stack
|
||||
for itemname,number in pairs(to_use) do
|
||||
stack=ItemStack({name=itemname, count=number})
|
||||
if not inventory:contains_item("src",stack) then return end
|
||||
end
|
||||
for itemname,number in pairs(to_use) do
|
||||
stack=ItemStack({name=itemname, count=number})
|
||||
inventory:remove_item("src",stack)
|
||||
end
|
||||
inventory:add_item("dst",result)
|
||||
for i=1,9 do
|
||||
inventory:add_item("dst",new.items[i])
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("civilization:factory",{
|
||||
description = "Craft items (automatically)",
|
||||
drawtype="normal",
|
||||
tiles={"civilization_factory.png"},
|
||||
groups={cracky=1,tubedevice=1,tubedevice_receiver=1},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:add_item("src",stack)
|
||||
end,
|
||||
can_insert=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:room_for_item("src",stack)
|
||||
end,
|
||||
input_inventory="dst"},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"size[6.5,6.5]"..
|
||||
"list[current_name;recipe;0,3.5;3,3;]"..
|
||||
"list[current_name;src;3.5,0;3,3;]"..
|
||||
"list[current_name;dst;3.5,3.5;3,3;]"..
|
||||
"list[current_player;main;0,0;3,3;]")
|
||||
meta:set_string("infotext", "Factory")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("src",3*3)
|
||||
inv:set_size("recipe",3*3)
|
||||
inv:set_size("dst",3*3)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return (inv:is_empty("src") and inv:is_empty("recipe") and inv:is_empty("dst"))
|
||||
end})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames={"civilization:factory"},
|
||||
interval=3,
|
||||
chance=1,
|
||||
action=function(pos,node)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
autocraft(inv)
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'civilization:factory',
|
||||
recipe = {
|
||||
{'default:mese', 'default:steel_ingot', 'default:mese'},
|
||||
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
|
||||
{'default:mese', 'default:steel_ingot', 'default:mese'},
|
||||
}
|
||||
})
|
|
@ -0,0 +1,22 @@
|
|||
_______ ___ __ __ ___ ___ ___ _______ _______ _______ ___ _______ __ _
|
||||
| || | | | | || | | | | | | || _ || || | | || | | |
|
||||
| || | | |_| || | | | | | |____ || |_| ||_ _|| | | _ || |_| |
|
||||
| || | | || | | | | | ____| || | | | | | | | | || |
|
||||
| _|| | | || | | |___ | | | ______|| | | | | | | |_| || _ |
|
||||
| |_ | | | | | | | || | | |_____ | _ | | | | | | || | | |
|
||||
|_______||___| |___| |___| |_______||___| |_______||__| |__| |___| |___| |_______||_| |__|
|
||||
|
||||
BY: bas080
|
||||
DESCRIPTION: Civilization minetest mod aims for collaborative gameplay
|
||||
VERSION: 0.1
|
||||
LICENCE: WTFPL
|
||||
FORUM: http://forum.minetest.net/viewtopic.php?id=4542
|
||||
|
||||
Changelog
|
||||
---------
|
||||
0.1
|
||||
* Removes craft grid from inventory
|
||||
* Reduces inventory size to 9 slots
|
||||
* Adds a craft node (factory)
|
||||
* oddly breakable by hand is dsiabled (wood requires axe)
|
||||
* Craft for factory
|
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 529 B |
|
@ -0,0 +1,390 @@
|
|||
--[[
|
||||
|
||||
Craft Guide for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-craft_guide
|
||||
License: GPLv3
|
||||
|
||||
CRAFT GUIDE API
|
||||
|
||||
]]--
|
||||
|
||||
|
||||
|
||||
-- expose object to other modules
|
||||
craft_guide = {}
|
||||
|
||||
|
||||
-- define api variables
|
||||
craft_guide.crafts = {}
|
||||
|
||||
|
||||
-- log
|
||||
craft_guide.log = function(message)
|
||||
--if not craft_guide.DEBUG then return end
|
||||
minetest.log("action", "[CraftGuide] "..message)
|
||||
end
|
||||
|
||||
|
||||
-- register_craft
|
||||
craft_guide.register_craft = function(options)
|
||||
if options.output == nil then
|
||||
return
|
||||
end
|
||||
local itemstack = ItemStack(options.output)
|
||||
if itemstack:is_empty() then
|
||||
return
|
||||
end
|
||||
--craft_guide.log("registered craft for - "..itemstack:get_name())
|
||||
if craft_guide.crafts[itemstack:get_name()]==nil then
|
||||
craft_guide.crafts[itemstack:get_name()] = {}
|
||||
end
|
||||
table.insert(craft_guide.crafts[itemstack:get_name()],options)
|
||||
end
|
||||
|
||||
|
||||
-- get_craft_guide_formspec
|
||||
craft_guide.get_craft_guide_formspec = function(meta, search, page, alternate)
|
||||
if search == nil then
|
||||
search = meta:get_string("search")
|
||||
end
|
||||
if page == nil then
|
||||
page = craft_guide.get_current_page(meta)
|
||||
end
|
||||
if alternate == nil then
|
||||
alternate = craft_guide.get_current_alternate(meta)
|
||||
end
|
||||
local inv = meta:get_inventory()
|
||||
local size = inv:get_size("main")
|
||||
local start = (page-1) * (5*14) + 1
|
||||
local pages = math.floor((size-1) / (5*14) + 1)
|
||||
local alternates = 0
|
||||
local stack = inv:get_stack("output",1)
|
||||
local crafts = craft_guide.crafts[stack:get_name()]
|
||||
if crafts ~= nil then
|
||||
alternates = #crafts
|
||||
end
|
||||
local formspec = "size[14,10;]"
|
||||
.."list[current_name;main;0,0;14,5;"..tostring(start).."]"
|
||||
|
||||
.."label[0,5;--== Learn to Craft ==--]"
|
||||
.."label[0,5.4;Drag any item to the Output box to see the]"
|
||||
.."label[0,5.8;craft. Save your favorite items in Bookmarks.]"
|
||||
|
||||
.."field[6,5.4;2,1;craft_guide_search_box;;"..tostring(search).."]"
|
||||
.."button[7.5,5.1;1.2,1;craft_guide_search_button;Search]"
|
||||
|
||||
.."label[9,5.2;page "..tostring(page).." of "..tostring(pages).."]"
|
||||
.."button[11,5;1.5,1;craft_guide_prev;<<]"
|
||||
.."button[12.5,5;1.5,1;craft_guide_next;>>]"
|
||||
|
||||
.."label[0,6.5;Output]"
|
||||
.."list[current_name;output;0,7;1,1;]"
|
||||
|
||||
.."label[2,6.5;Inventory Craft]"
|
||||
.."list[current_name;build;2,7;3,3;]"
|
||||
|
||||
.."label[6,6.5;Cook]"
|
||||
.."list[current_name;cook;6,7;1,1;]"
|
||||
.."label[6,8.5;Fuel]"
|
||||
.."list[current_name;fuel;6,9;1,1;]"
|
||||
|
||||
.."label[8,6.5;Bookmarks]"
|
||||
.."list[current_name;bookmark;8,7;6,3;]"
|
||||
|
||||
.."label[12,6.1;Bin ->]"
|
||||
.."list[current_name;bin;13,6;1,1;]"
|
||||
if alternates > 1 then
|
||||
formspec = formspec
|
||||
.."label[0,8.6;recipe "..tostring(alternate).." of "..tostring(alternates).."]"
|
||||
.."button[0,9;2,1;alternate;Alternate]"
|
||||
end
|
||||
return formspec
|
||||
end
|
||||
|
||||
|
||||
-- on_construct
|
||||
craft_guide.on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("output", 1)
|
||||
inv:set_size("build", 3*3)
|
||||
inv:set_size("cook", 1)
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("bookmark", 6*3)
|
||||
inv:set_size("bin", 1)
|
||||
craft_guide.create_inventory(inv)
|
||||
meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
|
||||
end
|
||||
|
||||
|
||||
-- on_receive_fields
|
||||
craft_guide.on_receive_fields = function(pos, formname, fields, player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
local size = inv:get_size("main",1)
|
||||
local stack = inv:get_stack("output",1)
|
||||
local crafts = craft_guide.crafts[stack:get_name()]
|
||||
local alternate = craft_guide.get_current_alternate(meta)
|
||||
local alternates = 0
|
||||
if crafts ~= nil then
|
||||
alternates = #crafts
|
||||
end
|
||||
|
||||
local page = craft_guide.get_current_page(meta)
|
||||
local pages = math.floor((size-1) / (5*14) + 1)
|
||||
|
||||
local search
|
||||
|
||||
-- search
|
||||
search = fields.craft_guide_search_box
|
||||
meta:set_string("search", search)
|
||||
if fields.craft_guide_search_button then
|
||||
page = 1
|
||||
end
|
||||
|
||||
-- change page
|
||||
if fields.craft_guide_prev then
|
||||
page = page - 1
|
||||
end
|
||||
if fields.craft_guide_next then
|
||||
page = page + 1
|
||||
end
|
||||
if page < 1 then
|
||||
page = 1
|
||||
end
|
||||
if page > pages then
|
||||
page = pages
|
||||
end
|
||||
|
||||
-- get an alternate recipe
|
||||
if fields.alternate then
|
||||
alternate = alternate+1
|
||||
craft_guide.update_recipe(meta, player, stack, alternate)
|
||||
end
|
||||
if alternate > alternates then
|
||||
alternate = 1
|
||||
end
|
||||
|
||||
-- update the formspec
|
||||
craft_guide.create_inventory(inv, search)
|
||||
meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta, search, page, alternate))
|
||||
end
|
||||
|
||||
|
||||
-- get_current_page
|
||||
craft_guide.get_current_page = function(meta)
|
||||
local formspec = meta:get_string("formspec")
|
||||
local page = string.match(formspec, "label%[[%d.]+,[%d.]+;page (%d+) of [%d.]+%]")
|
||||
page = tonumber(page) or 1
|
||||
return page
|
||||
end
|
||||
|
||||
|
||||
-- get_current_alternate
|
||||
craft_guide.get_current_alternate = function(meta)
|
||||
local formspec = meta:get_string("formspec")
|
||||
local alternate = string.match(formspec, "label%[[%d.]+,[%d.]+;recipe (%d+) of [%d.]+%]")
|
||||
alternate = tonumber(alternate) or 1
|
||||
return alternate
|
||||
end
|
||||
|
||||
|
||||
-- update_recipe
|
||||
craft_guide.update_recipe = function(meta, player, stack, alternate)
|
||||
local inv = meta:get_inventory()
|
||||
for i=0,inv:get_size("build"),1 do
|
||||
inv:set_stack("build", i, nil)
|
||||
end
|
||||
inv:set_stack("cook", 1, nil)
|
||||
inv:set_stack("fuel", 1, nil)
|
||||
|
||||
if stack==nil then return end
|
||||
inv:set_stack("output", 1, stack:get_name())
|
||||
|
||||
alternate = tonumber(alternate) or 1
|
||||
craft_guide.log(player:get_player_name().." requests recipe "..alternate.." for "..stack:get_name())
|
||||
local crafts = craft_guide.crafts[stack:get_name()]
|
||||
|
||||
if crafts == nil then
|
||||
minetest.chat_send_player(player:get_player_name(), "no recipe available for "..stack:get_name())
|
||||
meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
|
||||
return
|
||||
end
|
||||
if alternate < 1 or alternate > #crafts then
|
||||
alternate = 1
|
||||
end
|
||||
local craft = crafts[alternate]
|
||||
|
||||
-- show me the unknown items
|
||||
craft_guide.log(dump(craft))
|
||||
--minetest.chat_send_player(player:get_player_name(), "recipe for "..stack:get_name()..": "..dump(craft))
|
||||
|
||||
local itemstack = ItemStack(craft.output)
|
||||
inv:set_stack("output", 1, itemstack)
|
||||
|
||||
-- cook
|
||||
if craft.type == "cooking" then
|
||||
inv:set_stack("cook", 1, craft.recipe)
|
||||
meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
|
||||
return
|
||||
end
|
||||
-- fuel
|
||||
if craft.type == "fuel" then
|
||||
inv:set_stack("fuel", 1, craft.recipe)
|
||||
meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
|
||||
return
|
||||
end
|
||||
-- build (shaped or shapeless)
|
||||
if craft.recipe[1] then
|
||||
if (type(craft.recipe[1]) == "string") then
|
||||
inv:set_stack("build", 1, craft.recipe[1])
|
||||
else
|
||||
if craft.recipe[1][1] then
|
||||
inv:set_stack("build", 1, craft.recipe[1][1])
|
||||
end
|
||||
if craft.recipe[1][2] then
|
||||
inv:set_stack("build", 2, craft.recipe[1][2])
|
||||
end
|
||||
if craft.recipe[1][3] then
|
||||
inv:set_stack("build", 3, craft.recipe[1][3])
|
||||
end
|
||||
end
|
||||
end
|
||||
if craft.recipe[2] then
|
||||
if (type(craft.recipe[2]) == "string") then
|
||||
inv:set_stack("build", 2, craft.recipe[2])
|
||||
else
|
||||
if craft.recipe[2][1] then
|
||||
inv:set_stack("build", 4, craft.recipe[2][1])
|
||||
end
|
||||
if craft.recipe[2][2] then
|
||||
inv:set_stack("build", 5, craft.recipe[2][2])
|
||||
end
|
||||
if craft.recipe[2][3] then
|
||||
inv:set_stack("build", 6, craft.recipe[2][3])
|
||||
end
|
||||
end
|
||||
end
|
||||
if craft.recipe[3] then
|
||||
if (type(craft.recipe[3]) == "string") then
|
||||
inv:set_stack("build", 3, craft.recipe[3])
|
||||
else
|
||||
if craft.recipe[3][1] then
|
||||
inv:set_stack("build", 7, craft.recipe[3][1])
|
||||
end
|
||||
if craft.recipe[3][2] then
|
||||
inv:set_stack("build", 8, craft.recipe[3][2])
|
||||
end
|
||||
if craft.recipe[3][3] then
|
||||
inv:set_stack("build", 9, craft.recipe[3][3])
|
||||
end
|
||||
end
|
||||
end
|
||||
if craft.recipe[4] then
|
||||
if (type(craft.recipe[4]) == "string") then
|
||||
inv:set_stack("build", 4, craft.recipe[4])
|
||||
end
|
||||
end
|
||||
if craft.recipe[5] then
|
||||
if (type(craft.recipe[5]) == "string") then
|
||||
inv:set_stack("build", 5, craft.recipe[5])
|
||||
end
|
||||
end
|
||||
if craft.recipe[6] then
|
||||
if (type(craft.recipe[6]) == "string") then
|
||||
inv:set_stack("build", 6, craft.recipe[6])
|
||||
end
|
||||
end
|
||||
if craft.recipe[7] then
|
||||
if (type(craft.recipe[7]) == "string") then
|
||||
inv:set_stack("build", 7, craft.recipe[7])
|
||||
end
|
||||
end
|
||||
if craft.recipe[8] then
|
||||
if (type(craft.recipe[8]) == "string") then
|
||||
inv:set_stack("build", 8, craft.recipe[8])
|
||||
end
|
||||
end
|
||||
if craft.recipe[9] then
|
||||
if (type(craft.recipe[9]) == "string") then
|
||||
inv:set_stack("build", 9, craft.recipe[9])
|
||||
end
|
||||
end
|
||||
meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta))
|
||||
end
|
||||
|
||||
|
||||
-- create_inventory
|
||||
craft_guide.create_inventory = function(inv, search)
|
||||
local craft_guide_list = {}
|
||||
for name,def in pairs(minetest.registered_items) do
|
||||
-- local craft_recipe = minetest.get_craft_recipe(name);
|
||||
-- if craft_recipe.items ~= nil then
|
||||
local craft = craft_guide.crafts[name];
|
||||
if craft ~= nil then
|
||||
if (not def.groups.not_in_craft_guide or def.groups.not_in_craft_guide == 0)
|
||||
--and (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0)
|
||||
and def.description and def.description ~= "" then
|
||||
if search then
|
||||
if string.find(def.name, search) or string.find(def.description, search) then
|
||||
table.insert(craft_guide_list, name)
|
||||
end
|
||||
else
|
||||
table.insert(craft_guide_list, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
table.sort(craft_guide_list)
|
||||
for i=0,inv:get_size("main"),1 do
|
||||
inv:set_stack("main", i, nil)
|
||||
end
|
||||
inv:set_size("main", #craft_guide_list)
|
||||
for _,itemstring in ipairs(craft_guide_list) do
|
||||
inv:add_item("main", ItemStack(itemstring))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- allow_metadata_inventory_move
|
||||
craft_guide.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if to_list == "bin" and from_list == "output" then
|
||||
inv:set_stack(from_list,from_index,nil)
|
||||
craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index))
|
||||
end
|
||||
if to_list == "bin" and from_list == "bookmark" then
|
||||
inv:set_stack(from_list,from_index,nil)
|
||||
end
|
||||
if to_list == "bookmark" then
|
||||
inv:set_stack(to_list, to_index, inv:get_stack(from_list, from_index):get_name())
|
||||
if from_list == "output" then
|
||||
inv:set_stack(from_list,from_index,nil)
|
||||
end
|
||||
end
|
||||
if to_list == "output" or from_list == "output" then
|
||||
craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index))
|
||||
end
|
||||
if from_list == "bookmarks" and to_list == "bookmarks" then
|
||||
return count
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
-- allow_metadata_inventory_put
|
||||
craft_guide.allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
return 0
|
||||
end
|
||||
|
||||
|
||||
-- allow_metadata_inventory_take
|
||||
craft_guide.allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
return 0
|
||||
end
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
--[[
|
||||
|
||||
Craft Guide for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-craft_guide
|
||||
License: GPLv3
|
||||
|
||||
MAIN LOADER
|
||||
|
||||
]]--
|
||||
|
||||
-- load api
|
||||
dofile(minetest.get_modpath("craft_guide").."/api_craft_guide.lua")
|
||||
|
||||
-- override minetest.register_craft
|
||||
local minetest_register_craft = minetest.register_craft
|
||||
minetest.register_craft = function (options)
|
||||
minetest_register_craft(options)
|
||||
craft_guide.register_craft(options)
|
||||
end
|
||||
|
||||
-- register entities
|
||||
dofile(minetest.get_modpath("craft_guide").."/register_node.lua")
|
||||
dofile(minetest.get_modpath("craft_guide").."/register_craft.lua")
|
||||
|
||||
-- log that we started
|
||||
minetest.log("action", "[MOD]"..minetest.get_current_modname().." -- loaded from "..minetest.get_modpath(minetest.get_current_modname()))
|
|
@ -0,0 +1,41 @@
|
|||
--[[
|
||||
|
||||
Craft Guide for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-craft_guide
|
||||
License: GPLv3
|
||||
|
||||
REGISTER CRAFTS
|
||||
|
||||
]]--
|
||||
|
||||
|
||||
-- craft sign
|
||||
minetest.register_craft({
|
||||
output = 'craft_guide:sign_wall',
|
||||
recipe = {
|
||||
{'default:stick', 'default:stick'},
|
||||
{'default:stick', 'default:stick'},
|
||||
{'default:stick', ''},
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
-- craft pc
|
||||
minetest.register_craft({
|
||||
output = 'craft_guide:lcd_pc',
|
||||
recipe = {
|
||||
{'craft_guide:sign_wall'},
|
||||
{'default:glass'},
|
||||
{'stairs:slab_stone'},
|
||||
}
|
||||
})
|
||||
minetest.register_craft({
|
||||
output = 'craft_guide:lcd_pc',
|
||||
recipe = {
|
||||
{'craft_guide:sign_wall'},
|
||||
{'default:glass'},
|
||||
{'stairsplus:slab_stone'},
|
||||
}
|
||||
})
|
|
@ -0,0 +1,74 @@
|
|||
--[[
|
||||
|
||||
Craft Guide for Minetest
|
||||
|
||||
Copyright (c) 2012 cornernote, Brett O'Donnell <cornernote@gmail.com>
|
||||
Source Code: https://github.com/cornernote/minetest-craft_guide
|
||||
License: GPLv3
|
||||
|
||||
REGISTER NODES
|
||||
|
||||
]]--
|
||||
|
||||
|
||||
-- craft sign
|
||||
minetest.register_node("craft_guide:sign_wall", {
|
||||
description = "Craft Sign",
|
||||
drawtype = "signlike",
|
||||
tiles = {"craft_guide_sign.png"},
|
||||
inventory_image = "craft_guide_sign.png",
|
||||
paramtype = 'light',
|
||||
paramtype2 = "wallmounted",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
groups = {choppy=2,dig_immediate=2},
|
||||
--sounds = default.node_sound_defaults(),
|
||||
selection_box = {
|
||||
type = "wallmounted",
|
||||
},
|
||||
on_construct = craft_guide.on_construct,
|
||||
on_receive_fields = craft_guide.on_receive_fields,
|
||||
allow_metadata_inventory_move = craft_guide.allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_put = craft_guide.allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = craft_guide.allow_metadata_inventory_take,
|
||||
})
|
||||
|
||||
-- craft pc
|
||||
minetest.register_node("craft_guide:lcd_pc", {
|
||||
description = "Craft PC",
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
"craft_guide_pc_grey.png",
|
||||
"craft_guide_pc_grey.png",
|
||||
"craft_guide_pc_grey.png",
|
||||
"craft_guide_pc_grey.png",
|
||||
"craft_guide_pc_black.png",
|
||||
"craft_guide_pc_screen.png",
|
||||
},
|
||||
paramtype = 'light',
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
walkable = false,
|
||||
selection_box = {type="regular"},
|
||||
groups = {choppy=2,dig_immediate=2},
|
||||
-- thanks cactuz_pl for the nodebox code! =)
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-1.0000000e-1,-0.45259861,2.5136044e-2, 0.10000000,-2.5986075e-3,-2.4863956e-2},
|
||||
{-0.40006064,-0.25615262,-0.13023723, -0.37006064,0.26767738,-0.16023723},
|
||||
{0.37054221,-0.25615274,-0.13023723, 0.40054221,0.26767750,-0.16023723},
|
||||
{-0.40000000,-0.30600000,-0.13023723, 0.40000000,-0.25600000,-0.16023723},
|
||||
{-0.40000000,0.26433021,-0.12945597, 0.40000000,0.29433021,-0.15945597},
|
||||
{-0.35000000,-0.25514168,-2.9045502e-2, 0.35000000,0.24485832,-7.9045502e-2},
|
||||
{-0.40000000,-0.30617002,-8.0237234e-2, 0.40000000,0.29382998,-0.13023723},
|
||||
{-0.25000000,-0.50000000,0.25000000, 0.25000000,-0.45000000,-0.25000000}
|
||||
},
|
||||
},
|
||||
--sounds = default.node_sound_defaults(),
|
||||
on_construct = craft_guide.on_construct,
|
||||
on_receive_fields = craft_guide.on_receive_fields,
|
||||
allow_metadata_inventory_move = craft_guide.allow_metadata_inventory_move,
|
||||
allow_metadata_inventory_put = craft_guide.allow_metadata_inventory_put,
|
||||
allow_metadata_inventory_take = craft_guide.allow_metadata_inventory_take,
|
||||
})
|
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 157 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 263 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 @@
|
|||
default
|
|
@ -0,0 +1,162 @@
|
|||
-- minetest/creative/init.lua
|
||||
|
||||
local creative_inventory = {}
|
||||
creative_inventory.creative_inventory_size = 0
|
||||
|
||||
-- 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)
|
||||
return 0
|
||||
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
|
||||
inv:add_item("main", ItemStack(itemstring))
|
||||
end
|
||||
creative_inventory.creative_inventory_size = #creative_list
|
||||
print("creative inventory size: "..dump(creative_inventory.creative_inventory_size))
|
||||
end)
|
||||
|
||||
-- Create the trash field
|
||||
local trash = minetest.create_detached_inventory("creative_trash", {
|
||||
-- Allow the stack to be placed and remove it in on_put()
|
||||
-- This allows the creative inventory to restore the stack
|
||||
allow_put = function(inv, listname, index, stack, player)
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
on_put = function(inv, listname, index, stack, player)
|
||||
inv:set_stack(listname, index, "")
|
||||
end,
|
||||
})
|
||||
trash:set_size("main", 1)
|
||||
|
||||
|
||||
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;>>]"..
|
||||
"label[5,1.5;Trash:]"..
|
||||
"list[detached:creative_trash;main;5,2;1,1;]")
|
||||
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)
|
||||
|
||||
if minetest.setting_getbool("creative_mode") then
|
||||
|
||||
minetest.register_item(":", {
|
||||
type = "none",
|
||||
wield_image = "wieldhand.png",
|
||||
wield_scale = {x=1,y=1,z=2.5},
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 0.5,
|
||||
max_drop_level = 3,
|
||||
groupcaps = {
|
||||
crumbly = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
cracky = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
snappy = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
choppy = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
oddly_breakable_by_hand = {times={[1]=0.5, [2]=0.5, [3]=0.5}, uses=0, maxlevel=3},
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
|
||||
return true
|
||||
end)
|
||||
|
||||
function minetest.handle_node_drops(pos, drops, digger)
|
||||
if not digger or not digger:is_player() then
|
||||
return
|
||||
end
|
||||
local inv = digger:get_inventory()
|
||||
if inv then
|
||||
for _,item in ipairs(drops) do
|
||||
item = ItemStack(item):get_name()
|
||||
if not inv:contains_item("main", item) then
|
||||
inv:add_item("main", item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,132 @@
|
|||
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_stone_brick.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_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_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
|
||||
default_cobble.png
|
||||
|
||||
VanessaE's animated torches (WTFPL):
|
||||
default_torch_animated.png
|
||||
default_torch_on_ceiling_animated.png
|
||||
default_torch_on_floor_animated.png
|
||||
default_torch_on_floor.png
|
||||
|
||||
RealBadAngel's animated water (WTFPL):
|
||||
default_water_source_animated.png
|
||||
default_water_flowing_animated.png
|
||||
|
||||
VanessaE (WTFPL):
|
||||
default_nc_back.png
|
||||
default_nc_front.png
|
||||
default_nc_rb.png
|
||||
default_nc_side.png
|
||||
default_grass_*.png
|
||||
|
||||
Calinou (CC BY-SA):
|
||||
default_brick.png
|
||||
default_clay_brick.png
|
||||
default_papyrus.png
|
||||
default_tool_steelsword.png
|
||||
default_bronze_block.png
|
||||
default_bronze_ingot.png
|
||||
default_copper_ingot.png
|
||||
default_copper_lump.png
|
||||
default_mineral_copper.png
|
||||
|
||||
MirceaKitsune (WTFPL):
|
||||
character.x
|
||||
|
||||
Jordach (CC BY-SA 3.0):
|
||||
character.png
|
||||
|
||||
PilzAdam (WTFPL):
|
||||
default_jungleleaves.png
|
||||
default_junglesapling.png
|
||||
default_junglewood.png
|
||||
default_obsidian_glass.png
|
||||
default_obsidian_shard.png
|
||||
default_mossycobble.png
|
||||
default_gold_block.png
|
||||
default_gold_ingot.png
|
||||
default_gold_lump.png
|
||||
default_mineral_gold.png
|
||||
default_diamond.png
|
||||
default_diamond_block.png
|
||||
default_tool_diamondpick.png
|
||||
default_tool_diamondsword.png
|
||||
default_tool_diamondshovel.png
|
||||
default_tool_diamondaxe.png
|
||||
default_tool_meseaxe.png
|
||||
default_tool_meseshovel.png
|
||||
default_tool_mesesword.png
|
||||
default_tool_bronzeaxe.png
|
||||
default_tool_bronzepick.png
|
||||
default_tool_bronzeshovel.png
|
||||
default_tool_bronzesword.png
|
||||
|
||||
jojoa1997 (WTFPL):
|
||||
default_obsidian.png
|
||||
|
||||
InfinityProject (WTFPL):
|
||||
default_mineral_diamond.png
|
||||
|
||||
Glass breaking sounds (CC BY 3.0):
|
||||
1: http://www.freesound.org/people/cmusounddesign/sounds/71947/
|
||||
2: http://www.freesound.org/people/Tomlija/sounds/97669/
|
||||
3: http://www.freesound.org/people/lsprice/sounds/88808/
|
|
@ -0,0 +1 @@
|
|||
craft_guide
|
|
@ -0,0 +1,93 @@
|
|||
-- 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 and 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)
|
||||
nodeupdate(p0)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
|
@ -0,0 +1,463 @@
|
|||
-- 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_jungletree", "default:jungletree")
|
||||
minetest.register_alias("mapgen_jungleleaves", "default:jungleleaves")
|
||||
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
|
||||
--
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_coal",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 8*8*8,
|
||||
clust_num_ores = 8,
|
||||
clust_size = 3,
|
||||
height_min = -31000,
|
||||
height_max = 64,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_coal",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 24*24*24,
|
||||
clust_num_ores = 27,
|
||||
clust_size = 6,
|
||||
height_min = -31000,
|
||||
height_max = 0,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_iron",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 12*12*12,
|
||||
clust_num_ores = 3,
|
||||
clust_size = 2,
|
||||
height_min = -15,
|
||||
height_max = 2,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_iron",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 9*9*9,
|
||||
clust_num_ores = 5,
|
||||
clust_size = 3,
|
||||
height_min = -63,
|
||||
height_max = -16,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_iron",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 7*7*7,
|
||||
clust_num_ores = 5,
|
||||
clust_size = 3,
|
||||
height_min = -31000,
|
||||
height_max = -64,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_iron",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 24*24*24,
|
||||
clust_num_ores = 27,
|
||||
clust_size = 6,
|
||||
height_min = -31000,
|
||||
height_max = -64,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_mese",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 18*18*18,
|
||||
clust_num_ores = 3,
|
||||
clust_size = 2,
|
||||
height_min = -255,
|
||||
height_max = -64,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_mese",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 14*14*14,
|
||||
clust_num_ores = 5,
|
||||
clust_size = 3,
|
||||
height_min = -31000,
|
||||
height_max = -256,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:mese",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 36*36*36,
|
||||
clust_num_ores = 3,
|
||||
clust_size = 2,
|
||||
height_min = -31000,
|
||||
height_max = -1024,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_gold",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 15*15*15,
|
||||
clust_num_ores = 3,
|
||||
clust_size = 2,
|
||||
height_min = -255,
|
||||
height_max = -64,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_gold",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 13*13*13,
|
||||
clust_num_ores = 5,
|
||||
clust_size = 3,
|
||||
height_min = -31000,
|
||||
height_max = -256,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_diamond",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 17*17*17,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
height_min = -255,
|
||||
height_max = -128,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_diamond",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 15*15*15,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
height_min = -31000,
|
||||
height_max = -256,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_copper",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 12*12*12,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
height_min = -63,
|
||||
height_max = -16,
|
||||
})
|
||||
|
||||
minetest.register_ore({
|
||||
ore_type = "scatter",
|
||||
ore = "default:stone_with_copper",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 9*9*9,
|
||||
clust_num_ores = 5,
|
||||
clust_size = 3,
|
||||
height_min = -31000,
|
||||
height_max = -64,
|
||||
})
|
||||
|
||||
function default.generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, chunk_size, ore_per_chunk, height_min, height_max)
|
||||
minetest.log('action', "WARNING: default.generate_ore is deprecated")
|
||||
|
||||
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)
|
||||
if chunk_size >= y_max - y_min + 1 then
|
||||
return
|
||||
end
|
||||
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}
|
||||
local nn = minetest.env:get_node(p).name
|
||||
if minetest.registered_nodes[nn] and
|
||||
minetest.registered_nodes[nn].buildable_to then
|
||||
minetest.env:set_node(p, {name="default:papyrus"})
|
||||
else
|
||||
return
|
||||
end
|
||||
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}
|
||||
local nn = minetest.env:get_node(p).name
|
||||
if minetest.registered_nodes[nn] and
|
||||
minetest.registered_nodes[nn].buildable_to then
|
||||
minetest.env:set_node(p, {name="default:cactus"})
|
||||
else
|
||||
return
|
||||
end
|
||||
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)
|
||||
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 grass
|
||||
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 grass amount from perlin noise
|
||||
local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9)
|
||||
-- Find random positions for grass based on this random
|
||||
local pr = PseudoRandom(seed+1)
|
||||
for i=0,grass_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 ground_y then
|
||||
local p = {x=x,y=ground_y+1,z=z}
|
||||
local nn = minetest.env:get_node(p).name
|
||||
-- Check if the node can be replaced
|
||||
if minetest.registered_nodes[nn] and
|
||||
minetest.registered_nodes[nn].buildable_to then
|
||||
nn = minetest.env:get_node({x=x,y=ground_y,z=z}).name
|
||||
-- If desert sand, add dry shrub
|
||||
if nn == "default:desert_sand" then
|
||||
minetest.env:set_node(p,{name="default:dry_shrub"})
|
||||
|
||||
-- If dirt with grass, add grass
|
||||
elseif nn == "default:dirt_with_grass" then
|
||||
minetest.env:set_node(p,{name="default:grass_"..pr:next(1, 5)})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Generate nyan cats
|
||||
generate_nyancats(seed, minp, maxp)
|
||||
end)
|
||||
|
After Width: | Height: | Size: 3.2 KiB |
|
@ -0,0 +1,132 @@
|
|||
-- Minetest 0.4 mod: player
|
||||
-- See README.txt for licensing and other information.
|
||||
|
||||
--
|
||||
-- Start of configuration area:
|
||||
--
|
||||
|
||||
-- Player animation speed
|
||||
animation_speed = 30
|
||||
|
||||
-- Player animation blending
|
||||
-- Note: This is currently broken due to a bug in Irrlicht, leave at 0
|
||||
animation_blend = 0
|
||||
|
||||
-- Default player appearance
|
||||
default_model = "character.x"
|
||||
default_textures = {"character.png", }
|
||||
|
||||
-- Frame ranges for each player model
|
||||
function player_get_animations(model)
|
||||
if model == "character.x" then
|
||||
return {
|
||||
stand_START = 0,
|
||||
stand_END = 79,
|
||||
sit_START = 81,
|
||||
sit_END = 160,
|
||||
lay_START = 162,
|
||||
lay_END = 166,
|
||||
walk_START = 168,
|
||||
walk_END = 187,
|
||||
mine_START = 189,
|
||||
mine_END = 198,
|
||||
walk_mine_START = 200,
|
||||
walk_mine_END = 219
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
-- End of configuration area.
|
||||
--
|
||||
|
||||
-- Player stats and animations
|
||||
local player_model = {}
|
||||
local player_anim = {}
|
||||
local player_sneak = {}
|
||||
local ANIM_STAND = 1
|
||||
local ANIM_SIT = 2
|
||||
local ANIM_LAY = 3
|
||||
local ANIM_WALK = 4
|
||||
local ANIM_WALK_MINE = 5
|
||||
local ANIM_MINE = 6
|
||||
|
||||
-- Called when a player's appearance needs to be updated
|
||||
function player_update_visuals(pl)
|
||||
local name = pl:get_player_name()
|
||||
|
||||
player_model[name] = default_model
|
||||
player_anim[name] = 0 -- Animation will be set further below immediately
|
||||
player_sneak[name] = false
|
||||
prop = {
|
||||
mesh = default_model,
|
||||
textures = default_textures,
|
||||
visual = "mesh",
|
||||
visual_size = {x=1, y=1},
|
||||
}
|
||||
pl:set_properties(prop)
|
||||
end
|
||||
|
||||
-- Update appearance when the player joins
|
||||
minetest.register_on_joinplayer(player_update_visuals)
|
||||
|
||||
-- Check each player and apply animations
|
||||
function player_step(dtime)
|
||||
for _, pl in pairs(minetest.get_connected_players()) do
|
||||
local name = pl:get_player_name()
|
||||
local anim = player_get_animations(player_model[name])
|
||||
local controls = pl:get_player_control()
|
||||
local walking = false
|
||||
local animation_speed_mod = animation_speed
|
||||
|
||||
-- Determine if the player is walking
|
||||
if controls.up or controls.down or controls.left or controls.right then
|
||||
walking = true
|
||||
end
|
||||
|
||||
-- Determine if the player is sneaking, and reduce animation speed if so
|
||||
if controls.sneak and pl:get_hp() ~= 0 and (walking or controls.LMB) then
|
||||
animation_speed_mod = animation_speed_mod / 2
|
||||
-- Refresh player animation below if sneak state changed
|
||||
if not player_sneak[name] then
|
||||
player_anim[name] = 0
|
||||
player_sneak[name] = true
|
||||
end
|
||||
else
|
||||
-- Refresh player animation below if sneak state changed
|
||||
if player_sneak[name] then
|
||||
player_anim[name] = 0
|
||||
player_sneak[name] = false
|
||||
end
|
||||
end
|
||||
|
||||
-- Apply animations based on what the player is doing
|
||||
if pl:get_hp() == 0 then
|
||||
if player_anim[name] ~= ANIM_LAY then
|
||||
pl:set_animation({x=anim.lay_START, y=anim.lay_END}, animation_speed_mod, animation_blend)
|
||||
player_anim[name] = ANIM_LAY
|
||||
end
|
||||
elseif walking and controls.LMB then
|
||||
if player_anim[name] ~= ANIM_WALK_MINE then
|
||||
pl:set_animation({x=anim.walk_mine_START, y=anim.walk_mine_END}, animation_speed_mod, animation_blend)
|
||||
player_anim[name] = ANIM_WALK_MINE
|
||||
end
|
||||
elseif walking then
|
||||
if player_anim[name] ~= ANIM_WALK then
|
||||
pl:set_animation({x=anim.walk_START, y=anim.walk_END}, animation_speed_mod, animation_blend)
|
||||
player_anim[name] = ANIM_WALK
|
||||
end
|
||||
elseif controls.LMB then
|
||||
if player_anim[name] ~= ANIM_MINE then
|
||||
pl:set_animation({x=anim.mine_START, y=anim.mine_END}, animation_speed_mod, animation_blend)
|
||||
player_anim[name] = ANIM_MINE
|
||||
end
|
||||
elseif player_anim[name] ~= ANIM_STAND then
|
||||
pl:set_animation({x=anim.stand_START, y=anim.stand_END}, animation_speed_mod, animation_blend)
|
||||
player_anim[name] = ANIM_STAND
|
||||
end
|
||||
end
|
||||
end
|
||||
minetest.register_globalstep(player_step)
|
||||
|
||||
-- END
|
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 283 B |
After Width: | Height: | Size: 292 B |
After Width: | Height: | Size: 597 B |
After Width: | Height: | Size: 626 B |
After Width: | Height: | Size: 277 B |
After Width: | Height: | Size: 341 B |
After Width: | Height: | Size: 763 B |
After Width: | Height: | Size: 682 B |
After Width: | Height: | Size: 769 B |
After Width: | Height: | Size: 871 B |
After Width: | Height: | Size: 714 B |
After Width: | Height: | Size: 628 B |
After Width: | Height: | Size: 613 B |
After Width: | Height: | Size: 271 B |
After Width: | Height: | Size: 339 B |
After Width: | Height: | Size: 118 B |
After Width: | Height: | Size: 255 B |
After Width: | Height: | Size: 589 B |
After Width: | Height: | Size: 362 B |
After Width: | Height: | Size: 382 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 517 B |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 241 B |
After Width: | Height: | Size: 962 B |
After Width: | Height: | Size: 450 B |
After Width: | Height: | Size: 539 B |
After Width: | Height: | Size: 731 B |
After Width: | Height: | Size: 313 B |
After Width: | Height: | Size: 865 B |
After Width: | Height: | Size: 651 B |
After Width: | Height: | Size: 826 B |
After Width: | Height: | Size: 731 B |
After Width: | Height: | Size: 731 B |
After Width: | Height: | Size: 978 B |
After Width: | Height: | Size: 258 B |
After Width: | Height: | Size: 336 B |
After Width: | Height: | Size: 321 B |
After Width: | Height: | Size: 794 B |
After Width: | Height: | Size: 206 B |
After Width: | Height: | Size: 252 B |
After Width: | Height: | Size: 282 B |