ShadowNinja
2013-07-11 5d470cd753efe8f4640099165a7bfc0c6e181c35
commit | author | age
ee5c6c 1 local laser_mk1_max_charge=40000
K 2 technic.register_LV_power_tool ("technic:laser_mk1",laser_mk1_max_charge)
e23f87 3
82cba9 4 local laser_shoot = function(itemstack, player, pointed_thing)
R 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
e23f87 15                     end    
82cba9 16                 
R 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
50 end
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)
58         item=itemstack:to_table()
e23f87 59         local meta=get_item_meta(item["metadata"])
8f485a 60         if meta==nil then return end --tool not charghed
R 61         if meta["charge"]==nil then return end
e23f87 62         charge=meta["charge"]
82cba9 63         if charge-400>0 then
R 64          laser_shoot(item, user, pointed_thing)
ee5c6c 65          charge = charge-400;
K 66         technic.set_RE_wear(item,charge,laser_mk1_max_charge)
e23f87 67         meta["charge"]=charge
R 68         item["metadata"]=set_item_meta(meta)
82cba9 69         itemstack:replace(item)
R 70         end
71         return itemstack
72     end,
73 })
74
75 minetest.register_craft({
76     output = 'technic:laser_mk1',
77     recipe = {
279776 78         {'default:diamond', 'default:steel_ingot', 'technic:battery'},
3a3700 79         {'', 'default:steel_ingot', 'technic:battery'},
R 80         {'', '', 'default:copper_ingot'},
82cba9 81     }
R 82 })
83
84
85
86 minetest.register_node("technic:laser_beam_box", {
87     drawtype = "nodebox",
88     node_box = {
89         type = "fixed",
90         fixed = {
91             { -0.5 , -0.1, -0.1 ,  0.1 ,  0.1 , 0.1  },
92             { -0.1 , -0.1 , -0.1 , 0.5, 0.1 , 0.1  },
93         }
94     },
95     tiles = {"technic_laser_beam.png"},
96     groups = {not_in_creative_inventory=1},
97 })
98
99 minetest.register_node("technic:laser_beam_boxV", {
100     drawtype = "nodebox",
101     node_box = {
102         type = "fixed",
103         fixed = {
104             { -0.1 , -0.1 , -0.1 , 0.1 , 0.5, 0.1  },
105             { -0.1 , -0.5, -0.1 ,  0.1 ,  0.1 , 0.1  },
106
107         }
108     },
109     tiles = {"technic_laser_beam.png"},
110     groups = {not_in_creative_inventory=1},
111 })
112
113 LASER_BEAM_ENTITY={
114     physical = false,
115     timer=0,
116     visual = "wielditem",
117     visual_size = {x=0.2, y=0.2},
118     textures = {"technic:laser_beam_box"},
119     lastpos={},
120     max_range=10,
121     count=0,
122 --    digger=nil,
123     collisionbox = {0,0,0,0,0,0},
124 }
125
126 LASER_BEAM_ENTITY.on_step = function(self, dtime)
127     self.timer=self.timer+dtime
128     local pos = self.object:getpos()
129     if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end        
130     if self.lastpos.x ~=nil and self.lastpos.y ~=nil and self.lastpos.y ~=nil then 
131             temp1={x=math.floor(self.lastpos.x),y=math.floor(self.lastpos.y),z=math.floor(self.lastpos.z)}
132             temp2={x=math.floor(pos.x),y=math.floor(pos.y),z=math.floor(pos.z)}
133             if temp1.x==temp2.x and temp1.y==temp2.y and temp1.z==temp2.z then return end
134             end
135     self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
136     self.count=self.count+1
137     if self.count==self.max_range then self.object:remove() end
138 end
139
140 LASER_BEAM_ENTITYV={
141     physical = false,
142     timer=0,
143     visual = "wielditem",
144     visual_size = {x=0.2, y=0.2},
145     textures = {"technic:laser_beam_boxV"},
146     lastpos={},
147     max_range=15,
148     count=0,
149     collisionbox = {0,0,0,0,0,0},
150 }
151
152 LASER_BEAM_ENTITYV.on_step = function(self, dtime)
153     self.timer=self.timer+dtime
154     local pos = self.object:getpos()
155     if self.player~=nil then if self.lastpos.x~=nil then lazer_it (pos, self.player) end end        
156     if self.lastpos.x ~=nil and self.lastpos.y ~=nil and self.lastpos.y ~=nil then 
157             temp1={x=math.floor(self.lastpos.x),y=math.floor(self.lastpos.y),z=math.floor(self.lastpos.z)}
158             temp2={x=math.floor(pos.x),y=math.floor(pos.y),z=math.floor(pos.z)}
159             if temp1.x==temp2.x and temp1.y==temp2.y and temp1.z==temp2.z then return end
160             end
161     self.lastpos={x=pos.x, y=pos.y, z=pos.z}    
162     self.count=self.count+1
163     if self.count==self.max_range then self.object:remove() end
164 end
165
166
167 minetest.register_entity("technic:laser_beam_entity", LASER_BEAM_ENTITY)
168 minetest.register_entity("technic:laser_beam_entityV", LASER_BEAM_ENTITYV)
169
170 function lazer_it (pos, player)    
171     local pos1={}
172 --    pos1.x=math.floor(pos.x)
173 --    pos1.y=math.floor(pos.y)
174 --    pos1.z=math.floor(pos.z)
175     local node = minetest.env:get_node(pos)
176     if node.name == "air" or node.name == "ignore" or node.name == "default:lava_source" or node.name == "default:lava_flowing" then return end
177     if node.name == "default:water_source" or node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
178     if player then minetest.node_dig(pos,node,player) end
e23f87 179 end