1
0
Fork 0

Refactor sponge code

This commit is contained in:
Wuzzy 2017-03-03 00:19:13 +01:00
parent 7f5629fc2a
commit 6620ee91ae
1 changed files with 27 additions and 33 deletions

View File

@ -11,7 +11,7 @@ minetest.register_node("mcl_sponges:sponge", {
stack_max = 64, stack_max = 64,
sounds = mcl_sounds.node_sound_dirt_defaults(), sounds = mcl_sounds.node_sound_dirt_defaults(),
groups = {handy=1, building_block=1}, groups = {handy=1, building_block=1},
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local pn = placer:get_player_name() local pn = placer:get_player_name()
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return itemstack return itemstack
@ -28,63 +28,57 @@ minetest.register_node("mcl_sponges:sponge", {
if minetest.is_protected(pointed_thing.above, pn) then if minetest.is_protected(pointed_thing.above, pn) then
return itemstack return itemstack
end end
local change = false local change = false
local on_water = false local on_water = false
local pos = pointed_thing.above local pos = pointed_thing.above
-- verifier si il est dans l'eau ou a cotée local nn = minetest.get_node(pointed_thing.above).name
if string.find(minetest.get_node(pointed_thing.above).name, "water_source") if minetest.get_item_group(nn, "water") ~= 0 then
or string.find(minetest.get_node(pointed_thing.above).name, "water_flowing") then
on_water = true on_water = true
end end
for i=-1,1 do for i=-1,1 do
local p = {x=pos.x+i, y=pos.y, z=pos.z} local p = {x=pos.x+i, y=pos.y, z=pos.z}
local n = minetest.get_node(p) local n = minetest.get_node(p)
-- On verifie si il y a de l'eau if minetest.get_item_group(n.name, "water") ~= 0 then
if (n.name=="mcl_core:water_flowing") or (n.name == "mcl_core:water_source") then
on_water = true on_water = true
end end
end end
for i=-1,1 do for i=-1,1 do
local p = {x=pos.x, y=pos.y+i, z=pos.z} local p = {x=pos.x, y=pos.y+i, z=pos.z}
local n = minetest.get_node(p) local n = minetest.get_node(p)
-- On verifie si il y a de l'eau if minetest.get_item_group(n.name, "water") ~= 0 then
if (n.name=="mcl_core:water_flowing") or (n.name == "mcl_core:water_source") then
on_water = true on_water = true
end end
end end
for i=-1,1 do for i=-1,1 do
local p = {x=pos.x, y=pos.y, z=pos.z+i} local p = {x=pos.x, y=pos.y, z=pos.z+i}
local n = minetest.get_node(p) local n = minetest.get_node(p)
-- On verifie si il y a de l'eau if minetest.get_item_group(n.name, "water") ~= 0 then
if (n.name=="mcl_core:water_flowing") or (n.name == "mcl_core:water_source") then
on_water = true on_water = true
end end
end end
local p, n local p, n
if on_water == true then if on_water == true then
for i=-3,3 do for i=-3,3 do
for j=-3,3 do for j=-3,3 do
for k=-3,3 do for k=-3,3 do
p = {x=pos.x+i, y=pos.y+j, z=pos.z+k} p = {x=pos.x+i, y=pos.y+j, z=pos.z+k}
n = minetest.get_node(p) n = minetest.get_node(p)
-- On Supprime l'eau if minetest.get_item_group(n.name, "water") ~= 0 then
if (n.name=="mcl_core:water_flowing") or (n.name == "mcl_core:water_source")then minetest.add_node(p, {name="air"})
minetest.add_node(p, {name="air"}) change = true
change = true
end
end end
end end
end end
end end
p = {x=pos.x, y=pos.y, z=pos.z} end
n = minetest.get_node(p) p = {x=pos.x, y=pos.y, z=pos.z}
if change == true then n = minetest.get_node(p)
minetest.add_node(pointed_thing.above, {name = "mcl_sponges:sponge_wet"}) if change == true then
else minetest.add_node(pointed_thing.above, {name = "mcl_sponges:sponge_wet"})
minetest.add_node(pointed_thing.above, {name = "mcl_sponges:sponge"}) else
end minetest.add_node(pointed_thing.above, {name = "mcl_sponges:sponge"})
end
return itemstack return itemstack
end, end,
_mcl_blast_resistance = 3, _mcl_blast_resistance = 3,
_mcl_hardness = 0.6, _mcl_hardness = 0.6,