mirror of
https://github.com/minetest-mods/technic.git
synced 2024-12-22 05:42:33 +01:00
Localize most variables
This commit is contained in:
parent
0ea1bd1fa2
commit
5cf765b2f1
@ -1,21 +1,3 @@
|
||||
function get_item_meta (string)
|
||||
if string.find(string, "return {") then
|
||||
return minetest.deserialize(string)
|
||||
else return nil
|
||||
end
|
||||
end
|
||||
|
||||
function set_item_meta (table)
|
||||
return minetest.serialize(table)
|
||||
end
|
||||
|
||||
function has_locked_chest_privilege(meta, player)
|
||||
if player:get_player_name() ~= meta:get_string("owner") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.swap_node = minetest.swap_node or function(pos, node)
|
||||
local oldmeta = minetest.get_meta(pos):to_table()
|
||||
minetest.set_node(pos, node)
|
||||
|
@ -17,6 +17,7 @@ dofile(path.."/generator.lua")
|
||||
|
||||
-- The power radiator supplies appliances with inductive coupled power:
|
||||
-- Lighting and associated textures is taken directly from VanessaE's homedecor and made electric.
|
||||
dofile(path.."/power_radiator.lua")
|
||||
dofile(path.."/lighting.lua")
|
||||
-- This is currently useless, slow, and mostly copied
|
||||
--dofile(path.."/power_radiator.lua")
|
||||
--dofile(path.."/lighting.lua")
|
||||
|
||||
|
@ -21,7 +21,7 @@ minetest.register_craft({
|
||||
|
||||
})
|
||||
|
||||
mk1_on = function(pos, node)
|
||||
local function mk1_on(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local pos1={}
|
||||
@ -41,7 +41,7 @@ mk1_on = function(pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
mk1_off = function(pos, node)
|
||||
local function mk1_off(pos, node)
|
||||
if node.name == "technic:constructor_mk1_on" then
|
||||
technic.swap_node(pos,"technic:constructor_mk1_off")
|
||||
nodeupdate(pos)
|
||||
@ -97,7 +97,7 @@ minetest.register_node("technic:constructor_mk1_on", {
|
||||
|
||||
--Constructor Mk2
|
||||
|
||||
mk2_on = function(pos, node)
|
||||
local function mk2_on(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local pos1={}
|
||||
@ -123,7 +123,7 @@ mk2_on = function(pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
mk2_off = function(pos, node)
|
||||
local function mk2_off(pos, node)
|
||||
if node.name == "technic:constructor_mk2_on" then
|
||||
technic.swap_node(pos,"technic:constructor_mk2_off")
|
||||
nodeupdate(pos)
|
||||
@ -181,7 +181,7 @@ minetest.register_node("technic:constructor_mk2_on", {
|
||||
|
||||
|
||||
-- Constructor Mk3
|
||||
mk3_on = function(pos, node)
|
||||
local function mk3_on(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
@ -225,7 +225,7 @@ mk3_on = function(pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
mk3_off = function(pos, node)
|
||||
local function mk3_off(pos, node)
|
||||
if node.name == "technic:constructor_mk3_on" then
|
||||
technic.swap_node(pos,"technic:constructor_mk3_off")
|
||||
nodeupdate(pos)
|
||||
@ -289,7 +289,7 @@ minetest.register_node("technic:constructor_mk3_on", {
|
||||
})
|
||||
|
||||
|
||||
deploy_node =function (inv, slot_name, pos1, node1, node)
|
||||
local function deploy_node(inv, slot_name, pos1, node1, node)
|
||||
if node1.name == "air" then
|
||||
if not inv:is_empty(slot_name) then
|
||||
stack1=inv:get_list(slot_name)
|
||||
|
@ -43,7 +43,7 @@ local function get_face(pos,ppos,pvect)
|
||||
end
|
||||
end
|
||||
|
||||
function lines(str)
|
||||
local function lines(str)
|
||||
local t = {}
|
||||
local function helper(line) table.insert(t, line) return "" end
|
||||
helper((str:gsub("(.-)\r?\n", helper)))
|
||||
|
@ -74,7 +74,7 @@ minetest.register_abm({
|
||||
end,
|
||||
})
|
||||
|
||||
function inject_items (pos)
|
||||
local function inject_items (pos)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local mode=meta:get_string("mode")
|
||||
|
@ -6,11 +6,11 @@ technic.alloy_recipes = {}
|
||||
|
||||
-- Register recipe in a table
|
||||
technic.register_alloy_recipe = function(metal1, count1, metal2, count2, result, count3)
|
||||
in1 = {
|
||||
local in1 = {
|
||||
name = metal1,
|
||||
count = count1,
|
||||
}
|
||||
in2 = {
|
||||
local in2 = {
|
||||
name = metal2,
|
||||
count = count2,
|
||||
}
|
||||
|
@ -161,14 +161,14 @@ function technic.charge_tools(meta, batt_charge, charge_step)
|
||||
return batt_charge
|
||||
end
|
||||
local srcstack = inv:get_stack("src", 1)
|
||||
local src_meta = get_item_meta(srcstack:get_metadata())
|
||||
local src_meta = minetest.deserialize(srcstack:get_metadata())
|
||||
|
||||
local toolname = srcstack:get_name()
|
||||
if not technic.power_tools[toolname] then
|
||||
return batt_charge
|
||||
end
|
||||
-- Set meta data for the tool if it didn't do it itself
|
||||
src_meta = get_item_meta(srcstack:get_metadata())
|
||||
src_meta = minetest.deserialize(srcstack:get_metadata())
|
||||
src_meta = src_meta or {}
|
||||
if not src_meta.charge then
|
||||
src_meta.charge = 0
|
||||
@ -185,7 +185,7 @@ function technic.charge_tools(meta, batt_charge, charge_step)
|
||||
batt_charge = batt_charge - charge_step
|
||||
technic.set_RE_wear(srcstack, tool_charge, item_max_charge)
|
||||
src_meta.charge = tool_charge
|
||||
srcstack:set_metadata(set_item_meta(src_meta))
|
||||
srcstack:set_metadata(minetest.serialize(src_meta))
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
return batt_charge
|
||||
end
|
||||
@ -202,7 +202,7 @@ function technic.discharge_tools(meta, batt_charge, charge_step, max_charge)
|
||||
return batt_charge
|
||||
end
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
local src_meta = get_item_meta(srcstack:get_metadata())
|
||||
local src_meta = minetest.deserialize(srcstack:get_metadata())
|
||||
src_meta = src_meta or {}
|
||||
if not src_meta.charge then
|
||||
src_meta.charge = 0
|
||||
@ -220,7 +220,7 @@ function technic.discharge_tools(meta, batt_charge, charge_step, max_charge)
|
||||
batt_charge = batt_charge + charge_step
|
||||
technic.set_RE_wear(srcstack, tool_charge, item_max_charge)
|
||||
src_meta.charge = tool_charge
|
||||
srcstack:set_metadata(set_item_meta(src_meta))
|
||||
srcstack:set_metadata(minetest.serialize(src_meta))
|
||||
inv:set_stack("dst", 1, srcstack)
|
||||
return batt_charge
|
||||
end
|
||||
|
@ -3,44 +3,6 @@ local chainsaw_max_charge = 30000 -- 30000 - Maximum charge of the saw
|
||||
local chainsaw_charge_per_node = 12 -- 12 - Gives 2500 nodes on a single charge (about 50 complete normal trees)
|
||||
local chainsaw_leaves = true -- true - Cut down entire trees, leaves and all
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
technic.register_power_tool("technic:chainsaw", chainsaw_max_charge)
|
||||
|
||||
minetest.register_tool("technic:chainsaw", {
|
||||
description = S("Chainsaw"),
|
||||
inventory_image = "technic_chainsaw.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
-- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes.
|
||||
if meta.charge < chainsaw_charge_per_node then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
meta.charge = chainsaw_dig_it(pos, user, meta.charge)
|
||||
technic.set_RE_wear(itemstack, meta.charge, chainsaw_max_charge)
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic:chainsaw',
|
||||
recipe = {
|
||||
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'},
|
||||
{'technic:stainless_steel_ingot', 'technic:motor', 'technic:battery'},
|
||||
{'', '', 'default:copper_ingot'},
|
||||
}
|
||||
})
|
||||
|
||||
-- The default stuff
|
||||
local timber_nodenames={["default:jungletree"] = true,
|
||||
["default:papyrus"] = true,
|
||||
@ -155,55 +117,17 @@ if( minetest.get_modpath("farming_plus") ~= nil ) then
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local S = technic.getter
|
||||
|
||||
technic.register_power_tool("technic:chainsaw", chainsaw_max_charge)
|
||||
|
||||
-- Table for saving what was sawed down
|
||||
local produced
|
||||
|
||||
-- Saw down trees entry point
|
||||
chainsaw_dig_it = function(pos, player,current_charge)
|
||||
local remaining_charge=current_charge
|
||||
|
||||
-- Save the currently installed dropping mechanism so we can restore it.
|
||||
local original_handle_node_drops = minetest.handle_node_drops
|
||||
|
||||
-- A bit of trickery here: use a different node drop callback
|
||||
-- and restore the original afterwards.
|
||||
minetest.handle_node_drops = chainsaw_handle_node_drops
|
||||
|
||||
-- clear result and start sawing things down
|
||||
produced = {}
|
||||
remaining_charge = recursive_dig(pos, remaining_charge, player)
|
||||
minetest.sound_play("chainsaw", {pos = pos, gain = 1.0, max_hear_distance = 10,})
|
||||
|
||||
-- Restore the original noder drop handler
|
||||
minetest.handle_node_drops = original_handle_node_drops
|
||||
|
||||
-- Now drop items for the player
|
||||
local number, produced_item, p
|
||||
for produced_item,number in pairs(produced) do
|
||||
--print("ADDING ITEM: " .. produced_item .. " " .. number)
|
||||
-- Drop stacks of 99 or less
|
||||
p = {
|
||||
x = pos.x + math.random()*4,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random()*4
|
||||
}
|
||||
while number > 99 do
|
||||
minetest.env:add_item(p, produced_item .. " 99")
|
||||
p = {
|
||||
x = pos.x + math.random()*4,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random()*4
|
||||
}
|
||||
number = number - 99
|
||||
end
|
||||
minetest.env:add_item(p, produced_item .. " " .. number)
|
||||
end
|
||||
return remaining_charge
|
||||
end
|
||||
local produced = nil
|
||||
|
||||
-- Override the default handling routine to be able to count up the
|
||||
-- items sawed down so that we can drop them i an nice single stack
|
||||
chainsaw_handle_node_drops = function(pos, drops, digger)
|
||||
local function chainsaw_handle_node_drops(pos, drops, digger)
|
||||
-- Add dropped items to list of collected nodes
|
||||
local _, dropped_item
|
||||
for _, dropped_item in ipairs(drops) do
|
||||
@ -217,7 +141,7 @@ end
|
||||
|
||||
-- This function does all the hard work. Recursively we dig the node at hand
|
||||
-- if it is in the table and then search the surroundings for more stuff to dig.
|
||||
recursive_dig = function(pos, remaining_charge, player)
|
||||
local function recursive_dig(pos, remaining_charge, player)
|
||||
local node=minetest.env:get_node(pos)
|
||||
local i=1
|
||||
-- Lookup node name in timber table:
|
||||
@ -277,3 +201,81 @@ recursive_dig = function(pos, remaining_charge, player)
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
-- Saw down trees entry point
|
||||
local function chainsaw_dig_it(pos, player,current_charge)
|
||||
local remaining_charge=current_charge
|
||||
|
||||
-- Save the currently installed dropping mechanism so we can restore it.
|
||||
local original_handle_node_drops = minetest.handle_node_drops
|
||||
|
||||
-- A bit of trickery here: use a different node drop callback
|
||||
-- and restore the original afterwards.
|
||||
minetest.handle_node_drops = chainsaw_handle_node_drops
|
||||
|
||||
-- clear result and start sawing things down
|
||||
produced = {}
|
||||
remaining_charge = recursive_dig(pos, remaining_charge, player)
|
||||
minetest.sound_play("chainsaw", {pos = pos, gain = 1.0, max_hear_distance = 10,})
|
||||
|
||||
-- Restore the original noder drop handler
|
||||
minetest.handle_node_drops = original_handle_node_drops
|
||||
|
||||
-- Now drop items for the player
|
||||
local number, produced_item, p
|
||||
for produced_item,number in pairs(produced) do
|
||||
--print("ADDING ITEM: " .. produced_item .. " " .. number)
|
||||
-- Drop stacks of 99 or less
|
||||
p = {
|
||||
x = pos.x + math.random()*4,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random()*4
|
||||
}
|
||||
while number > 99 do
|
||||
minetest.env:add_item(p, produced_item .. " 99")
|
||||
p = {
|
||||
x = pos.x + math.random()*4,
|
||||
y = pos.y,
|
||||
z = pos.z + math.random()*4
|
||||
}
|
||||
number = number - 99
|
||||
end
|
||||
minetest.env:add_item(p, produced_item .. " " .. number)
|
||||
end
|
||||
return remaining_charge
|
||||
end
|
||||
|
||||
|
||||
minetest.register_tool("technic:chainsaw", {
|
||||
description = S("Chainsaw"),
|
||||
inventory_image = "technic_chainsaw.png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
-- Send current charge to digging function so that the chainsaw will stop after digging a number of nodes.
|
||||
if meta.charge < chainsaw_charge_per_node then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
meta.charge = chainsaw_dig_it(pos, user, meta.charge)
|
||||
technic.set_RE_wear(itemstack, meta.charge, chainsaw_max_charge)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic:chainsaw',
|
||||
recipe = {
|
||||
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:battery'},
|
||||
{'technic:stainless_steel_ingot', 'technic:motor', 'technic:battery'},
|
||||
{'', '', 'default:copper_ingot'},
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -151,14 +151,14 @@ function check_for_flashlight(player)
|
||||
local hotbar = inv:get_list("main")
|
||||
for i = 1, 8 do
|
||||
if hotbar[i]:get_name() == "technic:flashlight" then
|
||||
local meta = get_item_meta(hotbar[i]:get_metadata())
|
||||
local meta = minetest.deserialize(hotbar[i]:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return false
|
||||
end
|
||||
if meta.charge - 2 > 0 then
|
||||
meta.charge = meta.charge - 2;
|
||||
technic.set_RE_wear(hotbar[i], meta.charge, flashlight_max_charge)
|
||||
hotbar[i]:set_metadata(set_item_meta(meta))
|
||||
hotbar[i]:set_metadata(minetest.serialize(meta))
|
||||
inv:set_stack("main", i, hotbar[i])
|
||||
return true
|
||||
end
|
||||
|
@ -42,7 +42,102 @@ for i = 1, 4 do
|
||||
})
|
||||
end
|
||||
|
||||
function drill_dig_it(pos, player, drill_type, mode)
|
||||
local mining_drill_mode_text = {
|
||||
{S("Single node.")},
|
||||
{S("3 nodes deep.")},
|
||||
{S("3 nodes wide.")},
|
||||
{S("3 nodes tall.")},
|
||||
{S("3x3 nodes.")},
|
||||
}
|
||||
|
||||
local function drill_dig_it0 (pos,player)
|
||||
local node=minetest.env:get_node(pos)
|
||||
if node.name == "air" or node.name == "ignore" then return end
|
||||
if node.name == "default:lava_source" then return end
|
||||
if node.name == "default:lava_flowing" then return end
|
||||
if node.name == "default:water_source" then minetest.env:remove_node(pos) return end
|
||||
if node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
|
||||
minetest.node_dig(pos,node,player)
|
||||
end
|
||||
|
||||
local function drill_dig_it1 (player)
|
||||
local dir=player:get_look_dir()
|
||||
if math.abs(dir.x)>math.abs(dir.z) then
|
||||
if dir.x>0 then return 0 end
|
||||
return 1
|
||||
end
|
||||
if dir.z>0 then return 2 end
|
||||
return 3
|
||||
end
|
||||
|
||||
local function drill_dig_it2 (pos,player)
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
pos.y=pos.y+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
pos.y=pos.y-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
end
|
||||
|
||||
local function drill_dig_it3 (pos,player)
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.y=pos.y+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.y=pos.y-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
end
|
||||
|
||||
local function drill_dig_it4 (pos,player)
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
end
|
||||
|
||||
|
||||
local function drill_dig_it(pos, player, drill_type, mode)
|
||||
local charge
|
||||
if mode == 1 then
|
||||
drill_dig_it0(pos, player)
|
||||
@ -100,9 +195,9 @@ function drill_dig_it(pos, player, drill_type, mode)
|
||||
|
||||
if mode==4 then -- 3 tall, selected in the middle
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.y=pos.y+1
|
||||
pos.y=pos.y-1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.y=pos.y-2
|
||||
pos.y=pos.y-1
|
||||
drill_dig_it0 (pos,player)
|
||||
end
|
||||
|
||||
@ -135,92 +230,99 @@ function drill_dig_it(pos, player, drill_type, mode)
|
||||
return charge
|
||||
end
|
||||
|
||||
function drill_dig_it0 (pos,player)
|
||||
local node=minetest.env:get_node(pos)
|
||||
if node.name == "air" or node.name == "ignore" then return end
|
||||
if node.name == "default:lava_source" then return end
|
||||
if node.name == "default:lava_flowing" then return end
|
||||
if node.name == "default:water_source" then minetest.env:remove_node(pos) return end
|
||||
if node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end
|
||||
minetest.node_dig(pos,node,player)
|
||||
end
|
||||
|
||||
function drill_dig_it1 (player)
|
||||
local dir=player:get_look_dir()
|
||||
if math.abs(dir.x)>math.abs(dir.z) then
|
||||
if dir.x>0 then return 0 end
|
||||
return 1
|
||||
local function mining_drill_mk2_setmode(user,itemstack)
|
||||
local player_name=user:get_player_name()
|
||||
local item=itemstack:to_table()
|
||||
local meta=minetest.deserialize(item["metadata"])
|
||||
if meta==nil then
|
||||
meta={}
|
||||
mode=0
|
||||
end
|
||||
if dir.z>0 then return 2 end
|
||||
return 3
|
||||
if meta["mode"]==nil then
|
||||
minetest.chat_send_player(player_name, S("Hold shift and use to change Mining Drill Mk%d modes."):format(2))
|
||||
meta["mode"]=0
|
||||
mode=0
|
||||
end
|
||||
mode=(meta["mode"])
|
||||
mode=mode+1
|
||||
if mode>=5 then mode=1 end
|
||||
minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(2, mode)..": "..mining_drill_mode_text[mode][1])
|
||||
item["name"]="technic:mining_drill_mk2_"..mode
|
||||
meta["mode"]=mode
|
||||
item["metadata"]=minetest.serialize(meta)
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function drill_dig_it2 (pos,player)
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
pos.y=pos.y+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
pos.y=pos.y-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
end
|
||||
function drill_dig_it3 (pos,player)
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.y=pos.y+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.y=pos.y-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
local function mining_drill_mk3_setmode(user,itemstack)
|
||||
local player_name=user:get_player_name()
|
||||
local item=itemstack:to_table()
|
||||
local meta=minetest.deserialize(item["metadata"])
|
||||
if meta==nil then
|
||||
meta={}
|
||||
mode=0
|
||||
end
|
||||
if meta["mode"]==nil then
|
||||
minetest.chat_send_player(player_name, S("Hold shift and use to change Mining Drill Mk%d modes."):format(3))
|
||||
meta["mode"]=0
|
||||
mode=0
|
||||
end
|
||||
mode=(meta["mode"])
|
||||
mode=mode+1
|
||||
if mode>=6 then mode=1 end
|
||||
minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(3, mode)..": "..mining_drill_mode_text[mode][1])
|
||||
item["name"]="technic:mining_drill_mk3_"..mode
|
||||
meta["mode"]=mode
|
||||
item["metadata"]=minetest.serialize(meta)
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function drill_dig_it4 (pos,player)
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.z=pos.z+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
pos.z=pos.z-2
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x+1
|
||||
drill_dig_it0 (pos,player)
|
||||
pos.x=pos.x-2
|
||||
drill_dig_it0 (pos,player)
|
||||
|
||||
local function mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
||||
local keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.mode or keys.sneak then
|
||||
return mining_drill_mk2_setmode(user, itemstack)
|
||||
end
|
||||
if pointed_thing.type ~= "node" or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - mining_drill_power_usage > 0 then
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local charge_to_take = drill_dig_it(pos, user, 2, meta.mode)
|
||||
meta.charge = meta.charge - charge_to_take
|
||||
meta.charge = math.max(meta.charge, 0)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk2_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local function mining_drill_mk3_handler(itemstack, user, pointed_thing)
|
||||
local keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.mode or keys.sneak then
|
||||
return mining_drill_mk3_setmode(user, itemstack)
|
||||
end
|
||||
if pointed_thing.type ~= "node" or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - mining_drill_power_usage > 0 then
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local charge_to_take = drill_dig_it(pos, user, 3, meta.mode)
|
||||
meta.charge = meta.charge - charge_to_take
|
||||
meta.charge = math.max(meta.charge, 0)
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk3_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
technic.register_power_tool("technic:mining_drill", mining_drill_max_charge)
|
||||
|
||||
minetest.register_tool("technic:mining_drill", {
|
||||
description = S("Mining Drill Mk%d"):format(1),
|
||||
inventory_image = "technic_mining_drill.png",
|
||||
@ -229,7 +331,7 @@ minetest.register_tool("technic:mining_drill", {
|
||||
if pointed_thing.type ~= "node" then
|
||||
return itemstack
|
||||
end
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
@ -237,7 +339,7 @@ minetest.register_tool("technic:mining_drill", {
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
charge_to_take = drill_dig_it(pos, user, 1, 1)
|
||||
meta.charge = meta.charge - mining_drill_power_usage
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
@ -293,102 +395,3 @@ for i=1,5,1 do
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
function mining_drill_mk2_handler(itemstack, user, pointed_thing)
|
||||
local keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.mode or keys.sneak then
|
||||
return mining_drill_mk2_setmode(user, itemstack)
|
||||
end
|
||||
if pointed_thing.type ~= "node" or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - mining_drill_power_usage > 0 then
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local charge_to_take = drill_dig_it(pos, user, 2, meta.mode)
|
||||
meta.charge = meta.charge - charge_to_take
|
||||
meta.charge = math.max(meta.charge, 0)
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk2_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function mining_drill_mk3_handler(itemstack, user, pointed_thing)
|
||||
local keys = user:get_player_control()
|
||||
local player_name = user:get_player_name()
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
if not meta or not meta.mode or keys.sneak then
|
||||
return mining_drill_mk3_setmode(user, itemstack)
|
||||
end
|
||||
if pointed_thing.type ~= "node" or not meta.charge then
|
||||
return
|
||||
end
|
||||
if meta.charge - mining_drill_power_usage > 0 then
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, above)
|
||||
local charge_to_take = drill_dig_it(pos, user, 3, meta.mode)
|
||||
meta.charge = meta.charge - charge_to_take
|
||||
meta.charge = math.max(meta.charge, 0)
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk3_max_charge)
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
mining_drill_mode_text = {
|
||||
{S("Single node.")},
|
||||
{S("3 nodes deep.")},
|
||||
{S("3 nodes wide.")},
|
||||
{S("3 nodes tall.")},
|
||||
{S("3x3 nodes.")},
|
||||
}
|
||||
|
||||
function mining_drill_mk2_setmode(user,itemstack)
|
||||
local player_name=user:get_player_name()
|
||||
local item=itemstack:to_table()
|
||||
local meta=get_item_meta(item["metadata"])
|
||||
if meta==nil then
|
||||
meta={}
|
||||
mode=0
|
||||
end
|
||||
if meta["mode"]==nil then
|
||||
minetest.chat_send_player(player_name, S("Hold shift and use to change Mining Drill Mk%d modes."):format(2))
|
||||
meta["mode"]=0
|
||||
mode=0
|
||||
end
|
||||
mode=(meta["mode"])
|
||||
mode=mode+1
|
||||
if mode>=5 then mode=1 end
|
||||
minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(2, mode)..": "..mining_drill_mode_text[mode][1])
|
||||
item["name"]="technic:mining_drill_mk2_"..mode
|
||||
meta["mode"]=mode
|
||||
item["metadata"]=set_item_meta(meta)
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function mining_drill_mk3_setmode(user,itemstack)
|
||||
local player_name=user:get_player_name()
|
||||
local item=itemstack:to_table()
|
||||
local meta=get_item_meta(item["metadata"])
|
||||
if meta==nil then
|
||||
meta={}
|
||||
mode=0
|
||||
end
|
||||
if meta["mode"]==nil then
|
||||
minetest.chat_send_player(player_name, S("Hold shift and use to change Mining Drill Mk%d modes."):format(3))
|
||||
meta["mode"]=0
|
||||
mode=0
|
||||
end
|
||||
mode=(meta["mode"])
|
||||
mode=mode+1
|
||||
if mode>=6 then mode=1 end
|
||||
minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(3, mode)..": "..mining_drill_mode_text[mode][1])
|
||||
item["name"]="technic:mining_drill_mk3_"..mode
|
||||
meta["mode"]=mode
|
||||
item["metadata"]=set_item_meta(meta)
|
||||
itemstack:replace(item)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
|
@ -150,7 +150,7 @@ for _, m in pairs(mining_lasers_list) do
|
||||
inventory_image = "technic_mining_laser_mk"..m[1]..".png",
|
||||
stack_max = 1,
|
||||
on_use = function(itemstack, user)
|
||||
local meta = get_item_meta(itemstack:get_metadata())
|
||||
local meta = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta or not meta.charge then
|
||||
return
|
||||
end
|
||||
@ -158,7 +158,7 @@ for _, m in pairs(mining_lasers_list) do
|
||||
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
|
||||
meta.charge = meta.charge - 400
|
||||
technic.set_RE_wear(itemstack, meta.charge, m[3])
|
||||
itemstack:set_metadata(set_item_meta(meta))
|
||||
itemstack:set_metadata(minetest.serialize(meta))
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
|
@ -22,7 +22,7 @@ minetest.register_tool("technic:sonic_screwdriver", {
|
||||
if node.param2 == nil then
|
||||
return
|
||||
end
|
||||
local meta1 = get_item_meta(itemstack:get_metadata())
|
||||
local meta1 = minetest.deserialize(itemstack:get_metadata())
|
||||
if not meta1 or not meta1.charge then
|
||||
return
|
||||
end
|
||||
@ -48,7 +48,7 @@ minetest.register_tool("technic:sonic_screwdriver", {
|
||||
minetest.swap_node(pos, node)
|
||||
|
||||
meta1.charge = meta1.charge - 100
|
||||
itemstack:set_metadata(set_item_meta(meta1))
|
||||
itemstack:set_metadata(minetest.serialize(meta1))
|
||||
technic.set_RE_wear(itemstack, meta1.charge, sonic_screwdriver_max_charge)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user