mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-09 00:43:51 +01:00
Fixes to laser
This commit is contained in:
parent
d503d3d757
commit
c362f4ad99
1
init.lua
1
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").."/flashlight.lua")
|
||||||
dofile(minetest.get_modpath("technic").."/cans.lua")
|
dofile(minetest.get_modpath("technic").."/cans.lua")
|
||||||
dofile(minetest.get_modpath("technic").."/chainsaw.lua")
|
dofile(minetest.get_modpath("technic").."/chainsaw.lua")
|
||||||
|
dofile(minetest.get_modpath("technic").."/item_drop.lua")
|
||||||
|
|
||||||
|
|
||||||
function has_locked_chest_privilege(meta, player)
|
function has_locked_chest_privilege(meta, player)
|
||||||
|
100
item_drop.lua
Normal file
100
item_drop.lua
Normal 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
|
@ -11,13 +11,13 @@ local laser_shoot = function(itemstack, player, pointed_thing)
|
|||||||
if obj:get_luaentity().player == nil then
|
if obj:get_luaentity().player == nil then
|
||||||
obj:get_luaentity().player = player
|
obj:get_luaentity().player = player
|
||||||
end
|
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:setacceleration({x=0, y=0, z=0})
|
||||||
obj:setyaw(player:get_look_yaw()+math.pi)
|
obj:setyaw(player:get_look_yaw()+math.pi)
|
||||||
if obj:get_luaentity().player == nil then
|
if obj:get_luaentity().player == nil then
|
||||||
obj:get_luaentity().player = player
|
obj:get_luaentity().player = player
|
||||||
end
|
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,})
|
minetest.sound_play("technic_laser", {pos = playerpos, gain = 1.0, max_hear_distance = 10,})
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -88,7 +88,7 @@ LASER_BEAM_ENTITY={
|
|||||||
visual_size = {x=0.2, y=0.2},
|
visual_size = {x=0.2, y=0.2},
|
||||||
textures = {"technic:laser_beam_box"},
|
textures = {"technic:laser_beam_box"},
|
||||||
lastpos={},
|
lastpos={},
|
||||||
max_range=15,
|
max_range=10,
|
||||||
count=0,
|
count=0,
|
||||||
-- digger=nil,
|
-- digger=nil,
|
||||||
collisionbox = {0,0,0,0,0,0},
|
collisionbox = {0,0,0,0,0,0},
|
||||||
@ -97,11 +97,15 @@ LASER_BEAM_ENTITY={
|
|||||||
LASER_BEAM_ENTITY.on_step = function(self, dtime)
|
LASER_BEAM_ENTITY.on_step = function(self, dtime)
|
||||||
self.timer=self.timer+dtime
|
self.timer=self.timer+dtime
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local node = minetest.env:get_node(pos)
|
if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end
|
||||||
if self.lastpos.x~=nil then lazer_it (pos, node, self.player) 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.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
||||||
self.count=self.count+1
|
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
|
end
|
||||||
|
|
||||||
LASER_BEAM_ENTITYV={
|
LASER_BEAM_ENTITYV={
|
||||||
@ -119,9 +123,12 @@ LASER_BEAM_ENTITYV={
|
|||||||
LASER_BEAM_ENTITYV.on_step = function(self, dtime)
|
LASER_BEAM_ENTITYV.on_step = function(self, dtime)
|
||||||
self.timer=self.timer+dtime
|
self.timer=self.timer+dtime
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local node = minetest.env:get_node(pos)
|
if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end
|
||||||
if self.lastpos.x~=nil then lazer_it (pos, node, self.player,self.count) 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.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
||||||
self.count=self.count+1
|
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
|
||||||
@ -131,19 +138,13 @@ end
|
|||||||
minetest.register_entity("technic:laser_beam_entity", LASER_BEAM_ENTITY)
|
minetest.register_entity("technic:laser_beam_entity", LASER_BEAM_ENTITY)
|
||||||
minetest.register_entity("technic:laser_beam_entityV", LASER_BEAM_ENTITYV)
|
minetest.register_entity("technic:laser_beam_entityV", LASER_BEAM_ENTITYV)
|
||||||
|
|
||||||
function lazer_it (pos, node, player,count)
|
function lazer_it (pos, player)
|
||||||
if node.name == "air" or node.name == "ignore" then return end
|
local pos1={}
|
||||||
if node.name == "default:lava_source" then return end
|
-- pos1.x=math.floor(pos.x)
|
||||||
if node.name == "default:lava_flowing" then return end
|
-- pos1.y=math.floor(pos.y)
|
||||||
if node.name == "default:water_source" then minetest.env:remove_node(pos) return end
|
-- pos1.z=math.floor(pos.z)
|
||||||
if node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
|
local node = minetest.env:get_node(pos)
|
||||||
pos1={}
|
if node.name == "air" or node.name == "ignore" or node.name == "default:lava_source" or node.name == "default:lava_flowing" then return end
|
||||||
pos1.x=math.floor(pos.x)
|
if node.name == "default:water_source" or node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
|
||||||
pos1.y=math.floor(pos.y)
|
if player then minetest.node_dig(pos,node,player) end
|
||||||
pos1.z=math.floor(pos.z)
|
|
||||||
|
|
||||||
if player then
|
|
||||||
minetest.node_dig(pos1,node,player)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
BIN
sounds/item_drop_pickup.1.ogg
Normal file
BIN
sounds/item_drop_pickup.1.ogg
Normal file
Binary file not shown.
BIN
sounds/item_drop_pickup.2.ogg
Normal file
BIN
sounds/item_drop_pickup.2.ogg
Normal file
Binary file not shown.
BIN
sounds/item_drop_pickup.3.ogg
Normal file
BIN
sounds/item_drop_pickup.3.ogg
Normal file
Binary file not shown.
BIN
sounds/item_drop_pickup.4.ogg
Normal file
BIN
sounds/item_drop_pickup.4.ogg
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user