From fed37bca4d12579741be97e7994f1d4b8df4bbfd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 20 Nov 2013 21:54:37 +0100 Subject: Debuggers: Test harness for cWorld:ForEachBlockEntityInChunk(). The fill command will fill all empty slots in block entities with containment with gold nuggets, one per slot. --- MCServer/Plugins/Debuggers/Debuggers.lua | 78 ++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 19 deletions(-) (limited to 'MCServer/Plugins/Debuggers/Debuggers.lua') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 9350606cc..c4811b91a 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -28,25 +28,26 @@ function Initialize(Plugin) cPluginManager.AddHook(cPluginManager.HOOK_WORLD_TICK, OnWorldTick); cPluginManager.AddHook(cPluginManager.HOOK_CHUNK_GENERATED, OnChunkGenerated); - PluginManager = cRoot:Get():GetPluginManager(); - PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities"); - PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities"); - PluginManager:BindCommand("/wool", "debuggers", HandleWoolCmd, "- Sets all your armor to blue wool"); - PluginManager:BindCommand("/testwnd", "debuggers", HandleTestWndCmd, "- Opens up a window using plugin API"); - PluginManager:BindCommand("/gc", "debuggers", HandleGCCmd, "- Activates the Lua garbage collector"); - PluginManager:BindCommand("/fast", "debuggers", HandleFastCmd, "- Switches between fast and normal movement speed"); - PluginManager:BindCommand("/dash", "debuggers", HandleDashCmd, "- Switches between fast and normal sprinting speed"); - PluginManager:BindCommand("/hunger", "debuggers", HandleHungerCmd, "- Lists the current hunger-related variables"); - PluginManager:BindCommand("/poison", "debuggers", HandlePoisonCmd, "- Sets food-poisoning for 15 seconds"); - PluginManager:BindCommand("/starve", "debuggers", HandleStarveCmd, "- Sets the food level to zero"); - PluginManager:BindCommand("/fl", "debuggers", HandleFoodLevelCmd, "- Sets the food level to the given value"); - PluginManager:BindCommand("/spidey", "debuggers", HandleSpideyCmd, "- Shoots a line of web blocks until it hits non-air"); - PluginManager:BindCommand("/ench", "debuggers", HandleEnchCmd, "- Provides an instant dummy enchantment window"); - PluginManager:BindCommand("/fs", "debuggers", HandleFoodStatsCmd, "- Turns regular foodstats message on or off"); - PluginManager:BindCommand("/arr", "debuggers", HandleArrowCmd, "- Creates an arrow going away from the player"); - PluginManager:BindCommand("/fb", "debuggers", HandleFireballCmd, "- Creates a ghast fireball as if shot by the player"); - PluginManager:BindCommand("/xpa", "debuggers", HandleAddExperience, "- Adds 200 experience to the player"); - PluginManager:BindCommand("/xpr", "debuggers", HandleRemoveXp, "- Remove all xp"); + PM = cRoot:Get():GetPluginManager(); + PM:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "- Shows a list of all the loaded entities"); + PM:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "- Kills all the loaded entities"); + PM:BindCommand("/wool", "debuggers", HandleWoolCmd, "- Sets all your armor to blue wool"); + PM:BindCommand("/testwnd", "debuggers", HandleTestWndCmd, "- Opens up a window using plugin API"); + PM:BindCommand("/gc", "debuggers", HandleGCCmd, "- Activates the Lua garbage collector"); + PM:BindCommand("/fast", "debuggers", HandleFastCmd, "- Switches between fast and normal movement speed"); + PM:BindCommand("/dash", "debuggers", HandleDashCmd, "- Switches between fast and normal sprinting speed"); + PM:BindCommand("/hunger", "debuggers", HandleHungerCmd, "- Lists the current hunger-related variables"); + PM:BindCommand("/poison", "debuggers", HandlePoisonCmd, "- Sets food-poisoning for 15 seconds"); + PM:BindCommand("/starve", "debuggers", HandleStarveCmd, "- Sets the food level to zero"); + PM:BindCommand("/fl", "debuggers", HandleFoodLevelCmd, "- Sets the food level to the given value"); + PM:BindCommand("/spidey", "debuggers", HandleSpideyCmd, "- Shoots a line of web blocks until it hits non-air"); + PM:BindCommand("/ench", "debuggers", HandleEnchCmd, "- Provides an instant dummy enchantment window"); + PM:BindCommand("/fs", "debuggers", HandleFoodStatsCmd, "- Turns regular foodstats message on or off"); + PM:BindCommand("/arr", "debuggers", HandleArrowCmd, "- Creates an arrow going away from the player"); + PM:BindCommand("/fb", "debuggers", HandleFireballCmd, "- Creates a ghast fireball as if shot by the player"); + PM:BindCommand("/xpa", "debuggers", HandleAddExperience, "- Adds 200 experience to the player"); + PM:BindCommand("/xpr", "debuggers", HandleRemoveXp, "- Remove all xp"); + PM:BindCommand("/fill", "debuggers", HandleFill, "- Fills all block entities in current chunk with junk"); -- Enable the following line for BlockArea / Generator interface testing: -- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED); @@ -863,3 +864,42 @@ function HandleRemoveXp(a_Split, a_Player) return true; end + + + + + +function HandleFill(a_Split, a_Player) + local World = a_Player:GetWorld(); + local ChunkX = a_Player:GetChunkX(); + local ChunkZ = a_Player:GetChunkZ(); + World:ForEachBlockEntityInChunk(ChunkX, ChunkZ, + function(a_BlockEntity) + local BlockType = a_BlockEntity:GetBlockType(); + if ( + (BlockType == E_BLOCK_CHEST) or + (BlockType == E_BLOCK_DISPENSER) or + (BlockType == E_BLOCK_DROPPER) or + (BlockType == E_BLOCK_FURNACE) or + (BlockType == E_BLOCK_HOPPER) + ) then + -- This block entity has items (inherits from cBlockEntityWithItems), fill it: + -- Note that we're not touching lit furnaces, don't wanna mess them up + local EntityWithItems = tolua.cast(a_BlockEntity, "cBlockEntityWithItems"); + local ItemGrid = EntityWithItems:GetContents(); + local NumSlots = ItemGrid:GetNumSlots(); + local ItemToSet = cItem(E_ITEM_GOLD_NUGGET); + for i = 0, NumSlots - 1 do + if (ItemGrid:GetSlot(i):IsEmpty()) then + ItemGrid:SetSlot(i, ItemToSet); + end + end + end + end + ); + return true; +end + + + + -- cgit v1.2.3 From 07a1de8ebb58f61f2cd37db0e3382f0df9a784f0 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 22 Nov 2013 12:26:39 +0100 Subject: Debuggers: Added a test harness for cRoot:GetFurnaceRecipe(). The "/fr" command lists the furnace recipe for the currently held item. --- MCServer/Plugins/Debuggers/Debuggers.lua | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'MCServer/Plugins/Debuggers/Debuggers.lua') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index c4811b91a..e4c601da3 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -48,6 +48,7 @@ function Initialize(Plugin) PM:BindCommand("/xpa", "debuggers", HandleAddExperience, "- Adds 200 experience to the player"); PM:BindCommand("/xpr", "debuggers", HandleRemoveXp, "- Remove all xp"); PM:BindCommand("/fill", "debuggers", HandleFill, "- Fills all block entities in current chunk with junk"); + PM:BindCommand("/fr", "debuggers", HandleFurnaceRecipe, "- Shows the furnace recipe for the currently held item"); -- Enable the following line for BlockArea / Generator interface testing: -- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED); @@ -903,3 +904,23 @@ end + +function HandleFurnaceRecipe(a_Split, a_Player) + local HeldItem = a_Player:GetEquippedItem(); + local Out, NumTicks, In = cRoot.GetFurnaceRecipe(HeldItem); + if (Out ~= nil) then + a_Player:SendMessage( + "Furnace turns " .. ItemToFullString(In) .. + " to " .. ItemToFullString(Out) .. + " in " .. NumTicks .. " ticks (" .. + tostring(NumTicks / 20) .. " seconds)." + ); + else + a_Player:SendMessage("There is no furnace recipe that would smelt " .. ItemToString(HeldItem)); + end + return true; +end + + + + -- cgit v1.2.3 From 281bf8f90bbd295bb81ec09889bcaeefa689e6b2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 22 Nov 2013 16:50:03 +0100 Subject: Added cRoot:GetFurnaceFuelBurnTime() to Lua API. --- MCServer/Plugins/Debuggers/Debuggers.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'MCServer/Plugins/Debuggers/Debuggers.lua') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index e4c601da3..682a54676 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -49,6 +49,7 @@ function Initialize(Plugin) PM:BindCommand("/xpr", "debuggers", HandleRemoveXp, "- Remove all xp"); PM:BindCommand("/fill", "debuggers", HandleFill, "- Fills all block entities in current chunk with junk"); PM:BindCommand("/fr", "debuggers", HandleFurnaceRecipe, "- Shows the furnace recipe for the currently held item"); + PM:BindCommand("/ff", "debuggers", HandleFurnaceFuel, "- Shows how long the currently held item would burn in a furnace"); -- Enable the following line for BlockArea / Generator interface testing: -- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED); @@ -907,7 +908,7 @@ end function HandleFurnaceRecipe(a_Split, a_Player) local HeldItem = a_Player:GetEquippedItem(); - local Out, NumTicks, In = cRoot.GetFurnaceRecipe(HeldItem); + local Out, NumTicks, In = cRoot:GetFurnaceRecipe(HeldItem); if (Out ~= nil) then a_Player:SendMessage( "Furnace turns " .. ItemToFullString(In) .. @@ -924,3 +925,21 @@ end + +function HandleFurnaceFuel(a_Split, a_Player) + local HeldItem = a_Player:GetEquippedItem(); + local NumTicks = cRoot:GetFurnaceFuelBurnTime(HeldItem); + if (NumTicks > 0) then + a_Player:SendMessage( + ItemToFullString(HeldItem) .. " would power a furnace for " .. NumTicks .. + " ticks (" .. tostring(NumTicks / 20) .. " seconds)." + ); + else + a_Player:SendMessage(ItemToString(HeldItem) .. " will not power furnaces."); + end + return true; +end + + + + -- cgit v1.2.3 From 63753c5e8405837931510b8da648dc75d4970fe1 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 22 Nov 2013 20:11:24 +0100 Subject: Added cFile:GetFolderContents(). Fix 162. --- MCServer/Plugins/Debuggers/Debuggers.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'MCServer/Plugins/Debuggers/Debuggers.lua') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index 682a54676..c9a610f71 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -51,6 +51,8 @@ function Initialize(Plugin) PM:BindCommand("/fr", "debuggers", HandleFurnaceRecipe, "- Shows the furnace recipe for the currently held item"); PM:BindCommand("/ff", "debuggers", HandleFurnaceFuel, "- Shows how long the currently held item would burn in a furnace"); + Plugin:AddWebTab("Debuggers", HandleRequest_Debuggers); + -- Enable the following line for BlockArea / Generator interface testing: -- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED); @@ -943,3 +945,12 @@ end + +function HandleRequest_Debuggers(a_Request) + local FolderContents = cFile:GetFolderContents("./"); + return "

The following objects have been returned by cFile:GetFolderContents():

  • " .. table.concat(FolderContents, "
  • ") .. "

"; +end + + + + -- cgit v1.2.3