Updates moreblocks/ores/trees, skylands, technic

Hope all these files go through... :P
master
Chris N 2014-08-16 17:23:36 -10:00
parent 7cc8847b6e
commit cb3b35760b
939 changed files with 16186 additions and 2164 deletions

View File

@ -1,17 +0,0 @@
------------------------------------------------------------------------------
------------------------------ CONFIGURATION ---------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-------- Change settings by changing the values after the "=". ---------------
------------------------------------------------------------------------------
-- Whether to direct wood based on player yaw when placing the block (true or false)
wood_facedir = true
-- Allow stair/slab crafting without a circular saw or not (true or false)
allow_stair_slab_crafting = true
-- Show stairs/slabs/panels/microblocks in creative inventory (true or false)
show_stairsplus_creative_inv = false

View File

@ -122,7 +122,7 @@ function circular_saw:update_inventory(pos, amount)
end
local node_name = stack:get_name()
local name_parts = circular_saw.known_nodes[node_name]
local name_parts = circular_saw.known_nodes[node_name] or ""
local modname = name_parts[1]
local material = name_parts[2]

View File

@ -1,415 +0,0 @@
dofile(minetest.get_modpath("moreblocks").."/_config.txt")
-- Nodes will be called <modname>:{stair,slab,panel,micro}_<subname>
if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then
stairsplus_expect_infinite_stacks = false
else
stairsplus_expect_infinite_stacks = true
end
-- These vales are in order: facedir in degrees = 90, 0, 270, 180, 90
local dirs1 = { 21, 20, 23, 22, 21 }
local dirs2 = { 15, 8, 17, 6, 15 }
local dirs3 = { 14, 11, 16, 5, 14 }
stairsplus_can_it_stack = function(itemstack, placer, pointed_thing)
return false
--[[
if pointed_thing.type ~= "node" then
return itemstack
end
-- If it's being placed on an another similar one, replace it with
-- a full block
local slabpos = nil
local slabnode = nil
local p1 = pointed_thing.above
p1 = {x = p1.x, y = p1.y - 1, z = p1.z}
local n1 = minetest.env:get_node(p1)
if n1.name == modname .. ":slab_" .. subname then
slabpos = p1
slabnode = n1
end
if slabpos then
-- Remove the slab at slabpos
minetest.env:remove_node(slabpos)
-- Make a fake stack of a single item and try to place it
local fakestack = ItemStack(recipeitem)
pointed_thing.above = slabpos
fakestack = minetest.item_place(fakestack, placer, pointed_thing)
-- If the item was taken from the fake stack, decrement original
if not fakestack or fakestack:is_empty() then
itemstack:take_item(1)
-- Else put old node back
else
minetest.env:set_node(slabpos, slabnode)
end
return itemstack
end
if n1.name == modname .. ":slab_" .. subname .. "_quarter" then
slabpos = p1
slabnode = n1
end
if slabpos then
-- Remove the slab at slabpos
minetest.env:remove_node(slabpos)
-- Make a fake stack of a single item and try to place it
local fakestack = ItemStack(modname .. ":slab_" .. subname .. "_three_quarter")
pointed_thing.above = slabpos
fakestack = minetest.item_place(fakestack, placer, pointed_thing)
-- If the item was taken from the fake stack, decrement original
if not fakestack or fakestack:is_empty() then
itemstack:take_item(1)
-- Else put old node back
else
minetest.env:set_node(slabpos, slabnode)
end
return itemstack
end
-- Otherwise place regularly
return minetest.item_place(itemstack, placer, pointed_thing)
]]--
end
local function get_nodedef_field(nodename, fieldname)
if not minetest.registered_nodes[nodename] then
return nil
end
return minetest.registered_nodes[nodename][fieldname]
end
--[[
function(itemstack, placer, pointed_thing)
local keys=placer:get_player_control()
stairsplus_rotate_and_place(itemstack, placer, pointed_thing, keys["sneak"])
return itemstack
end
]]--
function stairsplus_rotate_and_place(itemstack, placer, pointed_thing)
if not moreblocks.node_is_owned(pointed_thing.under, placer) then
local keys=placer:get_player_control()
minetest.rotate_and_place(itemstack, placer, pointed_thing,
stairsplus_expect_infinite_stacks, {force_wall = keys.sneak})
end
return itemstack
end
function register_stair_slab_panel_micro(modname, subname, recipeitem, groups, images, description, drop, light)
if show_stairsplus_creative_inv then
groups.not_in_creative_inventory = 0
else
groups.not_in_creative_inventory = 1
end
register_stair(modname, subname, recipeitem, groups, images, description, drop, light)
register_slab( modname, subname, recipeitem, groups, images, description, drop, light)
register_panel(modname, subname, recipeitem, groups, images, description, drop, light)
register_micro(modname, subname, recipeitem, groups, images, description, drop, light)
register_6dfacedir_conversion(modname, subname)
end
-- Default stairs/slabs/panels/microblocks.
register_stair_slab_panel_micro("moreblocks", "wood", "default:wood",
{snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3},
{"default_wood.png"},
"Wooden",
"wood",
0)
register_stair_slab_panel_micro("moreblocks", "stone", "default:stone",
{cracky=3},
{"default_stone.png"},
"Stone",
"cobble",
0)
register_stair_slab_panel_micro("moreblocks", "cobble", "default:cobble",
{cracky=3},
{"default_cobble.png"},
"Cobblestone",
"cobble",
0)
register_stair_slab_panel_micro("moreblocks", "mossycobble", "default:mossycobble",
{cracky=3},
{"default_mossycobble.png"},
"Mossy Cobblestone",
"mossycobble",
0)
register_stair_slab_panel_micro("moreblocks", "brick", "default:brick",
{cracky=3},
{"default_brick.png"},
"Brick",
"brick",
0)
register_stair_slab_panel_micro("moreblocks", "sandstone", "default:sandstone",
{crumbly=2, cracky=2},
{"default_sandstone.png"},
"Sandstone",
"sandstone",
0)
register_stair_slab_panel_micro("moreblocks", "steelblock", "default:steelblock",
{cracky=1, level=2},
{"default_steel_block.png"},
"Steel Block",
"steelblock",
0)
register_stair_slab_panel_micro("moreblocks", "goldblock", "default:goldblock",
{cracky=1},
{"default_gold_block.png"},
"Gold Block",
"goldblock",
0)
register_stair_slab_panel_micro("moreblocks", "copperblock", "default:copperblock",
{cracky=1, level=2},
{"default_copper_block.png"},
"Copper Block",
"copperblock",
0)
register_stair_slab_panel_micro("moreblocks", "bronzeblock", "default:bronzeblock",
{cracky=1, level=2},
{"default_bronze_block.png"},
"Bronze Block",
"bronzeblock",
0)
register_stair_slab_panel_micro("moreblocks", "diamondblock", "default:diamondblock",
{cracky=1, level=3},
{"default_diamond_block.png"},
"Diamond Block",
"diamondblock",
0)
register_stair_slab_panel_micro("moreblocks", "desert_stone", "default:desert_stone",
{cracky=3},
{"default_desert_stone.png"},
"Desert Stone",
"desert_stone",
0)
register_stair_slab_panel_micro("moreblocks", "glass", "default:glass",
{snappy=2, cracky=3, oddly_breakable_by_hand=3},
{"moreblocks_glass_stairsplus.png"},
"Glass",
"glass",
0)
register_stair_slab_panel_micro("moreblocks", "tree", "default:tree",
{tree=1, snappy=1, choppy=2, oddly_breakable_by_hand=1, flammable=2},
{"default_tree_top.png", "default_tree_top.png", "default_tree.png"},
"Tree",
"tree",
0)
register_stair_slab_panel_micro("moreblocks", "jungletree", "default:jungletree",
{tree=1, snappy=1, choppy=2, oddly_breakable_by_hand=1, flammable=2},
{"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"},
"Jungle Tree",
"jungletree",
0)
register_stair_slab_panel_micro("moreblocks", "obsidian", "default:obsidian",
{cracky=1, level=2},
{"default_obsidian.png"},
"Obsidian",
"obsidian",
0)
register_stair_slab_panel_micro("moreblocks", "obsidian_glass", "default:obsidian_glass",
{cracky=3, oddly_breakable_by_hand=3},
{"moreblocks_obsidian_glass_stairsplus.png"},
"Obsidian Glass",
"obsidian_glass",
0)
register_stair_slab_panel_micro("moreblocks", "stonebrick", "default:stonebrick",
{cracky=3},
{"default_stone_brick.png"},
"Stone Bricks",
"stonebrick",
0)
register_stair_slab_panel_micro("moreblocks", "desert_stonebrick", "default:desert_stonebrick",
{cracky=3},
{"default_desert_stone_brick.png"},
"Desert Stone Bricks",
"desert_stonebrick",
0)
register_stair_slab_panel_micro("moreblocks", "sandstonebrick", "default:sandstonebrick",
{cracky=3},
{"default_sandstone_brick.png"},
"Sandstone Bricks",
"sandstonebrick",
0)
-- More Blocks stairs/slabs/panels/microblocks
register_stair_slab_panel_micro("moreblocks", "invisible", "air",
{unbreakable=1, not_in_creative_inventory=1},
{"invisible.png"},
"Invisible",
"invisible",
0)
register_stair_slab_panel_micro("moreblocks", "circle_stone_bricks", "moreblocks:circle_stone_bricks",
{cracky=3},
{"moreblocks_circle_stone_bricks.png"},
"Circle Stone Bricks",
"circle_stone_bricks",
0)
register_stair_slab_panel_micro("moreblocks", "coal_stone_bricks", "moreblocks:coal_stone_bricks",
{cracky=3},
{"moreblocks_coal_stone_bricks.png"},
"Coal Stone Bricks",
"Coal_stone_bricks",
0)
register_stair_slab_panel_micro("moreblocks", "iron_stone_bricks", "moreblocks:iron_stone_bricks",
{cracky=3},
{"moreblocks_iron_stone_bricks.png"},
"Iron Stone Bricks",
"iron_stone_bricks",
0)
register_stair_slab_panel_micro("moreblocks", "stone_tile", "moreblocks:stone_tile",
{cracky=3},
{"moreblocks_stone_tile.png"},
"Stonesquare",
"stone_tile",
0)
register_stair_slab_panel_micro("moreblocks", "split_stone_tile", "moreblocks:split_stone_tile",
{cracky=3},
{"moreblocks_split_stone_tile_top.png", "moreblocks_split_stone_tile.png"},
"Split Stonesquare",
"split_stone_tile",
0)
register_stair_slab_panel_micro("moreblocks", "jungle_wood", "default:junglewood", -- Compatibility
{snappy=1, choppy=2, oddly_breakable_by_hand=2,flammable=3},
{"default_junglewood.png"},
"Jungle Wood",
"jungle_wood",
0)
register_stair_slab_panel_micro("moreblocks", "junglewood", "default:junglewood",
{snappy=1, choppy=2, oddly_breakable_by_hand=2,flammable=3},
{"default_junglewood.png"},
"Jungle Wood",
"jungle_wood",
0)
register_stair_slab_panel_micro("moreblocks", "plankstone", "moreblocks:plankstone",
{cracky=3},
{"moreblocks_plankstone.png", "moreblocks_plankstone.png", "moreblocks_plankstone.png",
"moreblocks_plankstone.png", "moreblocks_plankstone.png^[transformR90", "moreblocks_plankstone.png^[transformR90"},
"Plankstone",
"plankstone",
0)
register_stair_slab_panel_micro("moreblocks", "coal_checker", "moreblocks:coal_checker",
{cracky=3},
{"moreblocks_coal_checker.png", "moreblocks_coal_checker.png", "moreblocks_coal_checker.png",
"moreblocks_coal_checker.png", "moreblocks_coal_checker.png^[transformR90", "moreblocks_coal_checker.png^[transformR90"},
"Coal Checker",
"coal_checker",
0)
register_stair_slab_panel_micro("moreblocks", "iron_checker", "moreblocks:iron_checker",
{cracky=3},
{"moreblocks_iron_checker.png", "moreblocks_iron_checker.png", "moreblocks_iron_checker.png",
"moreblocks_iron_checker.png", "moreblocks_iron_checker.png^[transformR90", "moreblocks_iron_checker.png^[transformR90"},
"Iron Checker",
"iron_checker",
0)
register_stair_slab_panel_micro("moreblocks", "cactus_checker", "moreblocks:cactus_checker",
{cracky=3},
{"moreblocks_cactus_checker.png", "moreblocks_cactus_checker.png", "moreblocks_cactus_checker.png",
"moreblocks_cactus_checker.png", "moreblocks_cactus_checker.png^[transformR90", "moreblocks_cactus_checker.png^[transformR90"},
"Cactus Checker",
"cactus_checker",
0)
register_stair_slab_panel_micro("moreblocks", "coal_stone", "moreblocks:coal_stone",
{cracky=3},
{"moreblocks_coal_stone.png"},
"Coal Stone",
"coal_stone",
0)
register_stair_slab_panel_micro("moreblocks", "iron_stone", "moreblocks:iron_stone",
{cracky=3},
{"moreblocks_iron_stone.png"},
"Iron Stone",
"iron_stone",
0)
register_stair_slab_panel_micro("moreblocks", "glow_glass", "moreblocks:glow_glass",
{snappy=2,cracky=3,oddly_breakable_by_hand=3},
{"moreblocks_glow_glass_stairsplus.png"},
"Glow Glass",
"glow_glass",
11)
register_stair_slab_panel_micro("moreblocks", "super_glow_glass", "moreblocks:super_glow_glass",
{snappy=2, cracky=3, oddly_breakable_by_hand=3},
{"moreblocks_super_glow_glass_stairsplus.png"},
"Super Glow Glass",
"super_glow_glass",
15)
register_stair_slab_panel_micro("moreblocks", "coal_glass", "moreblocks:coal_glass",
{snappy=2, cracky=3, oddly_breakable_by_hand=3},
{"moreblocks_coal_glass_stairsplus.png"},
"Coal Glass",
"coal_glass",
0)
register_stair_slab_panel_micro("moreblocks", "iron_glass", "moreblocks:iron_glass",
{snappy=2, cracky=3, oddly_breakable_by_hand=3},
{"moreblocks_iron_glass_stairsplus.png"},
"Iron Glass",
"iron_glass",
0)
register_stair_slab_panel_micro("moreblocks", "wood_tile", "moreblocks:wood_tile",
{snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3},
{"moreblocks_wood_tile.png", "moreblocks_wood_tile.png", "moreblocks_wood_tile.png",
"moreblocks_wood_tile.png", "moreblocks_wood_tile.png^[transformR90", "moreblocks_wood_tile.png^[transformR90"},
"Wooden Tile",
"wood_tile",
0)
register_stair_slab_panel_micro("moreblocks", "wood_tile_center", "moreblocks:wood_tile_center",
{snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3},
{"moreblocks_wood_tile_center.png", "moreblocks_wood_tile_center.png", "moreblocks_wood_tile_center.png",
"moreblocks_wood_tile_center.png", "moreblocks_wood_tile_center.png^[transformR90", "moreblocks_wood_tile_center.png^[transformR90"},
"Centered Wooden Tile",
"wood_tile_center",
0)
register_stair_slab_panel_micro("moreblocks", "wood_tile_full", "moreblocks:wood_tile_full",
{snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3},
{"moreblocks_wood_tile_full.png", "moreblocks_wood_tile_full.png", "moreblocks_wood_tile_full.png",
"moreblocks_wood_tile_full.png", "moreblocks_wood_tile_full.png^[transformR90", "moreblocks_wood_tile_full.png^[transformR90"},
"Full Wooden Tile",
"wood_tile_full",
0)

View File

@ -10,7 +10,7 @@ local default_nodes = { -- Default stairs/slabs/panels/microblocks:
"bronzeblock",
"diamondblock",
"desert_stone",
"desert_cobble",
-- "desert_cobble",
"glass",
"tree",
"wood",
@ -46,3 +46,4 @@ for _, name in pairs(default_nodes) do
sunlight_propagates = true,
})
end

View File

@ -1,133 +0,0 @@
-- Function to convert all stairs/slabs/etc nodes from
-- inverted, wall, etc to regular + 6d facedir
local dirs1 = { 21, 20, 23, 22, 21 }
local dirs2 = { 15, 8, 17, 6, 15 }
local dirs3 = { 14, 11, 16, 5, 14 }
function register_6dfacedir_conversion(modname, material)
--print("Register stairsplus 6d facedir conversion")
--print('ABM for '..modname..' "'..material..'"')
local objects_list1 = {
modname..":slab_" .. material .. "_inverted",
modname..":slab_" .. material .. "_quarter_inverted",
modname..":slab_" .. material .. "_three_quarter_inverted",
modname..":stair_" .. material .. "_inverted",
modname..":stair_" .. material .. "_wall",
modname..":stair_" .. material .. "_wall_half",
modname..":stair_" .. material .. "_wall_half_inverted",
modname..":stair_" .. material .. "_half_inverted",
modname..":stair_" .. material .. "_right_half_inverted",
modname..":panel_" .. material .. "_vertical",
modname..":panel_" .. material .. "_top",
}
local objects_list2 = {
modname..":slab_" .. material .. "_wall",
modname..":slab_" .. material .. "_quarter_wall",
modname..":slab_" .. material .. "_three_quarter_wall",
modname..":stair_" .. material .. "_inner_inverted",
modname..":stair_" .. material .. "_outer_inverted",
modname..":micro_" .. material .. "_top"
}
for j in ipairs(objects_list1) do
local flip_upside_down = false
local flip_to_wall = false
local object = objects_list1[j]
local dest_object = objects_list1[j]
if string.find(dest_object, "_inverted") then
flip_upside_down = true
dest_object = string.gsub(dest_object, "_inverted", "")
end
if string.find(dest_object, "_top") then
flip_upside_down = true
dest_object = string.gsub(dest_object, "_top", "")
end
if string.find(dest_object, "_wall") then
flip_to_wall = true
dest_object = string.gsub(dest_object, "_wall", "")
end
if string.find(dest_object, "_vertical") then
flip_to_wall = true
dest_object = string.gsub(dest_object, "_vertical", "")
end
if string.find(dest_object, "_half") and not string.find(dest_object, "_right_half") then
dest_object = string.gsub(dest_object, "_half", "_right_half")
elseif string.find(dest_object, "_right_half") then
dest_object = string.gsub(dest_object, "_right_half", "_half")
end
--print(" +---> convert "..object)
--print(" | to "..dest_object)
minetest.register_abm({
nodenames = { object },
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local fdir = node.param2 or 0
if flip_upside_down and not flip_to_wall then
nfdir = dirs1[fdir+2]
elseif flip_to_wall and not flip_upside_down then
nfdir = dirs2[fdir+1]
elseif flip_to_wall and flip_upside_down then
nfdir = dirs3[fdir+2]
end
minetest.env:add_node(pos, {name = dest_object, param2 = nfdir})
end
})
end
for j in ipairs(objects_list2) do
local flip_upside_down = false
local flip_to_wall = false
local object = objects_list2[j]
local dest_object = objects_list2[j]
if string.find(dest_object, "_inverted") then
flip_upside_down = true
dest_object = string.gsub(dest_object, "_inverted", "")
end
if string.find(dest_object, "_top") then
flip_upside_down = true
dest_object = string.gsub(dest_object, "_top", "")
end
if string.find(dest_object, "_wall") then
flip_to_wall = true
dest_object = string.gsub(dest_object, "_wall", "")
end
--print(" +---> convert "..object)
--print(" | to "..dest_object)
minetest.register_abm({
nodenames = { object },
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local fdir = node.param2
local nfdir = 20
if flip_upside_down and not flip_to_wall then
nfdir = dirs1[fdir+1]
elseif flip_to_wall and not flip_upside_down then
nfdir = dirs2[fdir+2]
end
minetest.env:add_node(pos, {name = dest_object, param2 = nfdir})
end
})
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 522 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 533 B

View File

@ -9,7 +9,7 @@ if (minetest.get_modpath("intllib")) then
end
moreores_modpath = minetest.get_modpath("moreores")
dofile(moreores_modpath.."/_config.txt")
dofile(moreores_modpath .. "/_config.txt")
--[[
****
@ -35,58 +35,47 @@ local function hoe_on_use(itemstack, user, pointed_thing, uses)
end
local under = minetest.get_node(pt.under)
local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
local above = minetest.get_node(p)
local pos = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z}
local above = minetest.get_node(pos)
-- return if any of the nodes is not registered
if not minetest.registered_nodes[under.name] then
return
end
if not minetest.registered_nodes[above.name] then
return
end
-- Return if any of the nodes is not registered:
if not minetest.registered_nodes[under.name] then return end
if not minetest.registered_nodes[above.name] then return end
-- check if the node above the pointed thing is air
if above.name ~= "air" then
return
end
-- Check if the node above the pointed thing is air:
if above.name ~= "air" then return end
-- check if pointing at dirt
if minetest.get_item_group(under.name, "soil") ~= 1 then
return
end
-- Check if pointing at dirt:
if minetest.get_item_group(under.name, "soil") ~= 1 then return end
-- turn the node into soil, wear out item and play sound
minetest.set_node(pt.under, {name="farming:soil"})
minetest.sound_play("default_dig_crumbly", {
pos = pt.under,
gain = 0.5,
})
itemstack:add_wear(65535/(uses-1))
-- Turn the node into soil, wear out item and play sound:
minetest.set_node(pt.under, {name ="farming:soil"})
minetest.sound_play("default_dig_crumbly", {pos = pt.under, gain = 0.5})
itemstack:add_wear(65535 / (uses - 1))
return itemstack
end
local function get_recipe(c, name)
if name == "sword" then
return {{c},{c},{"default:stick"}}
return {{c}, {c}, {"group:stick"}}
end
if name == "shovel" then
return {{c},{"default:stick"},{"default:stick"}}
return {{c}, {"group:stick"}, {"group:stick"}}
end
if name == "axe" then
return {{c,c},{c,"default:stick"},{"","default:stick"}}
return {{c, c}, {c, "group:stick"}, {"", "group:stick"}}
end
if name == "pick" then
return {{c,c,c},{"","default:stick",""},{"","default:stick",""}}
return {{c, c, c}, {"", "group:stick", ""}, {"", "group:stick", ""}}
end
if name == "hoe" then
return {{c,c},{"","default:stick"},{"","default:stick"}}
return {{c, c}, {"", "group:stick"}, {"", "group:stick"}}
end
if name == "block" then
return {{c,c,c},{c,c,c},{c,c,c}}
return {{c, c, c}, {c, c, c}, {c, c, c}}
end
if name == "lockedchest" then
return {{"default:wood","default:wood","default:wood"},{"default:wood",c,"default:wood"},{"default:wood","default:wood","default:wood"}}
return {{"group:wood", "group:wood", "group:wood"}, {"group:wood", c, "group:wood"}, {"group:wood", "group:wood", "group:wood"}}
end
end
@ -104,7 +93,7 @@ local function add_ore(modname, description, mineral_name, oredef)
minetest.register_node(modname .. ":mineral_"..mineral_name, {
description = S("%s Ore"):format(S(description)),
tiles = {"default_stone.png^"..modname.."_mineral_"..mineral_name..".png"},
groups = {cracky=3},
groups = {cracky = 3},
sounds = default_stone_sounds,
drop = lumpitem
})
@ -115,7 +104,7 @@ local function add_ore(modname, description, mineral_name, oredef)
minetest.register_node(blockitem, {
description = S("%s Block"):format(S(description)),
tiles = { img_base .. "_block.png" },
groups = {snappy=1,bendy=2,cracky=1,melty=2,level=2},
groups = {snappy = 1,bendy = 2, cracky = 1,melty = 2,level= 2},
sounds = default_stone_sounds
})
minetest.register_alias(mineral_name.."_block", blockitem)
@ -158,20 +147,20 @@ local function add_ore(modname, description, mineral_name, oredef)
if oredef.makes.chest then
minetest.register_craft( {
output = "default:chest_locked 1",
output = "default:chest_locked",
recipe = {
{ ingot },
{ "default:chest" }
{ingot},
{"default:chest"}
}
})
minetest.register_craft( {
output = "default:chest_locked 1",
output = "default:chest_locked",
recipe = get_recipe(ingot, "lockedchest")
})
end
oredef.oredef.ore_type = "scatter"
oredef.oredef.ore = modname..":mineral_"..mineral_name
oredef.oredef.ore = modname .. ":mineral_" .. mineral_name
oredef.oredef.wherein = "default:stone"
minetest.register_ore(oredef.oredef)
@ -181,25 +170,32 @@ local function add_ore(modname, description, mineral_name, oredef)
description = "",
inventory_image = toolimg_base .. toolname .. ".png",
tool_capabilities = {
max_drop_level=3,
groupcaps=tooldef
max_drop_level = 3,
groupcaps = tooldef
}
}
if toolname == "sword" then
tdef.full_punch_interval = oredef.punchint
tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval
tdef.tool_capabilities.damage_groups = oredef.damage_groups
tdef.description = S("%s Sword"):format(S(description))
end
if toolname == "pick" then
tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval
tdef.tool_capabilities.damage_groups = oredef.damage_groups
tdef.description = S("%s Pickaxe"):format(S(description))
end
if toolname == "axe" then
tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval
tdef.tool_capabilities.damage_groups = oredef.damage_groups
tdef.description = S("%s Axe"):format(S(description))
end
if toolname == "shovel" then
tdef.full_punch_interval = oredef.full_punch_interval
tdef.tool_capabilities.damage_groups = oredef.damage_groups
tdef.description = S("%s Shovel"):format(S(description))
end
@ -224,14 +220,13 @@ local function add_ore(modname, description, mineral_name, oredef)
end
end
-- Add everything (compact(ish)!)
-- Add everything:
local modname = "moreores"
local oredefs = {
silver = {
desc = "Silver",
makes = {ore=true, block=true, lump=true, ingot=true, chest=true},
makes = {ore = true, block = true, lump = true, ingot = true, chest = true},
oredef = {clust_scarcity = moreores_silver_chunk_size * moreores_silver_chunk_size * moreores_silver_chunk_size,
clust_num_ores = moreores_silver_ore_per_chunk,
clust_size = moreores_silver_chunk_size,
@ -240,29 +235,30 @@ local oredefs = {
},
tools = {
pick = {
cracky={times={[1]=2.60, [2]=1.00, [3]=0.60}, uses=100, maxlevel=1}
cracky = {times = {[1] = 2.60, [2] = 1.00, [3] = 0.60}, uses = 100, maxlevel= 1}
},
hoe = {
uses = 300
},
shovel = {
crumbly={times={[1]=1.10, [2]=0.40, [3]=0.25}, uses=100, maxlevel=1}
crumbly = {times = {[1] = 1.10, [2] = 0.40, [3] = 0.25}, uses = 100, maxlevel= 1}
},
axe = {
choppy={times={[1]=2.50, [2]=0.80, [3]=0.50}, uses=100, maxlevel=1},
fleshy={times={[2]=1.10, [3]=0.60}, uses=100, maxlevel=1}
choppy = {times = {[1] = 2.50, [2] = 0.80, [3] = 0.50}, uses = 100, maxlevel= 1},
fleshy = {times = {[2] = 1.10, [3] = 0.60}, uses = 100, maxlevel= 1}
},
sword = {
fleshy={times={[2]=0.70, [3]=0.30}, uses=100, maxlevel=1},
snappy={times={[2]=0.70, [3]=0.30}, uses=100, maxlevel=1},
choppy={times={[3]=0.80}, uses=100, maxlevel=0}
fleshy = {times = {[2] = 0.70, [3] = 0.30}, uses = 100, maxlevel= 1},
snappy = {times = {[2] = 0.70, [3] = 0.30}, uses = 100, maxlevel= 1},
choppy = {times = {[3] = 0.80}, uses = 100, maxlevel= 0}
}
},
punchint = 1.0
full_punch_interval = 1.0,
damage_groups = {fleshy = 6},
},
tin = {
desc = "Tin",
makes = {ore=true, block=true, lump=true, ingot=true, chest=false},
makes = {ore = true, block = true, lump = true, ingot = true, chest = false},
oredef = {clust_scarcity = moreores_tin_chunk_size * moreores_tin_chunk_size * moreores_tin_chunk_size,
clust_num_ores = moreores_tin_ore_per_chunk,
clust_size = moreores_tin_chunk_size,
@ -273,7 +269,7 @@ local oredefs = {
},
mithril = {
desc = "Mithril",
makes = {ore=true, block=true, lump=true, ingot=true, chest=false},
makes = {ore = true, block = true, lump = true, ingot = true, chest = false},
oredef = {clust_scarcity = moreores_mithril_chunk_size * moreores_mithril_chunk_size * moreores_mithril_chunk_size,
clust_num_ores = moreores_mithril_ore_per_chunk,
clust_size = moreores_mithril_chunk_size,
@ -282,25 +278,26 @@ local oredefs = {
},
tools = {
pick = {
cracky={times={[1]=2.25, [2]=0.55, [3]=0.35}, uses=200, maxlevel=1}
cracky = {times = {[1] = 2.25, [2] = 0.55, [3] = 0.35}, uses = 200, maxlevel= 1}
},
hoe = {
uses = 1000
},
shovel = {
crumbly={times={[1]=0.70, [2]=0.35, [3]=0.20}, uses=200, maxlevel=1}
crumbly = {times = {[1] = 0.70, [2] = 0.35, [3] = 0.20}, uses = 200, maxlevel= 1}
},
axe = {
choppy={times={[1]=1.75, [2]=0.45, [3]=0.45}, uses=200, maxlevel=1},
fleshy={times={[2]=0.95, [3]=0.30}, uses=200, maxlevel=1}
choppy = {times = {[1] = 1.75, [2] = 0.45, [3] = 0.45}, uses = 200, maxlevel= 1},
fleshy = {times = {[2] = 0.95, [3] = 0.30}, uses = 200, maxlevel= 1}
},
sword = {
fleshy={times={[2]=0.65, [3]=0.25}, uses=200, maxlevel=1},
snappy={times={[2]=0.70, [3]=0.25}, uses=200, maxlevel=1},
choppy={times={[3]=0.65}, uses=200, maxlevel=0}
fleshy = {times = {[2] = 0.65, [3] = 0.25}, uses = 200, maxlevel= 1},
snappy = {times = {[2] = 0.70, [3] = 0.25}, uses = 200, maxlevel= 1},
choppy = {times = {[3] = 0.65}, uses = 200, maxlevel= 0}
}
},
punchint = 0.45
full_punch_interval = 0.45,
damage_groups = {fleshy = 9},
}
}
@ -314,13 +311,12 @@ minetest.register_craft({
output = "moreores:copper_rail 16",
recipe = {
{"default:copper_ingot", "", "default:copper_ingot"},
{"default:copper_ingot", "default:stick", "default:copper_ingot"},
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
{"default:copper_ingot", "", "default:copper_ingot"}
}
})
-- Bronze has some special cases, because it is made from copper and tin
-- Bronze has some special cases, because it is made from copper and tin:
minetest.register_craft( {
type = "shapeless",
output = "default:bronze_ingot 3",
@ -331,8 +327,7 @@ minetest.register_craft( {
}
})
-- Unique node
-- Unique node:
minetest.register_node("moreores:copper_rail", {
description = S("Copper Rail"),
drawtype = "raillike",
@ -346,7 +341,7 @@ minetest.register_node("moreores:copper_rail", {
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,rail=1,connect_to_raillike=1},
groups = {bendy = 2,snappy = 1,dig_immediate = 2,rail= 1, connect_to_raillike = 1},
mesecons = {
effector = {
action_on = function(pos, node)
@ -360,9 +355,11 @@ minetest.register_node("moreores:copper_rail", {
},
})
-- mg suppport
-- mg support:
if minetest.get_modpath("mg") then
dofile(moreores_modpath.."/mg.lua")
end
print(S("[moreores] loaded."))
if minetest.setting_getbool("log_mods") then
print(S("[moreores] loaded."))
end

View File

@ -0,0 +1,22 @@
# Translation by Xanthin
[moreores] loaded. = [moreores] geladen.
%s Ore = %serz
%s Lump = %sklumpen
%s Ingot = %sbarren
%s Block = %sblock
%s Pickaxe = %sspitzhacke
%s Shovel = %sschaufel
%s Axe = %saxt
%s Sword = %sschwert
%s Hoe = %shacke
Copper = Kupfer
Tin = Zinn
Bronze = Bronze
Silver = Silber
Gold = Gold
Mithril = Mithril
Copper Rail = Kupferschiene

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 341 B

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 249 B

After

Width:  |  Height:  |  Size: 128 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 362 B

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 382 B

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 546 B

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 581 B

After

Width:  |  Height:  |  Size: 389 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 576 B

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 577 B

After

Width:  |  Height:  |  Size: 374 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 358 B

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 364 B

After

Width:  |  Height:  |  Size: 174 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 B

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 B

After

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 614 B

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 B

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 365 B

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 B

After

Width:  |  Height:  |  Size: 181 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 356 B

After

Width:  |  Height:  |  Size: 221 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 269 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 B

After

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 361 B

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 286 B

After

Width:  |  Height:  |  Size: 160 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 253 B

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 B

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 294 B

After

Width:  |  Height:  |  Size: 171 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 B

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 275 B

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 211 B

After

Width:  |  Height:  |  Size: 140 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 337 B

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 279 B

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 B

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 296 B

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 218 B

After

Width:  |  Height:  |  Size: 142 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 337 B

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 290 B

After

Width:  |  Height:  |  Size: 166 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 254 B

After

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 299 B

After

Width:  |  Height:  |  Size: 172 B

View File

@ -1,7 +1,5 @@
default
plants_lib
skylands
moreblocks?
skylands

View File

@ -60,17 +60,6 @@ else
moretrees.expect_infinite_stacks = true
end
-- node clone, for redefining stuff
function moretrees:clone_node(name)
node2={}
node=minetest.registered_nodes[name]
for k,v in pairs(node) do
node2[k]=v
end
return node2
end
-- tables, load other files
moretrees.cutting_tools = {
@ -171,7 +160,9 @@ end
if moretrees.enable_fir then
plantslib:register_generate_plant(moretrees.fir_biome, moretrees.spawn_fir_object)
plantslib:register_generate_plant(moretrees.fir_biome_snow, moretrees.spawn_fir_snow_object)
if minetest.get_modpath("snow") then
plantslib:register_generate_plant(moretrees.fir_biome_snow, moretrees.spawn_fir_snow_object)
end
end
-- Code to spawn a birch tree

View File

@ -19,14 +19,13 @@ end
if moretrees.enable_leafdecay then
for i in ipairs(moretrees.treelist) do
local treename = moretrees.treelist[i][1]
if treename ~= "jungletree" and treename ~= "fir" then
if treename ~= "jungletree" and treename ~= "fir" and treename ~= "palm" then
minetest.register_abm({
nodenames = "moretrees:"..treename.."_leaves",
interval = moretrees.leafdecay_delay,
chance = moretrees.leafdecay_chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.find_node_near(pos, moretrees.leafdecay_radius, "moretrees:"..treename.."_trunk") then return end
if minetest.find_node_near(pos, moretrees.leafdecay_radius, "ignore") then return end
if minetest.find_node_near(pos, moretrees.leafdecay_radius, { "ignore", "moretrees:"..treename.."_trunk" }) then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)
@ -40,8 +39,7 @@ if moretrees.enable_leafdecay then
interval = moretrees.leafdecay_delay,
chance = moretrees.leafdecay_chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.find_node_near(pos, moretrees.leafdecay_radius, {"default:jungletree", "moretrees:jungletree_trunk"}) then return end
if minetest.find_node_near(pos, moretrees.leafdecay_radius, "ignore") then return end
if minetest.find_node_near(pos, moretrees.leafdecay_radius, {"ignore", "default:jungletree", "moretrees:jungletree_trunk"}) then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)
@ -53,11 +51,10 @@ if moretrees.enable_leafdecay then
interval = moretrees.leafdecay_delay,
chance = moretrees.leafdecay_chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.find_node_near(pos, moretrees.leafdecay_radius, "moretrees:fir_trunk") then return end
if minetest.find_node_near(pos, moretrees.leafdecay_radius, "ignore") then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)
if minetest.find_node_near(pos, moretrees.leafdecay_radius, { "ignore", "moretrees:fir_trunk" }) then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)
end
})
@ -66,11 +63,10 @@ if moretrees.enable_leafdecay then
interval = moretrees.leafdecay_delay,
chance = moretrees.leafdecay_chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.find_node_near(pos, moretrees.palm_leafdecay_radius, "moretrees:palm_trunk") then return end
if minetest.find_node_near(pos, moretrees.palm_leafdecay_radius, "ignore") then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)
if minetest.find_node_near(pos, moretrees.palm_leafdecay_radius, { "ignore", "moretrees:palm_trunk" }) then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)
end
})
end
@ -82,8 +78,7 @@ if moretrees.enable_default_leafdecay then
interval = moretrees.default_leafdecay_delay,
chance = moretrees.default_leafdecay_chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.find_node_near(pos, moretrees.default_leafdecay_radius, "default:tree") then return end
if minetest.find_node_near(pos, moretrees.default_leafdecay_radius, "ignore") then return end
if minetest.find_node_near(pos, moretrees.default_leafdecay_radius, { "ignore", "default:tree" }) then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)
@ -98,8 +93,7 @@ if moretrees.enable_default_jungle_leafdecay then
interval = moretrees.default_jungle_leafdecay_delay,
chance = moretrees.default_jungle_leafdecay_chance,
action = function(pos, node, active_object_count, active_object_count_wider)
if minetest.find_node_near(pos, moretrees.default_jungle_leafdecay_radius, "default:jungletree") then return end
if minetest.find_node_near(pos, moretrees.default_jungle_leafdecay_radius, "ignore") then return end
if minetest.find_node_near(pos, moretrees.default_jungle_leafdecay_radius, { "ignore", "default:jungletree" }) then return end
process_drops(pos, node.name)
minetest.remove_node(pos)
nodeupdate(pos)

View File

@ -38,37 +38,45 @@ if moretrees.plantlike_leaves then
moretrees_plantlike_leaves_visual_scale = 1.189
end
local new_default_leaves = moretrees:clone_node("default:leaves")
if moretrees.enable_default_leafdecay then
new_default_leaves.groups = {snappy=3, flammable=2, leaves=1}
end
if moretrees.plantlike_leaves then
new_default_leaves.inventory_image = minetest.inventorycube("default_leaves.png")
new_default_leaves.drawtype = "plantlike"
new_default_leaves.visual_scale = moretrees_plantlike_leaves_visual_scale
new_default_leaves.tiles = {"default_leaves_plantlike.png"}
else
new_default_leaves.waving = 1
end
if moretrees.enable_default_leafdecay or moretrees.plantlike_leaves then
minetest.register_node(":default:leaves", new_default_leaves)
end
-- redefine default leaves to handle plantlike and/or leaf decay options
local new_default_jungleleaves = moretrees:clone_node("default:jungleleaves")
if moretrees.enable_default_leafdecay then
new_default_jungleleaves.groups = {snappy=3, flammable=2, leaves=1}
end
if moretrees.plantlike_leaves then
new_default_jungleleaves.inventory_image = minetest.inventorycube("default_jungleleaves.png")
new_default_jungleleaves.drawtype = "plantlike"
new_default_jungleleaves.visual_scale = moretrees_plantlike_leaves_visual_scale
new_default_jungleleaves.tiles = {"default_jungleleaves_plantlike.png"}
else
new_default_jungleleaves.waving = 1
end
if moretrees.enable_default_leafdecay or moretrees.plantlike_leaves then
minetest.register_node(":default:jungleleaves", new_default_jungleleaves)
end
if moretrees.enable_default_leafdecay then
minetest.override_item("default:leaves", {
groups = { snappy = 3, flammable = 2, leaves = 1 }
})
end
if moretrees.plantlike_leaves then
minetest.override_item("default:leaves", {
inventory_image = minetest.inventorycube("default_leaves.png"),
drawtype = "plantlike",
visual_scale = 1.189,
tiles = { "default_leaves_plantlike.png" }
})
else
minetest.override_item("default:leaves", {
waving = 1
})
end
-- redefine default jungle leaves for same
if moretrees.enable_default_leafdecay then
minetest.override_item("default:jungleleaves", {
groups = { snappy = 3, flammable = 2, leaves = 1 }
})
end
if moretrees.plantlike_leaves then
minetest.override_item("default:jungleleaves", {
inventory_image = minetest.inventorycube("default_jungleleaves.png"),
drawtype = "plantlike",
visual_scale = 1.189,
tiles = { "default_jungleleaves_plantlike.png" }
})
else
minetest.override_item("default:jungleleaves", {
waving = 1
})
end
for i in ipairs(moretrees.treelist) do
local treename = moretrees.treelist[i][1]
@ -348,9 +356,9 @@ minetest.register_node("moretrees:fir_leaves_bright", {
})
if moretrees.enable_redefine_apple then
local new_default_apple = moretrees:clone_node("default:apple")
new_default_apple.groups.attached_node = 1
minetest.register_node(":default:apple", new_default_apple)
minetest.override_item("default:apple",
{groups = { fleshy=3, dig_immediate=3, flammable=2, leafdecay=3, leafdecay_drop=1, attached_node = 1}
})
end
table.insert(moretrees.avoidnodes, "default:jungletree")
@ -379,10 +387,6 @@ minetest.register_node("moretrees:rubber_tree_trunk_empty", {
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
on_place = minetest.rotate_node,
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
meta:set_int("placed", 1)
end
})
minetest.register_abm({
@ -400,12 +404,15 @@ minetest.register_abm({
minetest.register_alias("technic:rubber_tree_full", "moretrees:rubber_tree_trunk")
minetest.register_alias("farming_plus:rubber_tree_full", "moretrees:rubber_tree_trunk")
minetest.register_alias("farming:rubber_tree_full", "moretrees:rubber_tree_trunk")
minetest.register_alias("technic:rubber_leaves", "moretrees:rubber_tree_leaves")
minetest.register_alias("farming_plus:rubber_leaves", "moretrees:rubber_tree_leaves")
minetest.register_alias("farming:rubber_leaves", "moretrees:rubber_tree_leaves")
minetest.register_alias("farming_plus:rubber_sapling", "moretrees:rubber_tree_sapling")
minetest.register_alias("technic:rubber_tree_sapling", "moretrees:rubber_tree_sapling")
minetest.register_alias("farming_plus:rubber_sapling", "moretrees:rubber_tree_sapling")
minetest.register_alias("farming:rubber_sapling", "moretrees:rubber_tree_sapling")
minetest.register_alias("default:junglesapling","moretrees:jungletree_sapling")
minetest.register_alias("moretrees:jungletree_trunk_sideways", "moreblocks:horizontal_jungle_tree")

View File

@ -1,72 +1,38 @@
-- autorouting for pneumatic tubes
local function in_table(table,element)
for _,el in ipairs(table) do
if el==element then return true end
end
return false
end
local function is_tube(nodename)
return in_table(pipeworks.tubenodes,nodename)
end
if pipeworks == nil then
pipeworks = {}
return table.contains(pipeworks.tubenodes, nodename)
end
--a function for determining which side of the node we are on
local function nodeside(node, tubedir)
if node and (node.param2 < 0 or node.param2 > 23) then node.param2 = 0 end
--get a vector pointing back
local backdir = minetest.facedir_to_dir(node.param2)
--check whether the vector is equivalent to the tube direction; if it is, the tube's on the backside
if backdir.x == tubedir.x and backdir.y == tubedir.y and backdir.z == tubedir.z then
return "back"
if node.param2 < 0 or node.param2 > 23 then
node.param2 = 0
end
--check whether the vector is antiparallel with the tube direction; that indicates the front
if backdir.x == -tubedir.x and backdir.y == -tubedir.y and backdir.z == -tubedir.z then
local backdir = minetest.facedir_to_dir(node.param2)
local back = vector.dot(backdir, tubedir)
if back == 1 then
return "back"
elseif back == -1 then
return "front"
end
--facedir is defined in terms of the top-bottom axis of the node; we'll take advantage of that
local topdir = ({[0]={x=0, y=1, z=0},
{x=0, y=0, z=1},
{x=0, y=0, z=-1},
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=-1, z=0}})[math.floor(node.param2/4)]
--is this the top?
if topdir.x == tubedir.x and topdir.y == tubedir.y and topdir.z == tubedir.z then
local topdir = minetest.facedir_to_top_dir(node.param2)
local top = vector.dot(topdir, tubedir)
if top == 1 then
return "top"
end
--or the bottom?
if topdir.x == -tubedir.x and topdir.y == -tubedir.y and topdir.z == -tubedir.z then
elseif top == -1 then
return "bottom"
end
--we shall apply some maths to obtain the right-facing vector
local rightdir = {x=topdir.y*backdir.z - backdir.y*topdir.z,
y=topdir.z*backdir.x - backdir.z*topdir.x,
z=topdir.x*backdir.y - backdir.x*topdir.y}
--is this the right side?
if rightdir.x == tubedir.x and rightdir.y == tubedir.y and rightdir.z == tubedir.z then
local rightdir = minetest.facedir_to_right_dir(node.param2)
local right = vector.dot(rightdir, tubedir)
if right == 1 then
return "right"
end
--or the left?
if rightdir.x == -tubedir.x and rightdir.y == -tubedir.y and rightdir.z == -tubedir.z then
else
return "left"
end
--we should be done by now; initiate panic mode
minetest.log("error", "nodeside has been confused by its parameters; see pipeworks autoplace_tubes.lua, line 78")
end
local vts = {0, 3, 1, 4, 2, 5}
@ -78,23 +44,23 @@ local function tube_autoroute(pos)
if not is_tube(nctr.name) then return end
local adjustments = {
{ x=-1, y=0, z=0 },
{ x=1, y=0, z=0 },
{ x=0, y=-1, z=0 },
{ x=0, y=1, z=0 },
{ x=0, y=0, z=-1 },
{ x=0, y=0, z=1 }
{x = -1, y = 0, z = 0},
{x = 1, y = 0, z = 0},
{x = 0, y = -1, z = 0},
{x = 0, y = 1, z = 0},
{x = 0, y = 0, z = -1},
{x = 0, y = 0, z = 1}
}
-- xm = 1, xp = 2, ym = 3, yp = 4, zm = 5, zp = 6
local positions = {}
local nodes = {}
for i,adj in ipairs(adjustments) do
positions[i] = {x=pos.x+adj.x, y=pos.y+adj.y, z=pos.z+adj.z}
for i, adj in ipairs(adjustments) do
positions[i] = vector.add(pos, adj)
nodes[i] = minetest.get_node(positions[i])
end
for i,node in ipairs(nodes) do
for i, node in ipairs(nodes) do
local idef = minetest.registered_nodes[node.name]
-- handle the tubes themselves
if is_tube(node.name) then
@ -102,7 +68,9 @@ local function tube_autoroute(pos)
-- handle new style connectors
elseif idef and idef.tube and idef.tube.connect_sides then
local dir = adjustments[i]
if idef.tube.connect_sides[nodeside(node, {x=-dir.x, y=-dir.y, z=-dir.z})] then active[i] = 1 end
if idef.tube.connect_sides[nodeside(node, vector.multiply(dir, -1))] then
active[i] = 1
end
end
end
@ -110,18 +78,17 @@ local function tube_autoroute(pos)
local nodedef = minetest.registered_nodes[nctr.name]
local basename = nodedef.basename
local newname
if nodedef.style == "old" then
local nsurround = ""
for i,n in ipairs(active) do
nsurround = nsurround .. n
for i, n in ipairs(active) do
nsurround = nsurround..n
end
nctr.name = basename.."_"..nsurround
elseif nodedef.style == "6d" then
local s = 0
for i,n in ipairs(active) do
for i, n in ipairs(active) do
if n == 1 then
s = s+2^vts[i]
s = s + 2^vts[i]
end
end
nctr.name = basename.."_"..tube_table[s]
@ -131,14 +98,9 @@ local function tube_autoroute(pos)
end
function pipeworks.scan_for_tube_objects(pos)
if pos == nil then return end
tube_autoroute({ x=pos.x-1, y=pos.y , z=pos.z })
tube_autoroute({ x=pos.x+1, y=pos.y , z=pos.z })
tube_autoroute({ x=pos.x , y=pos.y-1, z=pos.z })
tube_autoroute({ x=pos.x , y=pos.y+1, z=pos.z })
tube_autoroute({ x=pos.x , y=pos.y , z=pos.z-1 })
tube_autoroute({ x=pos.x , y=pos.y , z=pos.z+1 })
tube_autoroute(pos)
for side = 0, 6 do
tube_autoroute(vector.add(pos, directions.side_to_dir(side)))
end
end
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
@ -157,7 +119,7 @@ minetest.register_on_dignode(function(pos, oldnode, digger)
end
end)
if minetest.get_modpath("mesecons_mvps") ~= nil then
if minetest.get_modpath("mesecons_mvps") then
mesecon:register_on_mvps_move(function(moved_nodes)
for _, n in ipairs(moved_nodes) do
pipeworks.scan_for_tube_objects(n.pos)

144
mods/pipeworks/common.lua Normal file
View File

@ -0,0 +1,144 @@
----------------------
-- Vector functions --
----------------------
function vector.cross(a, b)
return {
x = a.y * b.z - a.z * b.y,
y = a.z * b.x - a.x * b.z,
z = a.x * b.y - a.y * b.x
}
end
function vector.dot(a, b)
return a.x * b.x + a.y * b.y + a.z * b.z
end
-----------------------
-- Facedir functions --
-----------------------
function minetest.facedir_to_top_dir(facedir)
return ({[0] = {x = 0, y = 1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1},
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = -1, z = 0}})
[math.floor(facedir / 4)]
end
function minetest.facedir_to_right_dir(facedir)
return vector.cross(
minetest.facedir_to_top_dir(facedir),
minetest.facedir_to_dir(facedir)
)
end
directions = {}
function directions.side_to_dir(side)
return ({[0] = vector.new(),
vector.new( 0, 1, 0),
vector.new( 0, -1, 0),
vector.new( 1, 0, 0),
vector.new(-1, 0, 0),
vector.new( 0, 0, 1),
vector.new( 0, 0, -1)
})[side]
end
function directions.dir_to_side(dir)
local c = vector.dot(dir, vector.new(1, 2, 3)) + 4
return ({6, 2, 4, 0, 3, 1, 5})[c]
end
----------------------
-- String functions --
----------------------
--[[function string.split(str, sep)
local fields = {}
local index = 1
local expr = "([^"..sep.."])+"
string.gsub(str, expr, function(substring)
fields[index] = substring
index = index + 1
end)
return fields
end]]
function string.startswith(str, substr)
return str:sub(1, substr:len()) == substr
end
---------------------
-- Table functions --
---------------------
function table.contains(tbl, element)
for _, elt in pairs(tbl) do
if elt == element then
return true
end
end
return false
end
function table.extend(tbl, tbl2)
local index = #tbl + 1
for _, elt in ipairs(tbl2) do
tbl[index] = elt
index = index + 1
end
end
function table.recursive_replace(tbl, pattern, replace_with)
if type(tbl) == "table" then
local tbl2 = {}
for key, value in pairs(tbl) do
tbl2[key] = table.recursive_replace(value, pattern, replace_with)
end
return tbl2
elseif type(tbl) == "string" then
return tbl:gsub(pattern, replace_with)
else
return tbl
end
end
------------------------
-- Formspec functions --
------------------------
fs_helpers = {}
function fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
for field, value in pairs(fields) do
if field:startswith("fs_helpers_cycling:") then
local l = field:split(":")
local new_value = tonumber(l[2])
local meta_name = l[3]
meta:set_int(meta_name, new_value)
end
end
end
function fs_helpers.cycling_button(meta, base, meta_name, values)
local current_value = meta:get_int(meta_name)
local new_value = (current_value + 1) % (#values)
local text = values[current_value + 1]
local field = "fs_helpers_cycling:"..new_value..":"..meta_name
return base..";"..field..";"..text.."]"
end
---------
-- Env --
---------
function minetest.load_position(pos)
if minetest.get_node_or_nil(pos) then
return
end
local vm = minetest.get_voxel_manip()
vm:read_from_map(pos, pos)
end

View File

@ -1,25 +1,17 @@
-- this bit of code modifies the default chests and furnaces to be compatible
-- with pipeworks.
function pipeworks.clone_node(name)
local node2 = {}
local node = minetest.registered_nodes[name]
for k, v in pairs(node) do
node2[k] = v
end
return node2
end
local furnace = pipeworks.clone_node("default:furnace")
furnace.tiles[1] = "default_furnace_top.png^pipeworks_tube_connection_stony.png"
furnace.tiles[2] = "default_furnace_bottom.png^pipeworks_tube_connection_stony.png"
furnace.tiles[3] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
furnace.tiles[4] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
furnace.tiles[5] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
-- note we don't redefine entry 6 ( front)
furnace.groups.tubedevice = 1
furnace.groups.tubedevice_receiver = 1
furnace.tube = {
minetest.override_item("default:furnace", {
tiles = {
"default_furnace_top.png^pipeworks_tube_connection_stony.png",
"default_furnace_bottom.png^pipeworks_tube_connection_stony.png",
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
"default_furnace_front.png"
},
groups = {cracky = 2, tubedevice = 1, tubedevice_receiver = 1},
tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -39,27 +31,30 @@ local furnace = pipeworks.clone_node("default:furnace")
end
end,
input_inventory = "dst",
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
}
furnace.after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
furnace.after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
})
minetest.register_node(":default:furnace", furnace)
local furnace_active = pipeworks.clone_node("default:furnace_active")
furnace_active.tiles[1] = "default_furnace_top.png^pipeworks_tube_connection_stony.png"
furnace_active.tiles[2] = "default_furnace_bottom.png^pipeworks_tube_connection_stony.png"
furnace_active.tiles[3] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
furnace_active.tiles[4] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
furnace_active.tiles[5] = "default_furnace_side.png^pipeworks_tube_connection_stony.png"
-- note we don't redefine entry 6 (front)
furnace_active.groups.tubedevice = 1
furnace_active.groups.tubedevice_receiver = 1
furnace_active.tube = {
minetest.override_item("default:furnace_active", {
tiles = {
"default_furnace_top.png^pipeworks_tube_connection_stony.png",
"default_furnace_bottom.png^pipeworks_tube_connection_stony.png",
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
{
image = "default_furnace_front_active.png",
backface_culling = false,
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.5
},
}
},
groups = {cracky = 2, tubedevice = 1, tubedevice_receiver = 1, not_in_creative_inventory = 1},
tube = {
insert_object = function(pos,node,stack,direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -79,28 +74,21 @@ local furnace_active = pipeworks.clone_node("default:furnace_active")
end
end,
input_inventory = "dst",
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
}
furnace_active.after_place_node= function(pos)
pipeworks.scan_for_tube_objects(pos)
end
furnace_active.after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
})
minetest.register_node(":default:furnace_active", furnace_active)
local chest = pipeworks.clone_node("default:chest")
chest.tiles[1] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
chest.tiles[2] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
chest.tiles[3] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
chest.tiles[4] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
chest.tiles[5] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
-- note we don't redefine entry 6 (front).
chest.groups.tubedevice = 1
chest.groups.tubedevice_receiver = 1
chest.tube = {
minetest.override_item("default:chest", {
tiles = {
"default_chest_top.png^pipeworks_tube_connection_wooden.png",
"default_chest_top.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_front.png"
},
groups = {choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1, tubedevice_receiver = 1},
tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
@ -112,28 +100,21 @@ local chest = pipeworks.clone_node("default:chest")
return inv:room_for_item("main", stack)
end,
input_inventory = "main",
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
}
chest.after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
chest.after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
})
minetest.register_node(":default:chest", chest)
local chest_locked = pipeworks.clone_node("default:chest_locked")
chest_locked.tiles[1] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
chest_locked.tiles[2] = "default_chest_top.png^pipeworks_tube_connection_wooden.png"
chest_locked.tiles[3] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
chest_locked.tiles[4] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
chest_locked.tiles[5] = "default_chest_side.png^pipeworks_tube_connection_wooden.png"
-- note we don't redefine entry 6 (front).
chest_locked.groups.tubedevice = 1
chest_locked.groups.tubedevice_receiver = 1
chest_locked.tube = {
minetest.override_item("default:chest_locked", {
tiles = {
"default_chest_top.png^pipeworks_tube_connection_wooden.png",
"default_chest_top.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
"default_chest_lock.png"
},
groups = {choppy = 2, oddly_breakable_by_hand = 2, 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()
@ -144,15 +125,6 @@ local chest_locked = pipeworks.clone_node("default:chest_locked")
local inv = meta:get_inventory()
return inv:room_for_item("main", stack)
end,
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
}
local old_after_place = minetest.registered_nodes["default:chest_locked"].after_place_node
chest_locked.after_place_node = function(pos, placer)
pipeworks.scan_for_tube_objects(pos)
old_after_place(pos, placer)
end
chest_locked.after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end
minetest.register_node(":default:chest_locked", chest_locked)
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
})

View File

@ -38,9 +38,9 @@ minetest.register_craft( {
})
minetest.register_craft( {
output = "pipeworks:valve_off 2",
output = "pipeworks:valve_off_empty 2",
recipe = {
{ "", "default:stick", "" },
{ "", "group:stick", "" },
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
{ "", "default:steel_ingot", "" }
},
@ -59,7 +59,7 @@ minetest.register_craft( {
output = "pipeworks:grating 2",
recipe = {
{ "default:steel_ingot", "", "default:steel_ingot" },
{ "", "default:steel_ingot", "" },
{ "", "pipeworks:pipe_1_empty", "" },
{ "default:steel_ingot", "", "default:steel_ingot" }
},
})
@ -87,54 +87,72 @@ minetest.register_craft( {
if minetest.get_modpath("homedecor") == nil then
minetest.register_craftitem(":homedecor:plastic_sheeting", {
description = "Plastic sheet",
inventory_image = "homedecor_plastic_sheeting.png",
minetest.register_craftitem(":homedecor:oil_extract", {
description = "Oil extract",
inventory_image = "homedecor_oil_extract.png",
})
minetest.register_craftitem(":homedecor:plastic_base", {
description = "Unprocessed Plastic base",
wield_image = "homedecor_plastic_base.png",
inventory_image = "homedecor_plastic_base_inv.png",
minetest.register_craftitem(":homedecor:paraffin", {
description = "Unprocessed paraffin",
inventory_image = "homedecor_paraffin.png",
})
minetest.register_alias("homedecor:plastic_base", "homedecor:paraffin")
minetest.register_craftitem(":homedecor:plastic_sheeting", {
description = "Plastic sheet",
inventory_image = "homedecor_plastic_sheeting.png",
})
minetest.register_craft({
type = "shapeless",
output = 'homedecor:plastic_base 4',
recipe = { "default:leaves",
"group:leaves",
"group:leaves",
"group:leaves",
"group:leaves",
"group:leaves"
output = "homedecor:oil_extract 4",
recipe = {
"group:leaves",
"group:leaves",
"group:leaves",
"group:leaves",
"group:leaves",
"group:leaves"
}
})
minetest.register_craft({
type = "cooking",
output = "homedecor:plastic_sheeting",
recipe = "homedecor:plastic_base",
type = "cooking",
output = "homedecor:paraffin",
recipe = "homedecor:oil_extract",
})
minetest.register_craft({
type = 'fuel',
recipe = 'homedecor:plastic_base',
burntime = 30,
type = "cooking",
output = "homedecor:plastic_sheeting",
recipe = "homedecor:paraffin",
})
minetest.register_craft({
type = 'fuel',
recipe = 'homedecor:plastic_sheeting',
burntime = 30,
type = "fuel",
recipe = "homedecor:oil_extract",
burntime = 30,
})
minetest.register_craft({
type = "fuel",
recipe = "homedecor:paraffin",
burntime = 30,
})
minetest.register_craft({
type = "fuel",
recipe = "homedecor:plastic_sheeting",
burntime = 30,
})
end
minetest.register_craft( {
output = "pipeworks:one_way_tube 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
@ -277,7 +295,7 @@ minetest.register_craft( {
output = "pipeworks:filter 2",
recipe = {
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "default:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
},
})
@ -286,7 +304,7 @@ minetest.register_craft( {
output = "pipeworks:mese_filter 2",
recipe = {
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "default:stick", "default:mese", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
},
})

View File

@ -3,6 +3,7 @@
pipeworks.enable_pipes = true
pipeworks.enable_autocrafter = true
pipeworks.enable_deployer = true
pipeworks.enable_dispenser = true
pipeworks.enable_node_breaker = true
pipeworks.enable_teleport_tube = true
pipeworks.enable_pipe_devices = true

View File

@ -1,286 +0,0 @@
--register aliases for when someone had technic installed, but then uninstalled it but not pipeworks
minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off")
minetest.register_alias("technic:deployer_on", "pipeworks:deployer_on")
--define the functions from https://github.com/minetest/minetest/pull/834 while waiting for the devs to notice it
local function dir_to_facedir(dir, is6d)
--account for y if requested
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
--from above
if dir.y < 0 then
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 19
else
return 13
end
else
if dir.z < 0 then
return 10
else
return 4
end
end
--from below
else
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 15
else
return 17
end
else
if dir.z < 0 then
return 6
else
return 8
end
end
end
--otherwise, place horizontally
elseif math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 3
else
return 1
end
else
if dir.z < 0 then
return 2
else
return 0
end
end
end
minetest.register_craft({
output = 'pipeworks:deployer_off 1',
recipe = {
{'group:wood', 'default:chest','group:wood'},
{'default:stone', 'mesecons:piston','default:stone'},
{'default:stone', 'mesecons:mesecon','default:stone'},
}
})
local function swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
local function delay(x)
return (function() return x end)
end
local function deployer_on(pos, node)
if node.name ~= "pipeworks:deployer_off" then
return
end
--locate the above and under positions
local dir = minetest.facedir_to_dir(node.param2)
local pos_under, pos_above = {x = pos.x - dir.x, y = pos.y - dir.y, z = pos.z - dir.z}, {x = pos.x - 2*dir.x, y = pos.y - 2*dir.y, z = pos.z - 2*dir.z}
swap_node(pos, "pipeworks:deployer_on")
nodeupdate(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local invlist = inv:get_list("main")
for i, stack in ipairs(invlist) do
if stack:get_name() ~= nil and stack:get_name() ~= "" and minetest.get_node(pos_under).name == "air" then --obtain the first non-empty item slot
local pitch
local yaw
if dir.z < 0 then
yaw = 0
pitch = 0
elseif dir.z > 0 then
yaw = math.pi
pitch = 0
elseif dir.x < 0 then
yaw = 3*math.pi/2
pitch = 0
elseif dir.x > 0 then
yaw = math.pi/2
pitch = 0
elseif dir.y > 0 then
yaw = 0
pitch = -math.pi/2
else
yaw = 0
pitch = math.pi/2
end
local placer = {
get_inventory_formspec = delay(meta:get_string("formspec")),
get_look_dir = delay({x = -dir.x, y = -dir.y, z = -dir.z}),
get_look_pitch = delay(pitch),
get_look_yaw = delay(yaw),
get_player_control = delay({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false}),
get_player_control_bits = delay(0),
get_player_name = delay("deployer"),
is_player = delay(true),
set_inventory_formspec = delay(),
getpos = delay({x = pos.x, y = pos.y - 1.5, z = pos.z}), -- Player height
get_hp = delay(20),
get_inventory = delay(inv),
get_wielded_item = delay(stack),
get_wield_index = delay(i),
get_wield_list = delay("main"),
moveto = delay(),
punch = delay(),
remove = delay(),
right_click = delay(),
setpos = delay(),
set_hp = delay(),
set_properties = delay(),
set_wielded_item = function(self, item) inv:set_stack("main", i, item) end,
set_animation = delay(),
set_attach = delay(),
set_detach = delay(),
set_bone_position = delay(),
}
local stack2 = minetest.item_place(stack, placer, {type="node", under=pos_under, above=pos_above})
if minetest.setting_getbool("creative_mode") and not minetest.get_modpath("unified_inventory") then --infinite stacks ahoy!
stack2:take_item()
end
invlist[i] = stack2
inv:set_list("main", invlist)
return
end
end
end
local deployer_off = function(pos, node)
if node.name == "pipeworks:deployer_on" then
swap_node(pos, "pipeworks:deployer_off")
nodeupdate(pos)
end
end
minetest.register_node("pipeworks:deployer_off", {
description = "Deployer",
tile_images = {"pipeworks_deployer_top.png","pipeworks_deployer_bottom.png","pipeworks_deployer_side2.png","pipeworks_deployer_side1.png",
"pipeworks_deployer_back.png","pipeworks_deployer_front_off.png"},
mesecons = {effector={rules=pipeworks.rules_all,action_on=deployer_on,action_off=deployer_off}},
tube={insert_object=function(pos,node,stack,direction)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("main",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("main",stack)
end,
input_inventory="main",
connect_sides={back=1}},
is_ground_content = true,
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"invsize[8,9;]"..
"label[0,0;Deployer]"..
"list[current_name;main;4,1;3,3;]"..
"list[current_player;main;0,5;8,4;]")
meta:set_string("infotext", "Deployer")
local inv = meta:get_inventory()
inv:set_size("main", 3*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
after_place_node = function (pos, placer)
pipeworks.scan_for_tube_objects(pos, placer)
local placer_pos = placer:getpos()
--correct for the player's height
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
--correct for 6d facedir
if placer_pos then
local dir = {
x = pos.x - placer_pos.x,
y = pos.y - placer_pos.y,
z = pos.z - placer_pos.z
}
local node = minetest.get_node(pos)
node.param2 = dir_to_facedir(dir, true)
minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2)
end
end,
after_dig_node = pipeworks.scan_for_tube_objects,
})
minetest.register_node("pipeworks:deployer_on", {
description = "Deployer",
tile_images = {"pipeworks_deployer_top.png","pipeworks_deployer_bottom.png","pipeworks_deployer_side2.png","pipeworks_deployer_side1.png",
"pipeworks_deployer_back.png","pipeworks_deployer_front_on.png"},
mesecons = {effector={rules=pipeworks.rules_all,action_on=deployer_on,action_off=deployer_off}},
tube={insert_object=function(pos,node,stack,direction)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("main",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("main",stack)
end,
input_inventory="main",
connect_sides={back=1}},
is_ground_content = true,
paramtype2 = "facedir",
tubelike=1,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"invsize[8,9;]"..
"label[0,0;Deployer]"..
"list[current_name;main;4,1;3,3;]"..
"list[current_player;main;0,5;8,4;]")
meta:set_string("infotext", "Deployer")
local inv = meta:get_inventory()
inv:set_size("main", 3*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
after_place_node = function (pos, placer)
pipeworks.scan_for_tube_objects(pos, placer)
local placer_pos = placer:getpos()
--correct for the player's height
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
--correct for 6d facedir
if placer_pos then
local dir = {
x = pos.x - placer_pos.x,
y = pos.y - placer_pos.y,
z = pos.z - placer_pos.z
}
local node = minetest.get_node(pos)
node.param2 = dir_to_facedir(dir, true)
minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2)
end
end,
after_dig_node = pipeworks.scan_for_tube_objects,
})

View File

@ -590,7 +590,7 @@ for fill = 0, 10 do
groups = {snappy=3, pipe=1, tankfill=fill+1, not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
walkable = true,
drop = "pipeworks:storage_tank_"..fill,
drop = "pipeworks:storage_tank_0",
after_place_node = function(pos)
pipeworks.look_for_stackable_tanks(pos)
pipeworks.scan_for_pipe_objects(pos)
@ -616,6 +616,7 @@ for fill = 0, 10 do
groups = sgroups,
sounds = default.node_sound_wood_defaults(),
walkable = true,
drop = "pipeworks:storage_tank_0",
after_place_node = function(pos)
pipeworks.look_for_stackable_tanks(pos)
pipeworks.scan_for_pipe_objects(pos)

View File

@ -106,21 +106,23 @@ end
-------------------------------------------
-- Load the various other parts of the mod
dofile(pipeworks.modpath.."/common.lua")
dofile(pipeworks.modpath.."/models.lua")
dofile(pipeworks.modpath.."/autoplace_pipes.lua")
dofile(pipeworks.modpath.."/autoplace_tubes.lua")
dofile(pipeworks.modpath.."/luaentity.lua")
dofile(pipeworks.modpath.."/item_transport.lua")
dofile(pipeworks.modpath.."/flowing_logic.lua")
dofile(pipeworks.modpath.."/crafts.lua")
dofile(pipeworks.modpath.."/tubes.lua")
dofile(pipeworks.modpath.."/trashcan.lua")
dofile(pipeworks.modpath.."/wielder.lua")
if pipeworks.enable_pipes then dofile(pipeworks.modpath.."/pipes.lua") end
if pipeworks.enable_teleport_tube then dofile(pipeworks.modpath.."/teleport_tube.lua") end
if pipeworks.enable_pipe_devices then dofile(pipeworks.modpath.."/devices.lua") end
if pipeworks.enable_redefines then dofile(pipeworks.modpath.."/compat.lua") end
if pipeworks.enable_autocrafter then dofile(pipeworks.modpath.."/autocrafter.lua") end
if pipeworks.enable_deployer then dofile(pipeworks.modpath.."/deployer.lua") end
if pipeworks.enable_node_breaker then dofile(pipeworks.modpath.."/node_breaker.lua") end
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")

View File

@ -1,28 +1,3 @@
dofile(pipeworks.modpath.."/compat.lua")
--and an extra function for getting the right-facing vector
local function facedir_to_right_dir(facedir)
--find the other directions
local backdir = minetest.facedir_to_dir(facedir)
local topdir = ({[0]={x=0, y=1, z=0},
{x=0, y=0, z=1},
{x=0, y=0, z=-1},
{x=1, y=0, z=0},
{x=-1, y=0, z=0},
{x=0, y=-1, z=0}})[math.floor(facedir/4)]
--return a cross product
return {x=topdir.y*backdir.z - backdir.y*topdir.z,
y=topdir.z*backdir.x - backdir.z*topdir.x,
z=topdir.x*backdir.y - backdir.x*topdir.y}
end
minetest.register_craftitem("pipeworks:filter", {
description = "Filter",
stack_max = 99,
})
local fakePlayer = {
get_player_name = function() return ":pipeworks" end,
-- any other player functions called by allow_metadata_inventory_take anywhere...
@ -30,10 +5,17 @@ local fakePlayer = {
}
function pipeworks.tube_item(pos, item)
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
end
function pipeworks.tube_inject_item(pos, start_pos, velocity, item)
-- Take item in any format
local stack = ItemStack(item)
local obj = minetest.add_entity(pos, "pipeworks:tubed_item")
obj:get_luaentity():set_item(stack:to_string())
local obj = luaentity.add_entity(pos, "pipeworks:tubed_item")
obj:set_item(stack:to_string())
obj.start_pos = vector.new(start_pos)
obj:setvelocity(velocity)
--obj:set_color("red") -- todo: this is test-only code
return obj
end
@ -43,19 +25,78 @@ end
-- both optional w/ sensible defaults and fallback to normal allow_* function
-- XXX: possibly change insert_object to insert_item
-- sname = the current name to allow for, or nil if it allows anything
local function set_filter_infotext(data, meta)
local infotext = data.wise_desc.." Filter-Injector"
if meta:get_int("slotseq_mode") == 2 then
infotext = infotext .. " (slot #"..meta:get_int("slotseq_index").." next)"
end
meta:set_string("infotext", infotext)
end
local function grabAndFire(frominv,frominvname,frompos,fromnode,sname,tube,idef,dir,all)
local function set_filter_formspec(data, meta)
local itemname = data.wise_desc.." Filter-Injector"
local formspec = "size[8,8.5]"..
"item_image[0,0;1,1;pipeworks:"..data.name.."]"..
"label[1,0;"..minetest.formspec_escape(itemname).."]"..
"label[0,1;Prefer item types:]"..
"list[current_name;main;0,1.5;8,2;]"..
fs_helpers.cycling_button(meta, "button[0,3.5;4,1", "slotseq_mode",
{"Sequence slots by Priority",
"Sequence slots Randomly",
"Sequence slots by Rotation"})..
"list[current_player;main;0,4.5;8,4;]"
meta:set_string("formspec", formspec)
end
-- todo SOON: this function has *way too many* parameters
local function grabAndFire(data,slotseq_mode,filtmeta,frominv,frominvname,frompos,fromnode,filtername,fromtube,fromdef,dir,all)
local sposes = {}
for spos,stack in ipairs(frominv:get_list(frominvname)) do
if (sname == nil and stack:get_name() ~= "") or stack:get_name() == sname then
local matches
if filtername == "" then
matches = stack:get_name() ~= ""
else
matches = stack:get_name() == filtername
end
if matches then table.insert(sposes, spos) end
end
if #sposes == 0 then return false end
if slotseq_mode == 1 then
for i = #sposes, 2, -1 do
local j = math.random(i)
local t = sposes[j]
sposes[j] = sposes[i]
sposes[i] = t
end
elseif slotseq_mode == 2 then
local headpos = filtmeta:get_int("slotseq_index")
table.sort(sposes, function (a, b)
if a >= headpos then
if b < headpos then return true end
else
if b >= headpos then return false end
end
return a < b
end)
end
for _, spos in ipairs(sposes) do
local stack = frominv:get_stack(frominvname, spos)
local doRemove = stack:get_count()
if tube.can_remove then
doRemove = tube.can_remove(frompos, fromnode, stack, dir)
elseif idef.allow_metadata_inventory_take then
doRemove = idef.allow_metadata_inventory_take(frompos,"main",spos, stack, fakePlayer)
if fromtube.can_remove then
doRemove = fromtube.can_remove(frompos, fromnode, stack, dir)
elseif fromdef.allow_metadata_inventory_take then
doRemove = fromdef.allow_metadata_inventory_take(frompos, frominvname,spos, stack, fakePlayer)
end
-- stupid lack of continue statements grumble
if doRemove > 0 then
if slotseq_mode == 2 then
local nextpos = spos + 1
if nextpos > frominv:get_size(frominvname) then
nextpos = 1
end
filtmeta:set_int("slotseq_index", nextpos)
set_filter_infotext(data, filtmeta)
end
local item
local count
if all then
@ -63,162 +104,116 @@ local function grabAndFire(frominv,frominvname,frompos,fromnode,sname,tube,idef,
else
count = 1
end
if tube.remove_items then
if fromtube.remove_items then
-- it could be the entire stack...
item = tube.remove_items(frompos, fromnode, stack, dir, count)
item = fromtube.remove_items(frompos, fromnode, stack, dir, count)
else
item = stack:take_item(count)
frominv:set_stack(frominvname, spos, stack)
if idef.on_metadata_inventory_take then
idef.on_metadata_inventory_take(frompos, "main", spos, item, fakePlayer)
if fromdef.on_metadata_inventory_take then
fromdef.on_metadata_inventory_take(frompos, frominvname, spos, item, fakePlayer)
end
end
local item1 = pipeworks.tube_item(vector.add(frompos, vector.multiply(dir, 1.4)), item)
item1:get_luaentity().start_pos = vector.add(frompos, dir)
item1:setvelocity(dir)
item1:setacceleration({x=0, y=0, z=0})
local pos = vector.add(frompos, vector.multiply(dir, 1.4))
local start_pos = vector.add(frompos, dir)
local item1 = pipeworks.tube_inject_item(pos, start_pos, dir, item)
return true-- only fire one item, please
end
end
end
return false
end
minetest.register_node("pipeworks:filter", {
description = "Filter",
tiles = {"pipeworks_filter_top.png", "pipeworks_filter_top.png", "pipeworks_filter_output.png",
"pipeworks_filter_input.png", "pipeworks_filter_side.png", "pipeworks_filter_top.png"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,mesecon=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"invsize[8,6.5;]"..
"list[current_name;main;0,0;8,2;]"..
"list[current_player;main;0,2.5;8,4;]")
meta:set_string("infotext", "Filter")
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
mesecons={effector={action_on=function(pos,node)
minetest.registered_nodes[node.name].on_punch(pos,node,nil)
end}},
tube={connect_sides={right=1}},
on_punch = function (pos, node, puncher)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local dir = facedir_to_right_dir(node.param2)
local frompos = {x=pos.x - dir.x, y=pos.y - dir.y, z=pos.z - dir.z}
local fromnode=minetest.get_node(frompos)
if not fromnode then return end
local idef = minetest.registered_nodes[fromnode.name]
-- assert(idef)
local tube = idef.tube
if not (tube and tube.input_inventory) then
return
end
local frommeta = minetest.get_meta(frompos)
local frominvname = tube.input_inventory
local frominv = frommeta:get_inventory()
local sname
for _,filter in ipairs(inv:get_list("main")) do
sname = filter:get_name()
if sname ~= "" then
-- XXX: that's a lot of parameters
if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir) then return end
local function punch_filter(data, filtpos, filtnode)
local filtmeta = minetest.get_meta(filtpos)
local filtinv = filtmeta:get_inventory()
local dir = minetest.facedir_to_right_dir(filtnode.param2)
local frompos = vector.subtract(filtpos, dir)
local fromnode = minetest.get_node(frompos)
if not fromnode then return end
local fromdef = minetest.registered_nodes[fromnode.name]
if not fromdef then return end
local fromtube = fromdef.tube
if not (fromtube and fromtube.input_inventory) then return end
local filters = {}
for _, filterstack in ipairs(filtinv:get_list("main")) do
local filtername = filterstack:get_name()
if filtername ~= "" then table.insert(filters, filtername) end
end
if #filters == 0 then table.insert(filters, "") end
local slotseq_mode = filtmeta:get_int("slotseq_mode")
local frommeta = minetest.get_meta(frompos)
local frominv = frommeta:get_inventory()
if fromtube.before_filter then fromtube.before_filter(frompos) end
for _, frominvname in ipairs(type(fromtube.input_inventory) == "table" and fromtube.input_inventory or {fromtube.input_inventory}) do
local done = false
for _, filtername in ipairs(filters) do
if grabAndFire(data, slotseq_mode, filtmeta, frominv, frominvname, frompos, fromnode, filtername, fromtube, fromdef, dir, data.stackwise) then
done = true
break
end
end
if inv:is_empty("main") then
grabAndFire(frominv,frominvname,frompos,fromnode,nil,tube,idef,dir)
end
end,
})
minetest.register_craftitem("pipeworks:mese_filter", {
description = "Mese filter",
stack_max = 99,
})
minetest.register_node("pipeworks:mese_filter", {
description = "Mese filter",
tiles = {"pipeworks_mese_filter_top.png", "pipeworks_mese_filter_top.png", "pipeworks_mese_filter_output.png",
"pipeworks_mese_filter_input.png", "pipeworks_mese_filter_side.png", "pipeworks_mese_filter_top.png"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,mesecon=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"invsize[8,6.5;]"..
"list[current_name;main;0,0;8,2;]"..
"list[current_player;main;0,2.5;8,4;]")
meta:set_string("infotext", "Mese filter")
local inv = meta:get_inventory()
inv:set_size("main", 8*4)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
mesecons={effector={action_on=function(pos,node)
minetest.registered_nodes[node.name].on_punch(pos,node,nil)
end}},
tube={connect_sides={right=1}},
on_punch = function (pos, node, puncher)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
local dir = facedir_to_right_dir(node.param2)
local frompos = {x=pos.x - dir.x, y=pos.y - dir.y, z=pos.z - dir.z}
local fromnode=minetest.get_node(frompos)
local idef = minetest.registered_nodes[fromnode.name]
-- assert(idef)
local tube = idef.tube
if not (tube and tube.input_inventory) then
return
end
local frommeta = minetest.get_meta(frompos)
local frominvname = minetest.registered_nodes[fromnode.name].tube.input_inventory
local frominv = frommeta:get_inventory()
local sname
for _,filter in ipairs(inv:get_list("main")) do
sname = filter:get_name()
if sname ~= "" then
if grabAndFire(frominv, frominvname, frompos, fromnode, sname, tube, idef, dir, true) then return end
end
end
if inv:is_empty("main") then
grabAndFire(frominv, frominvname, frompos, fromnode, nil, tube, idef, dir, true)
end
end,
})
local function roundpos(pos)
return {x=math.floor(pos.x+0.5),y=math.floor(pos.y+0.5),z=math.floor(pos.z+0.5)}
if done then break end
end
if fromtube.after_filter then fromtube.after_filter(frompos) end
end
local function addVect(pos,vect)
return {x=pos.x+vect.x,y=pos.y+vect.y,z=pos.z+vect.z}
for _, data in ipairs({
{
name = "filter",
wise_desc = "Itemwise",
stackwise = false,
},
{
name = "mese_filter",
wise_desc = "Stackwise",
stackwise = true,
},
}) do
minetest.register_node("pipeworks:"..data.name, {
description = data.wise_desc.." Filter-Injector",
tiles = {
"pipeworks_"..data.name.."_top.png",
"pipeworks_"..data.name.."_top.png",
"pipeworks_"..data.name.."_output.png",
"pipeworks_"..data.name.."_input.png",
"pipeworks_"..data.name.."_side.png",
"pipeworks_"..data.name.."_top.png",
},
paramtype2 = "facedir",
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, mesecon = 2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
set_filter_formspec(data, meta)
set_filter_infotext(data, meta)
local inv = meta:get_inventory()
inv:set_size("main", 8*2)
end,
on_receive_fields = function(pos, formname, fields, sender)
fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
meta:set_int("slotseq_index", 1)
set_filter_formspec(data, meta)
set_filter_infotext(data, meta)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
mesecons = {
effector = {
action_on = function(pos, node)
punch_filter(data, pos, node)
end,
},
},
tube = {connect_sides = {right = 1}},
on_punch = function (pos, node, puncher)
punch_filter(data, pos, node)
end,
})
end
local adjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}}
@ -232,95 +227,75 @@ function pipeworks.notvel(tbl, vel)
end
local function go_next(pos, velocity, stack)
local chests = {}
local tubes = {}
local next_positions = {}
local max_priority = 0
local cnode = minetest.get_node(pos)
local cmeta = minetest.get_meta(pos)
local n
local can_go
local speed = math.abs(velocity.x + velocity.y + velocity.z)
if speed == 0 then
speed = 1
end
local vel = {x = velocity.x/speed, y = velocity.y/speed, z = velocity.z/speed,speed=speed}
if speed >= 4.1 then
speed = 4
elseif speed >= 1.1 then
speed = speed-0.1
speed = speed - 0.1
else
speed = 1
end
vel.speed=speed
vel.speed = speed
if minetest.registered_nodes[cnode.name] and minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
can_go = minetest.registered_nodes[cnode.name].tube.can_go(pos, cnode, vel, stack)
else
can_go = pipeworks.notvel(adjlist, vel)
end
local meta = nil
for _,vect in ipairs(can_go) do
local npos = addVect(pos,vect)
for _, vect in ipairs(can_go) do
local npos = vector.add(pos, vect)
local node = minetest.get_node(npos)
local tube_receiver = minetest.get_item_group(node.name,"tubedevice_receiver")
meta = minetest.get_meta(npos)
local tubelike = meta:get_int("tubelike")
if tube_receiver == 1 then
if minetest.registered_nodes[node.name].tube and
minetest.registered_nodes[node.name].tube.can_insert and
minetest.registered_nodes[node.name].tube.can_insert(npos, node, stack, vect) then
local i = #chests + 1
chests[i] = {}
chests[i].pos = npos
chests[i].vect = vect
local tubedevice = minetest.get_item_group(node.name, "tubedevice")
local tube_def = minetest.registered_nodes[node.name].tube
local tube_priority = (tube_def and tube_def.priority) or 100
if tubedevice > 0 and tube_priority >= max_priority then
if not tube_def or not tube_def.can_insert or
tube_def.can_insert(npos, node, stack, vect) then
if tube_priority > max_priority then
max_priority = tube_priority
next_positions = {}
end
next_positions[#next_positions + 1] = {pos = npos, vect = vect}
end
elseif tubelike == 1 then
local i = #tubes + 1
tubes[i] = {}
tubes[i].pos = npos
tubes[i].vect = vect
end
end
if chests[1] == nil then--no chests found
if tubes[1] == nil then
return 0
else
n = (cmeta:get_int("tubedir")%(#tubes)) + 1
if pipeworks.enable_cyclic_mode then
cmeta:set_int("tubedir",n)
end
velocity.x = tubes[n].vect.x*vel.speed
velocity.y = tubes[n].vect.y*vel.speed
velocity.z = tubes[n].vect.z*vel.speed
end
else
n = (cmeta:get_int("tubedir")%(#chests))+1
if pipeworks.enable_cyclic_mode then
cmeta:set_int("tubedir",n)
end
velocity.x = chests[n].vect.x*speed
velocity.y = chests[n].vect.y*speed
velocity.z = chests[n].vect.z*speed
if not next_positions[1] then
return false, nil
end
return 1
local n = (cmeta:get_int("tubedir") % (#next_positions)) + 1
if pipeworks.enable_cyclic_mode then
cmeta:set_int("tubedir", n)
end
local new_velocity = vector.multiply(next_positions[n].vect, vel.speed)
return true, new_velocity
end
minetest.register_entity("pipeworks:tubed_item", {
initial_properties = {
hp_max = 1,
physical = false,
-- collisionbox = {0,0,0,0,0,0},
collisionbox = {0.1,0.1,0.1,0.1,0.1,0.1},
visual = "sprite",
visual_size = {x=0.5, y=0.5},
collisionbox = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
visual = "wielditem",
visual_size = {x = 0.15, y = 0.15},
textures = {""},
spritediv = {x=1, y=1},
initial_sprite_basepos = {x=0, y=0},
spritediv = {x = 1, y = 1},
initial_sprite_basepos = {x = 0, y = 0},
is_visible = false,
start_pos={},
route={}
},
itemstring = '',
physical_state = false,
set_item = function(self, itemstring)
self.itemstring = itemstring
from_data = function(self, itemstring)
local stack = ItemStack(itemstring)
local itemtable = stack:to_table()
local itemname = nil
@ -333,159 +308,171 @@ minetest.register_entity("pipeworks:tubed_item", {
item_texture = minetest.registered_items[itemname].inventory_image
item_type = minetest.registered_items[itemname].type
end
prop = {
self.object:set_properties({
is_visible = true,
visual = "sprite",
textures = {"unknown_item.png"}
}
if item_texture and item_texture ~= "" then
prop.visual = "sprite"
prop.textures = {item_texture}
prop.visual_size = {x=0.3, y=0.3}
else
prop.visual = "wielditem"
prop.textures = {itemname}
prop.visual_size = {x=0.15, y=0.15}
end
self.object:set_properties(prop)
textures = {stack:get_name()}
})
local def = stack:get_definition()
self.object:setyaw((def and def.type == "node") and 0 or math.pi * 0.25)
end,
get_staticdata = function(self)
if self.start_pos==nil then return end
local velocity=self.object:getvelocity()
--self.object:setvelocity({x=0,y=0,z=0})
self.object:setpos(self.start_pos)
return minetest.serialize({
itemstring=self.itemstring,
velocity=velocity,
start_pos=self.start_pos
})
end,
on_activate = function(self, staticdata)
if staticdata=="" or staticdata==nil then return end
local item = minetest.deserialize(staticdata)
local stack = ItemStack(item.itemstring)
local itemtable = stack:to_table()
local itemname = nil
if itemtable then
itemname = stack:to_table().name
get_staticdata = luaentity.get_staticdata,
on_activate = function(self, staticdata) -- Legacy code, should be replaced later by luaentity.on_activate
if staticdata == "" or staticdata == nil then
return
end
if itemname then
self.start_pos=item.start_pos
self.object:setvelocity(item.velocity)
self.object:setacceleration({x=0, y=0, z=0})
self.object:setpos(item.start_pos)
end
self:set_item(item.itemstring)
end,
on_step = function(self, dtime)
if self.start_pos==nil then
local pos = self.object:getpos()
self.start_pos=roundpos(pos)
end
local pos = self.object:getpos()
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
tubelike=meta:get_int("tubelike")
local stack = ItemStack(self.itemstring)
local drop_pos=nil
local velocity=self.object:getvelocity()
if velocity==nil then return end
local velocitycopy={x=velocity.x,y=velocity.y,z=velocity.z}
local moved=false
local speed=math.abs(velocity.x+velocity.y+velocity.z)
local vel={x=velocity.x/speed,y=velocity.y/speed,z=velocity.z/speed, speed=speed}
if math.abs(vel.x)==1 then
local next_node=math.abs(pos.x-self.start_pos.x)
if next_node >= 1 then
self.start_pos.x=self.start_pos.x+vel.x
moved=true
end
elseif math.abs(vel.y)==1 then
local next_node=math.abs(pos.y-self.start_pos.y)
if next_node >= 1 then
self.start_pos.y=self.start_pos.y+vel.y
moved=true
end
elseif math.abs(vel.z)==1 then
local next_node=math.abs(pos.z-self.start_pos.z)
if next_node >= 1 then
self.start_pos.z=self.start_pos.z+vel.z
moved=true
end
end
local sposcopy={x=self.start_pos.x,y=self.start_pos.y,z=self.start_pos.z}
node = minetest.get_node(self.start_pos)
if moved and minetest.get_item_group(node.name,"tubedevice_receiver")==1 then
local leftover = nil
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos,node,stack,vel)
else
leftover = stack
end
--drop_pos=minetest.find_node_near(self.start_pos,1,"air")
--if drop_pos and not leftover:is_empty() then minetest.item_drop(leftover,"",drop_pos) end
--self.object:remove()
if leftover:is_empty() then
if staticdata == "toremove" then
self.object:remove()
return
end
velocity.x=-velocity.x
velocity.y=-velocity.y
velocity.z=-velocity.z
self.object:setvelocity(velocity)
self:set_item(leftover:to_string())
return
end
if moved then
if go_next (self.start_pos, velocity, stack) == 0 then
drop_pos=minetest.find_node_near({x=self.start_pos.x+velocity.x,y=self.start_pos.y+velocity.y,z=self.start_pos.z+velocity.z}, 1, "air")
if drop_pos then
minetest.item_drop(stack, "", drop_pos)
self.object:remove()
end
end
end
if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z or
self.start_pos.x~=sposcopy.x or self.start_pos.y~=sposcopy.y or self.start_pos.z~=sposcopy.z then
self.object:setpos(self.start_pos)
self.object:setvelocity(velocity)
end
end
local item = minetest.deserialize(staticdata)
pipeworks.tube_inject_item(self.object:getpos(), item.start_pos, item.velocity, item.itemstring)
self.object:remove()
end,
})
if minetest.get_modpath("mesecons_mvps") ~= nil then
mesecon:register_mvps_unmov("pipeworks:tubed_item")
mesecon:register_on_mvps_move(function(moved_nodes)
local objects_to_move = {}
for _, n in ipairs(moved_nodes) do
local objects = minetest.get_objects_inside_radius(n.oldpos, 1)
for _, obj in ipairs(objects) do
local entity = obj:get_luaentity()
if entity and entity.name == "pipeworks:tubed_item" then
objects_to_move[#objects_to_move+1] = obj
minetest.register_entity("pipeworks:color_entity", {
initial_properties = {
hp_max = 1,
physical = false,
collisionbox = {0.1, 0.1, 0.1, 0.1, 0.1, 0.1},
visual = "cube",
visual_size = {x = 3.5, y = 3.5, z = 3.5}, -- todo: find correct size
textures = {""},
is_visible = false,
},
physical_state = false,
from_data = function(self, color)
local t = "pipeworks_color_"..color..".png"
local prop = {
is_visible = true,
visual = "cube",
textures = {t, t, t, t, t, t} -- todo: textures
}
self.object:set_properties(prop)
end,
get_staticdata = luaentity.get_staticdata,
on_activate = luaentity.on_activate,
})
luaentity.register_entity("pipeworks:tubed_item", {
itemstring = '',
item_entity = nil,
color_entity = nil,
color = nil,
start_pos = nil,
set_item = function(self, item)
local itemstring = ItemStack(item):to_string() -- Accept any input format
if self.itemstring == itemstring then
return
end
if self.item_entity then
self:remove_attached_entity(self.item_entity)
end
self.itemstring = itemstring
self.item_entity = self:add_attached_entity("pipeworks:tubed_item", itemstring)
end,
set_color = function(self, color)
if self.color == color then
return
end
self.color = color
if self.color_entity then
self:remove_attached_entity(self.color_entity)
end
if color then
self.color_entity = self:add_attached_entity("pipeworks:color_entity", color)
else
self.color_entity = nil
end
end,
on_step = function(self, dtime)
if self.start_pos == nil then
local pos = self:getpos()
self.start_pos = vector.round(pos)
self:setpos(pos)
end
local pos = self:getpos()
local stack = ItemStack(self.itemstring)
local drop_pos
local velocity = self:getvelocity()
local moved = false
local speed = math.abs(velocity.x + velocity.y + velocity.z)
if speed == 0 then
speed = 1
moved = true
end
local vel = {x = velocity.x / speed, y = velocity.y / speed, z = velocity.z / speed, speed = speed}
if vector.distance(pos, self.start_pos) >= 1 then
self.start_pos = vector.add(self.start_pos, vel)
moved = true
end
minetest.load_position(self.start_pos)
local node = minetest.get_node(self.start_pos)
if moved and minetest.get_item_group(node.name, "tubedevice_receiver") == 1 then
local leftover
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos, node, stack, vel)
else
leftover = stack
end
if leftover:is_empty() then
self:remove()
return
end
velocity = vector.multiply(velocity, -1)
self:setvelocity(velocity)
self:set_item(leftover:to_string())
return
end
if moved then
local found_next, new_velocity = go_next(self.start_pos, velocity, stack) -- todo: color
if not found_next then
drop_pos = minetest.find_node_near(vector.add(self.start_pos, velocity), 1, "air")
if drop_pos then
minetest.item_drop(stack, "", drop_pos)
self:remove()
return
end
end
if new_velocity and not vector.equals(velocity, new_velocity) then
self:setpos(self.start_pos)
self:setvelocity(new_velocity)
end
end
if #objects_to_move > 0 then
local dir = vector.subtract(moved_nodes[1].pos, moved_nodes[1].oldpos)
for _, obj in ipairs(objects_to_move) do
local entity = obj:get_luaentity()
obj:setpos(vector.add(obj:getpos(), dir))
entity.start_pos = vector.add(entity.start_pos, dir)
end
})
if minetest.get_modpath("mesecons_mvps") then
mesecon:register_mvps_unmov("pipeworks:tubed_item")
mesecon:register_mvps_unmov("pipeworks:color_entity")
mesecon:register_on_mvps_move(function(moved_nodes)
local moved = {}
for _, n in ipairs(moved_nodes) do
moved[minetest.hash_node_position(n.oldpos)] = vector.subtract(n.pos, n.oldpos)
end
for id, entity in pairs(luaentity.entities) do
if entity.name == "pipeworks:tubed_item" then
local pos = entity:getpos()
local rpos = vector.round(pos)
local dir = moved[minetest.hash_node_position(rpos)]
if dir then
entity:setpos(vector.add(pos, dir))
entity.start_pos = vector.add(entity.start_pos, dir)
end
end
end
end)

60
mods/pipeworks/legacy.lua Normal file
View File

@ -0,0 +1,60 @@
if not minetest.get_modpath("auto_tree_tap") and
minetest.get_modpath("technic") then
minetest.register_abm({
nodenames = { "auto_tree_tap:off", "auto_tree_tap:on" },
chance = 1,
interval = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local fdir = node.param2
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("pick", 1)
inv:set_size("ghost_pick", 1)
inv:set_size("main", 100)
minetest.set_node(pos, {name = "pipeworks:nodebreaker_off", param2 = fdir})
minetest.registered_nodes["pipeworks:nodebreaker_off"].on_punch(pos, node)
inv:set_stack("pick", 1, ItemStack("technic:treetap"))
end
})
minetest.register_node(":auto_tree_tap:off", {
description = "Auto-Tap",
tiles = {"pipeworks_nodebreaker_top_off.png","pipeworks_nodebreaker_bottom_off.png","pipeworks_nodebreaker_side2_off.png","pipeworks_nodebreaker_side1_off.png",
"pipeworks_nodebreaker_back.png","pipeworks_nodebreaker_front_off.png"},
is_ground_content = true,
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, not_in_creative_inventory=1 },
mesecons= {effector={rules=pipeworks.rules_all,action_on=node_breaker_on, action_off=node_breaker_off}},
sounds = default.node_sound_stone_defaults(),
tube = {connect_sides={back=1}},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("pick", 1)
inv:set_stack("pick", 1, ItemStack("default:pick_mese"))
end,
after_place_node = function (pos, placer)
pipeworks.scan_for_tube_objects(pos, placer)
local placer_pos = placer:getpos()
--correct for the player's height
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
--correct for 6d facedir
if placer_pos then
local dir = {
x = pos.x - placer_pos.x,
y = pos.y - placer_pos.y,
z = pos.z - placer_pos.z
}
local node = minetest.get_node(pos)
node.param2 = minetest.dir_to_facedir(dir, true)
minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2)
end
end,
after_dig_node = pipeworks.scan_for_tube_objects,
})
end

View File

@ -0,0 +1,334 @@
local max_entity_id = 1000000000000 -- If you need more, there's a problem with your code
luaentity = {}
luaentity.registered_entities = {}
local filename = minetest.get_worldpath().."/luaentities"
local function read_file()
local f = io.open(filename, "r")
if f == nil then return {} end
local t = f:read("*all")
f:close()
if t == "" or t == nil then return {} end
return minetest.deserialize(t)
end
local function write_file(tbl)
local f = io.open(filename, "w")
f:write(minetest.serialize(tbl))
f:close()
end
local function read_entities()
local t = read_file()
for _, entity in pairs(t) do
setmetatable(entity, luaentity.registered_entities[entity.name])
end
return t
end
local function write_entities()
for _, entity in pairs(luaentity.entities) do
setmetatable(entity, nil)
for _, attached in pairs(entity._attached_entities) do
if attached.entity then
attached.entity:remove()
attached.entity = nil
end
end
entity._attached_entities_master = nil
end
write_file(luaentity.entities)
end
minetest.register_on_shutdown(write_entities)
luaentity.entities_index = 0
local function get_blockpos(pos)
return {x = math.floor(pos.x / 16),
y = math.floor(pos.y / 16),
z = math.floor(pos.z / 16)}
end
local active_blocks = {} -- These only contain active blocks near players (i.e., not forceloaded ones)
local handle_active_blocks_step = 2
local handle_active_blocks_timer = 0
minetest.register_globalstep(function(dtime)
handle_active_blocks_timer = handle_active_blocks_timer + dtime
if handle_active_blocks_timer >= handle_active_blocks_step then
handle_active_blocks_timer = handle_active_blocks_timer - handle_active_blocks_step
local active_block_range = tonumber(minetest.setting_get("active_block_range"))
local new_active_blocks = {}
for _, player in ipairs(minetest.get_connected_players()) do
local blockpos = get_blockpos(player:getpos())
local minp = vector.subtract(blockpos, active_block_range)
local maxp = vector.add(blockpos, active_block_range)
for x = minp.x, maxp.x do
for y = minp.y, maxp.y do
for z = minp.z, maxp.z do
local pos = {x = x, y = y, z = z}
new_active_blocks[minetest.hash_node_position(pos)] = pos
end
end
end
end
active_blocks = new_active_blocks
-- todo: callbacks on block load/unload
end
end)
local function is_active(pos)
return active_blocks[minetest.hash_node_position(get_blockpos(pos))] ~= nil
end
local entitydef_default = {
_attach = function(self, attached, attach_to)
local attached_def = self._attached_entities[attached]
local attach_to_def = self._attached_entities[attach_to]
attached_def.entity:set_attach(
attach_to_def.entity, "",
vector.subtract(attached_def.offset, attach_to_def.offset), -- todo: Does not work because is object space
vector.new(0, 0, 0)
)
end,
_set_master = function(self, index)
self._attached_entities_master = index
if not index then
return
end
local def = self._attached_entities[index]
if not def.entity then
return
end
def.entity:setpos(vector.add(self._pos, def.offset))
def.entity:setvelocity(self._velocity)
def.entity:setacceleration(self._acceleration)
end,
_attach_all = function(self)
local master = self._attached_entities_master
if not master then
return
end
for id, entity in pairs(self._attached_entities) do
if id ~= master and entity.entity then
self:_attach(id, master)
end
end
end,
_detach_all = function(self)
local master = self._attached_entities_master
for id, entity in pairs(self._attached_entities) do
if id ~= master and entity.entity then
entity.entity:set_detach()
end
end
end,
_add_attached = function(self, index)
local entity = self._attached_entities[index]
if entity.entity then
return
end
local entity_pos = vector.add(self._pos, entity.offset)
if not is_active(entity_pos) then
return
end
local ent = minetest.add_entity(entity_pos, entity.name):get_luaentity()
ent:from_data(entity.data)
ent.parent_id = self._id
ent.attached_id = index
entity.entity = ent.object
local master = self._attached_entities_master
if master then
self:_attach(index, master)
else
self:_set_master(index)
end
end,
_remove_attached = function(self, index)
local master = self._attached_entities_master
local entity = self._attached_entities[index]
local ent = entity.entity
entity.entity = nil
if index == master then
self:_detach_all()
local newmaster
for id, attached in pairs(self._attached_entities) do
if id ~= master and attached.entity then
newmaster = id
break
end
end
self:_set_master(newmaster)
self:_attach_all()
elseif master and ent then
ent:set_detach()
end
if ent then
ent:remove()
end
end,
_add_loaded = function(self)
for id, _ in pairs(self._attached_entities) do
self:_add_attached(id)
end
end,
getid = function(self)
return self._id
end,
getpos = function(self)
return vector.new(self._pos)
end,
setpos = function(self, pos)
self._pos = vector.new(pos)
--for _, entity in pairs(self._attached_entities) do
-- if entity.entity then
-- entity.entity:setpos(vector.add(self._pos, entity.offset))
-- end
--end
local master = self._attached_entities_master
if master then
local master_def = self._attached_entities[master]
master_def.entity:setpos(vector.add(self._pos, master_def.offset))
end
end,
getvelocity = function(self)
return vector.new(self._velocity)
end,
setvelocity = function(self, velocity)
self._velocity = vector.new(velocity)
local master = self._attached_entities_master
if master then
self._attached_entities[master].entity:setvelocity(self._velocity)
end
end,
getacceleration = function(self)
return vector.new(self._acceleration)
end,
setacceleration = function(self, acceleration)
self._acceleration = vector.new(acceleration)
local master = self._attached_entities_master
if master then
self._attached_entities[master].entity:setacceleration(self._acceleration)
end
end,
remove = function(self)
self:_detach_all()
for _, entity in pairs(self._attached_entities) do
if entity.entity then
entity.entity:remove()
end
end
luaentity.entities[self._id] = nil
end,
add_attached_entity = function(self, name, data, offset)
local index = #self._attached_entities + 1
self._attached_entities[index] = {
name = name,
data = data,
offset = vector.new(offset),
}
self:_add_attached(index)
return index
end,
remove_attached_entity = function(self, index)
self:_remove_attached(index)
self._attached_entities[index] = nil
end,
}
function luaentity.register_entity(name, prototype)
-- name = check_modname_prefix(name)
prototype.name = name
setmetatable(prototype, {__index = entitydef_default})
prototype.__index = prototype -- Make it possible to use it as metatable
luaentity.registered_entities[name] = prototype
end
-- function luaentity.get_entity_definition(entity)
-- return luaentity.registered_entities[entity.name]
-- end
function luaentity.add_entity(pos, name)
local index = luaentity.entities_index
while luaentity.entities[index] do
index = index + 1
if index >= max_entity_id then
index = 0
end
end
luaentity.entities_index = index
local entity = {
name = name,
_id = index,
_pos = vector.new(pos),
_velocity = {x = 0, y = 0, z = 0},
_acceleration = {x = 0, y = 0, z = 0},
_attached_entities = {},
}
local prototype = luaentity.registered_entities[name]
setmetatable(entity, prototype) -- Default to prototype for other methods
luaentity.entities[index] = entity
if entity.on_activate then
entity:on_activate()
end
return entity
end
-- todo: check if remove in get_staticdata works
function luaentity.get_staticdata(self)
local parent = luaentity.entities[self.parent_id]
if parent and parent._remove_attached then
parent:_remove_attached(self.attached_id)
end
return "toremove"
end
function luaentity.on_activate(self, staticdata)
if staticdata == "toremove" then
self.object:remove()
end
end
function luaentity.get_objects_inside_radius(pos, radius)
local objects = {}
local index = 1
for id, entity in pairs(luaentity.entities) do
if vector.distance(pos, entity:getpos()) <= radius then
objects[index] = entity
index = index + 1
end
end
end
minetest.register_globalstep(function(dtime)
if not luaentity.entities then
luaentity.entities = read_entities()
end
for id, entity in pairs(luaentity.entities) do
local master = entity._attached_entities_master
if master then
local master_def = entity._attached_entities[master]
local master_entity = master_def.entity
entity._pos = vector.subtract(master_entity:getpos(), master_def.offset)
entity._velocity = master_entity:getvelocity()
entity._acceleration = master_entity:getacceleration()
else
entity._pos = vector.add(vector.add(
entity._pos,
vector.multiply(entity._velocity, dtime)),
vector.multiply(entity._acceleration, 0.5 * dtime * dtime))
entity._velocity = vector.add(
entity._velocity,
vector.multiply(entity._acceleration, dtime))
end
entity:_add_loaded()
if entity.on_step then
entity:on_step(dtime)
end
end
end)

View File

@ -1,281 +0,0 @@
--register aliases for when someone had technic installed, but then uninstalled it but not pipeworks
minetest.register_alias("technic:nodebreaker_off", "pipeworks:nodebreaker_off")
minetest.register_alias("technic:nodebreaker_on", "pipeworks:nodebreaker_on")
minetest.register_alias("technic:node_breaker_off", "pipeworks:nodebreaker_off") --old name
minetest.register_alias("technic:node_breaker_on", "pipeworks:nodebreaker_on") --old name
minetest.register_craft({
output = 'pipeworks:nodebreaker_off 1',
recipe = {
{'group:wood', 'default:pick_mese','group:wood'},
{'default:stone', 'mesecons:piston','default:stone'},
{'default:stone', 'mesecons:mesecon','default:stone'},
}
})
local function swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos, node)
end
--define the functions from https://github.com/minetest/minetest/pull/834 while waiting for the devs to notice it
local function dir_to_facedir(dir, is6d)
--account for y if requested
if is6d and math.abs(dir.y) > math.abs(dir.x) and math.abs(dir.y) > math.abs(dir.z) then
--from above
if dir.y < 0 then
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 19
else
return 13
end
else
if dir.z < 0 then
return 10
else
return 4
end
end
--from below
else
if math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 15
else
return 17
end
else
if dir.z < 0 then
return 6
else
return 8
end
end
end
--otherwise, place horizontally
elseif math.abs(dir.x) > math.abs(dir.z) then
if dir.x < 0 then
return 3
else
return 1
end
else
if dir.z < 0 then
return 2
else
return 0
end
end
end
local function delay(x)
return (function() return x end)
end
local function break_node (pos, facedir)
--locate the outgoing velocity, front, and back of the node via facedir_to_dir
if type(facedir) ~= "number" or facedir < 0 or facedir > 23 then return end
local vel = minetest.facedir_to_dir(facedir);
local front = {x=pos.x - vel.x, y=pos.y - vel.y, z=pos.z - vel.z}
local node = minetest.get_node(front)
if node.name == "air" or node.name == "ignore" then
return nil
elseif minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].liquidtype ~= "none" then
return nil
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_stack("pick", 1, ItemStack("default:pick_mese"))
local pitch
local yaw
if vel.z < 0 then
yaw = 0
pitch = 0
elseif vel.z > 0 then
yaw = math.pi
pitch = 0
elseif vel.x < 0 then
yaw = 3*math.pi/2
pitch = 0
elseif vel.x > 0 then
yaw = math.pi/2
pitch = 0
elseif vel.y > 0 then
yaw = 0
pitch = -math.pi/2
else
yaw = 0
pitch = math.pi/2
end
local digger = {
get_inventory_formspec = delay(""),
get_look_dir = delay({x = -vel.x, y = -vel.y, z = -vel.z}),
get_look_pitch = delay(pitch),
get_look_yaw = delay(yaw),
get_player_control = delay({jump=false, right=false, left=false, LMB=false, RMB=false, sneak=false, aux1=false, down=false, up=false}),
get_player_control_bits = delay(0),
get_player_name = delay("node_breaker"),
is_player = delay(true),
set_inventory_formspec = delay(),
getpos = delay({x = pos.x, y = pos.y - 1.5, z = pos.z}), -- Player height
get_hp = delay(20),
get_inventory = delay(inv),
get_wielded_item = delay(ItemStack("default:pick_mese")),
get_wield_index = delay(1),
get_wield_list = delay("pick"),
moveto = delay(),
punch = delay(),
remove = delay(),
right_click = delay(),
setpos = delay(),
set_hp = delay(),
set_properties = delay(),
set_wielded_item = delay(),
set_animation = delay(),
set_attach = delay(),
set_detach = delay(),
set_bone_position = delay(),
}
--check node to make sure it is diggable
local def = ItemStack({name=node.name}):get_definition()
if #def ~= 0 and not def.diggable or (def.can_dig and not def.can_dig(front, digger)) then --node is not diggable
return
end
--handle node drops
local drops = minetest.get_node_drops(node.name, "default:pick_mese")
for _, dropped_item in ipairs(drops) do
local item1 = pipeworks.tube_item({x=pos.x, y=pos.y, z=pos.z}, dropped_item)
item1:get_luaentity().start_pos = {x=pos.x, y=pos.y, z=pos.z}
item1:setvelocity(vel)
item1:setacceleration({x=0, y=0, z=0})
end
local oldmetadata = nil
if def.after_dig_node then
oldmetadata = minetest.get_meta(front):to_table()
end
minetest.remove_node(front)
--handle post-digging callback
if def.after_dig_node then
-- Copy pos and node because callback can modify them
local pos_copy = {x=front.x, y=front.y, z=front.z}
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
def.after_dig_node(pos_copy, node_copy, oldmetadata, digger)
end
--run digging event callbacks
for _, callback in ipairs(minetest.registered_on_dignodes) do
-- Copy pos and node because callback can modify them
local pos_copy = {x=front.x, y=front.y, z=front.z}
local node_copy = {name=node.name, param1=node.param1, param2=node.param2}
callback(pos_copy, node_copy, digger)
end
end
local node_breaker_on = function(pos, node)
if node.name == "pipeworks:nodebreaker_off" then
swap_node(pos, "pipeworks:nodebreaker_on")
break_node(pos, node.param2)
nodeupdate(pos)
end
end
local node_breaker_off = function(pos, node)
if node.name == "pipeworks:nodebreaker_on" then
swap_node(pos, "pipeworks:nodebreaker_off")
nodeupdate(pos)
end
end
minetest.register_node("pipeworks:nodebreaker_off", {
description = "Node Breaker",
tile_images = {"pipeworks_nodebreaker_top_off.png","pipeworks_nodebreaker_bottom_off.png","pipeworks_nodebreaker_side2_off.png","pipeworks_nodebreaker_side1_off.png",
"pipeworks_nodebreaker_back.png","pipeworks_nodebreaker_front_off.png"},
is_ground_content = true,
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1},
mesecons= {effector={rules=pipeworks.rules_all,action_on=node_breaker_on, action_off=node_breaker_off}},
sounds = default.node_sound_stone_defaults(),
tube = {connect_sides={back=1}},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("pick", 1)
inv:set_stack("pick", 1, ItemStack("default:pick_mese"))
end,
after_place_node = function (pos, placer)
pipeworks.scan_for_tube_objects(pos, placer)
local placer_pos = placer:getpos()
--correct for the player's height
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
--correct for 6d facedir
if placer_pos then
local dir = {
x = pos.x - placer_pos.x,
y = pos.y - placer_pos.y,
z = pos.z - placer_pos.z
}
local node = minetest.get_node(pos)
node.param2 = dir_to_facedir(dir, true)
minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2)
end
end,
after_dig_node = pipeworks.scan_for_tube_objects,
})
minetest.register_node("pipeworks:nodebreaker_on", {
description = "Node Breaker",
tile_images = {"pipeworks_nodebreaker_top_on.png","pipeworks_nodebreaker_bottom_on.png","pipeworks_nodebreaker_side2_on.png","pipeworks_nodebreaker_side1_on.png",
"pipeworks_nodebreaker_back.png","pipeworks_nodebreaker_front_on.png"},
mesecons= {effector={rules=pipeworks.rules_all,action_on=node_breaker_on, action_off=node_breaker_off}},
is_ground_content = true,
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1,not_in_creative_inventory=1},
sounds = default.node_sound_stone_defaults(),
tube = {connect_sides={back=1}},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
inv:set_size("pick", 1)
inv:set_stack("pick", 1, ItemStack("default:pick_mese"))
end,
after_place_node = function (pos, placer)
pipeworks.scan_for_tube_objects(pos, placer)
local placer_pos = placer:getpos()
--correct for the player's height
if placer:is_player() then placer_pos.y = placer_pos.y + 1.5 end
--correct for 6d facedir
if placer_pos then
local dir = {
x = pos.x - placer_pos.x,
y = pos.y - placer_pos.y,
z = pos.z - placer_pos.z
}
local node = minetest.get_node(pos)
node.param2 = dir_to_facedir(dir, true)
minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2)
end
end,
after_dig_node = pipeworks.scan_for_tube_objects,
})

View File

@ -3,10 +3,10 @@ local filename=minetest.get_worldpath() .. "/teleport_tubes"
local function read_file()
local f = io.open(filename, "r")
if f==nil then return {} end
if f == nil then return {} end
local t = f:read("*all")
f:close()
if t=="" or t==nil then return {} end
if t == "" or t == nil then return {} end
return minetest.deserialize(t)
end
@ -18,8 +18,8 @@ end
local function update_pos_in_file(pos)
local tbl=read_file()
for _,val in ipairs(tbl) do
if val.x==pos.x and val.y==pos.y and val.z==pos.z then
for _, val in ipairs(tbl) do
if val.x == pos.x and val.y == pos.y and val.z == pos.z then
local meta = minetest.get_meta(val)
val.channel = meta:get_string("channel")
val.cr = meta:get_int("can_receive")
@ -40,34 +40,56 @@ local function add_tube_in_file(pos,channel, cr)
end
local function remove_tube_in_file(pos)
local tbl=read_file()
local newtbl={}
for _,val in ipairs(tbl) do
if val.x~=pos.x or val.y~=pos.y or val.z~=pos.z then
table.insert(newtbl,val)
local tbl = read_file()
local newtbl = {}
for _, val in ipairs(tbl) do
if val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z then
table.insert(newtbl, val)
end
end
write_file(newtbl)
end
local function read_node_with_vm(pos)
local vm = VoxelManip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
local data = vm:get_data()
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
return minetest.get_name_from_content_id(data[area:index(pos.x, pos.y, pos.z)])
end
local function get_tubes_in_file(pos,channel)
local tbl=read_file()
local newtbl={}
local changed=false
for _,val in ipairs(tbl) do
local node = minetest.get_node(val)
local tbl = read_file()
local newtbl = {}
local changed = false
for _, val in ipairs(tbl) do
local meta = minetest.get_meta(val)
-- That shouldn't be needed anymore since the mvps callback, but we leave it nevertheless
if node.name~="ignore" and (val.channel~=meta:get_string("channel") or val.cr~=meta:get_int("can_receive")) then
val.channel=meta:get_string("channel")
val.cr=meta:get_int("can_receive")
changed=true
end
if val.cr==1 and val.channel==channel and (val.x~=pos.x or val.y~=pos.y or val.z~=pos.z) then
table.insert(newtbl,val)
local name = read_node_with_vm(val)
local is_loaded = (minetest.get_node_or_nil(val) ~= nil)
local is_teleport_tube = minetest.registered_nodes[name] and minetest.registered_nodes[name].is_teleport_tube
if is_teleport_tube then
if is_loaded and (val.channel ~= meta:get_string("channel") or val.cr ~= meta:get_int("can_receive")) then
val.channel = meta:get_string("channel")
val.cr = meta:get_int("can_receive")
changed = true
end
if val.cr == 1 and val.channel == channel and (val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z) then
table.insert(newtbl, val)
end
else
val.to_remove = true
changed = true
end
end
if changed then write_file(tbl) end
if changed then
local updated = {}
for _, val in ipairs(tbl) do
if not val.to_remove then
table.insert(updated, val)
end
end
write_file(updated)
end
return newtbl
end
@ -80,8 +102,17 @@ local teleport_end_textures={"pipeworks_teleport_tube_end.png","pipeworks_telepo
local teleport_short_texture="pipeworks_teleport_tube_short.png"
local teleport_inv_texture="pipeworks_teleport_tube_inv.png"
pipeworks.register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube segment",teleport_plain_textures,
local function set_teleport_tube_formspec(meta)
local cr = meta:get_int("can_receive") ~= 0
meta:set_string("formspec","size[10.5,1;]"..
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
"button[8,0;2.5,1;"..(cr and "cr0" or "cr1")..";"..
(cr and "Send and Receive" or "Send only").."]")
end
pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Segment",teleport_plain_textures,
teleport_noctr_textures,teleport_end_textures,teleport_short_texture,teleport_inv_texture, {
is_teleport_tube = true,
tube = {
can_go = function(pos,node,velocity,stack)
velocity.x = 0
@ -102,10 +133,8 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube seg
local meta = minetest.get_meta(pos)
meta:set_string("channel","")
meta:set_int("can_receive",1)
meta:set_string("formspec","size[9,1;]"..
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
"button[8,0;1,1;bt;On]")
add_tube_in_file(pos,"")
set_teleport_tube_formspec(meta)
end,
on_receive_fields = function(pos,formname,fields,sender)
local meta = minetest.get_meta(pos)
@ -121,7 +150,7 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube seg
return
--channels starting with '[name];' can be used by other players, but cannot be received from
elseif mode == ";" and (meta:get_int("can_receive") ~= 0) == (fields["bt"] == nil) then
elseif mode == ";" and (fields.cr1 or (meta:get_int("can_receive") ~= 0 and not fields.cr0)) then
minetest.chat_send_player(sender:get_player_name(), "Sorry, receiving from channel '"..fields.channel.."' is reserved for "..name)
return
end
@ -131,21 +160,11 @@ pipeworks.register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube seg
if fields.channel==nil then fields.channel=meta:get_string("channel") end
meta:set_string("channel",fields.channel)
remove_tube_in_file(pos)
if fields.cr0 then meta:set_int("can_receive", 0) end
if fields.cr1 then meta:set_int("can_receive", 1) end
local cr = meta:get_int("can_receive")
if fields["bt"] then
cr=1-cr
meta:set_int("can_receive",cr)
if cr==1 then
meta:set_string("formspec","size[9,1;]"..
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
"button[8,0;1,1;bt;On]")
else
meta:set_string("formspec","size[9,1;]"..
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
"button[8,0;1,1;bt;Off]")
end
end
add_tube_in_file(pos,fields.channel, cr)
add_tube_in_file(pos, fields.channel, meta:get_int("can_receive"))
set_teleport_tube_formspec(meta)
end,
on_destruct = function(pos)
remove_tube_in_file(pos)

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 600 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 440 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 569 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 169 B

After

Width:  |  Height:  |  Size: 380 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 B

View File

@ -0,0 +1,49 @@
minetest.register_node("pipeworks:trashcan", {
description = "Trash Can",
drawtype = "normal",
tiles = {
"pipeworks_trashcan_bottom.png",
"pipeworks_trashcan_bottom.png",
"pipeworks_trashcan_side.png",
"pipeworks_trashcan_side.png",
"pipeworks_trashcan_side.png",
"pipeworks_trashcan_side.png",
},
groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1},
tube = {
insert_object = function(pos, node, stack, direction)
return ItemStack("")
end,
connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1},
priority = 1, -- Lower than anything else
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[8,7]"..
"item_image[0,0;1,1;pipeworks:trashcan]"..
"label[1,0;Trash Can]"..
"list[current_name;trash;3.5,1;1,1;]"..
"list[current_player;main;0,3;8,4;]")
meta:set_string("infotext", "Trash Can")
meta:get_inventory():set_size("trash", 1)
end,
after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.get_meta(pos):get_inventory():set_stack(listname, index, ItemStack(""))
end,
})
minetest.register_craft({
output = "pipeworks:trashcan",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "", "default:steel_ingot" },
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
},
})

View File

@ -20,7 +20,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
end
for _, v in ipairs(connects) do
pipeworks.add_node_box(outboxes, pipeworks.tube_boxes[v])
table.extend(outboxes, pipeworks.tube_boxes[v])
table.insert(outsel, pipeworks.tube_selectboxes[v])
outimgs[vti[v]] = noctrs[v]
end
@ -31,13 +31,13 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
outimgs[vti[v]] = ends[v]
end
local tgroups = {snappy = 3, tube = 1, not_in_creative_inventory = 1}
local tgroups = {snappy = 3, tube = 1, tubedevice = 1, not_in_creative_inventory = 1}
local tubedesc = desc.." "..dump(connects).."... You hacker, you."
local iimg = plain[1]
local wscale = {x = 1, y = 1, z = 1}
if #connects == 0 then
tgroups = {snappy = 3, tube = 1}
tgroups = {snappy = 3, tube = 1, tubedevice = 1}
tubedesc = desc
iimg=inv
outimgs = {
@ -50,7 +50,8 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
wscale = {x = 1, y = 1, z = 0.01}
end
table.insert(pipeworks.tubenodes, name.."_"..tname)
local rname = name.."_"..tname
table.insert(pipeworks.tubenodes, rname)
local nodedef = {
description = tubedesc,
@ -62,7 +63,7 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
wield_scale = wscale,
paramtype = "light",
selection_box = {
type = "fixed",
type = "fixed",
fixed = outsel
},
node_box = {
@ -77,26 +78,22 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
style = style,
drop = name.."_"..dropname,
tubelike = 1,
tube = {connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("tubelike", 1)
if minetest.registered_nodes[name.."_"..tname].on_construct_ then
minetest.registered_nodes[name.."_"..tname].on_construct_(pos)
end
end,
after_place_node = function(pos)
tube = {
connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1},
priority = 50
},
--[[after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
if minetest.registered_nodes[name.."_"..tname].after_place_node_ then
minetest.registered_nodes[name.."_"..tname].after_place_node_(pos)
if minetest.registered_nodes[rname].after_place_node_ then
minetest.registered_nodes[rname].after_place_node_(pos)
end
end,
after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
if minetest.registered_nodes[name.."_"..tname].after_dig_node_ then
minetest.registered_nodes[name.."_"..tname].after_dig_node_(pos)
if minetest.registered_nodes[rname].after_dig_node_ then
minetest.registered_nodes[rname].after_dig_node_(pos)
end
end
end]]
}
if style == "6d" then
nodedef.paramtype2 = "facedir"
@ -105,9 +102,9 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
if special == nil then special = {} end
for key, value in pairs(special) do
if key == "on_construct" or key == "after_dig_node" or key == "after_place_node" then
nodedef[key.."_"] = value
elseif key == "groups" then
--if key == "after_dig_node" or key == "after_place_node" then
-- nodedef[key.."_"] = value
if key == "groups" then
for group, val in pairs(value) do
nodedef.groups[group] = val
end
@ -115,19 +112,12 @@ local register_one_tube = function(name, tname, dropname, desc, plain, noctrs, e
for key, val in pairs(value) do
nodedef.tube[key] = val
end
elseif type(value) == "table" then
nodedef[key] = pipeworks.replace_name(value, "#id", tname)
elseif type(value) == "string" then
nodedef[key] = string.gsub(value, "#id", tname)
else
nodedef[key] = value
nodedef[key] = table.recursive_replace(value, "#id", tname)
end
end
local prefix = ":"
if string.find(name, "pipeworks:") then prefix = "" end
minetest.register_node(prefix..name.."_"..tname, nodedef)
minetest.register_node(rname, nodedef)
end
pipeworks.register_tube = function(name, desc, plain, noctrs, ends, short, inv, special, old_registration)
@ -182,21 +172,17 @@ pipeworks.register_tube = function(name, desc, plain, noctrs, ends, short, inv,
paramtype = "light",
sunlight_propagates = true,
description = "Pneumatic tube segment (legacy)",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("tubelike", 1)
end,
after_place_node = function(pos)
--[[after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
if minetest.registered_nodes[name.."_1"].after_place_node_ then
minetest.registered_nodes[name.."_1"].after_place_node_(pos)
end
end,
groups = {not_in_creative_inventory = 1, tube_to_update = 1},
end,]]
groups = {not_in_creative_inventory = 1, tube_to_update = 1, tube = 1},
tube = {connect_sides = {front = 1, back = 1, left = 1, right = 1, top = 1, bottom = 1}},
drop = name.."_1",
})
table.insert(pipeworks.tubenodes,cname)
table.insert(pipeworks.tubenodes, cname)
for xm = 0, 1 do
for xp = 0, 1 do
for ym = 0, 1 do
@ -221,8 +207,8 @@ if REGISTER_COMPATIBILITY then
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local minp = {x = pos.x-1, y = pos.y-1, z = pos.z-1}
local maxp = {x = pos.x+1, y = pos.y+1, z = pos.z+1}
local minp = vector.subtract(pos, 1)
local maxp = vector.add(pos, 1)
if table.getn(minetest.find_nodes_in_area(minp, maxp, "ignore")) == 0 then
pipeworks.scan_for_tube_objects(pos)
end
@ -252,7 +238,40 @@ if pipeworks.enable_mese_tube then
"pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png", "pipeworks_mese_tube_end.png"}
local mese_short_texture = "pipeworks_mese_tube_short.png"
local mese_inv_texture = "pipeworks_mese_tube_inv.png"
pipeworks.register_tube("pipeworks:mese_tube", "Mese pneumatic tube segment", mese_plain_textures, mese_noctr_textures,
local function update_formspec(pos)
local meta = minetest.get_meta(pos)
local old_formspec = meta:get_string("formspec")
if string.find(old_formspec, "button1") then -- Old version
local inv = meta:get_inventory()
for i = 1, 6 do
for _, stack in ipairs(inv:get_list("line"..i)) do
minetest.item_drop(stack, "", pos)
end
end
end
meta:set_string("formspec",
"size[8,11]"..
"list[current_name;line1;1,0;6,1;]"..
"list[current_name;line2;1,1;6,1;]"..
"list[current_name;line3;1,2;6,1;]"..
"list[current_name;line4;1,3;6,1;]"..
"list[current_name;line5;1,4;6,1;]"..
"list[current_name;line6;1,5;6,1;]"..
"image[0,0;1,1;pipeworks_white.png]"..
"image[0,1;1,1;pipeworks_black.png]"..
"image[0,2;1,1;pipeworks_green.png]"..
"image[0,3;1,1;pipeworks_yellow.png]"..
"image[0,4;1,1;pipeworks_blue.png]"..
"image[0,5;1,1;pipeworks_red.png]"..
fs_helpers.cycling_button(meta, "button[7,0;1,1", "l1s", {"Off", "On"})..
fs_helpers.cycling_button(meta, "button[7,1;1,1", "l2s", {"Off", "On"})..
fs_helpers.cycling_button(meta, "button[7,2;1,1", "l3s", {"Off", "On"})..
fs_helpers.cycling_button(meta, "button[7,3;1,1", "l4s", {"Off", "On"})..
fs_helpers.cycling_button(meta, "button[7,4;1,1", "l5s", {"Off", "On"})..
fs_helpers.cycling_button(meta, "button[7,5;1,1", "l6s", {"Off", "On"})..
"list[current_player;main;0,7;8,4;]")
end
pipeworks.register_tube("pipeworks:mese_tube", "Sorting Pneumatic Tube Segment", mese_plain_textures, mese_noctr_textures,
mese_end_textures, mese_short_texture, mese_inv_texture,
{tube = {can_go = function(pos, node, velocity, stack)
local tbl = {}
@ -266,6 +285,7 @@ if pipeworks.enable_mese_tube then
if st:get_name() == name then
found = true
table.insert(tbl, vect)
break
end
end
end
@ -288,68 +308,40 @@ if pipeworks.enable_mese_tube then
meta:set_int("l"..tostring(i).."s", 1)
inv:set_size("line"..tostring(i), 6*1)
end
meta:set_string("formspec",
"size[8,11]"..
"list[current_name;line1;1,0;6,1;]"..
"list[current_name;line2;1,1;6,1;]"..
"list[current_name;line3;1,2;6,1;]"..
"list[current_name;line4;1,3;6,1;]"..
"list[current_name;line5;1,4;6,1;]"..
"list[current_name;line6;1,5;6,1;]"..
"image[0,0;1,1;pipeworks_white.png]"..
"image[0,1;1,1;pipeworks_black.png]"..
"image[0,2;1,1;pipeworks_green.png]"..
"image[0,3;1,1;pipeworks_yellow.png]"..
"image[0,4;1,1;pipeworks_blue.png]"..
"image[0,5;1,1;pipeworks_red.png]"..
"button[7,0;1,1;button1;On]"..
"button[7,1;1,1;button2;On]"..
"button[7,2;1,1;button3;On]"..
"button[7,3;1,1;button4;On]"..
"button[7,4;1,1;button5;On]"..
"button[7,5;1,1;button6;On]"..
"list[current_player;main;0,7;8,4;]")
update_formspec(pos)
meta:set_string("infotext", "Mese pneumatic tube")
end,
on_punch = update_formspec,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local i
if fields.quit then return end
for key, _ in pairs(fields) do i = key end
if i == nil then return end
i = string.sub(i,-1)
newstate = 1 - meta:get_int("l"..i.."s")
meta:set_int("l"..i.."s",newstate)
local frm = "size[8,11]"..
"list[current_name;line1;1,0;6,1;]"..
"list[current_name;line2;1,1;6,1;]"..
"list[current_name;line3;1,2;6,1;]"..
"list[current_name;line4;1,3;6,1;]"..
"list[current_name;line5;1,4;6,1;]"..
"list[current_name;line6;1,5;6,1;]"..
"image[0,0;1,1;pipeworks_white.png]"..
"image[0,1;1,1;pipeworks_black.png]"..
"image[0,2;1,1;pipeworks_green.png]"..
"image[0,3;1,1;pipeworks_yellow.png]"..
"image[0,4;1,1;pipeworks_blue.png]"..
"image[0,5;1,1;pipeworks_red.png]"
for i = 1, 6 do
local st = meta:get_int("l"..tostring(i).."s")
if st == 0 then
frm = frm.."button[7,"..tostring(i-1)..";1,1;button"..tostring(i)..";Off]"
else
frm = frm.."button[7,"..tostring(i-1)..";1,1;button"..tostring(i)..";On]"
end
end
frm = frm.."list[current_player;main;0,7;8,4;]"
meta:set_string("formspec", frm)
fs_helpers.on_receive_fields(pos, fields)
update_formspec(pos)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return (inv:is_empty("line1") and inv:is_empty("line2") and inv:is_empty("line3") and
inv:is_empty("line4") and inv:is_empty("line5") and inv:is_empty("line6"))
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
update_formspec(pos) -- For old tubes
local inv = minetest.get_meta(pos):get_inventory()
local stack_copy = ItemStack(stack)
stack_copy:set_count(1)
inv:set_stack(listname, index, stack_copy)
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
update_formspec(pos) -- For old tubes
local inv = minetest.get_meta(pos):get_inventory()
inv:set_stack(listname, index, ItemStack(""))
return 0
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
update_formspec(pos) -- For old tubes
local inv = minetest.get_meta(pos):get_inventory()
inv:set_stack(from_list, from_index, ItemStack(""))
return 0
end,
}, true) -- Must use old tubes, since the textures are rotated with 6d ones
end
@ -357,14 +349,16 @@ if pipeworks.enable_detector_tube then
local detector_plain_textures = {"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png",
"pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png", "pipeworks_detector_tube_plain.png"}
local detector_inv_texture = "pipeworks_detector_tube_inv.png"
pipeworks.register_tube("pipeworks:detector_tube_on", "Detector tube segment on (you hacker you)", detector_plain_textures, noctr_textures,
local detector_tube_step = 2 * tonumber(minetest.setting_get("dedicated_server_step"))
pipeworks.register_tube("pipeworks:detector_tube_on", "Detecting Pneumatic Tube Segment on (you hacker you)", detector_plain_textures, noctr_textures,
end_textures, short_texture, detector_inv_texture,
{tube = {can_go = function(pos, node, velocity, stack)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
local nitems = meta:get_int("nitems")+1
meta:set_int("nitems", nitems)
minetest.after(0.1, minetest.registered_nodes[name].item_exit, pos)
local saved_pos = vector.new(pos)
minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos)
return pipeworks.notvel(pipeworks.meseadjlist,velocity)
end},
groups = {mesecon = 2, not_in_creative_inventory = 1},
@ -388,9 +382,12 @@ if pipeworks.enable_detector_tube then
local meta = minetest.get_meta(pos)
meta:set_int("nitems", 1)
local name = minetest.get_node(pos).name
minetest.after(0.1, minetest.registered_nodes[name].item_exit,pos)
end})
pipeworks.register_tube("pipeworks:detector_tube_off", "Detector tube segment", detector_plain_textures, noctr_textures,
local saved_pos = vector.new(pos)
minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos)
end
})
pipeworks.register_tube("pipeworks:detector_tube_off", "Detecting Pneumatic Tube Segment", detector_plain_textures, noctr_textures,
end_textures, short_texture, detector_inv_texture,
{tube = {can_go = function(pos, node, velocity, stack)
local node = minetest.get_node(pos)
@ -423,7 +420,7 @@ if pipeworks.enable_conductor_tube then
local conductor_on_end_textures = {"pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png",
"pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png", "pipeworks_conductor_tube_on_end.png"}
pipeworks.register_tube("pipeworks:conductor_tube_off", "Conductor tube segment", conductor_plain_textures, conductor_noctr_textures,
pipeworks.register_tube("pipeworks:conductor_tube_off", "Conducting Pneumatic Tube Segment", conductor_plain_textures, conductor_noctr_textures,
conductor_end_textures, conductor_short_texture, conductor_inv_texture,
{groups = {mesecon = 2},
mesecons = {conductor = {state = "off",
@ -431,7 +428,7 @@ if pipeworks.enable_conductor_tube then
onstate = "pipeworks:conductor_tube_on_#id"}}
})
pipeworks.register_tube("pipeworks:conductor_tube_on", "Conductor tube segment on (you hacker you)", conductor_on_plain_textures, conductor_on_noctr_textures,
pipeworks.register_tube("pipeworks:conductor_tube_on", "Conducting Pneumatic Tube Segment on (you hacker you)", conductor_on_plain_textures, conductor_on_noctr_textures,
conductor_on_end_textures, conductor_short_texture, conductor_inv_texture,
{groups = {mesecon = 2, not_in_creative_inventory = 1},
drop = "pipeworks:conductor_tube_off_1",
@ -451,7 +448,7 @@ if pipeworks.enable_accelerator_tube then
local accelerator_short_texture = "pipeworks_accelerator_tube_short.png"
local accelerator_inv_texture = "pipeworks_accelerator_tube_inv.png"
pipeworks.register_tube("pipeworks:accelerator_tube", "Accelerator pneumatic tube segment", accelerator_plain_textures,
pipeworks.register_tube("pipeworks:accelerator_tube", "Accelerating Pneumatic Tube Segment", accelerator_plain_textures,
accelerator_noctr_textures, accelerator_end_textures, accelerator_short_texture, accelerator_inv_texture,
{tube = {can_go = function(pos, node, velocity, stack)
velocity.speed = velocity.speed+1
@ -461,7 +458,6 @@ if pipeworks.enable_accelerator_tube then
end
if pipeworks.enable_crossing_tube then
-- FIXME: The textures are not the correct ones
local crossing_noctr_textures = {"pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png",
"pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png", "pipeworks_crossing_tube_noctr.png"}
local crossing_plain_textures = {"pipeworks_crossing_tube_plain.png" ,"pipeworks_crossing_tube_plain.png", "pipeworks_crossing_tube_plain.png",
@ -471,7 +467,7 @@ if pipeworks.enable_crossing_tube then
local crossing_short_texture = "pipeworks_crossing_tube_short.png"
local crossing_inv_texture = "pipeworks_crossing_tube_inv.png"
pipeworks.register_tube("pipeworks:crossing_tube", "Crossing tube segment", crossing_plain_textures,
pipeworks.register_tube("pipeworks:crossing_tube", "Crossing Pneumatic Tube Segment", crossing_plain_textures,
crossing_noctr_textures, crossing_end_textures, crossing_short_texture, crossing_inv_texture,
{tube = {can_go = function(pos, node, velocity, stack)
return {velocity}
@ -489,7 +485,7 @@ if pipeworks.enable_sand_tube then
local sand_short_texture = "pipeworks_sand_tube_short.png"
local sand_inv_texture = "pipeworks_sand_tube_inv.png"
pipeworks.register_tube("pipeworks:sand_tube", "Sand pneumatic tube segment", sand_plain_textures, sand_noctr_textures, sand_end_textures,
pipeworks.register_tube("pipeworks:sand_tube", "Vacuuming Pneumatic Tube Segment", sand_plain_textures, sand_noctr_textures, sand_end_textures,
sand_short_texture, sand_inv_texture,
{groups = {sand_tube = 1}})
@ -500,10 +496,7 @@ if pipeworks.enable_sand_tube then
for _, object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
if object:get_luaentity().itemstring ~= "" then
local titem = pipeworks.tube_item(pos,object:get_luaentity().itemstring)
titem:get_luaentity().start_pos = {x = pos.x, y = pos.y-1, z = pos.z}
titem:setvelocity({x = 0.01, y = 1, z = -0.01})
titem:setacceleration({x = 0, y = 0, z = 0})
pipeworks.tube_inject_item(pos, pos, vector.new(0, 0, 0), object:get_luaentity().itemstring)
end
object:get_luaentity().itemstring = ""
object:remove()
@ -523,7 +516,7 @@ if pipeworks.enable_mese_sand_tube then
local mese_sand_short_texture = "pipeworks_mese_sand_tube_short.png"
local mese_sand_inv_texture = "pipeworks_mese_sand_tube_inv.png"
pipeworks.register_tube("pipeworks:mese_sand_tube", "Mese sand pneumatic tube segment", mese_sand_plain_textures, mese_sand_noctr_textures,
pipeworks.register_tube("pipeworks:mese_sand_tube", "Adjustable Vacuuming Pneumatic Tube Segment", mese_sand_plain_textures, mese_sand_noctr_textures,
mese_sand_end_textures, mese_sand_short_texture,mese_sand_inv_texture,
{groups = {mese_sand_tube = 1},
on_construct = function(pos)
@ -532,7 +525,7 @@ if pipeworks.enable_mese_sand_tube then
meta:set_string("formspec",
"size[2,1]"..
"field[.5,.5;1.5,1;dist;distance;${dist}]")
meta:set_string("infotext", "Mese sand pneumatic tube")
meta:set_string("infotext", "Adjustable Vacuuming Pneumatic Tube Segment")
end,
on_receive_fields = function(pos,formname,fields,sender)
local meta = minetest.env:get_meta(pos)
@ -563,10 +556,7 @@ if pipeworks.enable_mese_sand_tube then
for _,object in ipairs(get_objects_with_square_radius(pos, minetest.env:get_meta(pos):get_int("dist"))) do
if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
if object:get_luaentity().itemstring ~= "" then
local titem = pipeworks.tube_item(pos, object:get_luaentity().itemstring)
titem:get_luaentity().start_pos = {x = pos.x, y = pos.y-1, z = pos.z}
titem:setvelocity({x = 0.01, y = 1, z = -0.01})
titem:setacceleration({x = 0, y = 0, z = 0})
pipeworks.tube_inject_item(pos, pos, vector.new(0, 0, 0), object:get_luaentity().itemstring)
end
object:get_luaentity().itemstring = ""
object:remove()
@ -576,59 +566,29 @@ if pipeworks.enable_mese_sand_tube then
})
end
local function facedir_to_right_dir(facedir)
--find the other directions
local backdir = minetest.facedir_to_dir(facedir)
local topdir = ({[0] = {x = 0, y = 1, z = 0},
{x = 0, y = 0, z = 1},
{x = 0, y = 0, z = -1},
{x = 1, y = 0, z = 0},
{x = -1, y = 0, z = 0},
{x = 0, y = -1, z = 0}})[math.floor(facedir/4)]
--return a cross product
return {x = topdir.y*backdir.z - backdir.y*topdir.z,
y = topdir.z*backdir.x - backdir.z*topdir.x,
z = topdir.x*backdir.y - backdir.x*topdir.y}
end
if pipeworks.enable_one_way_tube then
minetest.register_node("pipeworks:one_way_tube", {
description = "One way tube",
tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png",
"pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"},
paramtype2 = "facedir",
drawtype = "nodebox",
paramtype = "light",
node_box = {type = "fixed",
fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1, tubedevice_receiver = 1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
tube = {connect_sides = {left = 1, right = 1},
can_go = function(pos, node, velocity, stack)
return velocity
end,
insert_object = function(pos, node, stack, direction)
item1 = pipeworks.tube_item(pos, stack)
item1:get_luaentity().start_pos = pos
item1:setvelocity({x = direction.x*direction.speed, y = direction.y*direction.speed, z = direction.z*direction.speed})
item1:setacceleration({x = 0, y = 0, z = 0})
return ItemStack("")
end,
can_insert = function(pos, node, stack, direction)
local dir = facedir_to_right_dir(node.param2)
if dir.x == direction.x and dir.y == direction.y and dir.z == direction.z then
return true
end
return false
end},
description = "One way tube",
tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png",
"pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"},
paramtype2 = "facedir",
drawtype = "nodebox",
paramtype = "light",
node_box = {type = "fixed",
fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
tube = {
connect_sides = {left = 1, right = 1},
can_go = function(pos, node, velocity, stack)
return {velocity}
end,
can_insert = function(pos, node, stack, direction)
local dir = minetest.facedir_to_right_dir(node.param2)
return vector.equals(dir, direction)
end,
priority = 75 -- Higher than normal tubes, but lower than receivers
},
})
end

423
mods/pipeworks/wielder.lua Normal file
View File

@ -0,0 +1,423 @@
local assumed_eye_pos = vector.new(0, 1.5, 0)
local function vector_copy(v)
return { x = v.x, y = v.y, z = v.z }
end
local function delay(x)
return (function() return x end)
end
local function set_wielder_formspec(data, meta)
meta:set_string("formspec",
"invsize[8,"..(6+data.wield_inv_height)..";]"..
"item_image[0,0;1,1;"..data.name_base.."_off]"..
"label[1,0;"..minetest.formspec_escape(data.description).."]"..
"list[current_name;"..minetest.formspec_escape(data.wield_inv_name)..";"..((8-data.wield_inv_width)*0.5)..",1;"..data.wield_inv_width..","..data.wield_inv_height..";]"..
"list[current_player;main;0,"..(2+data.wield_inv_height)..";8,4;]")
meta:set_string("infotext", data.description)
end
local function wielder_on(data, wielder_pos, wielder_node)
data.fixup_node(wielder_pos, wielder_node)
if wielder_node.name ~= data.name_base.."_off" then return end
wielder_node.name = data.name_base.."_on"
minetest.swap_node(wielder_pos, wielder_node)
nodeupdate(wielder_pos)
local wielder_meta = minetest.get_meta(wielder_pos)
local inv = wielder_meta:get_inventory()
local wield_inv_name = data.wield_inv_name
local wieldindex, wieldstack
for i, stack in ipairs(inv:get_list(wield_inv_name)) do
if not stack:is_empty() then
wieldindex = i
wieldstack = stack
break
end
end
if not wieldindex then
if not data.ghost_inv_name then return end
wield_inv_name = data.ghost_inv_name
inv:set_stack(wield_inv_name, 1, ItemStack(data.ghost_tool))
wieldindex = 1
wieldstack = inv:get_stack(wield_inv_name, 1)
end
local dir = minetest.facedir_to_dir(wielder_node.param2)
local under_pos = vector.subtract(wielder_pos, dir)
local above_pos = vector.subtract(under_pos, dir)
local pitch
local yaw
if dir.z < 0 then
yaw = 0
pitch = 0
elseif dir.z > 0 then
yaw = math.pi
pitch = 0
elseif dir.x < 0 then
yaw = 3*math.pi/2
pitch = 0
elseif dir.x > 0 then
yaw = math.pi/2
pitch = 0
elseif dir.y > 0 then
yaw = 0
pitch = -math.pi/2
else
yaw = 0
pitch = math.pi/2
end
local virtplayer = {
get_inventory_formspec = delay(wielder_meta:get_string("formspec")),
get_look_dir = delay(vector.multiply(dir, -1)),
get_look_pitch = delay(pitch),
get_look_yaw = delay(yaw),
get_player_control = delay({ jump=false, right=false, left=false, LMB=false, RMB=false, sneak=data.sneak, aux1=false, down=false, up=false }),
get_player_control_bits = delay(data.sneak and 64 or 0),
get_player_name = delay(data.masquerade_as_owner and wielder_meta:get_string("owner") or ":pipeworks:"..minetest.pos_to_string(wielder_pos)),
is_player = delay(true),
is_fake_player = true,
set_inventory_formspec = delay(),
getpos = delay(vector.subtract(wielder_pos, assumed_eye_pos)),
get_hp = delay(20),
get_inventory = delay(inv),
get_wielded_item = delay(wieldstack),
get_wield_index = delay(wieldindex),
get_wield_list = delay(wield_inv_name),
moveto = delay(),
punch = delay(),
remove = delay(),
right_click = delay(),
setpos = delay(),
set_hp = delay(),
set_properties = delay(),
set_wielded_item = function(self, item) inv:set_stack(wield_inv_name, wieldindex, item) end,
set_animation = delay(),
set_attach = delay(),
set_detach = delay(),
set_bone_position = delay(),
}
local pointed_thing = { type="node", under=under_pos, above=above_pos }
data.act(virtplayer, pointed_thing)
if data.eject_drops then
for i, stack in ipairs(inv:get_list("main")) do
if not stack:is_empty() then
pipeworks.tube_inject_item(wielder_pos, wielder_pos, dir, stack)
inv:set_stack("main", i, ItemStack(""))
end
end
end
end
local function wielder_off(data, pos, node)
if node.name == data.name_base.."_on" then
node.name = data.name_base.."_off"
minetest.swap_node(pos, node)
nodeupdate(pos)
end
end
local function register_wielder(data)
data.fixup_node = data.fixup_node or function (pos, node) end
data.fixup_oldmetadata = data.fixup_oldmetadata or function (m) return m end
for _, state in ipairs({ "off", "on" }) do
local groups = { snappy=2, choppy=2, oddly_breakable_by_hand=2, mesecon=2, tubedevice=1, tubedevice_receiver=1 }
if state == "on" then groups.not_in_creative_inventory = 1 end
local tile_images = {}
for _, face in ipairs({ "top", "bottom", "side2", "side1", "back", "front" }) do
table.insert(tile_images, data.texture_base.."_"..face..(data.texture_stateful[face] and "_"..state or "")..".png")
end
minetest.register_node(data.name_base.."_"..state, {
description = data.description,
tile_images = tile_images,
mesecons = {
effector = {
rules = pipeworks.rules_all,
action_on = function (pos, node)
wielder_on(data, pos, node)
end,
action_off = function (pos, node)
wielder_off(data, pos, node)
end,
},
},
tube = {
can_insert = function(pos, node, stack, tubedir)
if not data.tube_permit_anteroposterior_insert then
local nodedir = minetest.facedir_to_dir(node.param2)
if vector.equals(tubedir, nodedir) or vector.equals(tubedir, vector.multiply(nodedir, -1)) then
return false
end
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item(data.wield_inv_name, stack)
end,
insert_object = function(pos, node, stack, tubedir)
if not data.tube_permit_anteroposterior_insert then
local nodedir = minetest.facedir_to_dir(node.param2)
if vector.equals(tubedir, nodedir) or vector.equals(tubedir, vector.multiply(nodedir, -1)) then
return stack
end
end
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item(data.wield_inv_name, stack)
end,
input_inventory = data.wield_inv_name,
connect_sides = data.tube_connect_sides,
can_remove = function(pos, node, stack, tubedir)
return stack:get_count()
end,
},
is_ground_content = true,
paramtype2 = "facedir",
tubelike = 1,
groups = groups,
sounds = default.node_sound_stone_defaults(),
drop = data.name_base.."_off",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
set_wielder_formspec(data, meta)
local inv = meta:get_inventory()
inv:set_size(data.wield_inv_name, data.wield_inv_width*data.wield_inv_height)
if data.ghost_inv_name then
inv:set_size(data.ghost_inv_name, 1)
end
if data.eject_drops then
inv:set_size("main", 100)
end
end,
after_place_node = function (pos, placer)
pipeworks.scan_for_tube_objects(pos)
local placer_pos = placer:getpos()
if placer_pos and placer:is_player() then placer_pos = vector.add(placer_pos, assumed_eye_pos) end
if placer_pos then
local dir = vector.subtract(pos, placer_pos)
local node = minetest.get_node(pos)
node.param2 = minetest.dir_to_facedir(dir, true)
minetest.set_node(pos, node)
minetest.log("action", "real (6d) facedir: " .. node.param2)
end
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
end,
can_dig = (data.can_dig_nonempty_wield_inv and delay(true) or function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty(data.wield_inv_name)
end),
after_dig_node = function(pos, oldnode, oldmetadata, digger)
-- The legacy-node fixup is done here in a
-- different form from the standard fixup,
-- rather than relying on a standard fixup
-- in an on_dig callback, because some
-- non-standard diggers (such as technic's
-- mining drill) don't respect on_dig.
oldmetadata = data.fixup_oldmetadata(oldmetadata)
for _, stack in ipairs(oldmetadata.inventory[data.wield_inv_name] or {}) do
if not stack:is_empty() then
minetest.add_item(pos, stack)
end
end
pipeworks.scan_for_tube_objects(pos)
end,
on_punch = data.fixup_node,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
return 0
end
return count
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
if player:get_player_name() ~= meta:get_string("owner") and meta:get_string("owner") ~= "" then
return 0
end
return stack:get_count()
end,
})
end
end
if pipeworks.enable_node_breaker then
local data
data = {
name_base = "pipeworks:nodebreaker",
description = "Node Breaker",
texture_base = "pipeworks_nodebreaker",
texture_stateful = { top = true, bottom = true, side2 = true, side1 = true, front = true },
tube_connect_sides = { top=1, bottom=1, left=1, right=1, back=1 },
tube_permit_anteroposterior_insert = false,
wield_inv_name = "pick",
wield_inv_width = 1,
wield_inv_height = 1,
can_dig_nonempty_wield_inv = true,
ghost_inv_name = "ghost_pick",
ghost_tool = "default:pick_mese",
fixup_node = function (pos, node)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
-- Node breakers predating the visible pick slot
-- may have been partially updated. This code
-- fully updates them. Some have been observed
-- to have no pick slot at all; first add one.
if inv:get_size("pick") ~= 1 then
inv:set_size("pick", 1)
end
-- Originally, they had a ghost pick in a "pick"
-- inventory, no other inventory, and no form.
-- The partial update of early with-form node
-- breaker code gives them "ghost_pick" and "main"
-- inventories, but leaves the old ghost pick in
-- the "pick" inventory, and doesn't add a form.
-- First perform that partial update.
if inv:get_size("ghost_pick") ~= 1 then
inv:set_size("ghost_pick", 1)
inv:set_size("main", 100)
end
-- If the node breaker predates the visible pick
-- slot, which we can detect by it not having a
-- form, then the pick slot needs to be cleared
-- of the old ghost pick.
if (meta:get_string("formspec") or "") == "" then
inv:set_stack("pick", 1, ItemStack(""))
end
-- Finally, unconditionally set the formspec
-- and infotext. This not only makes the
-- pick slot visible for node breakers where
-- it wasn't before; it also updates the form
-- for node breakers that had an older version
-- of the form, and sets infotext where it was
-- missing for early with-form node breakers.
set_wielder_formspec(data, meta)
end,
fixup_oldmetadata = function (oldmetadata)
-- Node breakers predating the visible pick slot,
-- with node form, kept their ghost pick in an
-- inventory named "pick", the same name as the
-- later visible pick slot. The pick must be
-- removed to avoid spilling it.
if not oldmetadata.fields.formspec then
return { inventory = { pick = {} }, fields = oldmetadata.fields }
else
return oldmetadata
end
end,
masquerade_as_owner = true,
sneak = false,
act = function(virtplayer, pointed_thing)
local wieldstack = virtplayer:get_wielded_item()
local oldwieldstack = ItemStack(wieldstack)
local on_use = (minetest.registered_items[wieldstack:get_name()] or {}).on_use
if on_use then
virtplayer:set_wielded_item(on_use(wieldstack, virtplayer, pointed_thing) or wieldstack)
else
local under_node = minetest.get_node(pointed_thing.under)
local on_dig = (minetest.registered_nodes[under_node.name] or {on_dig=minetest.node_dig}).on_dig
on_dig(pointed_thing.under, under_node, virtplayer)
end
wieldstack = virtplayer:get_wielded_item()
local wieldname = wieldstack:get_name()
if wieldname == oldwieldstack:get_name() then
-- don't mechanically wear out tool
if wieldstack:get_count() == oldwieldstack:get_count() and
wieldstack:get_metadata() == oldwieldstack:get_metadata() and
((minetest.registered_items[wieldstack:get_name()] or {}).wear_represents or "mechanical_wear") == "mechanical_wear" then
virtplayer:set_wielded_item(oldwieldstack)
end
elseif wieldname ~= "" then
-- tool got replaced by something else:
-- treat it as a drop
virtplayer:get_inventory():add_item("main", wieldstack)
virtplayer:set_wielded_item(ItemStack(""))
end
end,
eject_drops = true,
}
register_wielder(data)
minetest.register_craft({
output = "pipeworks:nodebreaker_off",
recipe = {
{ "group:wood", "default:pick_mese", "group:wood" },
{ "default:stone", "mesecons:piston", "default:stone" },
{ "default:stone", "mesecons:mesecon", "default:stone" },
}
})
-- aliases for when someone had technic installed, but then uninstalled it but not pipeworks
minetest.register_alias("technic:nodebreaker_off", "pipeworks:nodebreaker_off")
minetest.register_alias("technic:nodebreaker_on", "pipeworks:nodebreaker_on")
minetest.register_alias("technic:node_breaker_off", "pipeworks:nodebreaker_off")
minetest.register_alias("technic:node_breaker_on", "pipeworks:nodebreaker_on")
-- turn legacy auto-tree-taps into node breakers
dofile(pipeworks.modpath.."/legacy.lua")
end
if pipeworks.enable_deployer then
register_wielder({
name_base = "pipeworks:deployer",
description = "Deployer",
texture_base = "pipeworks_deployer",
texture_stateful = { front = true },
tube_connect_sides = { back=1 },
tube_permit_anteroposterior_insert = true,
wield_inv_name = "main",
wield_inv_width = 3,
wield_inv_height = 3,
can_dig_nonempty_wield_inv = false,
masquerade_as_owner = true,
sneak = false,
act = function(virtplayer, pointed_thing)
local wieldstack = virtplayer:get_wielded_item()
virtplayer:set_wielded_item((minetest.registered_items[wieldstack:get_name()] or {on_place=minetest.item_place}).on_place(wieldstack, virtplayer, pointed_thing) or wieldstack)
end,
eject_drops = false,
})
minetest.register_craft({
output = "pipeworks:deployer_off",
recipe = {
{ "group:wood", "default:chest", "group:wood" },
{ "default:stone", "mesecons:piston", "default:stone" },
{ "default:stone", "mesecons:mesecon", "default:stone" },
}
})
-- aliases for when someone had technic installed, but then uninstalled it but not pipeworks
minetest.register_alias("technic:deployer_off", "pipeworks:deployer_off")
minetest.register_alias("technic:deployer_on", "pipeworks:deployer_on")
end
if pipeworks.enable_dispenser then
register_wielder({
name_base = "pipeworks:dispenser",
description = "Dispenser",
texture_base = "pipeworks_dispenser",
texture_stateful = { front = true },
tube_connect_sides = { back=1 },
tube_permit_anteroposterior_insert = true,
wield_inv_name = "main",
wield_inv_width = 3,
wield_inv_height = 3,
can_dig_nonempty_wield_inv = false,
masquerade_as_owner = false,
sneak = true,
act = function(virtplayer, pointed_thing)
local wieldstack = virtplayer:get_wielded_item()
virtplayer:set_wielded_item((minetest.registered_items[wieldstack:get_name()] or {on_drop=minetest.item_drop}).on_drop(wieldstack, virtplayer, virtplayer:getpos()) or wieldstack)
end,
eject_drops = false,
})
minetest.register_craft({
output = "pipeworks:dispenser_off",
recipe = {
{ "default:desert_sand", "default:chest", "default:desert_sand" },
{ "default:stone", "mesecons:piston", "default:stone" },
{ "default:stone", "mesecons:mesecon", "default:stone" },
}
})
end

View File

@ -1,2 +1 @@
default
skylands

View File

@ -1,5 +1,4 @@
-- Plantlife library mod by Vanessa Ezekowitz
-- last revision, 2014-05-15
--
-- License: WTFPL
--
@ -14,6 +13,8 @@ plantslib = {}
plantslib.modpath = minetest.get_modpath("plants_lib")
plantslib.intllib_modpath = minetest.get_modpath("intllib")
plantslib.total_legacy_calls = 0
local S
if plantslib.intllib_modpath then
dofile(plantslib.intllib_modpath.."/intllib.lua")
@ -69,15 +70,6 @@ function plantslib:is_node_loaded(node_pos)
return true
end
function plantslib:clone_node(name)
node2={}
node=minetest.registered_nodes[name]
for k,v in pairs(node) do
node2[k]=v
end
return node2
end
function plantslib:set_defaults(biome)
biome.seed_diff = biome.seed_diff or 0
biome.min_elevation = biome.min_elevation or -31000
@ -108,96 +100,180 @@ end
-- Spawn plants using the map generator
function plantslib:register_generate_plant(biomedef, node_or_function_or_model)
minetest.register_on_generated(plantslib:search_for_surfaces(minp, maxp, biomedef, node_or_function_or_model))
plantslib.surfaces_list = {}
plantslib.actions_list = {}
plantslib.surface_nodes = {}
local function search_table(t, s)
for i = 1, #t do
if t[i] == s then return true end
end
return false
end
function plantslib:search_for_surfaces(minp, maxp, biomedef, node_or_function_or_model)
return function(minp, maxp, blockseed)
local biome = biomedef
plantslib:set_defaults(biome)
-- register the list of surfaces to spawn stuff on, filtering out all duplicates.
local searchnodes = minetest.find_nodes_in_area(minp, maxp, biome.surface)
local in_biome_nodes = {}
for _ , pos in ipairs(searchnodes) do
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
local perlin1 = minetest.get_perlin(biome.seed_diff, perlin_octaves, perlin_persistence, perlin_scale)
local noise1 = perlin1:get2d({x=p_top.x, y=p_top.z})
local noise2 = plantslib.perlin_temperature:get2d({x=p_top.x, y=p_top.z})
local noise3 = plantslib.perlin_humidity:get2d({x=p_top.x+150, y=p_top.z+50})
if (not biome.depth or minetest.get_node({ x = pos.x, y = pos.y-biome.depth-1, z = pos.z }).name ~= biome.surface)
and (not biome.check_air or (biome.check_air and minetest.get_node(p_top).name == "air"))
and pos.y >= biome.min_elevation
and pos.y <= biome.max_elevation
and noise1 > biome.plantlife_limit
and noise2 <= biome.temp_min
and noise2 >= biome.temp_max
and noise3 <= biome.humidity_min
and noise3 >= biome.humidity_max
and (not biome.ncount or #(minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, biome.neighbors)) > biome.ncount)
and (not biome.near_nodes or #(minetest.find_nodes_in_area({x=pos.x-biome.near_nodes_size, y=pos.y-biome.near_nodes_vertical, z=pos.z-biome.near_nodes_size}, {x=pos.x+biome.near_nodes_size, y=pos.y+biome.near_nodes_vertical, z=pos.z+biome.near_nodes_size}, biome.near_nodes)) >= biome.near_nodes_count)
and math.random(1,100) > biome.rarity
and (not biome.below_nodes or string.find(dump(biome.below_nodes), minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name) )
then
table.insert(in_biome_nodes, pos)
function plantslib:register_generate_plant(biomedef, node_or_function_or_model)
-- if calling code passes an undefined node, don't register an action for it.
if type(node_or_function_or_model) == "string"
and string.find(node_or_function_or_model, ":")
and not minetest.registered_nodes[node_or_function_or_model] then
plantslib:dbg("Warning: Ignored registration for undefined spawn node: "..dump(node_or_function_or_model))
return
end
if type(node_or_function_or_model) == "string"
and not string.find(node_or_function_or_model, ":") then
plantslib:dbg("Warning: Registered function call using deprecated string method: "..dump(node_or_function_or_model))
end
if biomedef.check_air == false then
plantslib:dbg("Warning: Registered legacy mapgen hook: "..dump(node_or_function_or_model))
minetest.register_on_generated(plantslib:generate_block_legacy(minp, maxp, biomedef, node_or_function_or_model))
plantslib.total_legacy_calls = plantslib.total_legacy_calls + 1
else
plantslib.actions_list[#plantslib.actions_list + 1] = { biomedef, node_or_function_or_model }
local s = biomedef.surface
if type(s) == "string" then
if s and minetest.registered_nodes[s] then
if not search_table(plantslib.surfaces_list, s) then
plantslib.surfaces_list[#plantslib.surfaces_list + 1] = s
end
else
plantslib:dbg("Warning: Ignored registration for undefined surface node: "..dump(s))
end
else
for i = 1, #biomedef.surface do
local s = biomedef.surface[i]
if s and minetest.registered_nodes[s] then
if not search_table(plantslib.surfaces_list, s) then
plantslib.surfaces_list[#plantslib.surfaces_list + 1] = s
end
else
plantslib:dbg("Warning: Ignored registration for undefined surface node: "..dump(s))
end
end
end
end
end
function plantslib:generate_block(minp, maxp, blockseed)
return function(minp, maxp, blockseed)
-- use the block hash as a unique key into the surface_nodes
-- table, so that we can write the table thread-safely.
local blockhash = minetest.hash_node_position(minp)
local search_area = minetest.find_nodes_in_area(minp, maxp, plantslib.surfaces_list)
-- search the generated block for surfaces
local surface_nodes = {}
surface_nodes.blockhash = {}
for i = 1, #search_area do
local pos = search_area[i]
local p_top = { x=pos.x, y=pos.y+1, z=pos.z }
if minetest.get_node(p_top).name == "air" then
surface_nodes.blockhash[#surface_nodes.blockhash + 1] = pos
end
end
local num_in_biome_nodes = #in_biome_nodes
for action = 1, #plantslib.actions_list do
local biome = plantslib.actions_list[action][1]
local node_or_function_or_model = plantslib.actions_list[action][2]
if num_in_biome_nodes > 0 then
for i = 1, math.min(biome.max_count, num_in_biome_nodes) do
local tries = 0
local spawned = false
while tries < 2 and not spawned do
local pos = in_biome_nodes[math.random(1, num_in_biome_nodes)]
if biome.spawn_replace_node then
pos.y = pos.y-1
end
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
plantslib:set_defaults(biome)
if not (biome.avoid_nodes and biome.avoid_radius and minetest.find_node_near(p_top, biome.avoid_radius + math.random(-1.5,2), biome.avoid_nodes)) then
if biome.delete_above then
minetest.remove_node(p_top)
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z})
end
-- filter stage 1 - find nodes from the supplied surfaces that are within the current biome.
if biome.delete_above_surround then
minetest.remove_node({x=p_top.x-1, y=p_top.y, z=p_top.z})
minetest.remove_node({x=p_top.x+1, y=p_top.y, z=p_top.z})
minetest.remove_node({x=p_top.x, y=p_top.y, z=p_top.z-1})
minetest.remove_node({x=p_top.x, y=p_top.y, z=p_top.z+1})
local in_biome_nodes = {}
local perlin_fertile_area = minetest.get_perlin(biome.seed_diff, perlin_octaves, perlin_persistence, perlin_scale)
minetest.remove_node({x=p_top.x-1, y=p_top.y+1, z=p_top.z})
minetest.remove_node({x=p_top.x+1, y=p_top.y+1, z=p_top.z})
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z-1})
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z+1})
end
for i = 1, #surface_nodes.blockhash do
local pos = surface_nodes.blockhash[i]
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
local noise1 = perlin_fertile_area:get2d({x=pos.x, y=pos.z})
local noise2 = plantslib.perlin_temperature:get2d({x=pos.x, y=pos.z})
local noise3 = plantslib.perlin_humidity:get2d({x=pos.x+150, y=pos.z+50})
local biome_surfaces_string = dump(biome.surface)
if ((not biome.depth and string.find(biome_surfaces_string, minetest.get_node(pos).name)) or (biome.depth and not string.find(biome_surfaces_string, minetest.get_node({ x = pos.x, y = pos.y-biome.depth-1, z = pos.z }).name)))
and (not biome.check_air or (biome.check_air and minetest.get_node(p_top).name == "air"))
and pos.y >= biome.min_elevation
and pos.y <= biome.max_elevation
and noise1 > biome.plantlife_limit
and noise2 <= biome.temp_min
and noise2 >= biome.temp_max
and noise3 <= biome.humidity_min
and noise3 >= biome.humidity_max
and (not biome.ncount or #(minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, biome.neighbors)) > biome.ncount)
and (not biome.near_nodes or #(minetest.find_nodes_in_area({x=pos.x-biome.near_nodes_size, y=pos.y-biome.near_nodes_vertical, z=pos.z-biome.near_nodes_size}, {x=pos.x+biome.near_nodes_size, y=pos.y+biome.near_nodes_vertical, z=pos.z+biome.near_nodes_size}, biome.near_nodes)) >= biome.near_nodes_count)
and math.random(1,100) > biome.rarity
and (not biome.below_nodes or string.find(dump(biome.below_nodes), minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name) )
then
in_biome_nodes[#in_biome_nodes + 1] = pos
end
end
-- filter stage 2 - find places within that biome area to place the plants.
local num_in_biome_nodes = #in_biome_nodes
if num_in_biome_nodes > 0 then
for i = 1, math.min(biome.max_count, num_in_biome_nodes) do
local tries = 0
local spawned = false
while tries < 2 and not spawned do
local pos = in_biome_nodes[math.random(1, num_in_biome_nodes)]
if biome.spawn_replace_node then
minetest.remove_node(pos)
pos.y = pos.y-1
end
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
local objtype = type(node_or_function_or_model)
if not (biome.avoid_nodes and biome.avoid_radius and minetest.find_node_near(p_top, biome.avoid_radius + math.random(-1.5,2), biome.avoid_nodes)) then
if biome.delete_above then
minetest.remove_node(p_top)
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z})
end
if objtype == "table" then
plantslib:generate_tree(pos, node_or_function_or_model)
spawned = true
elseif objtype == "string" and
minetest.registered_nodes[node_or_function_or_model] then
minetest.add_node(p_top, { name = node_or_function_or_model })
spawned = true
elseif objtype == "function" then
node_or_function_or_model(pos)
spawned = trueload
elseif objtype == "string" and pcall(loadstring(("return %s(...)"):
format(node_or_function_or_model)),pos) then
spawned = true
if biome.delete_above_surround then
minetest.remove_node({x=p_top.x-1, y=p_top.y, z=p_top.z})
minetest.remove_node({x=p_top.x+1, y=p_top.y, z=p_top.z})
minetest.remove_node({x=p_top.x, y=p_top.y, z=p_top.z-1})
minetest.remove_node({x=p_top.x, y=p_top.y, z=p_top.z+1})
minetest.remove_node({x=p_top.x-1, y=p_top.y+1, z=p_top.z})
minetest.remove_node({x=p_top.x+1, y=p_top.y+1, z=p_top.z})
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z-1})
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z+1})
end
if biome.spawn_replace_node then
minetest.remove_node(pos)
end
local objtype = type(node_or_function_or_model)
if objtype == "table" then
plantslib:generate_tree(pos, node_or_function_or_model)
spawned = true
elseif objtype == "string" and
minetest.registered_nodes[node_or_function_or_model] then
minetest.set_node(p_top, { name = node_or_function_or_model })
spawned = true
elseif objtype == "function" then
node_or_function_or_model(pos)
spawned = true
elseif objtype == "string" and pcall(loadstring(("return %s(...)"):
format(node_or_function_or_model)),pos) then
spawned = true
else
plantslib:dbg("Warning: Ignored invalid definition for object "..dump(node_or_function_or_model).." that was pointed at {"..dump(pos).."}")
end
else
print("Ignored invalid definition for object "..dump(node_or_function_or_model).." that was pointed at {"..dump(pos).."}")
tries = tries + 1
end
else
tries = tries + 1
end
end
end
@ -205,6 +281,8 @@ function plantslib:search_for_surfaces(minp, maxp, biomedef, node_or_function_or
end
end
minetest.register_on_generated(plantslib:generate_block(minp, maxp, blockseed))
-- The spawning ABM
function plantslib:spawn_on_surfaces(sd,sp,sr,sc,ss,sa)
@ -239,8 +317,8 @@ function plantslib:spawn_on_surfaces(sd,sp,sr,sc,ss,sa)
action = function(pos, node, active_object_count, active_object_count_wider)
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
local n_top = minetest.get_node(p_top)
local perlin1 = minetest.get_perlin(biome.seed_diff, perlin_octaves, perlin_persistence, perlin_scale)
local noise1 = perlin1:get2d({x=p_top.x, y=p_top.z})
local perlin_fertile_area = minetest.get_perlin(biome.seed_diff, perlin_octaves, perlin_persistence, perlin_scale)
local noise1 = perlin_fertile_area:get2d({x=p_top.x, y=p_top.z})
local noise2 = plantslib.perlin_temperature:get2d({x=p_top.x, y=p_top.z})
local noise3 = plantslib.perlin_humidity:get2d({x=p_top.x+150, y=p_top.z+50})
if noise1 > biome.plantlife_limit
@ -262,7 +340,7 @@ function plantslib:spawn_on_surfaces(sd,sp,sr,sc,ss,sa)
local walldir = plantslib:find_adjacent_wall(p_top, biome.verticals_list)
if biome.alt_wallnode and walldir then
if n_top.name == "air" then
minetest.add_node(p_top, { name = biome.alt_wallnode, param2 = walldir })
minetest.set_node(p_top, { name = biome.alt_wallnode, param2 = walldir })
end
else
local currentsurface = minetest.get_node(pos).name
@ -279,19 +357,19 @@ function plantslib:spawn_on_surfaces(sd,sp,sr,sc,ss,sa)
assert(loadstring(spawn_plants.."(...)"))(pos)
elseif not biome.spawn_on_side and not biome.spawn_on_bottom and not biome.spawn_replace_node then
if n_top.name == "air" then
minetest.add_node(p_top, { name = plant_to_spawn, param2 = fdir })
minetest.set_node(p_top, { name = plant_to_spawn, param2 = fdir })
end
elseif biome.spawn_replace_node then
minetest.add_node(pos, { name = plant_to_spawn, param2 = fdir })
minetest.set_node(pos, { name = plant_to_spawn, param2 = fdir })
elseif biome.spawn_on_side then
local onside = plantslib:find_open_side(pos)
if onside then
minetest.add_node(onside.newpos, { name = plant_to_spawn, param2 = onside.facedir })
minetest.set_node(onside.newpos, { name = plant_to_spawn, param2 = onside.facedir })
end
elseif biome.spawn_on_bottom then
if minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name == "air" then
minetest.add_node({x=pos.x, y=pos.y-1, z=pos.z}, { name = plant_to_spawn, param2 = fdir} )
minetest.set_node({x=pos.x, y=pos.y-1, z=pos.z}, { name = plant_to_spawn, param2 = fdir} )
end
end
end
@ -338,11 +416,11 @@ function plantslib:grow_plants(opts)
-- corner case for changing short junglegrass
-- to dry shrub in desert
if n_bot.name == options.dry_early_node and options.grow_plant == "junglegrass:short" then
minetest.add_node(pos, { name = "default:dry_shrub" })
minetest.set_node(pos, { name = "default:dry_shrub" })
elseif options.grow_vertically and walldir then
if plantslib:search_downward(pos, options.height_limit, options.ground_nodes) then
minetest.add_node(p_top, { name = options.grow_plant, param2 = walldir})
minetest.set_node(p_top, { name = options.grow_plant, param2 = walldir})
end
elseif not options.grow_result and not options.grow_function then
@ -366,19 +444,19 @@ function plantslib:replace_object(pos, replacement, grow_function, walldir, seed
plantslib:grow_tree(pos, grow_function)
return
elseif growtype == "function" then
local perlin1 = minetest.get_perlin(seeddiff, perlin_octaves, perlin_persistence, perlin_scale)
local noise1 = perlin1:get2d({x=pos.x, y=pos.z})
local perlin_fertile_area = minetest.get_perlin(seeddiff, perlin_octaves, perlin_persistence, perlin_scale)
local noise1 = perlin_fertile_area:get2d({x=pos.x, y=pos.z})
local noise2 = plantslib.perlin_temperature:get2d({x=pos.x, y=pos.z})
grow_function(pos,noise1,noise2,walldir)
return
elseif growtype == "string" then
local perlin1 = minetest.get_perlin(seeddiff, perlin_octaves, perlin_persistence, perlin_scale)
local noise1 = perlin1:get2d({x=pos.x, y=pos.z})
local perlin_fertile_area = minetest.get_perlin(seeddiff, perlin_octaves, perlin_persistence, perlin_scale)
local noise1 = perlin_fertile_area:get2d({x=pos.x, y=pos.z})
local noise2 = plantslib.perlin_temperature:get2d({x=pos.x, y=pos.z})
assert(loadstring(grow_function.."(...)"))(pos,noise1,noise2,walldir)
return
elseif growtype == "nil" then
minetest.add_node(pos, { name = replacement, param2 = walldir})
minetest.set_node(pos, { name = replacement, param2 = walldir})
return
elseif growtype ~= "nil" and growtype ~= "string" and growtype ~= "table" then
error("Invalid grow function "..dump(grow_function).." used on object at ("..dump(pos)..")")
@ -456,5 +534,107 @@ function plantslib:get_nodedef_field(nodename, fieldname)
return minetest.registered_nodes[nodename][fieldname]
end
-- The old version of the mapgen spawner, for mods that require disabling of
-- checking for air during the initial map read stage.
function plantslib:generate_block_legacy(minp, maxp, biomedef, node_or_function_or_model)
return function(minp, maxp, blockseed)
local biome = biomedef
plantslib:set_defaults(biome)
local searchnodes = minetest.find_nodes_in_area(minp, maxp, biome.surface)
local in_biome_nodes = {}
local perlin_fertile_area = minetest.get_perlin(biome.seed_diff, perlin_octaves, perlin_persistence, perlin_scale)
for i = 1, #searchnodes do
local pos = searchnodes[i]
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
local noise1 = perlin_fertile_area:get2d({x=p_top.x, y=p_top.z})
local noise2 = plantslib.perlin_temperature:get2d({x=p_top.x, y=p_top.z})
local noise3 = plantslib.perlin_humidity:get2d({x=p_top.x+150, y=p_top.z+50})
if (not biome.depth or minetest.get_node({ x = pos.x, y = pos.y-biome.depth-1, z = pos.z }).name ~= biome.surface)
and pos.y >= biome.min_elevation
and pos.y <= biome.max_elevation
and noise1 > biome.plantlife_limit
and noise2 <= biome.temp_min
and noise2 >= biome.temp_max
and noise3 <= biome.humidity_min
and noise3 >= biome.humidity_max
and (not biome.ncount or #(minetest.find_nodes_in_area({x=pos.x-1, y=pos.y, z=pos.z-1}, {x=pos.x+1, y=pos.y, z=pos.z+1}, biome.neighbors)) > biome.ncount)
and (not biome.near_nodes or #(minetest.find_nodes_in_area({x=pos.x-biome.near_nodes_size, y=pos.y-biome.near_nodes_vertical, z=pos.z-biome.near_nodes_size}, {x=pos.x+biome.near_nodes_size, y=pos.y+biome.near_nodes_vertical, z=pos.z+biome.near_nodes_size}, biome.near_nodes)) >= biome.near_nodes_count)
and math.random(1,100) > biome.rarity
and (not biome.below_nodes or string.find(dump(biome.below_nodes), minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name) )
then
in_biome_nodes[#in_biome_nodes + 1] = pos
end
end
local num_in_biome_nodes = #in_biome_nodes
if num_in_biome_nodes > 0 then
for i = 1, math.min(biome.max_count, num_in_biome_nodes) do
local tries = 0
local spawned = false
while tries < 2 and not spawned do
local pos = in_biome_nodes[math.random(1, num_in_biome_nodes)]
if biome.spawn_replace_node then
pos.y = pos.y-1
end
local p_top = { x = pos.x, y = pos.y + 1, z = pos.z }
if not (biome.avoid_nodes and biome.avoid_radius and minetest.find_node_near(p_top, biome.avoid_radius + math.random(-1.5,2), biome.avoid_nodes)) then
if biome.delete_above then
minetest.remove_node(p_top)
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z})
end
if biome.delete_above_surround then
minetest.remove_node({x=p_top.x-1, y=p_top.y, z=p_top.z})
minetest.remove_node({x=p_top.x+1, y=p_top.y, z=p_top.z})
minetest.remove_node({x=p_top.x, y=p_top.y, z=p_top.z-1})
minetest.remove_node({x=p_top.x, y=p_top.y, z=p_top.z+1})
minetest.remove_node({x=p_top.x-1, y=p_top.y+1, z=p_top.z})
minetest.remove_node({x=p_top.x+1, y=p_top.y+1, z=p_top.z})
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z-1})
minetest.remove_node({x=p_top.x, y=p_top.y+1, z=p_top.z+1})
end
if biome.spawn_replace_node then
minetest.remove_node(pos)
end
local objtype = type(node_or_function_or_model)
if objtype == "table" then
plantslib:generate_tree(pos, node_or_function_or_model)
spawned = true
elseif objtype == "string" and
minetest.registered_nodes[node_or_function_or_model] then
minetest.set_node(p_top, { name = node_or_function_or_model })
spawned = true
elseif objtype == "function" then
node_or_function_or_model(pos)
spawned = trueload
elseif objtype == "string" and pcall(loadstring(("return %s(...)"):
format(node_or_function_or_model)),pos) then
spawned = true
else
plantslib:dbg("Warning: Ignored invalid definition for object "..dump(node_or_function_or_model).." that was pointed at {"..dump(pos).."}")
end
else
tries = tries + 1
end
end
end
end
end
end
print("[Plants Lib] Loaded")
minetest.after(0, function()
print("[Plants Lib] Registered a total of "..#plantslib.surfaces_list.." surface types to be evaluated,")
print("[Plants Lib] a total of "..#plantslib.actions_list.." actions, and "..plantslib.total_legacy_calls.." legacy mapgen hooks.")
end)
print(S("[Plantlife Library] Loaded"))

View File

@ -276,4 +276,5 @@ minetest.register_abm({
vm:write_to_map()
vm:update_map()
end,
})
})

View File

@ -1,11 +1,11 @@
-- skylands 4.0 by HeroOfTheWinds, based on floatindev 0.2.0 by paramat
-- skylands 4.2 by HeroOfTheWinds, based on floatindev 0.2.0 by paramat
-- For latest stable Minetest and back to 0.4.8
-- Depends default, fire, stairs, moreblocks?, moreores?, mesecons?
-- Depends default, fire, stairs, moreblocks?, moreores?, mesecons?, technic?
-- License: code WTFPL
-- Parameters
local YMIN = 700 -- Approximate realm limits.
local YMIN = -33000 -- Approximate realm limits.
local YMAX = 33000
local XMIN = -33000
local XMAX = 33000
@ -158,6 +158,7 @@ dofile(minetest.get_modpath("skylands").."/wheat.lua")
dofile(minetest.get_modpath("skylands").."/abms.lua")
dofile(minetest.get_modpath("skylands").."/functions.lua")
dofile(minetest.get_modpath("skylands").."/pools.lua")
dofile(minetest.get_modpath("skylands").."/tools.lua")
dofile(minetest.get_modpath("skylands").."/farming.lua")

View File

@ -23,6 +23,8 @@ function skylands:gen_pool(lakepoints, area, data, x0, z0, x1, z1)
local c_hvngrass = minetest.get_content_id("skylands:heaven_grass")
local c_rich = minetest.get_content_id("skylands:rich_dirt")
local c_cloud = minetest.get_content_id("skylands:cloud")
local sidelen = x1 - x0 -- actually sidelen - 1
@ -251,6 +253,7 @@ function skylands:gen_pool(lakepoints, area, data, x0, z0, x1, z1)
break
elseif data[viu] == c_hvngrass then
data[viu] = c_rich
break
else
break
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 376 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

Some files were not shown because too many files have changed in this diff Show More