From: Maciej Kasatkin Date: Tue, 23 Oct 2012 02:37:45 +0000 (+0200) Subject: Fixes to laser X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=c362f4ad99cadf2952706c0811ffe0591f14e24c;p=zefram%2Fminetest%2Ftechnic.git Fixes to laser --- diff --git a/init.lua b/init.lua index 85854d9..b81371a 100644 --- a/init.lua +++ b/init.lua @@ -47,6 +47,7 @@ dofile(minetest.get_modpath("technic").."/tree_tap.lua") 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) diff --git a/item_drop.lua b/item_drop.lua new file mode 100644 index 0000000..3165e6a --- /dev/null +++ b/item_drop.lua @@ -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 diff --git a/mining_laser_mk1.lua b/mining_laser_mk1.lua index 65ef128..76aaee8 100644 --- a/mining_laser_mk1.lua +++ b/mining_laser_mk1.lua @@ -11,13 +11,13 @@ local laser_shoot = function(itemstack, player, pointed_thing) 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 @@ LASER_BEAM_ENTITY={ 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={ 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={ 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 @@ end 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 \ No newline at end of file diff --git a/sounds/item_drop_pickup.1.ogg b/sounds/item_drop_pickup.1.ogg new file mode 100644 index 0000000..2ae432d Binary files /dev/null and b/sounds/item_drop_pickup.1.ogg differ diff --git a/sounds/item_drop_pickup.2.ogg b/sounds/item_drop_pickup.2.ogg new file mode 100644 index 0000000..f58bf08 Binary files /dev/null and b/sounds/item_drop_pickup.2.ogg differ diff --git a/sounds/item_drop_pickup.3.ogg b/sounds/item_drop_pickup.3.ogg new file mode 100644 index 0000000..cf57c94 Binary files /dev/null and b/sounds/item_drop_pickup.3.ogg differ diff --git a/sounds/item_drop_pickup.4.ogg b/sounds/item_drop_pickup.4.ogg new file mode 100644 index 0000000..bfe99d9 Binary files /dev/null and b/sounds/item_drop_pickup.4.ogg differ