Page 3 of 125

PostPosted: Mon Feb 11, 2013 18:49
by VanessaE
A texturable sun/moon would be nice, and has been discussed before. The result of that discussion was that it would be somewhat non-trivial to do, namely because of the color-shifting that would need to be applied to the two as they rise/set.

PostPosted: Mon Feb 11, 2013 20:43
by pandaro
I can understand the other functions but not this:

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

--how to a block NOT explode?
-how to calibrate the power of a explosion
I use TNT PilzAdam, I would like:
-a block does not explode,
-one explode if the explosion occurs at a short distance (1)
-and another block if the distance is greater, however, explodes (2 blocks away)

when I call this function what it does exactly?
where it needs to be made for it to work properly?

PostPosted: Thu Feb 14, 2013 15:27
by pandaro
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
local print_hello=function()
  print("hello")
end
local dtime=10.0
minetest.register_globalstep(function(dtime)
  hello()
end)


Seeking a way to update a formspec.
I will not clog up the engine by calling a function every 0.5sec or less.
Is there a way to enlarge dtime? what I posted does not seem to run.

PostPosted: Thu Feb 14, 2013 15:40
by Casimir
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

PostPosted: Thu Feb 14, 2013 17:35
by pandaro
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


it works, thanks

PostPosted: Fri Feb 15, 2013 02:26
by Evergreen
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?

PostPosted: Fri Feb 15, 2013 02:29
by 0gb.us
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.

PostPosted: Fri Feb 15, 2013 12:38
by Evergreen
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.


Thanks 0gb.us! :D

PostPosted: Fri Feb 15, 2013 13:41
by Evergreen
Still get a ModError.

I stuck this code inside the same init.lua
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 = {}

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?

PostPosted: Fri Feb 15, 2013 20:48
by pandaro
there a way(automatic) to update (refresh) an opened formspec?(without pressing buttons)

PostPosted: Fri Feb 15, 2013 21:06
by stu
Is there any way to catch when a player takes a hit, either from an entity or from another player?

Something like: entity.on_punch = function(self, puncher) ... but for players.

PostPosted: Fri Feb 15, 2013 21:42
by Evergreen
Evergreen wrote:Still get a ModError.

I stuck this code inside the same init.lua
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 = {}

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?

Nvm, I fixed it.

PostPosted: Sat Feb 16, 2013 11:36
by Evergreen
Now I have another question. Is the function math.random part of minetest?

PostPosted: Sat Feb 16, 2013 11:43
by PilzAdam
Evergreen wrote:Now I have another question. Is the function math.random part of minetest?

No, its part of Lua.

PostPosted: Sat Feb 16, 2013 12:15
by Evergreen
PilzAdam wrote:
Evergreen wrote:Now I have another question. Is the function math.random part of minetest?

No, its part of Lua.

Thanks

PostPosted: Sat Feb 16, 2013 12:18
by Evergreen
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
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


I get a ModError when I add this to the code. PS. The name of the mod is birch.

PostPosted: Sat Feb 16, 2013 12:35
by Calinou
Evergreen wrote:Now I have another question. Is the function math.random part of minetest?


Minetest-related functions usually start with... "minetest". 8)

PostPosted: Sat Feb 16, 2013 14:49
by 0gb.us
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?

PostPosted: Sat Feb 16, 2013 15:04
by Evergreen
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?

It says, "ModError: Failed to load and run /home/.minetest/mods/minetest/birch"

PostPosted: Sat Feb 16, 2013 15:59
by VanessaE
I might point out that More Trees already has birches.

PostPosted: Sat Feb 16, 2013 16:17
by Evergreen
VanessaE wrote:I might point out that More Trees already has birches.

I know. Everyone and their brother has told me that already.

PostPosted: Sat Feb 16, 2013 16:20
by Evergreen
Whoops, nevermind, that was a stupid mistake. "llocal" XD

PostPosted: Sat Feb 16, 2013 16:23
by Evergreen
The saplings officially work!

PostPosted: Sat Feb 16, 2013 16:42
by Evergreen
The treegen is working! Now to figure out how to make them less rare...

PostPosted: Sat Feb 16, 2013 17:42
by Evergreen
I need to ask this question to PilzAdam, because he is the one who coded the tree generation.
Here is the code for the generation of birch trees.
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_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)

Please tell me how to make them less rare.

PostPosted: Sat Feb 16, 2013 18:25
by Evergreen
I tried changing the random, but that didn't seem to help.

PostPosted: Sat Feb 16, 2013 21:48
by Casimir
So, how do I get the position of an entity?

PostPosted: Sat Feb 16, 2013 22:31
by pandaro
! attention this is wrong!

type:
self:getpos()

! attention this is wrong!

PostPosted: Sat Feb 16, 2013 22:32
by PilzAdam
pandaro wrote:type:
self:getpos()

Nope, its:
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
self.object:getpos()

PostPosted: Sat Feb 16, 2013 23:51
by Topywo
Evergreen wrote:I tried changing the random, but that didn't seem to help.


I think you must lower the 100. Just try changing it in 1 or 2 for a quick result.

Edit: teleport to an unloaded chunk or create a new world.