ShadowNinja
2013-10-19 eac48441754260fe42c7a605e72141a79ed79bc1
commit | author | age
ee0765 1 local laser_mk1_max_charge = 40000
S 2 technic.register_power_tool("technic:laser_mk1", laser_mk1_max_charge)
e23f87 3
eac484 4 local laser_shoot = function(player, pointed_thing)
S 5     local laser_straight_mode=0
6     local playerpos=player:getpos()
7     local dir=player:get_look_dir()
8     if pointed_thing.type=="node" then  
9         pos=minetest.get_pointed_thing_position(pointed_thing, above)
10         local node = minetest.env:get_node(pos)
11         if node.name~="ignore" then
12             minetest.node_dig(pos,node,player)
13         end
14         laser_straight_mode=1
15     end
16     
17     direction_y=math.abs(math.floor(dir.y*100))
18     if direction_y>50 then entity_name="technic:laser_beam_entityV"
19         else entity_name="technic:laser_beam_entity" end
20     
21     if laser_straight_mode==1  then
22         pos1=minetest.get_pointed_thing_position(pointed_thing, under)
23         pos1.x=math.floor(pos1.x) 
24         pos1.y=math.floor(pos1.y)
25         pos1.z=math.floor(pos1.z)
26         obj=minetest.env:add_entity(pos1,entity_name)
27     else
28     obj=minetest.env:add_entity({x=playerpos.x,y=playerpos.y+1.6,z=playerpos.z},entity_name)
29     end
30     if obj:get_luaentity().player == nil then
31         obj:get_luaentity().player = player
32     end
33     if laser_straight_mode==1 and direction_y<50 then
34         obj:setvelocity({x=dir.x*8, y=0, z=dir.z*8})
35     else if laser_straight_mode==1 and direction_y>50 then
36         obj:setvelocity({x=0, y=dir.y*8, z=dir.z*8})
37         end
38     end
39     if laser_straight_mode==0 then
40         obj:setvelocity({x=dir.x*8, y=dir.y*8, z=dir.z*8})
41         end
42     obj:setacceleration({x=0, y=0, z=0})
43     obj:setyaw(player:get_look_yaw()+math.pi)
44     if obj:get_luaentity().player == nil then
45         obj:get_luaentity().player = player
46     end
47     --obj:get_luaentity().node = player:get_inventory():get_stack("main", 1):get_name()
48     minetest.sound_play("technic_laser", {pos = playerpos, gain = 1.0, max_hear_distance = 10,})
49     return true
82cba9 50 end
R 51
52
53 minetest.register_tool("technic:laser_mk1", {
54     description = "Mining Laser MK1",
55     inventory_image = "technic_mining_laser_mk1.png",
56     stack_max = 1,
57     on_use = function(itemstack, user, pointed_thing)
eac484 58         local meta = get_item_meta(itemstack:get_metadata())
S 59         if not meta or not meta.charge then
60             return
61         end
62         if meta.charge - 400 > 0 then
63             laser_shoot(user, pointed_thing)
64             meta.charge = meta.charge - 400
65             technic.set_RE_wear(itemstack, meta.charge, laser_mk1_max_charge)
66             itemstack:set_metadata(set_item_meta(meta))
82cba9 67         end
R 68         return itemstack
69     end,
70 })
71
72 minetest.register_craft({
73     output = 'technic:laser_mk1',
74     recipe = {
279776 75         {'default:diamond', 'default:steel_ingot', 'technic:battery'},
3a3700 76         {'', 'default:steel_ingot', 'technic:battery'},
R 77         {'', '', 'default:copper_ingot'},
82cba9 78     }
R 79 })
80
81
82
83 minetest.register_node("technic:laser_beam_box", {
84     drawtype = "nodebox",
85     node_box = {
86         type = "fixed",
87         fixed = {
88             { -0.5 , -0.1, -0.1 ,  0.1 ,  0.1 , 0.1  },
89             { -0.1 , -0.1 , -0.1 , 0.5, 0.1 , 0.1  },
90         }
91     },
92     tiles = {"technic_laser_beam.png"},
93     groups = {not_in_creative_inventory=1},
94 })
95
96 minetest.register_node("technic:laser_beam_boxV", {
97     drawtype = "nodebox",
98     node_box = {
99         type = "fixed",
100         fixed = {
101             { -0.1 , -0.1 , -0.1 , 0.1 , 0.5, 0.1  },
102             { -0.1 , -0.5, -0.1 ,  0.1 ,  0.1 , 0.1  },
103
104         }
105     },
106     tiles = {"technic_laser_beam.png"},
107     groups = {not_in_creative_inventory=1},
108 })
109
110 LASER_BEAM_ENTITY={
111     physical = false,
112     timer=0,
113     visual = "wielditem",
114     visual_size = {x=0.2, y=0.2},
115     textures = {"technic:laser_beam_box"},
116     lastpos={},
117     max_range=10,
118     count=0,
119 --    digger=nil,
120     collisionbox = {0,0,0,0,0,0},
121 }
122
123 LASER_BEAM_ENTITY.on_step = function(self, dtime)
124     self.timer=self.timer+dtime
125     local pos = self.object:getpos()
126     if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end        
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
132     self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
133     self.count=self.count+1
134     if self.count==self.max_range then self.object:remove() end
135 end
136
137 LASER_BEAM_ENTITYV={
138     physical = false,
139     timer=0,
140     visual = "wielditem",
141     visual_size = {x=0.2, y=0.2},
142     textures = {"technic:laser_beam_boxV"},
143     lastpos={},
144     max_range=15,
145     count=0,
146     collisionbox = {0,0,0,0,0,0},
147 }
148
149 LASER_BEAM_ENTITYV.on_step = function(self, dtime)
150     self.timer=self.timer+dtime
151     local pos = self.object:getpos()
152     if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end        
153     if self.lastpos.x ~=nil and self.lastpos.y ~=nil and self.lastpos.y ~=nil then 
154             temp1={x=math.floor(self.lastpos.x),y=math.floor(self.lastpos.y),z=math.floor(self.lastpos.z)}
155             temp2={x=math.floor(pos.x),y=math.floor(pos.y),z=math.floor(pos.z)}
156             if temp1.x==temp2.x and temp1.y==temp2.y and temp1.z==temp2.z then return end
157             end
158     self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
159     self.count=self.count+1
160     if self.count==self.max_range then self.object:remove() end
161 end
162
163
164 minetest.register_entity("technic:laser_beam_entity", LASER_BEAM_ENTITY)
165 minetest.register_entity("technic:laser_beam_entityV", LASER_BEAM_ENTITYV)
166
167 function lazer_it (pos, player)    
168     local pos1={}
169 --    pos1.x=math.floor(pos.x)
170 --    pos1.y=math.floor(pos.y)
171 --    pos1.z=math.floor(pos.z)
172     local node = minetest.env:get_node(pos)
173     if node.name == "air" or node.name == "ignore" or node.name == "default:lava_source" or node.name == "default:lava_flowing" then return end
174     if node.name == "default:water_source" or node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
175     if player then minetest.node_dig(pos,node,player) end
e23f87 176 end