Fix bug issues
This commit is contained in:
parent
f11df56799
commit
e90d1e2a57
@ -1,4 +1,2 @@
|
|||||||
default
|
default
|
||||||
inventory_plus
|
|
||||||
farming
|
farming
|
||||||
moreores
|
|
@ -1,12 +1,13 @@
|
|||||||
--Handle node drops to be compatible with the Technic node drops
|
--Handle node drops to be compatible with the Technic node drops
|
||||||
local technic = minetest.get_modpath("technic")
|
local itemDrop = minetest.get_modpath("item_drop")
|
||||||
local code = "local tool = digger:get_wielded_item():get_name()\n"..
|
|
||||||
|
if(itemDrop ~= "" and itemDrop ~= nil) then
|
||||||
|
local code = "local tool = digger:get_wielded_item():get_name()\n"..
|
||||||
"if(tool:find('superheat') ~= nil)then\n"..
|
"if(tool:find('superheat') ~= nil)then\n"..
|
||||||
"output = minetest.get_craft_result({method='cooking', items={name}})\n"..
|
"output = minetest.get_craft_result({method='cooking', items={name}})\n"..
|
||||||
"if(output.item ~= nil)then name = output.item:get_name()end\n"..
|
"if(output.item ~= nil)then name = output.item:get_name()end\n"..
|
||||||
"end\n"
|
"end\n"
|
||||||
if(technic ~= "" and technic ~= nil) then
|
local readfile = io.open(itemDrop.."/init.lua", "r")
|
||||||
local readfile = io.open(technic.."/item_drop.lua", "r")
|
|
||||||
local newfile = ""
|
local newfile = ""
|
||||||
local numlines = 9
|
local numlines = 9
|
||||||
for line in readfile:lines() do
|
for line in readfile:lines() do
|
||||||
@ -82,36 +83,52 @@ function minetest.handle_node_drops(pos, drops, digger)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_soil(pos, inv, p)
|
local function create_soil(user, pointed_thing)
|
||||||
if pos == nil then
|
local pt = pointed_thing
|
||||||
|
-- check if pointing at a node
|
||||||
|
if not pt then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
local node = minetest.env:get_node(pos)
|
if pt.type ~= "node" then
|
||||||
local name = node.name
|
return false
|
||||||
local above = minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z})
|
|
||||||
if name == "default:dirt" or name == "default:dirt_with_grass" then
|
|
||||||
if above.name == "air" then
|
|
||||||
node.name = "farming:soil"
|
|
||||||
minetest.env:set_node(pos, node)
|
|
||||||
if inv and p and name == "default:dirt_with_grass" then
|
|
||||||
for name,rarity in pairs(farming.seeds) do
|
|
||||||
if math.random(1, rarity-p) == 1 then
|
|
||||||
inv:add_item("main", ItemStack(name))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local under = minetest.get_node(pt.under)
|
||||||
|
local p = {x=pt.under.x, y=pt.under.y+1, z=pt.under.z}
|
||||||
|
local above = minetest.get_node(p)
|
||||||
|
|
||||||
|
-- return if any of the nodes is not registered
|
||||||
|
if not minetest.registered_nodes[under.name] then
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
if not minetest.registered_nodes[above.name] then
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- check if the node above the pointed thing is air
|
||||||
|
if above.name ~= "air" then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check if pointing at dirt
|
||||||
|
if minetest.get_item_group(under.name, "soil") ~= 1 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- turn the node into soil, wear out item and play sound
|
||||||
|
minetest.set_node(pt.under, {name="farming:soil"})
|
||||||
|
minetest.sound_play("default_dig_crumbly", {
|
||||||
|
pos = pt.under,
|
||||||
|
gain = 0.5,
|
||||||
|
})
|
||||||
return true
|
return true
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function nodeIsValid(node)
|
local function nodeIsPlant(node)
|
||||||
local nums = {"1","2","3","4","5","6","7","8","9"}
|
|
||||||
local lastChar = node.name:sub(#node.name)
|
local lastChar = node.name:sub(#node.name)
|
||||||
local isNum = false
|
local isNum = false
|
||||||
for _,num in pairs(nums) do
|
for num=1,9,1 do
|
||||||
if(lastChar == num) then isNum = true end
|
if(lastChar == tostring(num)) then isNum = true end
|
||||||
end
|
end
|
||||||
return (node.name:find("farming") ~= nil) and (node.name:find("soil") == nil) and (not isNum)
|
return (node.name:find("farming") ~= nil) and (node.name:find("soil") == nil) and (not isNum)
|
||||||
end
|
end
|
||||||
@ -128,10 +145,11 @@ for name, def in pairs(minetest.registered_tools) do
|
|||||||
local newdef = def
|
local newdef = def
|
||||||
newdef.description = def.description.." "..special.description
|
newdef.description = def.description.." "..special.description
|
||||||
newdef.inventory_image = def.inventory_image.."^specialties_"..special.name..".png"
|
newdef.inventory_image = def.inventory_image.."^specialties_"..special.name..".png"
|
||||||
|
newdef.wield_image = def.inventory_image.."^specialties_"..special.name..".png"
|
||||||
if(name:find(":hoe") ~= nil) then
|
if(name:find(":hoe") ~= nil) then
|
||||||
newdef.on_use = function(itemstack, user, pointed_thing)
|
newdef.on_use = function(itemstack, user, pointed_thing)
|
||||||
if(pointed_thing.type == "nothing" or pointed_thing.type == "object") then return itemstack end
|
if pointed_thing.type == "nothing" or pointed_thing.type == "object" or pointed_thing.above == nil then return itemstack end
|
||||||
if create_soil(pointed_thing.under, user:get_inventory(), 0) then
|
if create_soil(user, pointed_thing) then
|
||||||
itemstack:add_wear(65535/specialties.hoewear[name:sub(name:find("_")+1)])
|
itemstack:add_wear(65535/specialties.hoewear[name:sub(name:find("_")+1)])
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
@ -141,7 +159,7 @@ for name, def in pairs(minetest.registered_tools) do
|
|||||||
pos.z = (pointed_thing.above.z+pointed_thing.under.z)/2
|
pos.z = (pointed_thing.above.z+pointed_thing.under.z)/2
|
||||||
pos.y = pos.y-.5
|
pos.y = pos.y-.5
|
||||||
local node = minetest.env:get_node(pos)
|
local node = minetest.env:get_node(pos)
|
||||||
if(nodeIsValid(node)) then
|
if(nodeIsPlant(node)) then
|
||||||
minetest.env:dig_node(pos)
|
minetest.env:dig_node(pos)
|
||||||
if(not enable_item_drop) then
|
if(not enable_item_drop) then
|
||||||
minetest.handle_node_drops(user:getpos(), minetest.get_node_drops(node.name, toolname), user)
|
minetest.handle_node_drops(user:getpos(), minetest.get_node_drops(node.name, toolname), user)
|
||||||
|
46
init.lua
46
init.lua
@ -10,7 +10,7 @@ time = 0
|
|||||||
|
|
||||||
local get_specialInfo = function(player, specialty)
|
local get_specialInfo = function(player, specialty)
|
||||||
local formspec = "size[8,8]" -- size of the formspec page
|
local formspec = "size[8,8]" -- size of the formspec page
|
||||||
.."button[0,0;2,0.5;main;Back]" -- back to main inventory
|
.."button_exit[0,0;0.75,0.5;close;X]" -- back to main inventory
|
||||||
.."button[2,0;2,0.5;miner;Miner]"
|
.."button[2,0;2,0.5;miner;Miner]"
|
||||||
.."button[2,.75;2,0.5;lumberjack;Lumberjack]"
|
.."button[2,.75;2,0.5;lumberjack;Lumberjack]"
|
||||||
.."button[2,1.5;2,0.5;digger;Digger]"
|
.."button[2,1.5;2,0.5;digger;Digger]"
|
||||||
@ -36,8 +36,13 @@ end)
|
|||||||
|
|
||||||
--Initial XP Extraction
|
--Initial XP Extraction
|
||||||
--optimizes the amount of calls to files
|
--optimizes the amount of calls to files
|
||||||
|
minetest.register_chatcommand("spec", {
|
||||||
|
description = "Show Specialties menu",
|
||||||
|
func = function(name, param)
|
||||||
|
minetest.show_formspec(name, "specialties:spec", get_specialInfo(minetest.get_player_by_name(name), ""))
|
||||||
|
end,
|
||||||
|
})
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
inventory_plus.register_button(player,"specialties","Specialties")
|
|
||||||
player:get_inventory():set_size("pick", 1)
|
player:get_inventory():set_size("pick", 1)
|
||||||
player:get_inventory():set_size("axe", 1)
|
player:get_inventory():set_size("axe", 1)
|
||||||
player:get_inventory():set_size("shovel", 1)
|
player:get_inventory():set_size("shovel", 1)
|
||||||
@ -50,32 +55,38 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
specialties.players[name][skill] = specialties.readXP(name, skill)
|
specialties.players[name][skill] = specialties.readXP(name, skill)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
local function show_formspec(player, specialty)
|
||||||
|
minetest.show_formspec(player, "specialties:spec", get_specialInfo(minetest.get_player_by_name(player), specialty))
|
||||||
|
end
|
||||||
|
|
||||||
--Skill Events
|
--Skill Events
|
||||||
local function healTool(player, list, specialty, cost)
|
local function healTool(player, list, specialty, cost)
|
||||||
tool = player:get_inventory():get_list(list)[1]
|
tool = player:get_inventory():get_list(list)[1]
|
||||||
if (tool:get_name():find(":"..list) ~= nil and tool:get_wear() ~= 0 and specialties.healAmount[tool:get_name()] ~= nil)then
|
if tool:get_name():find(":"..list) == nil then return end
|
||||||
if (specialties.changeXP(player:get_player_name(), specialty, -cost)) then
|
if tool:get_wear() ~= 0 and specialties.healAmount[tool:get_name()] ~= nil then
|
||||||
|
if specialties.changeXP(player:get_player_name(), specialty, -cost) then
|
||||||
tool:add_wear(-specialties.healAmount[tool:get_name()])
|
tool:add_wear(-specialties.healAmount[tool:get_name()])
|
||||||
player:get_inventory():set_stack(list, 1, tool)
|
player:get_inventory():set_stack(list, 1, tool)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, specialty))
|
show_formspec(player:get_player_name(), specialty)
|
||||||
end
|
end
|
||||||
local function upgradeTool(player, list, specialty, cost)
|
local function upgradeTool(player, list, specialty, cost)
|
||||||
tool = player:get_inventory():get_list(list)[1]
|
tool = player:get_inventory():get_list(list)[1]
|
||||||
if(tool:get_name():find(":"..list) ~= nil and specialties.upgradeTree[tool:get_name()] ~= nil) then
|
if tool:get_name():find(":"..list) == nil then return end
|
||||||
if (specialties.changeXP(player:get_player_name(), specialty, -cost)) then
|
if specialties.upgradeTree[tool:get_name()] ~= nil then
|
||||||
|
if specialties.changeXP(player:get_player_name(), specialty, -cost) then
|
||||||
player:get_inventory():set_stack(list, 1, specialties.upgradeTree[tool:get_name()])
|
player:get_inventory():set_stack(list, 1, specialties.upgradeTree[tool:get_name()])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, specialty))
|
show_formspec(player:get_player_name(), specialty)
|
||||||
end
|
end
|
||||||
local function addSpecial2Tool(player, skill, list, specialty, cost)
|
local function addSpecial2Tool(player, skill, list, specialty, cost)
|
||||||
local tool = player:get_inventory():get_list(list)[1]
|
local tool = player:get_inventory():get_list(list)[1]
|
||||||
local toolname = tool:get_name()
|
local toolname = tool:get_name()
|
||||||
if(toolname:find("_"..skill) ~= nil) then return end
|
if toolname:find(":"..list) == nil then return end
|
||||||
if (specialties.changeXP(player:get_player_name(), specialty, -cost)) then
|
if toolname:find("_"..skill) ~= nil then return end
|
||||||
|
if specialties.changeXP(player:get_player_name(), specialty, -cost) then
|
||||||
local def = tool:get_definition()
|
local def = tool:get_definition()
|
||||||
local colonpos = toolname:find(":")
|
local colonpos = toolname:find(":")
|
||||||
local modname = toolname:sub(0,colonpos-1)
|
local modname = toolname:sub(0,colonpos-1)
|
||||||
@ -83,7 +94,7 @@ local function addSpecial2Tool(player, skill, list, specialty, cost)
|
|||||||
local name = toolname.."_"..skill
|
local name = toolname.."_"..skill
|
||||||
player:get_inventory():set_stack(list, 1, name)
|
player:get_inventory():set_stack(list, 1, name)
|
||||||
end
|
end
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, specialty))
|
show_formspec(player:get_player_name(), specialty)
|
||||||
end
|
end
|
||||||
local function doTransfer(player, list, factor)
|
local function doTransfer(player, list, factor)
|
||||||
|
|
||||||
@ -92,13 +103,13 @@ end
|
|||||||
--GUI Events
|
--GUI Events
|
||||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||||
if fields.specialties then
|
if fields.specialties then
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, ""))
|
show_formspec(player:get_player_name(), "")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--MINER
|
--MINER
|
||||||
if fields.miner then
|
if fields.miner then
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "miner"))
|
show_formspec(player:get_player_name(), "miner")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if fields.healpick then healTool(player, "pick", "miner", 100) end
|
if fields.healpick then healTool(player, "pick", "miner", 100) end
|
||||||
@ -107,7 +118,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
|
|
||||||
--LUMBERJACK
|
--LUMBERJACK
|
||||||
if fields.lumberjack then
|
if fields.lumberjack then
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "lumberjack"))
|
show_formspec(player:get_player_name(), "lumberjack")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if fields.healaxe then healTool(player, "axe", "lumberjack", 100) end
|
if fields.healaxe then healTool(player, "axe", "lumberjack", 100) end
|
||||||
@ -116,7 +127,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
|
|
||||||
--DIGGER
|
--DIGGER
|
||||||
if fields.digger then
|
if fields.digger then
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "digger"))
|
show_formspec(player:get_player_name(), "digger")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if fields.healshovel then healTool(player, "shovel", "digger", 100) end
|
if fields.healshovel then healTool(player, "shovel", "digger", 100) end
|
||||||
@ -125,7 +136,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
|
|
||||||
--FARMER
|
--FARMER
|
||||||
if fields.farmer then
|
if fields.farmer then
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "farmer"))
|
show_formspec(player:get_player_name(), "farmer")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if fields.healhoe then healTool(player, "hoe", "farmer", 100) end
|
if fields.healhoe then healTool(player, "hoe", "farmer", 100) end
|
||||||
@ -134,7 +145,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
|
|
||||||
--BUILDER
|
--BUILDER
|
||||||
if fields.builder then
|
if fields.builder then
|
||||||
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "builder"))
|
show_formspec(player:get_player_name(), "builder")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if fields.dorefill then doTransfer(player, "refill", 1) end
|
if fields.dorefill then doTransfer(player, "refill", 1) end
|
||||||
@ -142,6 +153,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--XP Events
|
--XP Events
|
||||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||||
if(digger == nil) then
|
if(digger == nil) then
|
||||||
|
Loading…
Reference in New Issue
Block a user