- merged colored giftboxes from mt_seasons mod
- added aliases for original colored giftboxes
master
Leslie Krause 2017-12-23 22:03:00 -05:00
commit 3275c40896
15 changed files with 357 additions and 0 deletions

51
config.lua Normal file
View File

@ -0,0 +1,51 @@
-- giftbox mod configuration file
giftbox.present_infotext = "Christmas Present"
giftbox.present_greeting = "present_greeting.png"
giftbox.present_items = {
"default:torch 60",
"default:apple 40",
"farming:bread 20",
"mt_seasons:pumpkin_slice 10",
"default:junglesapling 5",
"default:pine_sapling 5",
"default:aspen_sapling 5",
"default:acacia_sapling 5",
"default:pick_diamond",
"default:sword_diamond",
"default:pick_bronze",
"default:sword_bronze",
"3d_armor:helmet_diamond",
"3d_armor:leggings_diamond",
"3d_armor:chestplate_diamond",
"3d_armor:boots_diamond",
"default:coalblock 20",
"tnt:tnt 15",
"default:obsidian 10",
"default:snowblock 5",
"mobs:cursed_stone",
"jt_mods:griefer_soul_block",
"default:meselamp_white 10",
"default:meselamp 10",
}
giftbox.giftbox_drops = {
-- digging gift box allows for a single drop of items with a given a rarity
{ items = { "default:sword_diamond" }, rarity = 50 },
{ items = { "default:sword_bronze" }, rarity = 25 },
{ items = { "default:pick_diamond" }, rarity = 50 },
{ items = { "default:pick_bronze" }, rarity = 25 },
{ items = { "default:gold_lump 5" }, rarity = 10 },
{ items = { "default:coal_lump 10" }, rarity = 10 },
-- default drop must be placed last and have rarity of 0 to avoid empty drops
{ items = { "farming:gingerbread_cookie 5", "farming:candycane 10" }, rarity = 0 },
}

1
depends.txt Normal file
View File

@ -0,0 +1 @@
default

243
init.lua Normal file
View File

@ -0,0 +1,243 @@
--------------------------------------------------------
-- Minetest :: Giftbox Mod v2.0 alpha (giftbox)
--
-- See README.txt for licensing and other information.
-- Copyright (c) 2016-2017, Leslie Ellen Krause
--
-- ./games/just_test_tribute/mods/giftbox/init.lua
--------------------------------------------------------
giftbox = { }
dofile( minetest.get_modpath( "giftbox" ) .. "/config.lua" )
local box_colors = { "black", "blue", "cyan", "green", "magenta", "red", "white", "yellow" }
-- black = black + grey
-- blue = blue + magenta
-- brown => yellow
-- cyan = cyan + yellow
-- dark_green => green
-- dark_grey => cyan
-- green = green + red
-- grey => white
-- magenta = magenta + cyan
-- orange => red
-- pink => magenta
-- red = red + green
-- violet => blue
-- white = white + grey
-- yellow = yellow + green
minetest.register_node( "giftbox:giftbox", {
description = "Gift Box",
tiles = { "giftbox_top.png", "giftbox_bottom.png", "giftbox_side.png",
"giftbox_side.png", "giftbox_side.png", "giftbox_side.png" },
is_ground_content = false,
groups = { choppy = 2, oddly_breakable_by_hand = 2 },
sounds = default.node_sound_wood_defaults( ),
after_place_node = function( pos, player )
local owner = player:get_player_name( ) or "singleplayer"
local meta = minetest.get_meta( pos )
-- meta:set_string( "owner", owner )
meta:set_string( "infotext", giftbox.present_infotext .. " (placed by " .. owner .. ")" )
end,
on_construct = function ( pos )
local meta = minetest.get_meta( pos )
meta:get_inventory( ):set_size( "main", 1 )
meta:set_string( "oldtime", os.time( ) )
meta:set_string( "newtime", os.time( ) )
end,
can_dig = function ( pos, player )
return not minetest.is_protected( pos, player:get_player_name( ) ) and default.is_empty( pos )
end,
allow_metadata_inventory_take = function( pos, listname, index, stack, player )
if not default.is_owner( pos, player ) then
return 0
end
return stack:get_count( )
end,
allow_metadata_inventory_put = function( pos, listname, index, stack, player )
return 0
end,
on_metadata_inventory_take = function( pos, listname, index, stack, player )
if default.is_empty( pos ) then
minetest.remove_node( pos )
end
minetest.log( "action", string.format( default.STATUS_CONTAINER_GET, player:get_player_name( ), "giftbox", minetest.pos_to_string( pos ) ) )
end,
on_open = function( pos, clicker )
local pname = clicker:get_player_name( )
local spos = pos.x .. "," .. pos.y .. "," .. pos.z
if minetest.check_player_privs( pname, { give = true } ) then
local slot, name
local formspec =
"size[8,6]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"label[1,0.8;Select an item to place in the gift box.]" ..
"list[nodemeta:%s;main;6,0.5;1,1;]"
slot = 0
for _, name in ipairs( giftbox.present_items ) do
formspec = formspec .. "item_image_button[ " .. ( slot % 8 ) .. "," .. ( math.floor ( slot / 8 ) + 2 ) .. ";1,1;" .. name .. ";add " .. name .. ";]"
slot = slot + 1
end
return string.format( formspec, spos )
elseif not minetest.is_protected( pos, pname ) then
local formspec =
"size[10,6.5]" ..
"image[0,0;12,6;" .. giftbox.present_greeting .. "]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"list[nodemeta:%s;main;7,4;1,1;]" ..
"list[current_player;main;1,5.5;8,1;]" ..
default.get_hotbar_bg(1,5.5)
return string.format( formspec, spos )
end
end,
on_close = function( pos, player, fields )
local fname, item
fname = next( fields, nil ) -- use next since we only care about the name of a single button
if minetest.check_player_privs( player:get_player_name( ), { give = true } ) and fname then
item = string.match( fname, "add (.+)" )
if item then
minetest.get_meta( pos ):get_inventory( ):set_stack( "main", 1, item )
minetest.log( "action", string.format( default.STATUS_CONTAINER_PUT, player:get_player_name( ), "present", minetest.pos_to_string( pos ) ) )
end
end
end,
})
for i, color in ipairs( box_colors ) do
minetest.register_node( "giftbox:giftbox_" .. color, {
description = ( color:gsub( "^%l", string.upper ) ) .. " Gift Box",
drawtype = "mesh",
mesh = "giftbox.obj",
tiles = { "giftbox_" .. color .. ".png" },
paramtype = "light",
visual_scale = 0.45,
wield_scale = { x = 1, y = 1, z = 1 }, -- apparently no way to set wield scale of mesh?
sunlight_propagates = true,
is_ground_content = false,
groups = { choppy = 2, oddly_breakable_by_hand = 2, flammable = 1 },
sounds = default.node_sound_dirt_defaults(),
paramtype2 = "facedir",
selection_box = {
type = "fixed",
fixed = {
{ -0.45, -0.5, -0.45, 0.45, 0.45, 0.45 },
}
},
drop = { max_items = 1, items = giftbox.giftbox_drops },
after_place_node = function( pos, player )
-- initial item string: Gift Box (placed by sorcerykid)
local placer = player:get_player_name( ) or "singleplayer"
local meta = minetest.get_meta( pos )
meta:set_string( "owner", default.OWNER_NOBODY )
meta:set_string( "placer", placer )
meta:set_string( "is_anonymous", "false" )
meta:set_string( "infotext", "Public Gift Box (from " .. placer .. ")" )
end,
on_open = function( pos, player, fields )
local meta = minetest.get_meta( pos )
local formspec =
"size[8,3]" ..
default.gui_bg ..
default.gui_bg_img ..
"button_exit[6,2.5;2,0.3;save;Save]" ..
"checkbox[6,1.6;is_anonymous;Anonymous Sender;" .. meta:get_string( "is_anonymous" ) .. "]" ..
"label[0.1,0;Personalize your holiday greeting (or leave blank for the default):]" ..
"field[0.4,1;7.5,0.25;message;;" .. meta:get_string( "message" ) .. "]" ..
"label[0.1,1.5;Recipient:]" ..
"field[1.8,1.9;3.5,0.25;owner;;" .. meta:get_string( "owner" ) .. "]"
-- only placer of gift box should edit properties, not the receiver
if meta:get_string( "placer" ) ~= placer then
return formspec
end
end,
on_close = function( pos, player, fields )
local placer = player:get_player_name( )
local meta = minetest.get_meta( pos )
-- only placer of gift box should edit properties, not the receiver
if meta:get_string( "placer" ) ~= placer then return end
if fields.is_anonymous then
-- in next version of active formspecs, we should save checkbox state
-- in form meta first rather than directly to node meta
meta:set_string( "is_anonymous", fields.is_anonymous )
elseif fields.save and fields.message and fields.owner then
local infotext
if string.len( fields.message ) > 50 then
minetest.chat_send_player( placer, "The specified message is too long." )
return
elseif fields.owner == placer then
minetest.chat_send_player( placer, "You cannot send a gift to yourself." )
return
elseif not "" and not string.find( fields.owner, "^[_A-Za-z0-9]+$" ) then
minetest.chat_send_player( placer, "The specified recipient is invalid." )
return
end
-- item string with message: Dear sorcerykid: "Happy holidays!" (placed by sorcerykid)
-- item string without message: Gift Box for maikerumine (placed by sorcerykid)
if fields.owner == default.OWNER_NOBODY then
-- public gift box
infotext = fields.message == "" and "Gift Box" or "\"" .. fields.message .. "\""
else
-- private gift box
infotext = fields.message == "" and "Gift Box for " .. fields.owner or "Dear " .. fields.owner .. ": \"" .. fields.message .. "\""
end
if meta:get_string( "is_anonymous" ) == "false" then
infotext = infotext .. " (from " .. placer .. ")"
end
minetest.log( "action", string.format( default.STATUS_SIGNATURE_SET, player:get_player_name( ), fields.message, "giftbox", minetest.pos_to_string( pos ) ) )
meta:set_string( "owner", fields.owner )
meta:set_string( "message", fields.message )
meta:set_string( "infotext", infotext )
end
end,
} )
minetest.register_craft( {
output = "giftbox:giftbox_" .. color,
recipe = {
{ "wool:" .. color, "farming:cotton", "wool:" .. color },
{ "default:paper", "default:mese_crystal", "default:paper" },
{ "wool:" .. color, "default:paper", "wool:" .. color },
}
} )
end
minetest.register_alias( "mt_seasons:gift_box_brown", "giftbox:giftbox_yellow" )
minetest.register_alias( "mt_seasons:gift_box_dark_green", "giftbox:giftbox_green" )
minetest.register_alias( "mt_seasons:gift_box_dark_grey", "giftbox:giftbox_cyan" )
minetest.register_alias( "mt_seasons:gift_box_grey", "giftbox:giftbox_white" )
minetest.register_alias( "mt_seasons:gift_box_orange", "giftbox:giftbox_red" )
minetest.register_alias( "mt_seasons:gift_box_pink", "giftbox:giftbox_magenta" )
minetest.register_alias( "mt_seasons:gift_box_violet", "giftbox:giftbox_blue" )
minetest.register_alias( "mt_seasons:gift_box_red", "giftbox:giftbox_red" )
minetest.register_alias( "mt_seasons:gift_box_green", "giftbox:giftbox_green" )
minetest.register_alias( "mt_seasons:gift_box_blue", "giftbox:giftbox_blue" )
minetest.register_alias( "mt_seasons:gift_box_cyan", "giftbox:giftbox_cyan" )
minetest.register_alias( "mt_seasons:gift_box_magenta", "giftbox:giftbox_magenta" )
minetest.register_alias( "mt_seasons:gift_box_yellow", "giftbox:giftbox_yellow" )
minetest.register_alias( "mt_seasons:gift_box_white", "giftbox:giftbox_white" )
minetest.register_alias( "mt_seasons:gift_box_black", "giftbox:giftbox_black" )

62
models/giftbox.obj Normal file
View File

@ -0,0 +1,62 @@
# Blender v2.78 (sub 0) OBJ File: ''
# www.blender.org
mtllib present.mtl
o Shape1
v 1.000000 -1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v -1.000000 -1.000000 1.000000
v 1.000000 -1.000000 1.000000
v 1.000000 1.000000 1.000000
v -1.000000 1.000000 1.000000
v -0.707107 1.000000 0.707107
v 0.707107 1.000000 -0.707107
v 0.707107 3.000000 -0.707106
v -0.707107 3.000000 0.707108
v 0.707107 1.000000 0.707107
v -0.707107 1.000000 -0.707107
v -0.707107 3.000000 -0.707106
v 0.707107 3.000000 0.707108
vt 0.2500 0.0000
vt 0.5000 0.0000
vt 0.5000 0.5000
vt 0.2500 0.5000
vt 0.7500 0.0000
vt 1.0000 0.0000
vt 1.0000 0.5000
vt 0.7500 0.5000
vt 0.5000 1.0000
vt 0.2500 1.0000
vt 0.5000 0.5000
vt 0.7500 0.5000
vt 0.7500 1.0000
vt 0.5000 1.0000
vt 0.0000 0.0000
vt 0.0000 0.5000
vt -0.0000 0.5000
vt 0.2500 0.5000
vt 0.2500 1.0000
vt -0.0000 1.0000
vt 0.0000 0.5000
vt 0.2500 0.5000
vt 0.2500 1.0000
vt 0.0000 1.0000
vn 0.0000 0.0000 -1.0000
vn 0.0000 -0.0000 1.0000
vn 0.0000 1.0000 0.0000
vn 0.0000 -1.0000 -0.0000
vn 1.0000 0.0000 0.0000
vn -1.0000 0.0000 0.0000
vn 0.7071 -0.0000 0.7071
vn 0.7071 0.0000 -0.7071
usemtl None
s 1
f 1/1/1 2/2/1 3/3/1 4/4/1
f 5/5/2 6/6/2 7/7/2 8/8/2
f 4/4/3 3/3/3 8/9/3 7/10/3
f 6/11/4 5/12/4 2/13/4 1/14/4
f 6/15/5 1/1/5 4/4/5 7/16/5
f 2/2/6 5/5/6 8/8/6 3/3/6
f 9/17/7 10/18/7 11/19/7 12/20/7
f 13/21/8 14/22/8 15/23/8 16/24/8

BIN
textures/giftbox_black.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
textures/giftbox_blue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
textures/giftbox_bottom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 B

BIN
textures/giftbox_cyan.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
textures/giftbox_green.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

BIN
textures/giftbox_red.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
textures/giftbox_side.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

BIN
textures/giftbox_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

BIN
textures/giftbox_white.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
textures/giftbox_yellow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB