upgrade shop test
This commit is contained in:
parent
f188340182
commit
32df3200a9
@ -261,6 +261,8 @@ local function set_vendor_settings(pos, SettingsDef)
|
||||
meta:set_string("settings", minetest.serialize(SettingsDef))
|
||||
end
|
||||
|
||||
emeraldbank.set_vendor_settings = set_vendor_settings
|
||||
|
||||
local function reset_vendor_settings(pos)
|
||||
local settings_default = {
|
||||
input_item = "", -- Don't change this unless you plan on setting this up to add this item to the inventories
|
||||
|
@ -123,31 +123,34 @@ function emeraldbank.upgrade_shop(pos)
|
||||
local old_meta = core.get_meta(pos)
|
||||
local old_meta_table = core.get_meta(pos):to_table()
|
||||
local nodename = core.get_node(pos).name
|
||||
local old_inv = old_meta:get_inventory()
|
||||
local old_list = old_inv:get_list("stock")
|
||||
local old_stack = old_inv:get_stack("stock", 1)
|
||||
|
||||
-- set the new shop node
|
||||
core.swap_node(pos, {name = "fancy_vend:player_vendor"})
|
||||
|
||||
|
||||
-- setup the new shop node
|
||||
-- Set variables for access later (for various checks, etc.)
|
||||
local owner = old_meta:get_string("owner") or ""
|
||||
pos.y = pos.y + 1
|
||||
local above_node = minetest.get_node(pos).name
|
||||
|
||||
-- If node above is air or the display node, and it is not protected, attempt to place the vendor. If vendor sucessfully places, place display node above, otherwise alert the user
|
||||
if (minetest.registered_nodes[above_node].buildable_to or above_node == "fancy_vend:display_node") and not minetest.is_protected(pos, owner) then
|
||||
if above_node ~= "fancy_vend:display_node" then
|
||||
minetest.set_node(pos, minetest.registered_nodes["fancy_vend:display_node"])
|
||||
end
|
||||
-- Set owner
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", owner or "")
|
||||
|
||||
-- Set default meta
|
||||
meta:set_string("log", minetest.serialize({"Vendor placed by "..owner,}))
|
||||
emeraldbank.reset_vendor_settings(pos)
|
||||
emeraldbank.refresh_vendor(pos)
|
||||
else
|
||||
minetest.chat_send_player(owner, S("Vendors require 2 nodes of space."))
|
||||
end
|
||||
pos.y = pos.y + 1
|
||||
-- local above_node = minetest.get_node(pos).name
|
||||
|
||||
-- -- If node above is air or the display node, and it is not protected, attempt to place the vendor. If vendor sucessfully places, place display node above, otherwise alert the user
|
||||
-- if (minetest.registered_nodes[above_node].buildable_to or above_node == "fancy_vend:display_node") and not minetest.is_protected(pos, owner) then
|
||||
-- if above_node ~= "fancy_vend:display_node" then
|
||||
-- minetest.set_node(pos, minetest.registered_nodes["fancy_vend:display_node"])
|
||||
-- end
|
||||
|
||||
-- Set owner
|
||||
local owner = old_meta:get_string("owner") or ""
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("owner", owner)
|
||||
|
||||
-- Set default meta
|
||||
meta:set_string("log", minetest.serialize({"Vendor placed by "..owner,}))
|
||||
emeraldbank.reset_vendor_settings(pos)
|
||||
emeraldbank.refresh_vendor(pos)
|
||||
|
||||
if minetest.get_modpath("pipeworks") then
|
||||
pipeworks.after_place(pos)
|
||||
@ -155,18 +158,29 @@ function emeraldbank.upgrade_shop(pos)
|
||||
|
||||
-- copy old metadata in new node
|
||||
core.get_meta(pos):from_table(old_meta_table)
|
||||
|
||||
-- new node
|
||||
local node = core.get_node(pos)
|
||||
local meta = core.get_meta(pos)
|
||||
local count = meta:get_int("count")
|
||||
local price = meta:get_int("price")
|
||||
local shop_item = meta:get_string("shop_item")
|
||||
local minv = meta:get_inventory()
|
||||
local settings = emeraldbank.get_vendor_settings(pos)
|
||||
|
||||
-- settings
|
||||
settings.input_item = "mcl_core:emerald"
|
||||
settings.input_item_qty = price
|
||||
settings.output_item = shop_item
|
||||
settings.output_item_qty = count
|
||||
|
||||
-- inv
|
||||
-- local inv = meta:get_inventory()
|
||||
-- inv:set_size("main", 15*6)
|
||||
-- inv:set_size("wanted_item", 1*1)
|
||||
-- inv:set_size("given_item", 1*1)
|
||||
-- inv:set_stack("main", i, old_stack)
|
||||
|
||||
|
||||
emeraldbank.set_vendor_settings(pos, settings)
|
||||
emeraldbank.refresh_vendor(pos)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user