From cc411efe4c7025b7e18dbc0e6ea05f5d4f9bd469 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 7 Jan 2018 16:53:25 +0100 Subject: [PATCH] Move mob spawner change code to mobs mod --- mods/ENTITIES/mobs/api.lua | 17 +++++++++++++++++ mods/ITEMS/mcl_mobspawners/init.lua | 18 ------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/mods/ENTITIES/mobs/api.lua b/mods/ENTITIES/mobs/api.lua index 584d86c4b..5eb357cf1 100644 --- a/mods/ENTITIES/mobs/api.lua +++ b/mods/ENTITIES/mobs/api.lua @@ -3152,6 +3152,9 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) inventory_image = invimg, groups = grp, + _doc_items_longdesc = "This allows you to place a single mob.", + _doc_items_usagehelp = "Just place it where you want the mob to appear. Animals will spawn tamed, unless you hold down the sneak key while placing. If you place this on a monster spawner, you change the monster it spawns.", + on_place = function(itemstack, placer, pointed_thing) local pos = pointed_thing.above @@ -3171,6 +3174,20 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative) return end + local name = placer:get_player_name() + local privs = minetest.get_player_privs(name) + if not privs.maphack then + minetest.chat_send_player(name, "You need the “maphack” privilege to change the mob spawner.") + return itemstack + end + if minetest.get_modpath("mcl_mobspawners") and under.name == "mcl_mobspawners:spawner" then + mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name()) + if not minetest.settings:get_bool("creative_mode") then + itemstack:take_item() + end + return itemstack + end + pos.y = pos.y + 1 local mob = minetest.add_entity(pos, mob) diff --git a/mods/ITEMS/mcl_mobspawners/init.lua b/mods/ITEMS/mcl_mobspawners/init.lua index 50bfa708b..2d44572c6 100644 --- a/mods/ITEMS/mcl_mobspawners/init.lua +++ b/mods/ITEMS/mcl_mobspawners/init.lua @@ -304,24 +304,6 @@ minetest.register_node("mcl_mobspawners:spawner", { end, sounds = mcl_sounds.node_sound_metal_defaults(), - on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) - -- Change mob type if placing spawn egg into monster spawner. - -- Shift-click to ignore. - if minetest.get_item_group(itemstack:get_name(), "spawn_egg") == 1 then - local name = clicker:get_player_name() - local privs = minetest.get_player_privs(name) - if not privs.maphack then - minetest.chat_send_player(name, "You need the “maphack” privilege to change the spawned monster.") - return itemstack - end - mcl_mobspawners.setup_spawner(pos, itemstack:get_name()) - if not minetest.settings:get_bool("creative_mode") then - itemstack:take_item() - end - return itemstack - end - end, - _mcl_blast_resistance = 25, _mcl_hardness = 5, })