Fix bug issues

This commit is contained in:
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,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)