diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-19 23:58:22 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-19 23:58:22 +0200 |
commit | 47f963ba720b4eb47eaada44368b01c05159fb41 (patch) | |
tree | c4810f3028e99b6137c559bd0ef99363dda4d7ad | |
parent | Removed json-related methods from Lua API (diff) | |
download | cuberite-47f963ba720b4eb47eaada44368b01c05159fb41.tar cuberite-47f963ba720b4eb47eaada44368b01c05159fb41.tar.gz cuberite-47f963ba720b4eb47eaada44368b01c05159fb41.tar.bz2 cuberite-47f963ba720b4eb47eaada44368b01c05159fb41.tar.lz cuberite-47f963ba720b4eb47eaada44368b01c05159fb41.tar.xz cuberite-47f963ba720b4eb47eaada44368b01c05159fb41.tar.zst cuberite-47f963ba720b4eb47eaada44368b01c05159fb41.zip |
-rw-r--r-- | Plugins/Core/main.lua | 88 | ||||
-rw-r--r-- | Plugins/Core/oncraftingnorecipe.lua | 205 |
2 files changed, 249 insertions, 44 deletions
diff --git a/Plugins/Core/main.lua b/Plugins/Core/main.lua index 4ef67e424..ed2692349 100644 --- a/Plugins/Core/main.lua +++ b/Plugins/Core/main.lua @@ -16,54 +16,54 @@ function Initialize( Plugin ) Plugin:SetVersion( 8 )
PluginManager = cRoot:Get():GetPluginManager()
- PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_PLAYER_JOIN )
- PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_LOGIN )
- PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_PLACE )
- PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_BLOCK_DIG )
- PluginManager:AddHook( Plugin, cPluginManager.E_PLUGIN_KILLED )
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_JOIN)
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN)
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_PLACE)
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_DIG)
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLED)
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE)
- Plugin:AddCommand("/help", " - [Page] Show this message", "core.help")
- Plugin:AddCommand("/pluginlist", " - Show list of plugins", "core.pluginlist")
- Plugin:AddCommand("/tp", " - [Player] - Teleport yourself to a player", "core.teleport")
- Plugin:AddCommand("/item", " - [ItemID/Name] <Amount> - Spawn an item for yourself", "core.item")
- Plugin:AddCommand("/list", " - Shows list of connected players", "core.playerlist")
- Plugin:AddCommand("/motd", " - Show message of the day", "core.motd")
- Plugin:AddCommand("/reload", " - Reload all plugins", "core.reload")
- Plugin:AddCommand("/time", " - [Day/Night] - Sets the time of day", "core.time")
- Plugin:AddCommand("/spawn", " - Return to the spawn", "core.spawn")
- Plugin:AddCommand("/kick", " - [Player] - Kick a player", "core.kick")
- Plugin:AddCommand("/ban", " - [Player] - Ban a player", "core.ban")
- Plugin:AddCommand("/unban", " - [Player] - Unban a player", "core.unban")
- Plugin:AddCommand("/top", " - Teleport yourself to the top most block", "core.top")
- Plugin:AddCommand("/gm", " - [Gamemode (0|1)] - Change your gamemode", "core.changegm")
- Plugin:AddCommand("/gotoworld", " - Move to a different world!", "core.gotoworld")
- Plugin:AddCommand("/coords", " - Show your current server coordinates", "core.coords")
+ Plugin:AddCommand("/help", " - [Page] Show this message", "core.help")
+ Plugin:AddCommand("/pluginlist", " - Show list of plugins", "core.pluginlist")
+ Plugin:AddCommand("/tp", " - [Player] - Teleport yourself to a player", "core.teleport")
+ Plugin:AddCommand("/item", " - [ItemID/Name] <Amount> - Spawn an item for yourself", "core.item")
+ Plugin:AddCommand("/list", " - Shows list of connected players", "core.playerlist")
+ Plugin:AddCommand("/motd", " - Show message of the day", "core.motd")
+ Plugin:AddCommand("/reload", " - Reload all plugins", "core.reload")
+ Plugin:AddCommand("/time", " - [Day/Night] - Sets the time of day", "core.time")
+ Plugin:AddCommand("/spawn", " - Return to the spawn", "core.spawn")
+ Plugin:AddCommand("/kick", " - [Player] - Kick a player", "core.kick")
+ Plugin:AddCommand("/ban", " - [Player] - Ban a player", "core.ban")
+ Plugin:AddCommand("/unban", " - [Player] - Unban a player", "core.unban")
+ Plugin:AddCommand("/top", " - Teleport yourself to the top most block", "core.top")
+ Plugin:AddCommand("/gm", " - [Gamemode (0|1)] - Change your gamemode", "core.changegm")
+ Plugin:AddCommand("/gotoworld", " - Move to a different world!", "core.gotoworld")
+ Plugin:AddCommand("/coords", " - Show your current server coordinates", "core.coords")
Plugin:AddCommand("/viewdistance", " - [".. cClientHandle.MIN_VIEW_DISTANCE .."-".. cClientHandle.MAX_VIEW_DISTANCE .."] - Change your view distance", "core.viewdistance")
Plugin:AddCommand("/regeneratechunk", " - <X [Z]> - Regenerates a chunk", "core.regeneratechunk")
- Plugin:BindCommand( "/help", "core.help", HandleHelpCommand )
- Plugin:BindCommand( "/pluginlist", "core.pluginlist", HandlePluginListCommand )
- Plugin:BindCommand( "/tp", "core.teleport", HandleTPCommand )
- Plugin:BindCommand( "/item", "core.item", HandleItemCommand )
- Plugin:BindCommand( "/i", "core.item", HandleItemCommand )
- Plugin:BindCommand( "/list", "core.playerlist", HandlePlayerListCommand )
- Plugin:BindCommand( "/who", "core.playerlist", HandlePlayerListCommand )
- Plugin:BindCommand( "/playerlist", "core.playerlist", HandlePlayerListCommand )
- Plugin:BindCommand( "/motd", "core.motd", HandleMOTDCommand )
- Plugin:BindCommand( "/reload", "core.reload", HandleReloadCommand )
- Plugin:BindCommand( "/time", "core.time", HandleTimeCommand )
- Plugin:BindCommand( "/spawn", "core.spawn", HandleSpawnCommand )
- Plugin:BindCommand( "/home", "core.spawn", HandleSpawnCommand )
- Plugin:BindCommand( "/kick", "core.kick", HandleKickCommand )
- Plugin:BindCommand( "/ban", "core.ban", HandleBanCommand )
- Plugin:BindCommand( "/unban", "core.unban", HandleUnbanCommand )
- Plugin:BindCommand( "/top", "core.top", HandleTopCommand )
- Plugin:BindCommand( "/gm", "core.changegm", HandleChangeGMCommand )
- Plugin:BindCommand( "/gotoworld", "core.gotoworld", HandleGotoWorldCommand )
- Plugin:BindCommand( "/coords", "core.coords", HandleCoordsCommand )
- Plugin:BindCommand( "/viewdistance","core.viewdistance", HandleViewDistanceCommand )
- Plugin:BindCommand( "/regeneratechunk","core.regeneratechunk", HandleRegenerateChunkCommand )
-
+ Plugin:BindCommand( "/help", "core.help", HandleHelpCommand )
+ Plugin:BindCommand( "/pluginlist", "core.pluginlist", HandlePluginListCommand )
+ Plugin:BindCommand( "/tp", "core.teleport", HandleTPCommand )
+ Plugin:BindCommand( "/item", "core.item", HandleItemCommand )
+ Plugin:BindCommand( "/i", "core.item", HandleItemCommand )
+ Plugin:BindCommand( "/list", "core.playerlist", HandlePlayerListCommand )
+ Plugin:BindCommand( "/who", "core.playerlist", HandlePlayerListCommand )
+ Plugin:BindCommand( "/playerlist", "core.playerlist", HandlePlayerListCommand )
+ Plugin:BindCommand( "/motd", "core.motd", HandleMOTDCommand )
+ Plugin:BindCommand( "/reload", "core.reload", HandleReloadCommand )
+ Plugin:BindCommand( "/time", "core.time", HandleTimeCommand )
+ Plugin:BindCommand( "/spawn", "core.spawn", HandleSpawnCommand )
+ Plugin:BindCommand( "/home", "core.spawn", HandleSpawnCommand )
+ Plugin:BindCommand( "/kick", "core.kick", HandleKickCommand )
+ Plugin:BindCommand( "/ban", "core.ban", HandleBanCommand )
+ Plugin:BindCommand( "/unban", "core.unban", HandleUnbanCommand )
+ Plugin:BindCommand( "/top", "core.top", HandleTopCommand )
+ Plugin:BindCommand( "/gm", "core.changegm", HandleChangeGMCommand )
+ Plugin:BindCommand( "/gotoworld", "core.gotoworld", HandleGotoWorldCommand )
+ Plugin:BindCommand( "/coords", "core.coords", HandleCoordsCommand )
+ Plugin:BindCommand( "/viewdistance", "core.viewdistance", HandleViewDistanceCommand )
+ Plugin:BindCommand( "/regeneratechunk", "core.regeneratechunk", HandleRegenerateChunkCommand )
local IniFile = cIniFile("settings.ini")
if ( IniFile:ReadFile() == true ) then
diff --git a/Plugins/Core/oncraftingnorecipe.lua b/Plugins/Core/oncraftingnorecipe.lua new file mode 100644 index 000000000..78f2cf65a --- /dev/null +++ b/Plugins/Core/oncraftingnorecipe.lua @@ -0,0 +1,205 @@ +
+-- Implements item-repair using the HOOK_CRAFTING_NO_RECIPE hook
+-- Based on Fixies plugin v2 by Taugeshtu
+
+
+-- how much "extra" points are healed per a repair operation (fraction)
+BONUS = 0.1
+
+
+
+
+
+function OnCraftingNoRecipe(Player, Grid, Recipe)
+ local _do_fix = false
+ local Items = {}
+ for x = 0, Grid:GetWidth() - 1 do
+ for y = 0, Grid:GetHeight() - 1 do
+ local Item = Grid:GetItem(x, y)
+ if (Item.m_ItemID ~= E_ITEM_EMPTY) then
+ table.insert(Items, Item)
+ end
+ end
+ end
+
+ if (#Items ~= 2) then
+ -- Only two items together can be fixed
+ return false
+ end
+
+ if (Items[1].m_ItemID ~= Items[2].m_ItemID) then
+ -- Only same items may be fixed
+ return false
+ end
+
+ local _ID = Items[1].m_ItemID
+ local _least_hp = math.max(Items[1].m_ItemHealth, Items[2].m_ItemHealth)
+ local _most_hp = math.min(Items[1].m_ItemHealth, Items[2].m_ItemHealth)
+ local _item_hp = 0
+
+ -- TODO: This could be refactored into better code, using an _ID-indexed table for _item_hp
+
+ if (
+ (_ID == E_ITEM_WOODEN_SHOVEL) or
+ (_ID == E_ITEM_WOODEN_AXE) or
+ (_ID == E_ITEM_WOODEN_PICKAXE) or
+ (_ID == E_ITEM_WOODEN_SWORD) or
+ (_ID == E_ITEM_WOODEN_HOE)
+ )
+ then
+ _item_hp = 60
+ _do_fix = true
+ end
+
+ if (
+ (_ID == E_ITEM_STONE_SHOVEL) or
+ (_ID == E_ITEM_STONE_AXE) or
+ (_ID == E_ITEM_STONE_PICKAXE) or
+ (_ID == E_ITEM_STONE_SWORD) or
+ (_ID == E_ITEM_STONE_HOE)
+ )
+ then
+ _item_hp = 132
+ _do_fix = true
+ end
+
+ if (
+ (_ID == E_ITEM_IRON_SHOVEL) or
+ (_ID == E_ITEM_IRON_AXE) or
+ (_ID == E_ITEM_IRON_PICKAXE) or
+ (_ID == E_ITEM_IRON_SWORD) or
+ (_ID == E_ITEM_IRON_HOE)
+ )
+ then
+ _item_hp = 251
+ _do_fix = true
+ end
+
+ if (
+ (_ID == E_ITEM_GOLD_SHOVEL) or
+ (_ID == E_ITEM_GOLD_AXE) or
+ (_ID == E_ITEM_GOLD_PICKAXE) or
+ (_ID == E_ITEM_GOLD_SWORD) or
+ (_ID == E_ITEM_GOLD_HOE)
+ )
+ then
+ _item_hp = 33
+ _do_fix = true
+ end
+
+ if (
+ (_ID == E_ITEM_DIAMOND_SHOVEL) or
+ (_ID == E_ITEM_DIAMOND_AXE) or
+ (_ID == E_ITEM_DIAMOND_PICKAXE) or
+ (_ID == E_ITEM_DIAMOND_SWORD) or
+ (_ID == E_ITEM_DIAMOND_HOE)
+ )
+ then
+ _item_hp = 1562
+ _do_fix = true
+ end
+
+ if (_ID == E_ITEM_LEATHER_CAP) then
+ _item_hp = 56
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_LEATHER_TUNIC) then
+ _item_hp = 82
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_LEATHER_PANTS) then
+ _item_hp = 76
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_LEATHER_BOOTS) then
+ _item_hp = 66
+ _do_fix = true
+ end
+
+
+ if (_ID == E_ITEM_CHAIN_HELMET) then
+ _item_hp = 78
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_CHAIN_CHESTPLATE) then
+ _item_hp = 114
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_CHAIN_LEGGINGS) then
+ _item_hp = 106
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_CHAIN_BOOTS) then
+ _item_hp = 92
+ _do_fix = true
+ end
+
+
+ if (_ID == E_ITEM_IRON_HELMET) then
+ _item_hp = 166
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_IRON_CHESTPLATE) then
+ _item_hp = 242
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_IRON_LEGGINGS) then
+ _item_hp = 226
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_IRON_BOOTS) then
+ _item_hp = 196
+ _do_fix = true
+ end
+
+
+ if (_ID == E_ITEM_GOLD_HELMET) then
+ _item_hp = 78
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_GOLD_CHESTPLATE) then
+ _item_hp = 114
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_GOLD_LEGGINGS) then
+ _item_hp = 106
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_GOLD_BOOTS) then
+ _item_hp = 92
+ _do_fix = true
+ end
+
+
+ if (_ID == E_ITEM_DIAMOND_HELMET) then
+ _item_hp = 364
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_DIAMOND_CHESTPLATE)then
+ _item_hp = 529
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_DIAMOND_LEGGINGS) then
+ _item_hp = 496
+ _do_fix = true
+ end
+ if (_ID == E_ITEM_DIAMOND_BOOTS) then
+ _item_hp = 430
+ _do_fix = true
+ end
+ -- /////////////////////////////////////////////////////
+
+ if (_do_fix == true) then
+ local _hp = _most_hp - (_item_hp - _least_hp) - _item_hp * BONUS
+ _hp = math.max(_hp, 0)
+ Recipe:SetResult(_ID, 1, _hp)
+ Recipe:SetIngredient(Items[1].x, Items[1].y, Items[1]);
+ Recipe:SetIngredient(Items[2].x, Items[2].y, Items[2]);
+ return true
+ end
+ return false
+end
+
+
+
+
|