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