From 5c3235ecdc3f718ce20e006f1ecfa2159df82c87 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 26 May 2013 14:39:04 +0000 Subject: Implemented droppers Added a common ancestor class "DropSpenser" that has the common code for dropper and dispenser and is Lua-accessible, too. The Debuggers plugin now triggers both droppers and dispensers when rclking them with a redstone torch. git-svn-id: http://mc-server.googlecode.com/svn/trunk@1514 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- MCServer/Plugins/Debuggers/Debuggers.lua | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'MCServer/Plugins/Debuggers') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 571f1f185..edb638e22 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -3,8 +3,7 @@ PLUGIN = {}; -- Reference to own plugin object ShouldDumpFunctions = true; -- If set to true, all available functions are logged upon plugin initialization -g_DispensersToActivate = {}; -- A list of dispensers (as {World, X, Y Z} quadruplets) that are to be activated every tick -g_DroppersToActivate = {}; -- A list of droppers (as {World, X, Y Z} quadruplets) that are to be activated every tick +g_DropSpensersToActivate = {}; -- A list of dispensers and droppers (as {World, X, Y Z} quadruplets) that are to be activated every tick @@ -366,11 +365,11 @@ function OnUsingRedstoneTorch(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX -- Redstone torch activates a rapid dispenser / dropper discharge (at every tick): local BlockType = Player:GetWorld():GetBlock(BlockX, BlockY, BlockZ); if (BlockType == E_BLOCK_DISPENSER) then - table.insert(g_DispensersToActivate, {World = Player:GetWorld(), x = BlockX, y = BlockY, z = BlockZ}); + table.insert(g_DropSpensersToActivate, {World = Player:GetWorld(), x = BlockX, y = BlockY, z = BlockZ}); Player:SendMessage("Dispenser at {" .. BlockX .. ", " .. BlockY .. ", " .. BlockZ .. "} discharging"); return true; elseif (BlockType == E_BLOCK_DROPPER) then - table.insert(g_DroppersToActivate, {World = Player:GetWorld(), x = BlockX, y = BlockY, z = BlockZ}); + table.insert(g_DropSpensersToActivate, {World = Player:GetWorld(), x = BlockX, y = BlockY, z = BlockZ}); Player:SendMessage("Dropper at {" .. BlockX .. ", " .. BlockY .. ", " .. BlockZ .. "} discharging"); return true; else @@ -445,20 +444,20 @@ end function OnTick() - -- Activate all dispensers in the g_DispensersToActivate list: - local ActivateDisp = function(Dispenser) - if (Dispenser:GetContents():GetFirstUsedSlot() == -1) then + -- Activate all dropspensers in the g_DropSpensersToActivate list: + local ActivateDrSp = function(DropSpenser) + if (DropSpenser:GetContents():GetFirstUsedSlot() == -1) then return true; end - Dispenser:Activate(); + DropSpenser:Activate(); return false; end - - local idx = #g_DispensersToActivate; + -- Walk the list backwards, because we're removing some items + local idx = #g_DropSpensersToActivate; for i = idx, 1, -1 do - local Disp = g_DispensersToActivate[i]; - if not(Disp.World:DoWithDispenserAt(Disp.x, Disp.y, Disp.z, ActivateDisp)) then - table.remove(g_DispensersToActivate, i); + local DrSp = g_DropSpensersToActivate[i]; + if not(DrSp.World:DoWithDropSpenserAt(DrSp.x, DrSp.y, DrSp.z, ActivateDrSp)) then + table.remove(g_DropSpensersToActivate, i); end end -- cgit v1.2.3