on_blast = func(pos, intensity),
^ intensity: 1.0 = mid range of regular TNT
^ If defined, called when an explosion touches the node, instead of
removing the node
local print_hello=function()
print("hello")
end
local dtime=10.0
minetest.register_globalstep(function(dtime)
hello()
end)
minetest.register_globalstep(function(dtime)
ifnot time then time = dtime end
if time >= 10 then
hello()
time = 0
end
time = time + dtime
end
Casimir wrote:Just a guess, there might be a better solution.Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_globalstep(function(dtime)
ifnot time then time = dtime end
if time >= 10 then
hello()
time = 0
end
time = time + dtime
end
stairs.register_stair_and_slab("birch", "birch:wood",
{cracky=3},
{"birch_wood.png"},
"Birch Wood stair",
"Birch Wood slab")
Evergreen wrote:I have a question about stairs and slabs. I'm making a birch tree mod, and I need to make stairs and slabs from it. Here is the code I used to add stairs and slabs:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
stairs.register_stair_and_slab("birch", "birch:wood",
{cracky=3},
{"birch_wood.png"},
"Birch Wood stair",
"Birch Wood slab")
But I get a run error. How do I fix?
0gb.us wrote:Evergreen wrote:I have a question about stairs and slabs. I'm making a birch tree mod, and I need to make stairs and slabs from it. Here is the code I used to add stairs and slabs:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
stairs.register_stair_and_slab("birch", "birch:wood",
{cracky=3},
{"birch_wood.png"},
"Birch Wood stair",
"Birch Wood slab")
But I get a run error. How do I fix?
The error is caused by a bug in the stable version of stairs. Copy the code in stars and change the prefix "Stairs:" to the prefix for your plugin.
stairs = {}
function birch.register_stair(subname, recipeitem, groups, images, description)
minetest.register_node("stairs:stair_" .. subname, {
description = description,
drawtype = "nodebox",
tiles = images,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = true,
groups = groups,
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
{-0.5, 0, 0, 0.5, 0.5, 0.5},
},
},
})
minetest.register_craft({
output = 'stairs:stair_' .. subname .. ' 4',
recipe = {
{recipeitem, "", ""},
{recipeitem, recipeitem, ""},
{recipeitem, recipeitem, recipeitem},
},
})
-- Flipped recipe for the silly minecrafters
minetest.register_craft({
output = 'stairs:stair_' .. subname .. ' 4',
recipe = {
{"", "", recipeitem},
{"", recipeitem, recipeitem},
{recipeitem, recipeitem, recipeitem},
},
})
end
-- Node will be called stairs:slab_<subname>
function birch.register_slab(subname, recipeitem, groups, images, description)
minetest.register_node("stairs:slab_" .. subname, {
description = description,
drawtype = "nodebox",
tiles = images,
paramtype = "light",
is_ground_content = true,
groups = groups,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
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 p0 = pointed_thing.under
local p1 = pointed_thing.above
local n0 = minetest.env:get_node(p0)
if n0.name == "stairs:slab_" .. subname and
p0.y+1 == p1.y then
slabpos = p0
slabnode = n0
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
-- Otherwise place regularly
return minetest.item_place(itemstack, placer, pointed_thing)
end,
})
minetest.register_craft({
output = 'stairs:slab_' .. subname .. ' 3',
recipe = {
{recipeitem, recipeitem, recipeitem},
},
})
end
-- Nodes will be called stairs:{stair,slab}_<subname>
function birch.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab)
birch.register_stair(subname, recipeitem, groups, images, desc_stair)
birch.register_slab(subname, recipeitem, groups, images, desc_slab)
end
birch.register_stair_and_slab("birch", "birch:wood",
{snappy=2,choppy=2,oddly_breakable_by_hand=2},
{"birch_wood.png"},
"Birch Wood stair",
"Birch Wood slab")
Evergreen wrote:Still get a ModError.
I stuck this code inside the same init.luaYour phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
stairs = {}
function birch.register_stair(subname, recipeitem, groups, images, description)
minetest.register_node("stairs:stair_" .. subname, {
description = description,
drawtype = "nodebox",
tiles = images,
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = true,
groups = groups,
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0, 0.5},
{-0.5, 0, 0, 0.5, 0.5, 0.5},
},
},
})
minetest.register_craft({
output = 'stairs:stair_' .. subname .. ' 4',
recipe = {
{recipeitem, "", ""},
{recipeitem, recipeitem, ""},
{recipeitem, recipeitem, recipeitem},
},
})
-- Flipped recipe for the silly minecrafters
minetest.register_craft({
output = 'stairs:stair_' .. subname .. ' 4',
recipe = {
{"", "", recipeitem},
{"", recipeitem, recipeitem},
{recipeitem, recipeitem, recipeitem},
},
})
end
-- Node will be called stairs:slab_<subname>
function birch.register_slab(subname, recipeitem, groups, images, description)
minetest.register_node("stairs:slab_" .. subname, {
description = description,
drawtype = "nodebox",
tiles = images,
paramtype = "light",
is_ground_content = true,
groups = groups,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_place = function(itemstack, placer, pointed_thing)
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 p0 = pointed_thing.under
local p1 = pointed_thing.above
local n0 = minetest.env:get_node(p0)
if n0.name == "stairs:slab_" .. subname and
p0.y+1 == p1.y then
slabpos = p0
slabnode = n0
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
-- Otherwise place regularly
return minetest.item_place(itemstack, placer, pointed_thing)
end,
})
minetest.register_craft({
output = 'stairs:slab_' .. subname .. ' 3',
recipe = {
{recipeitem, recipeitem, recipeitem},
},
})
end
-- Nodes will be called stairs:{stair,slab}_<subname>
function birch.register_stair_and_slab(subname, recipeitem, groups, images, desc_stair, desc_slab)
birch.register_stair(subname, recipeitem, groups, images, desc_stair)
birch.register_slab(subname, recipeitem, groups, images, desc_slab)
end
birch.register_stair_and_slab("birch", "birch:wood",
{snappy=2,choppy=2,oddly_breakable_by_hand=2},
{"birch_wood.png"},
"Birch Wood stair",
"Birch Wood slab")
What am I doing wrong?
Evergreen wrote:Now I have another question. Is the function math.random part of minetest?
PilzAdam wrote:Evergreen wrote:Now I have another question. Is the function math.random part of minetest?
No, its part of Lua.
llocal generate_birch_tree = function(pos)
node = {name = ""}
for dy=1,4 do
pos.y = pos.y+dy
if minetest.env:get_node(pos).name ~= "air" then
return
end
pos.y = pos.y-dy
end
node.name = "birch:tree"
for dy=0,4 do
pos.y = pos.y+dy
minetest.env:set_node(pos, node)
pos.y = pos.y-dy
end
node.name = "birch:leaves"
pos.y = pos.y+3
for dx=-2,2 do
for dz=-2,2 do
for dy=0,3 do
pos.x = pos.x+dx
pos.y = pos.y+dy
pos.z = pos.z+dz
if dx == 0 and dz == 0 and dy==3 then
if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.env:set_node(pos, node)
end
elseif dx == 0 and dz == 0 and dy==4 then
if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.env:set_node(pos, node)
end
elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then
if minetest.env:get_node(pos).name == "air" then
minetest.env:set_node(pos, node)
end
else
if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then
if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then
minetest.env:set_node(pos, node)
end
end
end
pos.x = pos.x-dx
pos.y = pos.y-dy
pos.z = pos.z-dz
end
end
end
end
Evergreen wrote:Now I have another question. Is the function math.random part of minetest?
Evergreen wrote:I'm getting so close to finishing my birch tree mod. PilzAdam, I used your rubber.lua from your farming mod to generate the trees, make the sapling, leaves, and sapling growth.
Here is the tree growth that seems to cause a problem when I add it to the code.Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
...
I get a ModError when I add this to the code. PS. The name of the mod is birch.
0gb.us wrote:Evergreen wrote:I'm getting so close to finishing my birch tree mod. PilzAdam, I used your rubber.lua from your farming mod to generate the trees, make the sapling, leaves, and sapling growth.
Here is the tree growth that seems to cause a problem when I add it to the code.Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
...
I get a ModError when I add this to the code. PS. The name of the mod is birch.
"a ModError" isn't very specific. What is the error?
VanessaE wrote:I might point out that More Trees already has birches.
minetest.register_on_generated(function(minp, maxp, blockseed)
if math.random(1, 100) ~= 1 then
return
end
local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z}
local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
if pos ~= nil then
generate_birch_tree({x=pos.x, y=pos.y+1, z=pos.z})
end
end)
pandaro wrote:type:
self:getpos()
self.object:getpos()
Evergreen wrote:I tried changing the random, but that didn't seem to help.
Users browsing this forum: No registered users and 10 guests