Add snow golem summon utility function

This commit is contained in:
Wuzzy 2017-07-01 20:58:22 +02:00
parent f832972d38
commit beb40dc3cf
3 changed files with 40 additions and 0 deletions

View File

@ -63,6 +63,7 @@ mobs_mc.items = {
-- Minetest Game
top_snow = "default:snow",
snow_block = "default:snowblock",
mushroom_red = "flowers:mushroom_red",
bucket = "bucket:bucket_empty",
grass_block = "default:dirt_with_grass",
@ -137,6 +138,7 @@ mobs_mc.items = {
wool_black = "wool:black",
-- Light blue intentionally missing
-- Special items
music_discs = {}, -- No music discs by default; used by creeper. Override this if your subgame has music discs.
}

View File

@ -9,6 +9,9 @@ if not minetest.get_modpath("mobs_mc_gameconfig") then
mobs_mc = {}
end
-- For utility functions
mobs_mc.tools = {}
-- This function checks if the item ID has been overwritten and returns true if it is unchanged
if minetest.get_modpath("mobs_mc_gameconfig") and mobs_mc.override and mobs_mc.override.items then
mobs_mc.is_item_variable_overridden = function(id)

View File

@ -95,6 +95,41 @@ mobs:register_mob("mobs_mc:snowman", {
end,
})
-- This is to be called when a pumpkin or jack'o lantern has been placed. Recommended: In the on_construct function
-- of the node.
-- This summons a snow golen when pos is next to a row of two snow blocks.
mobs_mc.tools.check_snow_golem_summon = function(pos)
local checks = {
-- These are the possible placement patterns
-- { snow block pos. 1, snow block pos. 2, snow golem spawn position }
{ {x=pos.x, y=pos.y-1, z=pos.z}, {x=pos.x, y=pos.y-2, z=pos.z}, {x=pos.x, y=pos.y-2.5, z=pos.z} },
{ {x=pos.x, y=pos.y+1, z=pos.z}, {x=pos.x, y=pos.y+2, z=pos.z}, {x=pos.x, y=pos.y-0.5, z=pos.z} },
{ {x=pos.x-1, y=pos.y, z=pos.z}, {x=pos.x-2, y=pos.y, z=pos.z}, {x=pos.x-2, y=pos.y-0.5, z=pos.z} },
{ {x=pos.x+1, y=pos.y, z=pos.z}, {x=pos.x+2, y=pos.y, z=pos.z}, {x=pos.x+2, y=pos.y-0.5, z=pos.z} },
{ {x=pos.x, y=pos.y, z=pos.z-1}, {x=pos.x, y=pos.y, z=pos.z-2}, {x=pos.x, y=pos.y-0.5, z=pos.z-2} },
{ {x=pos.x, y=pos.y, z=pos.z+1}, {x=pos.x, y=pos.y, z=pos.z+2}, {x=pos.x, y=pos.y-0.5, z=pos.z+2} },
}
for c=1, #checks do
local b1 = checks[c][1]
local b2 = checks[c][2]
local place = checks[c][3]
local b1n = minetest.get_node(b1)
local b2n = minetest.get_node(b2)
if b1n.name == mobs_mc.items.snow_block and b2n.name == mobs_mc.items.snow_block then
-- Remove the pumpkin and both snow blocks and summon the snow golem
minetest.remove_node(pos)
minetest.remove_node(b1)
minetest.remove_node(b2)
core.check_for_falling(pos)
core.check_for_falling(b1)
core.check_for_falling(b2)
minetest.add_entity(place, "mobs_mc:snowman")
break
end
end
end
mobs:register_egg("mobs_mc:snowman", "Snow Golem", "mobs_mc_spawn_icon_snowman.png", 0)
if minetest.settings:get_bool("log_mods") then