Fix bug issues

master
Austin Shenk 2013-06-29 16:46:10 -04:00
parent f11df56799
commit e90d1e2a57
3 changed files with 78 additions and 50 deletions

View File

@ -1,4 +1,2 @@
default
inventory_plus
farming
moreores
farming

View File

@ -1,12 +1,13 @@
--Handle node drops to be compatible with the Technic node drops
local technic = minetest.get_modpath("technic")
local code = "local tool = digger:get_wielded_item():get_name()\n"..
local itemDrop = minetest.get_modpath("item_drop")
if(itemDrop ~= "" and itemDrop ~= nil) then
local code = "local tool = digger:get_wielded_item():get_name()\n"..
"if(tool:find('superheat') ~= nil)then\n"..
"output = minetest.get_craft_result({method='cooking', items={name}})\n"..
"if(output.item ~= nil)then name = output.item:get_name()end\n"..
"end\n"
if(technic ~= "" and technic ~= nil) then
local readfile = io.open(technic.."/item_drop.lua", "r")
local readfile = io.open(itemDrop.."/init.lua", "r")
local newfile = ""
local numlines = 9
for line in readfile:lines() do
@ -82,36 +83,52 @@ function minetest.handle_node_drops(pos, drops, digger)
end
end
local function create_soil(pos, inv, p)
if pos == nil then
local function create_soil(user, pointed_thing)
local pt = pointed_thing
-- check if pointing at a node
if not pt then
return false
end
local node = minetest.env:get_node(pos)
local name = node.name
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
end
return true
end
if pt.type ~= "node" then
return false
end
return false
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
if not minetest.registered_nodes[above.name] then
return false
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
end
local function nodeIsValid(node)
local nums = {"1","2","3","4","5","6","7","8","9"}
local function nodeIsPlant(node)
local lastChar = node.name:sub(#node.name)
local isNum = false
for _,num in pairs(nums) do
if(lastChar == num) then isNum = true end
for num=1,9,1 do
if(lastChar == tostring(num)) then isNum = true end
end
return (node.name:find("farming") ~= nil) and (node.name:find("soil") == nil) and (not isNum)
end
@ -128,10 +145,11 @@ for name, def in pairs(minetest.registered_tools) do
local newdef = def
newdef.description = def.description.." "..special.description
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
newdef.on_use = function(itemstack, user, pointed_thing)
if(pointed_thing.type == "nothing" or pointed_thing.type == "object") then return itemstack end
if create_soil(pointed_thing.under, user:get_inventory(), 0) then
if pointed_thing.type == "nothing" or pointed_thing.type == "object" or pointed_thing.above == nil then return itemstack end
if create_soil(user, pointed_thing) then
itemstack:add_wear(65535/specialties.hoewear[name:sub(name:find("_")+1)])
return itemstack
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.y = pos.y-.5
local node = minetest.env:get_node(pos)
if(nodeIsValid(node)) then
if(nodeIsPlant(node)) then
minetest.env:dig_node(pos)
if(not enable_item_drop) then
minetest.handle_node_drops(user:getpos(), minetest.get_node_drops(node.name, toolname), user)

View File

@ -10,7 +10,7 @@ time = 0
local get_specialInfo = function(player, specialty)
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,.75;2,0.5;lumberjack;Lumberjack]"
.."button[2,1.5;2,0.5;digger;Digger]"
@ -36,8 +36,13 @@ end)
--Initial XP Extraction
--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)
inventory_plus.register_button(player,"specialties","Specialties")
player:get_inventory():set_size("pick", 1)
player:get_inventory():set_size("axe", 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)
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
local function healTool(player, list, specialty, cost)
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 (specialties.changeXP(player:get_player_name(), specialty, -cost)) then
if tool:get_name():find(":"..list) == nil then return end
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()])
player:get_inventory():set_stack(list, 1, tool)
end
end
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, specialty))
show_formspec(player:get_player_name(), specialty)
end
local function upgradeTool(player, list, specialty, cost)
tool = player:get_inventory():get_list(list)[1]
if(tool:get_name():find(":"..list) ~= nil and specialties.upgradeTree[tool:get_name()] ~= nil) then
if (specialties.changeXP(player:get_player_name(), specialty, -cost)) then
if tool:get_name():find(":"..list) == nil then return end
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()])
end
end
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, specialty))
show_formspec(player:get_player_name(), specialty)
end
local function addSpecial2Tool(player, skill, list, specialty, cost)
local tool = player:get_inventory():get_list(list)[1]
local toolname = tool:get_name()
if(toolname:find("_"..skill) ~= nil) then return end
if (specialties.changeXP(player:get_player_name(), specialty, -cost)) then
if toolname:find(":"..list) == nil then return end
if toolname:find("_"..skill) ~= nil then return end
if specialties.changeXP(player:get_player_name(), specialty, -cost) then
local def = tool:get_definition()
local colonpos = toolname:find(":")
local modname = toolname:sub(0,colonpos-1)
@ -83,7 +94,7 @@ local function addSpecial2Tool(player, skill, list, specialty, cost)
local name = toolname.."_"..skill
player:get_inventory():set_stack(list, 1, name)
end
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, specialty))
show_formspec(player:get_player_name(), specialty)
end
local function doTransfer(player, list, factor)
@ -92,13 +103,13 @@ end
--GUI Events
minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.specialties then
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, ""))
show_formspec(player:get_player_name(), "")
return
end
--MINER
if fields.miner then
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "miner"))
show_formspec(player:get_player_name(), "miner")
return
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
if fields.lumberjack then
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "lumberjack"))
show_formspec(player:get_player_name(), "lumberjack")
return
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
if fields.digger then
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "digger"))
show_formspec(player:get_player_name(), "digger")
return
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
if fields.farmer then
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "farmer"))
show_formspec(player:get_player_name(), "farmer")
return
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
if fields.builder then
inventory_plus.set_inventory_formspec(player, get_specialInfo(player, "builder"))
show_formspec(player:get_player_name(), "builder")
return
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)
--XP Events
minetest.register_on_dignode(function(pos, oldnode, digger)
if(digger == nil) then