Fixes to laser

This commit is contained in:
Maciej Kasatkin 2012-10-23 04:37:45 +02:00
parent d503d3d757
commit c362f4ad99
7 changed files with 126 additions and 24 deletions

View File

@ -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)

100
item_drop.lua Normal file
View 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

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.