From 85c7ed84251a22b1dc8e679cb8feb9b66b1a3832 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Mon, 27 May 2019 14:24:11 -0400 Subject: [PATCH] rework creative and materials-in-survival checks on simple street lights check if the user has concrete when they try to shift-place in survival fix wrong pole check/deduct count add informational messages for when the player is short on materials --- simple.lua | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/simple.lua b/simple.lua index aaf5575..41808a3 100644 --- a/simple.lua +++ b/simple.lua @@ -60,17 +60,34 @@ local function check_and_place(itemstack, placer, pointed_thing, pole, light, pa if sneak and minetest.is_protected(pos1, player_name) then return end - if not creative or not creative.is_enabled_for(player_name) then + if not creative.is_enabled_for(player_name) then local inv = placer:get_inventory() - if not inv:contains_item("main", pole.." 5") or not inv:contains_item("main", light) then return end - if sneak and inv:contains_item("main", streetlights.concrete) then - inv:remove_item("main", streetlights.concrete) - else + if not inv:contains_item("main", pole.." 6") then + minetest.chat_send_player(placer:get_player_name(), "*** You don't have enough "..pole.." in your inventory!") return end - inv:remove_item("main", pole.." 5") + if not inv:contains_item("main", light) then + minetest.chat_send_player(placer:get_player_name(), "*** You don't have any "..light.." in your inventory!") + return + end + + if sneak then + if not inv:contains_item("main", streetlights.concrete) then + minetest.chat_send_player(placer:get_player_name(), "*** You don't have any concrete in your inventory!") + return + else + inv:remove_item("main", streetlights.concrete) + end + end + + inv:remove_item("main", pole.." 6") inv:remove_item("main", light) + + end + + if sneak then + minetest.set_node(pos1, { name = streetlights.concrete }) end for i = 1, 5 do @@ -79,9 +96,6 @@ local function check_and_place(itemstack, placer, pointed_thing, pole, light, pa end minetest.set_node(pos3, { name = pole }) minetest.set_node(pos4, { name = light, param2 = param2 }) - if sneak then - minetest.set_node(pos1, { name = streetlights.concrete }) - end end local poles_tab = {