Move banner pattern code to patterncraft.lua

This commit is contained in:
Wuzzy 2017-07-28 14:54:34 +02:00
parent 84bcfd0913
commit b14c33039f
2 changed files with 147 additions and 143 deletions

View File

@ -32,47 +32,6 @@ local colors = {
local base_color_ratio = 224 local base_color_ratio = 224
local layer_ratio = 255 local layer_ratio = 255
local patterns = {
"border",
"bricks",
"circle",
"creeper",
"cross",
"curly_border",
"diagonal_left",
"diagonal_right",
"diagonal_up_left",
"diagonal_up_right",
"flower",
"gradient",
"gradient_up",
"half_horizontal_bottom",
"half_horizontal",
"half_vertical",
"half_vertical_right",
"thing",
"rhombus",
"skull",
"small_stripes",
"square_bottom_left",
"square_bottom_right",
"square_top_left",
"square_top_right",
"straight_cross",
"stripe_bottom",
"stripe_center",
"stripe_downleft",
"stripe_downright",
"stripe_left",
"stripe_middle",
"stripe_right",
"stripe_top",
"triangle_bottom",
"triangles_bottom",
"triangles_top",
"triangle_top",
}
-- After destroying the standing banner node -- After destroying the standing banner node
local on_destruct_standing_banner = function(pos) local on_destruct_standing_banner = function(pos)
-- Find this node's banner entity and make it drop as an item -- Find this node's banner entity and make it drop as an item
@ -284,108 +243,7 @@ minetest.register_entity("mcl_banners:standing_banner", {
end, end,
}) })
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv) dofile(minetest.get_modpath("mcl_banners").."/patterncraft.lua")
if minetest.get_item_group(itemstack:get_name(), "banner") ~= 1 then
return
end
local original
local index
for i = 1, player:get_inventory():get_size("craft") do
if minetest.get_item_group(old_craft_grid[i]:get_name(), "banner") == 1 then
original = old_craft_grid[i]
index = i
end
end
if not original then
return
end
local imeta = itemstack:get_meta()
imeta:set_string("description", "Emblazoned Banner")
return itemstack
end)
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
if minetest.get_item_group(itemstack:get_name(), "banner") ~= 1 then
return
end
local original
local index
for i = 1, player:get_inventory():get_size("craft") do
local itemname = old_craft_grid[i]:get_name()
if minetest.get_item_group(itemname, "banner") == 1 then
original = old_craft_grid[i]
index = i
end
end
if not original then
return
end
local ometa = original:get_meta()
local layers_raw = ometa:get_string("layers")
local layers = minetest.deserialize(layers_raw)
if type(layers) ~= "table" then
layers = {}
end
table.insert(layers, {pattern="circle", color = "unicolor_yellow"})
local imeta = itemstack:get_meta()
imeta:set_string("layers", minetest.serialize(layers))
imeta:set_string("description", "Emblazoned Banner")
return itemstack
end)
minetest.register_craft({
recipe = {
{ "", "", "" },
{ "", "mcl_banners:banner_item_red", "" },
{ "mcl_dye:yellow", "mcl_dye:yellow", "mcl_dye:yellow" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "mcl_dye:yellow", "mcl_dye:yellow", "mcl_dye:yellow" },
{ "", "mcl_banners:banner_item_red", "" },
{ "", "", "" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "mcl_dye:yellow", "", "" },
{ "mcl_dye:yellow", "mcl_banners:banner_item_red", "" },
{ "mcl_dye:yellow", "", "" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "", "mcl_dye:yellow", "" },
{ "", "mcl_dye:yellow", "mcl_banners:banner_item_red", },
{ "", "mcl_dye:yellow", "" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "", "", "mcl_dye:yellow", },
{ "", "mcl_banners:banner_item_red", "mcl_dye:yellow", },
{ "", "", "mcl_dye:yellow" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",

View File

@ -0,0 +1,146 @@
local patterns = {
"border",
"bricks",
"circle",
"creeper",
"cross",
"curly_border",
"diagonal_left",
"diagonal_right",
"diagonal_up_left",
"diagonal_up_right",
"flower",
"gradient",
"gradient_up",
"half_horizontal_bottom",
"half_horizontal",
"half_vertical",
"half_vertical_right",
"thing",
"rhombus",
"skull",
"small_stripes",
"square_bottom_left",
"square_bottom_right",
"square_top_left",
"square_top_right",
"straight_cross",
"stripe_bottom",
"stripe_center",
"stripe_downleft",
"stripe_downright",
"stripe_left",
"stripe_middle",
"stripe_right",
"stripe_top",
"triangle_bottom",
"triangles_bottom",
"triangles_top",
"triangle_top",
}
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv)
if minetest.get_item_group(itemstack:get_name(), "banner") ~= 1 then
return
end
local original
local index
for i = 1, player:get_inventory():get_size("craft") do
if minetest.get_item_group(old_craft_grid[i]:get_name(), "banner") == 1 then
original = old_craft_grid[i]
index = i
end
end
if not original then
return
end
local imeta = itemstack:get_meta()
imeta:set_string("description", "Emblazoned Banner")
return itemstack
end)
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
if minetest.get_item_group(itemstack:get_name(), "banner") ~= 1 then
return
end
local original
local index
for i = 1, player:get_inventory():get_size("craft") do
local itemname = old_craft_grid[i]:get_name()
if minetest.get_item_group(itemname, "banner") == 1 then
original = old_craft_grid[i]
index = i
end
end
if not original then
return
end
local ometa = original:get_meta()
local layers_raw = ometa:get_string("layers")
local layers = minetest.deserialize(layers_raw)
if type(layers) ~= "table" then
layers = {}
end
table.insert(layers, {pattern="circle", color = "unicolor_yellow"})
local imeta = itemstack:get_meta()
imeta:set_string("layers", minetest.serialize(layers))
imeta:set_string("description", "Emblazoned Banner")
return itemstack
end)
minetest.register_craft({
recipe = {
{ "", "", "" },
{ "", "mcl_banners:banner_item_red", "" },
{ "mcl_dye:yellow", "mcl_dye:yellow", "mcl_dye:yellow" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "mcl_dye:yellow", "mcl_dye:yellow", "mcl_dye:yellow" },
{ "", "mcl_banners:banner_item_red", "" },
{ "", "", "" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "mcl_dye:yellow", "", "" },
{ "mcl_dye:yellow", "mcl_banners:banner_item_red", "" },
{ "mcl_dye:yellow", "", "" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "", "mcl_dye:yellow", "" },
{ "", "mcl_dye:yellow", "mcl_banners:banner_item_red", },
{ "", "mcl_dye:yellow", "" },
},
output = "mcl_banners:banner_item_red",
})
minetest.register_craft({
recipe = {
{ "", "", "mcl_dye:yellow", },
{ "", "mcl_banners:banner_item_red", "mcl_dye:yellow", },
{ "", "", "mcl_dye:yellow" },
},
output = "mcl_banners:banner_item_red",
})