Maciej Kasatkin
2012-10-23 c362f4ad99cadf2952706c0811ffe0591f14e24c
Fixes to laser
5 files added
2 files modified
150 ■■■■ changed files
init.lua 1 ●●●● patch | view | raw | blame | history
item_drop.lua 100 ●●●●● patch | view | raw | blame | history
mining_laser_mk1.lua 49 ●●●● patch | view | raw | blame | history
sounds/item_drop_pickup.1.ogg patch | view | raw | blame | history
sounds/item_drop_pickup.2.ogg patch | view | raw | blame | history
sounds/item_drop_pickup.3.ogg patch | view | raw | blame | history
sounds/item_drop_pickup.4.ogg patch | view | raw | blame | history
init.lua
@@ -47,6 +47,7 @@
dofile(minetest.get_modpath("technic").."/flashlight.lua")
dofile(minetest.get_modpath("technic").."/cans.lua")
dofile(minetest.get_modpath("technic").."/chainsaw.lua")
dofile(minetest.get_modpath("technic").."/item_drop.lua")
function has_locked_chest_privilege(meta, player)
item_drop.lua
New file
@@ -0,0 +1,100 @@
-- This part written by PilzAdam (item_drop mod)
minetest.register_globalstep(function(dtime)
    for _,player in ipairs(minetest.get_connected_players()) do
        local pos = player:getpos()
        pos.y = pos.y+0.5
        local inv = player:get_inventory()
        for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
            if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
                if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
                    inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
                    if object:get_luaentity().itemstring ~= "" then
                        minetest.sound_play("item_drop_pickup", {
                            to_player = player:get_player_name(),
                        })
                    end
                    object:get_luaentity().itemstring = ""
                    object:remove()
                end
            end
        end
        for _,object in ipairs(minetest.env: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().collect then
                    if inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
                        local pos1 = pos
                        pos1.y = pos1.y+0.2
                        local pos2 = object:getpos()
                        local vec = {x=pos1.x-pos2.x, y=pos1.y-pos2.y, z=pos1.z-pos2.z}
                        vec.x = vec.x*3
                        vec.y = vec.y*3
                        vec.z = vec.z*3
                        object:setvelocity(vec)
                        minetest.after(1, function(args)
                            local lua = object:get_luaentity()
                            if object == nil or lua == nil or lua.itemstring == nil then
                                return
                            end
                            if inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then
                                inv:add_item("main", ItemStack(object:get_luaentity().itemstring))
                                if object:get_luaentity().itemstring ~= "" then
                                    minetest.sound_play("item_drop_pickup", {
                                        to_player = player:get_player_name(),
                                    })
                                end
                                object:get_luaentity().itemstring = ""
                                object:remove()
                            else
                                object:setvelocity({x=0,y=0,z=0})
                            end
                        end, {player, object})
                    end
                end
            end
        end
    end
end)
function minetest.handle_node_drops(pos, drops, digger)
    for _,item in ipairs(drops) do
        local count, name
        if type(item) == "string" then
            count = 1
            name = item
        else
            count = item:get_count()
            name = item:get_name()
        end
        for i=1,count do
            local obj = minetest.env:add_item(pos, name)
            if obj ~= nil then
                obj:get_luaentity().collect = true
                local x = math.random(1, 5)
                if math.random(1,2) == 1 then
                    x = -x
                end
                local z = math.random(1, 5)
                if math.random(1,2) == 1 then
                    z = -z
                end
                obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z})
                -- FIXME this doesnt work for deactiveted objects
                if minetest.setting_get("remove_items") and tonumber(minetest.setting_get("remove_items")) then
                    minetest.after(tonumber(minetest.setting_get("remove_items")), function(obj)
                        obj:remove()
                    end, obj)
                end
            end
        end
    end
end
if minetest.setting_get("log_mods") then
    minetest.log("action", "item_drop loaded")
end
mining_laser_mk1.lua
@@ -11,13 +11,13 @@
                if obj:get_luaentity().player == nil then
                    obj:get_luaentity().player = player
                end
                obj:setvelocity({x=dir.x*12, y=dir.y*12, z=dir.z*12})
                obj:setvelocity({x=dir.x*10, y=dir.y*10, z=dir.z*10})
                obj:setacceleration({x=0, y=0, z=0})
                obj:setyaw(player:get_look_yaw()+math.pi)
                if obj:get_luaentity().player == nil then
                    obj:get_luaentity().player = player
                end
                obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
                --obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
                minetest.sound_play("technic_laser", {pos = playerpos, gain = 1.0, max_hear_distance = 10,})
                return true
end
@@ -88,7 +88,7 @@
    visual_size = {x=0.2, y=0.2},
    textures = {"technic:laser_beam_box"},
    lastpos={},
    max_range=15,
    max_range=10,
    count=0,
--    digger=nil,
    collisionbox = {0,0,0,0,0,0},
@@ -97,11 +97,15 @@
LASER_BEAM_ENTITY.on_step = function(self, dtime)
    self.timer=self.timer+dtime
    local pos = self.object:getpos()
    local node = minetest.env:get_node(pos)
    if self.lastpos.x~=nil then lazer_it (pos, node, self.player) end
    if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end
    if self.lastpos.x ~=nil and self.lastpos.y ~=nil and self.lastpos.y ~=nil then
            temp1={x=math.floor(self.lastpos.x),y=math.floor(self.lastpos.y),z=math.floor(self.lastpos.z)}
            temp2={x=math.floor(pos.x),y=math.floor(pos.y),z=math.floor(pos.z)}
            if temp1.x==temp2.x and temp1.y==temp2.y and temp1.z==temp2.z then return end
            end
    self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
    self.count=self.count+1
    if self.count>=self.max_range then self.object:remove() end
    if self.count==self.max_range then self.object:remove() end
end
LASER_BEAM_ENTITYV={
@@ -119,9 +123,12 @@
LASER_BEAM_ENTITYV.on_step = function(self, dtime)
    self.timer=self.timer+dtime
    local pos = self.object:getpos()
    local node = minetest.env:get_node(pos)
    if self.lastpos.x~=nil then lazer_it (pos, node, self.player,self.count) end
    if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end
    if self.lastpos.x ~=nil and self.lastpos.y ~=nil and self.lastpos.y ~=nil then
            temp1={x=math.floor(self.lastpos.x),y=math.floor(self.lastpos.y),z=math.floor(self.lastpos.z)}
            temp2={x=math.floor(pos.x),y=math.floor(pos.y),z=math.floor(pos.z)}
            if temp1.x==temp2.x and temp1.y==temp2.y and temp1.z==temp2.z then return end
            end
    self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
    self.count=self.count+1
    if self.count==self.max_range then self.object:remove() end
@@ -131,19 +138,13 @@
minetest.register_entity("technic:laser_beam_entity", LASER_BEAM_ENTITY)
minetest.register_entity("technic:laser_beam_entityV", LASER_BEAM_ENTITYV)
function lazer_it (pos, node, player,count)
    if node.name == "air" or node.name == "ignore" then return end
    if node.name == "default:lava_source" then return end
    if node.name == "default:lava_flowing" then return end
    if node.name == "default:water_source" then minetest.env:remove_node(pos) return end
    if node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
    pos1={}
    pos1.x=math.floor(pos.x)
    pos1.y=math.floor(pos.y)
    pos1.z=math.floor(pos.z)
    if player then
        minetest.node_dig(pos1,node,player)
    end
function lazer_it (pos, player)
    local pos1={}
--    pos1.x=math.floor(pos.x)
--    pos1.y=math.floor(pos.y)
--    pos1.z=math.floor(pos.z)
    local node = minetest.env:get_node(pos)
    if node.name == "air" or node.name == "ignore" or node.name == "default:lava_source" or node.name == "default:lava_flowing" then return end
    if node.name == "default:water_source" or node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
    if player then minetest.node_dig(pos,node,player) end
end
sounds/item_drop_pickup.1.ogg
Binary files differ
sounds/item_drop_pickup.2.ogg
Binary files differ
sounds/item_drop_pickup.3.ogg
Binary files differ
sounds/item_drop_pickup.4.ogg
Binary files differ