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