Maciej Kasatkin
2012-10-23 c362f4ad99cadf2952706c0811ffe0591f14e24c
commit | author | age
167434 1 laser_mk1_max_charge=40000
MK 2
3 local laser_shoot = function(itemstack, player, pointed_thing)
4                 local playerpos=player:getpos()
5                 local dir=player:get_look_dir()
6                 direction_y=math.abs(math.floor(dir.y*100))
7                 print (direction_y)
8                 if direction_y>50 then entity_name="technic:laser_beam_entityV"
9                     else entity_name="technic:laser_beam_entity" end
10                 local obj=minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.6,z=playerpos.z},entity_name)
11                 if obj:get_luaentity().player == nil then
12                     obj:get_luaentity().player = player
13                 end
c362f4 14                 obj:setvelocity({x=dir.x*10, y=dir.y*10, z=dir.z*10})
77e838 15                 obj:setacceleration({x=0, y=0, z=0})
167434 16                 obj:setyaw(player:get_look_yaw()+math.pi)
MK 17                 if obj:get_luaentity().player == nil then
18                     obj:get_luaentity().player = player
19                 end
c362f4 20                 --obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
167434 21                 minetest.sound_play("technic_laser", {pos = playerpos, gain = 1.0, max_hear_distance = 10,})
MK 22                 return true
23 end
24
25
26 minetest.register_tool("technic:laser_mk1", {
27     description = "Mining Laser MK1",
28     inventory_image = "technic_mining_laser_mk1.png",
29     stack_max = 1,
30     on_use = function(itemstack, user, pointed_thing)
31         item=itemstack:to_table()
32         local charge=tonumber((item["wear"])) 
33         if charge ==0 then charge =65535 end
34         charge=get_RE_item_load(charge,laser_mk1_max_charge)
35         if charge-400>0 then
36          laser_shoot(item, user, pointed_thing)
37          charge =charge-400;    
38         charge=set_RE_item_load(charge,laser_mk1_max_charge)
39         item["wear"]=tostring(charge)
40         itemstack:replace(item)
41         end
42         return itemstack
43     end,
44 })
45
46 minetest.register_craft({
47     output = 'technic:laser_mk1',
48     recipe = {
49         {'technic:diamond', 'default:steel_ingot', 'technic:battery'},
50         {'', 'default:steel_ingot', 'technic:battery'},
51         {'', '', 'moreores:copper_ingot'},
52     }
53 })
54
55
56
57 minetest.register_node("technic:laser_beam_box", {
58     drawtype = "nodebox",
59     node_box = {
60         type = "fixed",
61         fixed = {
62             { -0.5 , -0.1, -0.1 ,  0.1 ,  0.1 , 0.1  },
63             { -0.1 , -0.1 , -0.1 , 0.5, 0.1 , 0.1  },
64         }
65     },
66     tiles = {"technic_laser_beam.png"},
67     groups = {not_in_creative_inventory=1},
68 })
69
70 minetest.register_node("technic:laser_beam_boxV", {
71     drawtype = "nodebox",
72     node_box = {
73         type = "fixed",
74         fixed = {
75             { -0.1 , -0.1 , -0.1 , 0.1 , 0.5, 0.1  },
76             { -0.1 , -0.5, -0.1 ,  0.1 ,  0.1 , 0.1  },
77
78         }
79     },
80     tiles = {"technic_laser_beam.png"},
81     groups = {not_in_creative_inventory=1},
82 })
83
84 LASER_BEAM_ENTITY={
85     physical = false,
86     timer=0,
87     visual = "wielditem",
88     visual_size = {x=0.2, y=0.2},
89     textures = {"technic:laser_beam_box"},
90     lastpos={},
c362f4 91     max_range=10,
167434 92     count=0,
MK 93 --    digger=nil,
94     collisionbox = {0,0,0,0,0,0},
95 }
96
97 LASER_BEAM_ENTITY.on_step = function(self, dtime)
98     self.timer=self.timer+dtime
99     local pos = self.object:getpos()
c362f4 100     if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end        
MK 101     if self.lastpos.x ~=nil and self.lastpos.y ~=nil and self.lastpos.y ~=nil then 
102             temp1={x=math.floor(self.lastpos.x),y=math.floor(self.lastpos.y),z=math.floor(self.lastpos.z)}
103             temp2={x=math.floor(pos.x),y=math.floor(pos.y),z=math.floor(pos.z)}
104             if temp1.x==temp2.x and temp1.y==temp2.y and temp1.z==temp2.z then return end
105             end
167434 106     self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
MK 107     self.count=self.count+1
c362f4 108     if self.count==self.max_range then self.object:remove() end
167434 109 end
MK 110
111 LASER_BEAM_ENTITYV={
112     physical = false,
113     timer=0,
114     visual = "wielditem",
115     visual_size = {x=0.2, y=0.2},
116     textures = {"technic:laser_beam_boxV"},
117     lastpos={},
118     max_range=15,
119     count=0,
120     collisionbox = {0,0,0,0,0,0},
121 }
122
123 LASER_BEAM_ENTITYV.on_step = function(self, dtime)
124     self.timer=self.timer+dtime
125     local pos = self.object:getpos()
c362f4 126     if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end        
MK 127     if self.lastpos.x ~=nil and self.lastpos.y ~=nil and self.lastpos.y ~=nil then 
128             temp1={x=math.floor(self.lastpos.x),y=math.floor(self.lastpos.y),z=math.floor(self.lastpos.z)}
129             temp2={x=math.floor(pos.x),y=math.floor(pos.y),z=math.floor(pos.z)}
130             if temp1.x==temp2.x and temp1.y==temp2.y and temp1.z==temp2.z then return end
131             end
167434 132     self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
MK 133     self.count=self.count+1
134     if self.count==self.max_range then self.object:remove() end
135 end
136
137
138 minetest.register_entity("technic:laser_beam_entity", LASER_BEAM_ENTITY)
139 minetest.register_entity("technic:laser_beam_entityV", LASER_BEAM_ENTITYV)
140
c362f4 141 function lazer_it (pos, player)    
MK 142     local pos1={}
143 --    pos1.x=math.floor(pos.x)
144 --    pos1.y=math.floor(pos.y)
145 --    pos1.z=math.floor(pos.z)
146     local node = minetest.env:get_node(pos)
147     if node.name == "air" or node.name == "ignore" or node.name == "default:lava_source" or node.name == "default:lava_flowing" then return end
148     if node.name == "default:water_source" or node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
149     if player then minetest.node_dig(pos,node,player) end
167434 150 end