Get dropped items on step over (like minecraft)

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

Get dropped items on step over (like minecraft)

by lkjoel » Mon Apr 09, 2012 02:43

New version! It fixes the block going high up into the sky

I promised I'd make this, and I finally did. When you walk over a dropped block (usually with the Q key, not to be confused with placing blocks) it adds it like as if you picked it up manually.
Make sure you have the latest GIT version of minetest, and patch builtin/item_entity.lua as so:
Code: Select all
25a26,30
>       dontbugme = true,
>       outercircle = 2.0,
>       innercircle = 0.5,
>       gravity = true,
>       whocaresaboutnodes = false,
58d62
<
75c79
<               if minetest.registered_nodes[nn].walkable then
---
>               if minetest.registered_nodes[nn].walkable and self.whocaresaboutnodes == false then
77c81
<                               self.object:setvelocity({x=0,y=0,z=0})
---
>                               self.object:setvelocity({x=0, y=0, z=0})
82a87
>                               self.dontbugme = false
85,86c90,91
<                       if not self.physical_state then
<                               self.object:setvelocity({x=0,y=0,z=0})
---
>                       if not self.physical_state and self.gravity == true then
>                               self.object:setvelocity({x=0, y=0, z=0})
91a97,111
>                               self.dontbugme = true
>                       end
>               end
>               local pos = p
>               local objs = minetest.env:get_objects_inside_radius(pos, self.innercircle)
>               local objs2 = minetest.env:get_objects_inside_radius(pos, self.outercircle)
>               for k, obj in pairs(objs) do
>                       local objpos=obj:getpos()
>                       if objpos.y>pos.y-1 and objpos.y<pos.y+0.5 then
>                               if obj:get_player_name() ~= nil then
>                                       if self.itemstring ~= '' then
>                                               obj:get_inventory():add_item("main", self.itemstring)
>                                       end
>                                       self.object:remove()
>                               end
92a113,140
>               end
>               local playerfound = false
>               for k, obj in pairs(objs2) do
>                       if obj:get_player_name() ~= nil then
>                               playerfound = true
>                               if self.dontbugme == false then
>                                       local objpos=obj:getpos()
>                                       local fx = objpos.x - pos.x
>                                       local fy = objpos.y - pos.y
>                                       local fz = objpos.z - pos.z
>                                       self.gravity = false
>                                       self.physical_state = false
>                                       self.object:set_properties({
>                                               physical = false
>                                       })
>                                       self.object:setvelocity({x=fx * 5, y=fy * 5, z=fz * 5})
>                                       self.dontbugme = true
>                                       self.whocaresaboutnodes = true
>                               end
>                       end
>               end
>               if playerfound == false then
>                       self.gravity = true
>                       self.physical_state = true
>                       self.object:set_properties({
>                               physical = true
>                       })
>                       self.whocaresaboutnodes = false

And then patch item.lua like so:
Code: Select all
200c200
<               v.y = v.y*2 + 1
---
>               v.y = v.y*2 + 2

This, of course, is based on Jeija's mesecon code.
Here is the full source code (if the patch doesn't work) of item_entity.lua:
Code: Select all
-- Minetest: builtin/item_entity.lua

function minetest.spawn_item(pos, item)
    -- Take item in any format
    local stack = ItemStack(item)
    local obj = minetest.env:add_entity(pos, "__builtin:item")
    obj:get_luaentity():set_item(stack:to_string())
    return obj
end

minetest.register_entity("__builtin:item", {
    initial_properties = {
        hp_max = 1,
        physical = true,
        collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
        visual = "sprite",
        visual_size = {x=0.5, y=0.5},
        textures = {""},
        spritediv = {x=1, y=1},
        initial_sprite_basepos = {x=0, y=0},
        is_visible = false,
    },
   
    itemstring = '',
    physical_state = true,
    dontbugme = true,
    outercircle = 2.0,
    innercircle = 0.5,
    gravity = true,
    whocaresaboutnodes = false,

    set_item = function(self, itemstring)
        self.itemstring = itemstring
        local stack = ItemStack(itemstring)
        local itemtable = stack:to_table()
        local itemname = nil
        if itemtable then
            itemname = stack:to_table().name
        end
        local item_texture = nil
        local item_type = ""
        if minetest.registered_items[itemname] then
            item_texture = minetest.registered_items[itemname].inventory_image
            item_type = minetest.registered_items[itemname].type
        end
        prop = {
            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.50, y=0.50}
        else
            prop.visual = "wielditem"
            prop.textures = {itemname}
            prop.visual_size = {x=0.20, y=0.20}
            prop.automatic_rotate = math.pi * 0.25
        end
        self.object:set_properties(prop)
    end,
    get_staticdata = function(self)
        return self.itemstring
    end,

    on_activate = function(self, staticdata)
        self.itemstring = staticdata
        self.object:set_armor_groups({immortal=1})
        self.object:setvelocity({x=0, y=2, z=0})
        self.object:setacceleration({x=0, y=-10, z=0})
        self:set_item(self.itemstring)
    end,

    on_step = function(self, dtime)
        local p = self.object:getpos()
        p.y = p.y - 0.3
        local nn = minetest.env:get_node(p).name
        if minetest.registered_nodes[nn].walkable and self.whocaresaboutnodes == false then
            if self.physical_state then
                self.object:setvelocity({x=0, y=0, z=0})
                self.object:setacceleration({x=0, y=0, z=0})
                self.physical_state = false
                self.object:set_properties({
                    physical = false
                })
                self.dontbugme = false
            end
        else
            if not self.physical_state and self.gravity == true then
                self.object:setvelocity({x=0, y=0, z=0})
                self.object:setacceleration({x=0, y=-10, z=0})
                self.physical_state = true
                self.object:set_properties({
                    physical = true
                })
                self.dontbugme = true
            end
        end
        local pos = p
        local objs = minetest.env:get_objects_inside_radius(pos, self.innercircle)
        local objs2 = minetest.env:get_objects_inside_radius(pos, self.outercircle)
        for k, obj in pairs(objs) do
            local objpos=obj:getpos()
            if objpos.y>pos.y-1 and objpos.y<pos.y+0.5 then
                if obj:get_player_name() ~= nil then
                    if self.itemstring ~= '' then
                        obj:get_inventory():add_item("main", self.itemstring)
                    end
                    self.object:remove()
                end
            end
        end
        local playerfound = false
        for k, obj in pairs(objs2) do
            if obj:get_player_name() ~= nil then
                playerfound = true
                if self.dontbugme == false then
                    local objpos=obj:getpos()
                    local fx = objpos.x - pos.x
                    local fy = objpos.y - pos.y
                    local fz = objpos.z - pos.z
                    self.gravity = false
                    self.physical_state = false
                    self.object:set_properties({
                        physical = false
                    })
                    self.object:setvelocity({x=fx * 5, y=fy * 5, z=fz * 5})
                    self.dontbugme = true
                    self.whocaresaboutnodes = true
                end
            end
        end
        if playerfound == false then
            self.gravity = true
            self.physical_state = true
            self.object:set_properties({
                physical = true
            })
            self.whocaresaboutnodes = false
        end
    end,

    on_punch = function(self, hitter)
        if self.itemstring ~= '' then
            hitter:get_inventory():add_item("main", self.itemstring)
        end
        self.object:remove()
    end,
})

And of item.lua:
Code: Select all
-- Minetest: builtin/item.lua

--
-- Item definition helpers
--

function minetest.inventorycube(img1, img2, img3)
    img2 = img2 or img1
    img3 = img3 or img1
    return "[inventorycube"
            .. "{" .. img1:gsub("%^", "&")
            .. "{" .. img2:gsub("%^", "&")
            .. "{" .. img3:gsub("%^", "&")
end

function minetest.get_pointed_thing_position(pointed_thing, above)
    if pointed_thing.type == "node" then
        if above then
            -- The position where a node would be placed
            return pointed_thing.above
        else
            -- The position where a node would be dug
            return pointed_thing.under
        end
    elseif pointed_thing.type == "object" then
        obj = pointed_thing.ref
        if obj ~= nil then
            return obj:getpos()
        else
            return nil
        end
    else
        return nil
    end
end

function minetest.dir_to_facedir(dir)
    if 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

function minetest.dir_to_wallmounted(dir)
    if math.abs(dir.y) > math.max(math.abs(dir.x), math.abs(dir.z)) then
        if dir.y < 0 then
            return 1
        else
            return 0
        end
    elseif math.abs(dir.x) > math.abs(dir.z) then
        if dir.x < 0 then
            return 3
        else
            return 2
        end
    else
        if dir.z < 0 then
            return 5
        else
            return 4
        end
    end
end

function minetest.get_node_drops(nodename, toolname)
    local drop = ItemStack({name=nodename}):get_definition().drop
    if drop == nil then
        -- default drop
        return {ItemStack({name=nodename})}
    elseif type(drop) == "string" then
        -- itemstring drop
        return {ItemStack(drop)}
    elseif drop.items == nil then
        -- drop = {} to disable default drop
        return {}
    end

    -- Extended drop table
    local got_items = {}
    local got_count = 0
    local _, item, tool
    for _, item in ipairs(drop.items) do
        local good_rarity = true
        local good_tool = true
        if item.rarity ~= nil then
            good_rarity = item.rarity < 1 or math.random(item.rarity) == 1
        end
        if item.tools ~= nil then
            good_tool = false
            for _, tool in ipairs(item.tools) do
                if tool:sub(1, 1) == '~' then
                    good_tool = toolname:find(tool:sub(2)) ~= nil
                else
                    good_tool = toolname == tool
                end
                if good_tool then
                    break
                end
            end
            end
        if good_rarity and good_tool then
            got_count = got_count + 1
            for _, add_item in ipairs(item.items) do
                got_items[#got_items+1] = add_item
            end
            if drop.max_items ~= nil and got_count == drop.max_items then
                break
            end
        end
    end
    return got_items
end

function minetest.item_place_node(itemstack, placer, pointed_thing)
    local item = itemstack:peek_item()
    local def = itemstack:get_definition()
    if def.type == "node" and pointed_thing.type == "node" then
        local pos = pointed_thing.above
        local oldnode = minetest.env:get_node(pos)
        local olddef = ItemStack({name=oldnode.name}):get_definition()

        if not olddef.buildable_to then
            minetest.log("info", placer:get_player_name() .. " tried to place"
                .. " node in invalid position " .. minetest.pos_to_string(pos)
                .. ", replacing " .. oldnode.name)
            return
        end

        minetest.log("action", placer:get_player_name() .. " places node "
            .. def.name .. " at " .. minetest.pos_to_string(pos))

        local newnode = {name = def.name, param1 = 0, param2 = 0}

        -- Calculate direction for wall mounted stuff like torches and signs
        if def.paramtype2 == 'wallmounted' then
            local under = pointed_thing.under
            local above = pointed_thing.above
            local dir = {x = under.x - above.x, y = under.y - above.y, z = under.z - above.z}
            newnode.param2 = minetest.dir_to_wallmounted(dir)
        -- Calculate the direction for furnaces and chests and stuff
        elseif def.paramtype2 == 'facedir' then
            local playerpos = placer:getpos()
            local dir = {x = pos.x - playerpos.x, y = pos.y - playerpos.y, z = pos.z - playerpos.z}
            newnode.param2 = minetest.dir_to_facedir(dir)
            minetest.log("action", "facedir: " .. newnode.param2)
        end

        -- Add node and update
        minetest.env:add_node(pos, newnode)

        -- Set metadata owner
        if def.metadata_name ~= "" then
            minetest.env:get_meta(pos):set_owner(placer:get_player_name())
        end

        -- Run script hook
        local _, callback
        for _, callback in ipairs(minetest.registered_on_placenodes) do
            callback(pos, newnode, placer)
        end

        itemstack:take_item()
    end
    return itemstack
end

function minetest.item_place_object(itemstack, placer, pointed_thing)
    local pos = minetest.get_pointed_thing_position(pointed_thing, true)
    if pos ~= nil then
        local item = itemstack:take_item()
        minetest.env:add_item(pos, item)
    end
    return itemstack
end

function minetest.item_place(itemstack, placer, pointed_thing)
    if itemstack:get_definition().type == "node" then
        return minetest.item_place_node(itemstack, placer, pointed_thing)
    else
        return minetest.item_place_object(itemstack, placer, pointed_thing)
    end
end

function minetest.item_drop(itemstack, dropper, pos)
    if dropper.get_player_name then
        local v = dropper:get_look_dir()
        local p = {x=pos.x+v.x, y=pos.y+1.5+v.y, z=pos.z+v.z}
        local obj = minetest.env:add_item(p, itemstack)
        v.x = v.x*2
        v.y = v.y*2 + 2
        v.z = v.z*2
        obj:setvelocity(v)
    else
        minetest.env:add_item(pos, itemstack)
    end
    return ""
end

function minetest.item_eat(hp_change, replace_with_item)
    return function(itemstack, user, pointed_thing)  -- closure
        if itemstack:take_item() ~= nil then
            user:set_hp(user:get_hp() + hp_change)
            itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
        end
        return itemstack
    end
end

function minetest.node_punch(pos, node, puncher)
    -- Run script hook
    local _, callback
    for _, callback in ipairs(minetest.registered_on_punchnodes) do
        callback(pos, node, puncher)
    end

end

function minetest.node_dig(pos, node, digger)
    minetest.debug("node_dig")

    local def = ItemStack({name=node.name}):get_definition()
    if not def.diggable then
        minetest.debug("not diggable")
        minetest.log("info", digger:get_player_name() .. " tried to dig "
            .. node.name .. " which is not diggable "
            .. minetest.pos_to_string(pos))
        return
    end

    local meta = minetest.env:get_meta(pos)
    if meta ~= nil and not meta:get_allow_removal() then
        minetest.debug("dig prevented by metadata")
        minetest.log("info", digger:get_player_name() .. " tried to dig "
            .. node.name .. ", but removal is disabled by metadata "
            .. minetest.pos_to_string(pos))
        return
    end

    minetest.log('action', digger:get_player_name() .. " digs "
        .. node.name .. " at " .. minetest.pos_to_string(pos))

    if not minetest.setting_getbool("creative_mode") then
        local wielded = digger:get_wielded_item()
        local drops = minetest.get_node_drops(node.name, wielded:get_name())

        -- Wear out tool
        tp = wielded:get_tool_capabilities()
        dp = minetest.get_dig_params(def.groups, tp)
        wielded:add_wear(dp.wear)
        digger:set_wielded_item(wielded)

        -- Add dropped items
        local _, dropped_item
        for _, dropped_item in ipairs(drops) do
            digger:get_inventory():add_item("main", dropped_item)
        end
    end

    -- Remove node and update
    minetest.env:remove_node(pos)

    -- Run script hook
    local _, callback
    for _, callback in ipairs(minetest.registered_on_dignodes) do
        callback(pos, node, digger)
    end
end

-- This is used to allow mods to redefine minetest.item_place and so on
local function redef_wrapper(table, name)
    return function(...)
        return table[name](...)
    end
end

--
-- Item definition defaults
--

minetest.nodedef_default = {
    -- Item properties
    type="node",
    -- name intentionally not defined here
    description = "",
    groups = {},
    inventory_image = "",
    wield_image = "",
    wield_scale = {x=1,y=1,z=1},
    stack_max = 99,
    usable = false,
    liquids_pointable = false,
    tool_capabilities = nil,

    -- Interaction callbacks
    on_place = redef_wrapper(minetest, 'item_place'), -- minetest.item_place
    on_drop = redef_wrapper(minetest, 'item_drop'), -- minetest.item_drop
    on_use = nil,

    on_punch = redef_wrapper(minetest, 'node_punch'), -- minetest.node_punch
    on_dig = redef_wrapper(minetest, 'node_dig'), -- minetest.node_dig

    -- Node properties
    drawtype = "normal",
    visual_scale = 1.0,
    tile_images = {""},
    special_materials = {
        {image="", backface_culling=true},
        {image="", backface_culling=true},
    },
    alpha = 255,
    post_effect_color = {a=0, r=0, g=0, b=0},
    paramtype = "none",
    paramtype2 = "none",
    is_ground_content = false,
    sunlight_propagates = false,
    walkable = true,
    pointable = true,
    diggable = true,
    climbable = false,
    buildable_to = false,
    metadata_name = "",
    liquidtype = "none",
    liquid_alternative_flowing = "",
    liquid_alternative_source = "",
    liquid_viscosity = 0,
    light_source = 0,
    damage_per_second = 0,
    selection_box = {type="regular"},
    legacy_facedir_simple = false,
    legacy_wallmounted = false,
}

minetest.craftitemdef_default = {
    type="craft",
    -- name intentionally not defined here
    description = "",
    groups = {},
    inventory_image = "",
    wield_image = "",
    wield_scale = {x=1,y=1,z=1},
    stack_max = 99,
    liquids_pointable = false,
    tool_capabilities = nil,

    -- Interaction callbacks
    on_place = redef_wrapper(minetest, 'item_place'), -- minetest.item_place
    on_drop = redef_wrapper(minetest, 'item_drop'), -- minetest.item_drop
    on_use = nil,
}

minetest.tooldef_default = {
    type="tool",
    -- name intentionally not defined here
    description = "",
    groups = {},
    inventory_image = "",
    wield_image = "",
    wield_scale = {x=1,y=1,z=1},
    stack_max = 1,
    liquids_pointable = false,
    tool_capabilities = nil,

    -- Interaction callbacks
    on_place = redef_wrapper(minetest, 'item_place'), -- minetest.item_place
    on_drop = redef_wrapper(minetest, 'item_drop'), -- minetest.item_drop
    on_use = nil,
}

minetest.noneitemdef_default = {  -- This is used for the hand and unknown items
    type="none",
    -- name intentionally not defined here
    description = "",
    groups = {},
    inventory_image = "",
    wield_image = "",
    wield_scale = {x=1,y=1,z=1},
    stack_max = 99,
    liquids_pointable = false,
    tool_capabilities = nil,

    -- Interaction callbacks
    on_place = nil,
    on_drop = nil,
    on_use = nil,
}
Last edited by lkjoel on Thu Apr 12, 2012 18:12, edited 1 time in total.
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 02:47

awesome new node drop with 3d rotating cube will work very nicely with the timber mod thanks ikjoel your the man:D
Keep calm and code python^_^
 

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

by lkjoel » Mon Apr 09, 2012 02:59

What does the timber mod do? I never really understood it
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 03:13

drops the blocks from a tree if you cut it in the middle, much like in the real life. basically chopping trees down.
Keep calm and code python^_^
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21
Location: USA,Michigan

by bgsmithjr » Mon Apr 09, 2012 03:15

theres a function for this , the timber mod
default.register_falling_item("default:tree","default_tree.png")
Something like that.
Last edited by bgsmithjr on Mon Apr 09, 2012 03:15, edited 1 time in total.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 03:18

bgsmithjr wrote:theres a function for this , the timber mod
default.register_falling_item("default:tree","default_tree.png")
Something like that.

and something like that would enable picking up item by walking over them?
Keep calm and code python^_^
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21
Location: USA,Michigan

by bgsmithjr » Mon Apr 09, 2012 03:19

Death Dealer wrote:
bgsmithjr wrote:theres a function for this , the timber mod
default.register_falling_item("default:tree","default_tree.png")
Something like that.

and something like that would enable picking up item by walking over them?

No, I said for the timber mod.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 03:22

bgsmithjr wrote:
Death Dealer wrote:
bgsmithjr wrote:theres a function for this , the timber mod
default.register_falling_item("default:tree","default_tree.png")
Something like that.

and something like that would enable picking up item by walking over them?

No, I said for the timber mod.

i was describing the timber mod to ikjoel-_- im not sure where your going with this..
Keep calm and code python^_^
 

User avatar
bgsmithjr
Member
 
Posts: 436
Joined: Thu Mar 08, 2012 23:21
Location: USA,Michigan

by bgsmithjr » Mon Apr 09, 2012 03:24

sorry, but it was just conversation, what the timbermod does can be obtained with a function in the default, so you don't need a mod or programming knowledge you just add one line, but if you would rather have it as a mod, I understand, sorry to spam the topic
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 03:27

bgsmithjr wrote:sorry, but it was just conversation, what the timbermod does can be obtained with a function in the default, so you don't need a mod or programming knowledge you just add one line, but if you would rather have it as a mod, I understand, sorry to spam the topic

no its ok, i didnt know it could be added so easyly.
Keep calm and code python^_^
 

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

by lkjoel » Mon Apr 09, 2012 03:49

Death Dealer wrote:drops the blocks from a tree if you cut it in the middle, much like in the real life. basically chopping trees down.

oh, I get it
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

by lkjoel » Mon Apr 09, 2012 03:55

does my mod work?
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
Jordach
Member
 
Posts: 4523
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Mon Apr 09, 2012 11:39

So which lines do we put this over???
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

User avatar
Jordach
Member
 
Posts: 4523
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Mon Apr 09, 2012 12:18

Work out my problem: Minetest returns this:
Code: Select all
unexpected symbol near 'local' line 96.


Code: Select all
-- Minetest: builtin/item_entity.lua

function minetest.spawn_item(pos, item)
    -- Take item in any format
    local stack = ItemStack(item)
    local obj = minetest.env:add_entity(pos, "__builtin:item")
    obj:get_luaentity():set_item(stack:to_string())
    return obj
end

minetest.register_entity("__builtin:item", {
    initial_properties = {
        hp_max = 1,
        physical = true,
        collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
        visual = "sprite",
        visual_size = {x=0.5, y=0.5},
        textures = {""},
        spritediv = {x=1, y=1},
        initial_sprite_basepos = {x=0, y=0},
        is_visible = false,
    },
   
    itemstring = '',
    physical_state = true,

    set_item = function(self, itemstring)
        self.itemstring = itemstring
        local stack = ItemStack(itemstring)
        local itemtable = stack:to_table()
        local itemname = nil
        if itemtable then
            itemname = stack:to_table().name
        end
        local item_texture = nil
        local item_type = ""
        if minetest.registered_items[itemname] then
            item_texture = minetest.registered_items[itemname].inventory_image
            item_type = minetest.registered_items[itemname].type
        end
        prop = {
            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.50, y=0.50}
        else
            prop.visual = "wielditem"
            prop.textures = {itemname}
            prop.visual_size = {x=0.20, y=0.20}
            prop.automatic_rotate = math.pi * 0.25
        end
        self.object:set_properties(prop)
    end,

    get_staticdata = function(self)
        return self.itemstring
    end,

    on_activate = function(self, staticdata)
        self.itemstring = staticdata
        self.object:set_armor_groups({immortal=1})
        self.object:setvelocity({x=0, y=2, z=0})
        self.object:setacceleration({x=0, y=-10, z=0})
        self:set_item(self.itemstring)
    end,

    on_step = function(self, dtime)
        local p = self.object:getpos()
        p.y = p.y - 0.3
        local nn = minetest.env:get_node(p).name
        if minetest.registered_nodes[nn].walkable then
            if self.physical_state then
                self.object:setvelocity({x=0,y=0,z=0})
                self.object:setacceleration({x=0, y=0, z=0})
                self.physical_state = false
                self.object:set_properties({
                    physical = false
                })
            end
        else
            if not self.physical_state then
                self.object:setvelocity({x=0,y=0,z=0})
                self.object:setacceleration({x=0, y=-10, z=0})
                self.physical_state = true
                self.object:set_properties({
                    physical = true
                })
            end
        end
    end,

    local pos = p
        local objs = minetest.env:get_objects_inside_radius(pos, 1)
        for k, obj in pairs(objs) do
                local objpos=obj:getpos()
                if objpos.y>pos.y-1 and objpos.y<pos.y+1 then
                        if obj:get_player_name() ~= nil then
                                if self.itemstring ~= '' then
                                        obj:get_inventory():add_item("main", self.itemstring)
                                end
                                self.object:remove()
                        end
                end
        end,
})
Last edited by Jordach on Mon Apr 09, 2012 12:19, edited 1 time in total.
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 15:06

thats the same thin i did jordach with no luck... witch im sure you know.
Keep calm and code python^_^
 

User avatar
Jordach
Member
 
Posts: 4523
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Mon Apr 09, 2012 15:10

it don't wanna work, even though LATEST MINETEST IS THE NEW BUILD.
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 15:19

yep ive try several different configuration trying to get this to work. no luck yet.
Keep calm and code python^_^
 

lkjoel
Member
 
Posts: 779
Joined: Wed Feb 29, 2012 19:27
Location: Gallifrey

by lkjoel » Mon Apr 09, 2012 17:39

Jordach wrote:Work out my problem: Minetest returns this:
Code: Select all
unexpected symbol near 'local' line 96.


Code: Select all
-- Minetest: builtin/item_entity.lua

function minetest.spawn_item(pos, item)
    -- Take item in any format
    local stack = ItemStack(item)
    local obj = minetest.env:add_entity(pos, "__builtin:item")
    obj:get_luaentity():set_item(stack:to_string())
    return obj
end

minetest.register_entity("__builtin:item", {
    initial_properties = {
        hp_max = 1,
        physical = true,
        collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
        visual = "sprite",
        visual_size = {x=0.5, y=0.5},
        textures = {""},
        spritediv = {x=1, y=1},
        initial_sprite_basepos = {x=0, y=0},
        is_visible = false,
    },
   
    itemstring = '',
    physical_state = true,

    set_item = function(self, itemstring)
        self.itemstring = itemstring
        local stack = ItemStack(itemstring)
        local itemtable = stack:to_table()
        local itemname = nil
        if itemtable then
            itemname = stack:to_table().name
        end
        local item_texture = nil
        local item_type = ""
        if minetest.registered_items[itemname] then
            item_texture = minetest.registered_items[itemname].inventory_image
            item_type = minetest.registered_items[itemname].type
        end
        prop = {
            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.50, y=0.50}
        else
            prop.visual = "wielditem"
            prop.textures = {itemname}
            prop.visual_size = {x=0.20, y=0.20}
            prop.automatic_rotate = math.pi * 0.25
        end
        self.object:set_properties(prop)
    end,

    get_staticdata = function(self)
        return self.itemstring
    end,

    on_activate = function(self, staticdata)
        self.itemstring = staticdata
        self.object:set_armor_groups({immortal=1})
        self.object:setvelocity({x=0, y=2, z=0})
        self.object:setacceleration({x=0, y=-10, z=0})
        self:set_item(self.itemstring)
    end,

    on_step = function(self, dtime)
        local p = self.object:getpos()
        p.y = p.y - 0.3
        local nn = minetest.env:get_node(p).name
        if minetest.registered_nodes[nn].walkable then
            if self.physical_state then
                self.object:setvelocity({x=0,y=0,z=0})
                self.object:setacceleration({x=0, y=0, z=0})
                self.physical_state = false
                self.object:set_properties({
                    physical = false
                })
            end
        else
            if not self.physical_state then
                self.object:setvelocity({x=0,y=0,z=0})
                self.object:setacceleration({x=0, y=-10, z=0})
                self.physical_state = true
                self.object:set_properties({
                    physical = true
                })
            end
        end
    end,

    local pos = p
        local objs = minetest.env:get_objects_inside_radius(pos, 1)
        for k, obj in pairs(objs) do
                local objpos=obj:getpos()
                if objpos.y>pos.y-1 and objpos.y<pos.y+1 then
                        if obj:get_player_name() ~= nil then
                                if self.itemstring ~= '' then
                                        obj:get_inventory():add_item("main", self.itemstring)
                                end
                                self.object:remove()
                        end
                end
        end,
})

that's weird... I have a different version than you do...
Use this code for the file:
Code: Select all
-- Minetest: builtin/item_entity.lua

function minetest.spawn_item(pos, item)
    -- Take item in any format
    local stack = ItemStack(item)
    local obj = minetest.env:add_entity(pos, "__builtin:item")
    obj:get_luaentity():set_item(stack:to_string())
    return obj
end

minetest.register_entity("__builtin:item", {
    initial_properties = {
        hp_max = 1,
        physical = true,
        collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
        visual = "sprite",
        visual_size = {x=0.5, y=0.5},
        textures = {""},
        spritediv = {x=1, y=1},
        initial_sprite_basepos = {x=0, y=0},
        is_visible = false,
    },
   
    itemstring = '',
    physical_state = true,

    set_item = function(self, itemstring)
        self.itemstring = itemstring
        local stack = ItemStack(itemstring)
        local itemtable = stack:to_table()
        local itemname = nil
        if itemtable then
            itemname = stack:to_table().name
        end
        local item_texture = nil
        local item_type = ""
        if minetest.registered_items[itemname] then
            item_texture = minetest.registered_items[itemname].inventory_image
            item_type = minetest.registered_items[itemname].type
        end
        prop = {
            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.50, y=0.50}
        else
            prop.visual = "wielditem"
            prop.textures = {itemname}
            prop.visual_size = {x=0.20, y=0.20}
            prop.automatic_rotate = math.pi * 0.25
        end
        self.object:set_properties(prop)
    end,

    get_staticdata = function(self)
        return self.itemstring
    end,

    on_activate = function(self, staticdata)
        self.itemstring = staticdata
        self.object:set_armor_groups({immortal=1})
        self.object:setvelocity({x=0, y=2, z=0})
        self.object:setacceleration({x=0, y=-10, z=0})
        self:set_item(self.itemstring)
    end,

    on_step = function(self, dtime)
        local p = self.object:getpos()
        p.y = p.y - 0.3
        local nn = minetest.env:get_node(p).name
        if minetest.registered_nodes[nn].walkable then
            if self.physical_state then
                self.object:setvelocity({x=0,y=0,z=0})
                self.object:setacceleration({x=0, y=0, z=0})
                self.physical_state = false
                self.object:set_properties({
                    physical = false
                })
            end
        else
            if not self.physical_state then
                self.object:setvelocity({x=0,y=0,z=0})
                self.object:setacceleration({x=0, y=-10, z=0})
                self.physical_state = true
                self.object:set_properties({
                    physical = true
                })
            end
        end
        local pos = p
        local objs = minetest.env:get_objects_inside_radius(pos, 1)
        for k, obj in pairs(objs) do
            local objpos=obj:getpos()
            if objpos.y>pos.y-1 and objpos.y<pos.y+1 then
                if obj:get_player_name() ~= nil then
                    if self.itemstring ~= '' then
                        obj:get_inventory():add_item("main", self.itemstring)
                    end
                    self.object:remove()
                end
            end
        end
    end,

    on_punch = function(self, hitter)
        if self.itemstring ~= '' then
            hitter:get_inventory():add_item("main", self.itemstring)
        end
        self.object:remove()
    end,
})
My mods: The Nether | Doctor Who (WIP)

I have quit minetest ... again. I am heavily unimpressed by both the game and the community.
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Mon Apr 09, 2012 18:18

yep worked like a charm thanks ikjoel:D
Keep calm and code python^_^
 

z10N30NC1UB10z
Member
 
Posts: 14
Joined: Wed Apr 04, 2012 21:03
Location: Rhode Island, USA

by z10N30NC1UB10z » Mon Apr 09, 2012 18:47

Is there any possible way this mod can work with the 1/22 version?
 

User avatar
Jordach
Member
 
Posts: 4523
Joined: Mon Oct 03, 2011 17:58
Location: Blender Scene
GitHub: Jordach
IRC: Jordach
In-game: Jordach

by Jordach » Mon Apr 09, 2012 18:51

Nope, never. Sorry about that.
viewtopic.php?f=10&t=19056 Solar Plains Dev Server
 

z10N30NC1UB10z
Member
 
Posts: 14
Joined: Wed Apr 04, 2012 21:03
Location: Rhode Island, USA

by z10N30NC1UB10z » Mon Apr 09, 2012 18:54

It's alright, thanks for the quick response Jordach.
 

User avatar
sfan5
Moderator
 
Posts: 3792
Joined: Wed Aug 24, 2011 09:44
Location: Germany
GitHub: sfan5
IRC: sfan5

by sfan5 » Mon Apr 09, 2012 19:31

Nice!I'll use this
Mods: Mesecons | WorldEdit | Nuke & Minetest builds for Windows (32-bit & 64-bit)
 

User avatar
jordan4ibanez
Member
 
Posts: 1895
Joined: Tue Sep 27, 2011 18:44
Location: Rhode Island, USA
GitHub: jordan4ibanez
IRC: jordan4ibanez
In-game: jordan4ibanez

by jordan4ibanez » Tue Apr 10, 2012 16:32

https://github.com/jordan4ibanez/minetest
this code and the other one works great! i included it in my git!
I've been gone for a long time
 

User avatar
Death Dealer
Member
 
Posts: 1379
Joined: Wed Feb 15, 2012 18:46
Location: Limbo

by Death Dealer » Tue Apr 10, 2012 16:38

to get all blocks to drop nodes themselves would be pretty simple then?? its off topic i know but its relating.. would it be possible to addapt the timber mod to work with all nodes? maybe not in the same fashion just as far as the 3d cube node drop. ill see what i can figure out here: /
Last edited by Death Dealer on Tue Apr 10, 2012 16:54, edited 1 time in total.
Keep calm and code python^_^
 

Next

Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 6 guests