Browse Source

updated protector and bees, added awards and bergsee

master
bas080 8 years ago
parent
commit
b5b9e64233
  1. 22
      mods/awards/.gitattributes
  2. 215
      mods/awards/.gitignore
  3. 423
      mods/awards/api.lua
  4. 8
      mods/awards/config.txt
  5. 168
      mods/awards/init.lua
  6. 52
      mods/awards/readme.md
  7. BIN
      mods/awards/textures/bg_default.png
  8. BIN
      mods/awards/textures/bg_mining.png
  9. BIN
      mods/awards/textures/mese.png
  10. BIN
      mods/awards/textures/miniminer.png
  11. BIN
      mods/awards/textures/novicebuilder.png
  12. BIN
      mods/awards/textures/template.png
  13. BIN
      mods/awards/textures/unknown.png
  14. 229
      mods/awards/triggers.lua
  15. 733
      mods/bees/init.lua
  16. BIN
      mods/bees/textures/bees_comb.png
  17. BIN
      mods/bees/textures/bees_frame_empty.png
  18. BIN
      mods/bees/textures/bees_frame_full.png
  19. BIN
      mods/bees/textures/bees_hive_artificial.png
  20. 4
      mods/bergsee/README
  21. 1
      mods/bergsee/depends.txt
  22. 176
      mods/bergsee/init.lua
  23. 3
      mods/default/tools.lua
  24. 205
      mods/doors/init.lua~
  25. 5
      mods/protector/README.md
  26. 2
      mods/protector/depends.txt
  27. 270
      mods/protector/init.lua
  28. BIN
      mods/protector/textures/protector_display.png
  29. BIN
      mods/protector/textures/protector_side.png
  30. BIN
      mods/protector/textures/protector_top.png
  31. 1
      mods/trees/conifertree.lua

22
mods/awards/.gitattributes vendored

@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

215
mods/awards/.gitignore vendored

@ -0,0 +1,215 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg

423
mods/awards/api.lua

@ -0,0 +1,423 @@
-- AWARDS
-- by Rubenwardy, CC-BY-SA
-------------------------------------------------------
-- this is api function file
-------------------------------------------------------
-- The global award namespace
awards = {}
-- Table Save Load Functions
function awards.save()
local file = io.open(minetest.get_worldpath().."/awards.txt", "w")
if file then
file:write(minetest.serialize(awards.players))
file:close()
end
end
function awards.load()
local file = io.open(minetest.get_worldpath().."/awards.txt", "r")
if file then
local table = minetest.deserialize(file:read("*all"))
if type(table) == "table" then
return table
end
end
return {}
end
awards.players = awards.load()
function awards.player(name)
return awards.players[name]
end
-- A table of award definitions
awards.def = {}
function awards.tbv(tb,value,default)
if not default then
default = {}
end
if not tb or type(tb) ~= "table" then
if not value then
value = "[NULL]"
end
minetest.log("error", "awards.tbv - table "..dump(value).." is null, or not a table! Dump: "..dump(tb))
return
end
if not value then
error("[ERROR] awards.tbv was not used correctly!\n"..
"Value: '"..dump(value).."'\n"..
"Dump:"..dump(tb))
return
end
if not tb[value] then
tb[value] = default
end
end
function awards.assertPlayer(playern)
awards.tbv(awards.players, playern)
awards.tbv(awards.players[playern], "name", playern)
awards.tbv(awards.players[playern], "unlocked")
awards.tbv(awards.players[playern], "place")
awards.tbv(awards.players[playern], "count")
awards.tbv(awards.players[playern], "deaths", 0)
awards.tbv(awards.players[playern], "joins", 0)
awards.tbv(awards.players[playern], "chats", 0)
end
-- Load files
dofile(minetest.get_modpath("awards").."/triggers.lua")
dofile(minetest.get_modpath("awards").."/config.txt")
-- API Functions
function awards._additional_triggers(name, data_table)
-- To add triggers in another mod, you should override this function
-- If the code can't handle the trigger passed, then call the last value of _additional_triggers
--[[
local add_trig = awards._additional_triggers
awards._additional_triggers = function(name, data_table)
if data_table.trigger.type == "trigger" then
local tmp = {
award = name,
node = data_table.trigger.node,
target = data_table.trigger.target,
}
table.insert(awards.onTrigger,tmp)
elseif data_table.trigger.type == "trigger2" then
local tmp = {
award = name,
node = data_table.trigger.node,
target = data_table.trigger.target,
}
table.insert(awards.onTrigger2,tmp)
else
add_trig(name, data_table)
end
end
]]--
end
function awards.register_achievement(name,data_table)
-- see if a trigger is defined in the achievement definition
if data_table.trigger and data_table.trigger.type then
if data_table.trigger.type == "dig" then
local tmp = {
award = name,
node = data_table.trigger.node,
target = data_table.trigger.target,
}
table.insert(awards.onDig,tmp)
elseif data_table.trigger.type == "place" then
local tmp = {
award = name,
node = data_table.trigger.node,
target = data_table.trigger.target,
}
table.insert(awards.onPlace,tmp)
elseif data_table.trigger.type == "death" then
local tmp = {
award = name,
target = data_table.trigger.target,
}
table.insert(awards.onDeath,tmp)
elseif data_table.trigger.type == "chat" then
local tmp = {
award = name,
target = data_table.trigger.target,
}
table.insert(awards.onChat,tmp)
elseif data_table.trigger.type == "join" then
local tmp = {
award = name,
target = data_table.trigger.target,
}
table.insert(awards.onJoin,tmp)
else
awards._additional_triggers(name, data_table)
end
end
-- check icon, background and custom_announce data
if data_table.icon == nil or data_table.icon == "" then
data_table.icon = "unknown.png"
end
if data_table.background == nil or data_table.background == "" then
data_table.background = "bg_default.png"
end
if data_table.custom_announce == nil or data_table.custom_announce == "" then
data_table.custom_announce = "Achievement Unlocked:"
end
-- add the achievement to the definition table
data_table.name = name
awards.def[name] = data_table
end
-- run a function when a node is dug
function awards.register_onDig(func)
table.insert(awards.onDig,func)
end
-- run a function when a node is placed
function awards.register_onPlace(func)
table.insert(awards.onPlace,func)
end
-- run a function when a player dies
function awards.register_onDeath(func)
table.insert(awards.onDeath,func)
end
-- run a function when a player chats
function awards.register_onChat(func)
table.insert(awards.onChat,func)
end
-- run a function when a player joins
function awards.register_onJoin(func)
table.insert(awards.onJoin,func)
end
-- This function is called whenever a target condition is met.
-- It checks if a player already has that achievement, and if they do not,
-- it gives it to them
----------------------------------------------
--awards.give_achievement(name,award)
-- name - the name of the player
-- award - the name of the award to give
function awards.give_achievement(name,award)
-- Access Player Data
local data = awards.players[name]
-- Perform checks
if not data then
return
end
if not awards.def[award] then
return
end
awards.tbv(data,"unlocked")
-- check to see if the player does not already have that achievement
if not data.unlocked[award] or data.unlocked[award]~=award then
-- Set award flag
data.unlocked[award]=award
-- Get data from definition tables
local title = award
local desc = ""
local background = ""
local icon = ""
local custom_announce = ""
if awards.def[award].title then
title = awards.def[award].title
end
if awards.def[award].custom_announce then
custom_announce = awards.def[award].custom_announce
end
if awards.def[award].background then
background = awards.def[award].background
end
if awards.def[award].icon then
icon = awards.def[award].icon
end
if awards.def[award] and awards.def[award].description then
desc = awards.def[award].description
end
-- send the won award message to the player
if Use_Formspec == true then
-- use a formspec to send it
minetest.show_formspec(name, "achievements:unlocked", "size[4,2]"..
"image_button_exit[0,0;4,2;"..background..";close1; ]"..
"image_button_exit[0.2,0.8;1,1;"..icon..";close2; ]"..
"label[1.1,1;"..title.."]"..
"label[0.3,0.1;"..custom_announce.."]")
else
-- use the chat console to send it
minetest.chat_send_player(name, "Achievement Unlocked: "..title)
if desc~="" then
minetest.chat_send_player(name, desc)
end
end
-- record this in the log
minetest.log("action", name.." has unlocked award "..title)
-- save playertable
awards.save()
end
end
-- List a player's achievements
minetest.register_chatcommand("list_awards", {
params = "obsolete",
description = "list_awards: obsolete. Use /awards",
func = function(name, param)
minetest.chat_send_player(name, "This command has been made obsolete. Use /awards instead.")
awards.showto(name, name, nil, false)
end
})
minetest.register_chatcommand("awards", {
params = "",
description = "awards: list awards",
func = function(name, param)
awards.showto(name, name, nil, false)
end
})
minetest.register_chatcommand("cawards", {
params = "",
description = "awards: list awards in chat",
func = function(name, param)
awards.showto(name, name, nil, true)
end
})
minetest.register_chatcommand("awd", {
params = "award name",
description = "awd: Details of awd gotten",
func = function(name, param)
local def = awards.def[param]
if def then
minetest.chat_send_player(name,def.title..": "..def.description)
else
minetest.chat_send_player(name,"Award not found.")
end
end
})
--[[minetest.register_chatcommand("gawd", {
params = "award name",
description = "gawd: give award to self",
func = function(name, param)
awards.give_achievement(name,param)
end
})]]--
function awards._order_awards(name)
local done = {}
local retval = {}
local player = awards.player(name)
if player and player.unlocked then
for _,got in pairs(player.unlocked) do
done[got] = true
table.insert(retval,{name=got,got=true})
end
end
for _,def in pairs(awards.def) do
if not done[def.name] then
table.insert(retval,{name=def.name,got=false})
end
end
return retval
end
function awards.showto(name, to, sid, text)
if name == "" or name == nil then
name = to
end
if text then
if not awards.players[name] or not awards.players[name].unlocked then
minetest.chat_send_player(to, "You have not unlocked any awards")
return
end
minetest.chat_send_player(to, name.."'s awards:")
for _, str in pairs(awards.players[name].unlocked) do
local def = awards.def[str]
if def and def.title then
if def.description then
minetest.chat_send_player(to, def.title..": "..def.description)
else
minetest.chat_send_player(to, def.title)
end
else
minetest.chat_send_player(to, str)
end
end
else
if sid == nil or sid < 1 then
sid = 1
end
local formspec = "size[11,5]"
local listofawards = awards._order_awards(name)
-- Sidebar
if sid then
local item = listofawards[sid+0]
local def = awards.def[item.name]
if def and def.secret and not item.got then
formspec = formspec .. "label[1,2.75;Secret Award]"..
"image[1,0;3,3;unknown.png]"
if def and def.description then
formspec = formspec .. "label[0,3.25;Unlock this award to find out what it is]"
end
else
local title = item.name
if def and def.title then
title = def.title
end
local status = ""
if item.got then
status = " (got)"
end
if def and def.icon then
icon = def.icon
end
formspec = formspec .. "label[1,2.75;"..title..status.."]"..
"image[1,0;3,3;"..icon.."]"
if def and def.description then
formspec = formspec .. "label[0,3.25;"..def.description.."]"
end
end
end
-- Create list box
formspec = formspec .. "textlist[4.75,0;6,5;awards;"
local first = true
for _,award in pairs(listofawards) do
if not first then
formspec = formspec .. ","
end
first = false
local def = awards.def[award.name]
if def and def.secret and not award.got then
formspec = formspec .. "#ACACACSecret Award"
else
local title = award.name
if def and def.title then
title = def.title
end
if award.got then
formspec = formspec .. minetest.formspec_escape(title)
else
formspec = formspec .. "#ACACAC".. minetest.formspec_escape(title)
end
end
end
formspec = formspec .. ";"..sid.."]"
-- Show formspec to user
minetest.show_formspec(to,"awards:awards",formspec)
end
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname~="awards:awards" then
return false
end
if fields.quit then
return true
end
local name = player:get_player_name()
if fields.awards then
local event = minetest.explode_textlist_event(fields.awards)
if event.type == "CHG" then
awards.showto(name,name,event.index,false)
end
end
return true
end)

8
mods/awards/config.txt

@ -0,0 +1,8 @@
-- AWARDS
-- by Rubenwardy, CC-BY-SA
-------------------------------------------------------
-- this is the configuration file for the awards mod
-------------------------------------------------------
Use_Formspec = true
--Use a graphical display for unlocking achievements. (Possible values: true | false)

168
mods/awards/init.lua

@ -0,0 +1,168 @@
-- AWARDS
-- by Rubenwardy, CC-BY-SA
-------------------------------------------------------
-- this is the init file for the award mod
-------------------------------------------------------
local S
if (intllib) then
dofile(minetest.get_modpath("intllib").."/intllib.lua")
S = intllib.Getter(minetest.get_current_modname())
else
S = function ( s ) return s end
end
dofile(minetest.get_modpath("awards").."/api.lua")
-- Light it up
awards.register_achievement("award_lightitup",{
title = S("Light It Up"),
description = S("Place 100 torches"),
icon = "novicebuilder.png",
trigger = {
type = "place",
node = "default:torch",
target = 100
}
})
-- Lumber Jack
awards.register_achievement("award_lumberjack",{
title = S("Lumber Jack"),
description = S("Dig 100 tree blocks"),
trigger = {
type = "dig",
node = "default:tree",
target = 100
}
})
-- Found some Mese!
awards.register_achievement("award_mesefind",{
title = S("First Mese Find"),
description = S("Found some Mese!"),
icon = "mese.png",
background = "bg_mining.png",
trigger = {
type = "dig",
node = "default:mese",
target = 1
}
})
-- Found a Nyan cat!
awards.register_achievement("award_nyanfind",{
title = S("OMG, Nyan Cat!"),
description = S("Find a nyan cat"),
trigger = {
type = "dig",
node = "default:nyancat",
target = 1
}
})
-- Just entered the mine
awards.register_achievement("award_mine1",{
title = S("Entering the mine"),
description = S("You have dug 10 stone blocks"),
icon = "miniminer.png",
background = "bg_mining.png",
trigger = {
type = "dig",
node = "default:stone",
target = 10
}
})
-- Mini Miner
awards.register_achievement("award_mine2",{
title = S("Mini Miner"),
description = S("You have dug 100 stone blocks"),
icon = "miniminer.png",
background = "bg_mining.png",
trigger = {
type = "dig",
node = "default:stone",
target = 100
}
})
-- Hardened Miner
awards.register_achievement("award_mine3",{
title = S("Hardened Miner"),
description = S("You have dug 1000 stone blocks"),
icon = "miniminer.png",
background = "bg_mining.png",
trigger = {
type = "dig",
node = "default:stone",
target = 1000
}
})
-- Master Miner
awards.register_achievement("award_mine4",{
title = S("Master Miner"),
description = S("You have dug 10000 stone blocks"),
icon = "miniminer.png",
background = "bg_mining.png",
trigger = {
type = "dig",
node = "default:stone",
target = 10000
}
})
-- First Death
awards.register_achievement("award_death1",{
title = S("First Death"),
description = S("You have more lives than a cat!"),
trigger = {
type = "death",
target = 1
}
})
-- Burned to death
awards.register_achievement("award_burn",{
title = S("You're a witch!"),
description = S("Burn to death in a fire")
})
-- 1 sentence
awards.register_achievement("award_chat1",{
title = S("First Word"),
description = S("Use the chat to talk to players"),
trigger = {
type = "chat",
target = 1
}
})
-- Join
awards.register_achievement("award_join1",{
title = S("Welcome!"),
description = S("Connect to the server"),
trigger = {
type = "join",
target = 1
}
})
awards.register_achievement("award_join2",{
title = S("Frequent Visitor"),
description = S("Connect to the server 50 times"),
trigger = {
type = "join",
target = 50
},
secret = true
})
awards.register_onDeath(function(player,data)
local pos = player:getpos()
if pos and minetest.find_node_near(pos, 1, "fire:basic_flame") ~= nil then
return "award_burn"
end
return nil
end)

52
mods/awards/readme.md

@ -0,0 +1,52 @@
Awards
------
by Andrew "Rubenwardy" Ward, CC-BY-SA.
This mod adds achievements to Minetest.
Code Reference
--------------
The API
=======
* awards.register_achievement(name,data_table)
* name
* desciption
* sound [optional]
* image [optional]
* trigger [optional] [table]
* type - "dig", "place", "death", "chat" or "join"
* (for dig/place type) node - the nodes name
* (for all types) target - how many to dig / place
* secret [optional] - if true, then player needs to unlock to find out what it is.
* awards.give_achievement(name,award)
* -- gives an award to a player
* awards.register_onDig(func(player,data))
* -- return award name or null
* awards.register_onPlace(func(player,data))
* -- return award name or null
* awards.register_onDeath(func(player,data))
* -- return award name or null
* awards.register_onChat(func(player,data))
* -- return award name or null
* awards.register_onJoin(func(player,data))
* -- return award name or null
Player Data
===========
A list of data referenced/hashed by the player's name.
* player name
* name [string]
* count [table] - dig counter
* modname [table]
* itemname [int]
* place [table] - place counter
* modname [table]
* itemname [int]
* deaths
* chats
* joins

BIN
mods/awards/textures/bg_default.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
mods/awards/textures/bg_mining.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

BIN
mods/awards/textures/mese.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 B

BIN
mods/awards/textures/miniminer.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 B

BIN
mods/awards/textures/novicebuilder.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 B

BIN
mods/awards/textures/template.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

BIN
mods/awards/textures/unknown.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 322 B

229
mods/awards/triggers.lua

@ -0,0 +1,229 @@
-- AWARDS
-- by Rubenwardy, CC-BY-SA
-------------------------------------------------------
-- this is the trigger handler file for the awards mod
-------------------------------------------------------
-- Function and table holders for Triggers
awards.onDig = {}
awards.onPlace = {}
awards.onChat = {}
awards.onDeath = {}
awards.onJoin = {}
-- Trigger Handles
minetest.register_on_dignode(function(pos, oldnode, digger)
if not digger or not pos or not oldnode then
return
end
local nodedug = string.split(oldnode.name, ":")
if #nodedug ~= 2 then
minetest.log("error","Awards mod: "..oldnode.name.." is in wrong format!")
return
end
local mod = nodedug[1]
local item = nodedug[2]
local playern = digger:get_player_name()
if (not playern or not nodedug or not mod or not item) then
return
end
awards.assertPlayer(playern)
awards.tbv(awards.players[playern].count, mod)
awards.tbv(awards.players[playern].count[mod], item, 0)
-- Increment counter
awards.players[playern].count[mod][item]=awards.players[playern].count[mod][item] + 1
-- Run callbacks and triggers
local player=digger
local data=awards.players[playern]
for i=1,# awards.onDig do
local res = nil
if type(awards.onDig[i]) == "function" then
-- Run trigger callback
res = awards.onDig[i](player,data)
elseif type(awards.onDig[i]) == "table" then
-- Handle table trigger
if not awards.onDig[i].node or not awards.onDig[i].target or not awards.onDig[i].award then
-- table running failed!
print("[ERROR] awards - onDig trigger "..i.." is invalid!")
else
-- run the table
local tnodedug = string.split(awards.onDig[i].node, ":")
local tmod=tnodedug[1]
local titem=tnodedug[2]
if tmod==nil or titem==nil or not data.count[tmod] or not data.count[tmod][titem] then
-- table running failed!
elseif data.count[tmod][titem] > awards.onDig[i].target-1 then
res=awards.onDig[i].award
end
end
end
if res then
awards.give_achievement(playern,res)
end
end
end)
minetest.register_on_placenode(function(pos,node,digger)
if not digger or not pos or not node or not digger:get_player_name() or digger:get_player_name()=="" then
return
end
local nodedug = string.split(node.name, ":")
if #nodedug ~= 2 then
minetest.log("error","Awards mod: "..node.name.." is in wrong format!")
return
end
local mod=nodedug[1]
local item=nodedug[2]
local playern = digger:get_player_name()
-- Run checks
if (not playern or not nodedug or not mod or not item) then
return
end
awards.assertPlayer(playern)
awards.tbv(awards.players[playern].place, mod)
awards.tbv(awards.players[playern].place[mod], item, 0)
-- Increment counter
awards.players[playern].place[mod][item] = awards.players[playern].place[mod][item] + 1
-- Run callbacks and triggers
local player = digger
local data = awards.players[playern]
for i=1,# awards.onPlace do
local res = nil
if type(awards.onPlace[i]) == "function" then
-- Run trigger callback
res = awards.onPlace[i](player,data)
elseif type(awards.onPlace[i]) == "table" then
-- Handle table trigger
if not awards.onPlace[i].node or not awards.onPlace[i].target or not awards.onPlace[i].award then
print("[ERROR] awards - onPlace trigger "..i.." is invalid!")
else
-- run the table
local tnodedug = string.split(awards.onPlace[i].node, ":")
local tmod = tnodedug[1]
local titem = tnodedug[2]
if tmod==nil or titem==nil or not data.place[tmod] or not data.place[tmod][titem] then
-- table running failed!
elseif data.place[tmod][titem] > awards.onPlace[i].target-1 then
res = awards.onPlace[i].award
end
end
end
if res then
awards.give_achievement(playern,res)
end
end
end)
minetest.register_on_dieplayer(function(player)
-- Run checks
local name = player:get_player_name()
if not player or not name or name=="" then
return
end
-- Get player
awards.assertPlayer(name)
local data = awards.players[name]
-- Increment counter
data.deaths = data.deaths + 1
-- Run callbacks and triggers
for _,trigger in pairs(awards.onDeath) do
local res = nil
if type(trigger) == "function" then
res = trigger(player,data)
elseif type(trigger) == "table" then
if trigger.target and trigger.award then
if data.deaths and data.deaths >= trigger.target then
res = trigger.award
end
end
end
if res ~= nil then
awards.give_achievement(name,res)
end
end
end)
minetest.register_on_joinplayer(function(player)
-- Run checks
local name = player:get_player_name()
if not player or not name or name=="" then
return
end
-- Get player
awards.assertPlayer(name)
local data = awards.players[name]
-- Increment counter
data.joins = data.joins + 1
-- Run callbacks and triggers
for _,trigger in pairs(awards.onJoin) do
local res = nil
if type(trigger) == "function" then
res = trigger(player,data)
elseif type(trigger) == "table" then
if trigger.target and trigger.award then
if data.joins and data.joins >= trigger.target then
res = trigger.award
end
end
end
if res ~= nil then
awards.give_achievement(name,res)
end
end
end)
minetest.register_on_chat_message(function(name, message)
-- Run checks
local idx = string.find(message,"/")
if not name or (idx ~= nil and idx <= 1) then
return
end
-- Get player
awards.assertPlayer(name)
local data = awards.players[name]
local player = minetest.get_player_by_name(name)
-- Increment counter
data.chats = data.chats + 1
-- Run callbacks and triggers
for _,trigger in pairs(awards.onChat) do
local res = nil
if type(trigger) == "function" then
res = trigger(player,data)
elseif type(trigger) == "table" then
if trigger.target and trigger.award then
if data.chats and data.chats >= trigger.target then
res = trigger.award
end
end
end
if res ~= nil then
awards.give_achievement(name,res)
end
end
end)
minetest.register_on_newplayer(function(player)
local playern = player:get_player_name()
awards.assertPlayer(playern)
end)
minetest.register_on_shutdown(function()
awards.save()
end)

733
mods/bees/init.lua

@ -1,358 +1,425 @@
--Bees mod by bas080
--[[TODO
Smoker
Grafting Tool
--Bees
------
--Author Bas080
--Version 2.0
--License WTFPL
--[[TODO
smoker maybe
Spreading bee colonies
x Grafting Tool - to remove queen bees from wild hives
x Make flowers reproduce when near a hive
x Add formspec to twild hive when using grafting tool
]]
local sound = {}
local particles = {}
--VARIABLES
local sound = {}
local particles = {}
local bees = {}
local formspecs = {}
--nodes
minetest.register_node("bees:bees", {
description = "Wild Bees",
drawtype = "plantlike",
paramtype = "light",
tiles = {
{
name="bees_strip.png",
animation={type="vertical_frames", aspect_w=16,aspect_h=16, length=2.0}
}
},
damage_per_second = 1,
walkable = false,
buildable_to = true,
pointable = false,
on_punch = function(pos, node, puncher)
local health = puncher:get_hp()
puncher:set_hp(health-2)
end,
on_construct = function(pos)
spawn_bees(pos)
end,
on_destruct = function(pos)
remove_bees(pos)
end,
})
minetest.register_node("bees:hive", {
description = "Wild Bee Hive",
tile_images = {"bees_hive_wild.png","bees_hive_wild.png","bees_hive_wild.png", "bees_hive_wild.png", "bees_hive_wild_bottom.png"}, --Neuromancer's base texture
drawtype = "nodebox",
paramtype = "light",
paramtype2 = 'wallmounted',
drop = {
max_items = 6,
items = {
{ items = {'bees:honey_comb'} },
{ items = {'bees:honey_comb'}, rarity = 2},
{ items = {'bees:honey_comb'}, rarity = 5},
{ items = {'bees:queen'}, rarity = 10 }
}
},
groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,attached_node=1},
node_box = { --VanessaE's wild hive nodebox contribution
type = "fixed",
fixed = {
{-0.250000,-0.500000,-0.250000,0.250000,0.375000,0.250000}, --NodeBox 2
{-0.312500,-0.375000,-0.312500,0.312500,0.250000,0.312500}, --NodeBox 4
{-0.375000,-0.250000,-0.375000,0.375000,0.125000,0.375000}, --NodeBox 5
{-0.062500,-0.500000,-0.062500,0.062500,0.500000,0.062500}, --NodeBox 6
}
},
on_construct = function(pos)
spawn_bees(pos)
minetest.get_node(pos).param2 = 0
end,
on_punch = function(pos, node, puncher)
local health = puncher:get_hp()
puncher:set_hp(health-2)
end,
after_dig_node = function(pos, oldnode, oldmetadata, user)
local wielded if user:get_wielded_item() ~= nil then wielded = user:get_wielded_item() else return end
if 'bees:grafting_tool' == wielded:get_name() then
local inv = user:get_inventory()
if inv then
inv:add_item("main", ItemStack("bees:queen"))
end
--FUNCTIONS
function formspecs.hive_wild(pos, grafting)
local spos = pos.x .. ',' .. pos.y .. ',' ..pos.z
local formspec =
'size[8,9]'..
'list[nodemeta:'.. spos .. ';combs;1.5,3;5,1;]'..
'list[current_player;main;0,5;8,4;]'
if grafting then
formspec = formspec..'list[nodemeta:'.. spos .. ';queen;3.5,1;1,1;]'
end
return formspec
end
})
minetest.register_node("bees:hive_artificial", {
description = "Bee Hive",
tiles = {"default_wood.png","default_wood.png","default_wood.png", "default_wood.png","default_wood.png","bees_hive_artificial.png"},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
{-4/8, 2/8, -4/8, 4/8, 3/8, 4/8},
{-3/8, -4/8, -2/8, 3/8, 2/8, 3/8},
{-3/8, 0/8, -3/8, 3/8, 2/8, -2/8},
{-3/8, -4/8, -3/8, 3/8, -1/8, -2/8},
{-3/8, -1/8, -3/8, -1/8, 0/8, -2/8},
{1/8, -1/8, -3/8, 3/8, 0/8, -2/8},
}
},
on_construct = function(pos)
local tmr = minetest.get_node_timer(pos)
tmr:start(10)
local meta = minetest.get_meta(pos)
meta:set_string('inhabited','false')
meta:set_string('infotext','Requires the Queen bee');
end,
})
function formspecs.hive_artificial(pos)
local spos = pos.x..','..pos.y..','..pos.z
local formspec =
'size[8,9]'..
'list[nodemeta:'..spos..';queen;3.5,1;1,1;]'..
'list[nodemeta:'..spos..';frames;0,3;8,1;]'..
'list[current_player;main;0,5;8,4;]'
return formspec
end
minetest.register_node("bees:hive_artificial_inhabited", {
description = "Bee Hive",
tiles = {"default_wood.png","default_wood.png","default_wood.png", "default_wood.png","default_wood.png","bees_hive_artificial.png"},
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-4/8, 2/8, -4/8, 4/8, 3/8, 4/8},
{-3/8, -4/8, -2/8, 3/8, 2/8, 3/8},
{-3/8, 0/8, -3/8, 3/8, 2/8, -2/8},
{-3/8, -4/8, -3/8, 3/8, -1/8, -2/8},
{-3/8, -1/8, -3/8, -1/8, 0/8, -2/8},
{1/8, -1/8, -3/8, 3/8, 0/8, -2/8},
}
},
drop = "bees:hive_artificial 1",
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
sounds = default.node_sound_wood_defaults(),
--on_punch = candles.collect,
on_timer = function(pos,elapsed)
local rad = 10
local minp = {x=pos.x-rad, y=pos.y-rad, z=pos.z-rad}
local maxp = {x=pos.x+rad, y=pos.y+rad, z=pos.z+rad}
local flower_in_area = minetest.find_nodes_in_area(minp, maxp, "group:flower")
local flower_number = 0
for i in ipairs(flower_in_area) do
flower_number = flower_number + 1
function bees.polinate_flower(pos, flower)
local spawn_pos = { x=pos.x+math.random(-3,3) , y=pos.y+math.random(-3,3) , z=pos.z+math.random(-3,3) }
local floor_pos = { x=spawn_pos.x , y=spawn_pos.y-1 , z=spawn_pos.z }
local spawn = minetest.get_node(spawn_pos).name
local floor = minetest.get_node(floor_pos).name
if floor == 'default:dirt_with_grass' and spawn == 'air' then
minetest.set_node(spawn_pos, {name=flower})
end
local meta = minetest.get_meta(pos)
local honey = meta:get_int("honey")
honey = honey + flower_number/10
if honey < 100 then
meta:set_string('infotext',honey.."%");
meta:set_int("honey", honey)
local tmr = minetest.get_node_timer(pos)
tmr:start(60)
else
meta:set_string('infotext',"100% - Time to harvest");
meta:set_int("honey", 100)
end
end,
on_construct = function(pos)
spawn_bees(pos)
local tmr = minetest.get_node_timer(pos)
tmr:start(60)
local meta = minetest.get_meta(pos)
meta:set_string('inhabited','false')
meta:set_int("honey", 0)
meta:set_string('infotext','0%');
end,
on_punch = function(pos, node, puncher)
local health = puncher:get_hp()
puncher:set_hp(health-2)
spawn_bees(pos)
end,
on_rightclick = function(pos, node, puncher)
local meta = minetest.get_meta(pos)
local honey = meta:get_int("honey")
if honey == 100 then
for i=math.random(1,3), 0, -1 do
local p = {x=pos.x+math.random()-0.5,y=pos.y+1,z=pos.z+math.random()-0.5}
minetest.add_item(p, "bees:honey_comb")
end
--NODES
minetest.register_node('bees:bees', {
description = 'Flying Bees',
drawtype = 'plantlike',
paramtype = 'light',
tiles = {
{
name='bees_strip.png',
animation={type='vertical_frames', aspect_w=16,aspect_h=16, length=2.0}
}
},
damage_per_second = 1,
walkable = false,
buildable_to = true,
pointable = false,
on_punch = function(pos, node, puncher)
local health = puncher:get_hp()
puncher:set_hp(health-2)
end,
})
minetest.register_node('bees:hive_wild', {
description = 'wild bee hive',
tile_images = {'bees_hive_wild.png','bees_hive_wild.png','bees_hive_wild.png', 'bees_hive_wild.png', 'bees_hive_wild_bottom.png'}, --Neuromancer's base texture
drawtype = 'nodebox',
paramtype = 'light',
paramtype2 = 'wallmounted',
drop = {
max_items = 6,
items = {
{ items = {'bees:honey_comb'}, rarity = 5}
}
},
groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,attached_node=1},
node_box = { --VanessaE's wild hive nodebox contribution
type = 'fixed',
fixed = {
{-0.250000,-0.500000,-0.250000,0.250000,0.375000,0.250000}, --NodeBox 2
{-0.312500,-0.375000,-0.312500,0.312500,0.250000,0.312500}, --NodeBox 4
{-0.375000,-0.250000,-0.375000,0.375000,0.125000,0.375000}, --NodeBox 5
{-0.062500,-0.500000,-0.062500,0.062500,0.500000,0.062500}, --NodeBox 6
}
},
on_timer = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local timer= minetest.get_node_timer(pos)
local rad = 10
local minp = {x=pos.x-rad, y=pos.y-rad, z=pos.z-rad}
local maxp = {x=pos.x+rad, y=pos.y+rad, z=pos.z+rad}
local flowers = minetest.find_nodes_in_area(minp, maxp, 'group:flower')
if #flowers == 0 then
inv:set_stack('queen', 1, '')
meta:set_string('infotext', 'this colony died, not enough flowers in area')
return
end --not any flowers nearby The queen dies!
if #flowers < 3 then return end --requires 2 or more flowers before can make honey
local flower = flowers[math.random(#flowers)]
bees.polinate_flower(flower, minetest.get_node(flower).name)
local stacks = inv:get_list('combs')
for k, v in pairs(stacks) do