2012-10-16 08:20:45 +00:00
-- Global variables
2013-02-02 13:43:55 +00:00
PLUGIN = {}; -- Reference to own plugin object
2013-02-06 18:22:30 +00:00
ShouldDumpFunctions = false ; -- If set to true, all available functions are logged upon plugin initialization
2012-10-16 08:20:45 +00:00
function Initialize ( Plugin )
PLUGIN = Plugin
Plugin : SetName ( "Debuggers" )
Plugin : SetVersion ( 1 )
PluginManager = cRoot : Get (): GetPluginManager ()
2013-02-08 20:57:42 +00:00
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_PLAYER_USING_ITEM );
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_TAKE_DAMAGE );
PluginManager : AddHook ( Plugin , cPluginManager.HOOK_CHUNK_GENERATED );
2012-10-16 08:20:45 +00:00
LOG ( "Initialized " .. Plugin : GetName () .. " v." .. Plugin : GetVersion ())
2013-01-26 03:44:09 +00:00
-- dump all available functions to console:
if ( ShouldDumpFunctions ) then
LOG ( "Dumping all available functions:" );
2013-02-02 13:43:55 +00:00
function dump ( prefix , a , Output )
2013-01-26 03:44:09 +00:00
for i , v in pairs ( a ) do
if ( type ( v ) == "table" ) then
2013-01-27 02:34:38 +00:00
if ( GetChar ( i , 1 ) ~= "." ) then
if ( v == _G ) then
LOG ( prefix .. i .. " == _G, CYCLE, ignoring" );
elseif ( v == _G.package ) then
LOG ( prefix .. i .. " == _G.package, ignoring" );
else
2013-02-02 13:43:55 +00:00
dump ( prefix .. i .. "." , v , Output )
2013-01-27 02:34:38 +00:00
end
2013-01-26 03:44:09 +00:00
end
elseif ( type ( v ) == "function" ) then
2013-02-02 13:43:55 +00:00
if ( string.sub ( i , 1 , 2 ) ~= "__" ) then
table.insert ( Output , prefix .. i .. "()" );
end
2013-01-27 02:34:38 +00:00
end
2013-01-26 03:44:09 +00:00
end
end
2013-02-02 13:43:55 +00:00
local Output = {};
dump ( "" , _G , Output );
table.sort ( Output );
local f = io.open ( "API.txt" , "w" );
for i , n in ipairs ( Output ) do
f : write ( n , " \n " );
end
f : close ();
2013-01-26 03:44:09 +00:00
end
2013-02-10 15:15:41 +00:00
-- Debug block area merging:
local BA1 = cBlockArea ();
local BA2 = cBlockArea ();
if ( BA1 : LoadFromSchematicFile ( "schematics/test.schematic" )) then
if ( BA2 : LoadFromSchematicFile ( "schematics/fountain.schematic" )) then
BA2 : SetRelBlockType ( 0 , 0 , 0 , E_BLOCK_LAPIS_BLOCK );
BA2 : SetRelBlockType ( 1 , 0 , 0 , E_BLOCK_LAPIS_BLOCK );
BA2 : SetRelBlockType ( 2 , 0 , 0 , E_BLOCK_LAPIS_BLOCK );
BA1 : Merge ( BA2 , 1 , 10 , 1 , cBlockArea.msImprint );
BA1 : SaveToSchematicFile ( "schematics/merge.schematic" );
end
end
2013-02-11 12:27:02 +00:00
-- Debug block area cuboid filling:
BA1 : FillRelCuboid ( 2 , 9 , 2 , 8 , 2 , 8 , cBlockArea.baTypes , E_BLOCK_GOLD_BLOCK );
2013-02-13 19:54:26 +00:00
BA1 : RelLine ( 2 , 2 , 2 , 9 , 8 , 8 , cBlockArea.baTypes or cBlockArea.baMetas , E_BLOCK_SAPLING , E_META_SAPLING_BIRCH );
2013-02-11 12:27:02 +00:00
BA1 : SaveToSchematicFile ( "schematics/fillrel.schematic" );
2013-01-26 03:44:09 +00:00
2012-10-16 08:20:45 +00:00
return true
end
2013-01-13 11:10:26 +00:00
function OnPlayerUsingItem ( Player , BlockX , BlockY , BlockZ , BlockFace , CursorX , CursorY , CursorZ )
2012-10-16 08:20:45 +00:00
-- dont check if the direction is in the air
2013-01-13 11:10:26 +00:00
if ( BlockFace == BLOCK_FACE_NONE ) then
2012-10-16 08:20:45 +00:00
return false
end
2013-01-13 11:10:26 +00:00
local HeldItem = Player : GetEquippedItem ();
2013-02-06 22:29:29 +00:00
2012-10-16 08:20:45 +00:00
if ( HeldItem.m_ItemType == E_ITEM_STICK ) then
-- Magic sTick of ticking: set the pointed block for ticking at the next tick
Player : SendMessage ( cChatColor.LightGray .. "Setting next block tick to {" .. BlockX .. ", " .. BlockY .. ", " .. BlockZ .. "}" )
Player : GetWorld (): SetNextBlockTick ( BlockX , BlockY , BlockZ );
return true
end
2013-02-06 22:29:29 +00:00
2012-10-16 08:20:45 +00:00
if ( HeldItem.m_ItemType == E_ITEM_BLAZE_ROD ) then
-- Magic rod of query: show block types and metas for both neighbors of the pointed face
local Type = 0 ;
local Meta = 0 ;
2013-01-13 11:10:26 +00:00
local Valid = false ;
Valid , Type , Meta = Player : GetWorld (): GetBlockTypeMeta ( BlockX , BlockY , BlockZ , Type , Meta );
2012-10-16 08:20:45 +00:00
if ( Type == E_BLOCK_AIR ) then
Player : SendMessage ( cChatColor.LightGray .. "Block {" .. BlockX .. ", " .. BlockY .. ", " .. BlockZ .. "}: air:" .. Meta );
else
local TempItem = cItem ( Type , 1 , Meta );
Player : SendMessage ( cChatColor.LightGray .. "Block {" .. BlockX .. ", " .. BlockY .. ", " .. BlockZ .. "}: " .. ItemToFullString ( TempItem ) .. " (" .. Type .. ":" .. Meta .. ")" );
end
local X = BlockX ;
local Y = BlockY ;
local Z = BlockZ ;
2013-01-13 11:10:26 +00:00
X , Y , Z = AddFaceDirection ( BlockX , BlockY , BlockZ , BlockFace );
Valid , Type , Meta = Player : GetWorld (): GetBlockTypeMeta ( X , Y , Z , Type , Meta );
2012-10-16 08:20:45 +00:00
if ( Type == E_BLOCK_AIR ) then
Player : SendMessage ( cChatColor.LightGray .. "Block {" .. X .. ", " .. Y .. ", " .. Z .. "}: air:" .. Meta );
else
local TempItem = cItem ( Type , 1 , Meta );
Player : SendMessage ( cChatColor.LightGray .. "Block {" .. X .. ", " .. Y .. ", " .. Z .. "}: " .. ItemToFullString ( TempItem ) .. " (" .. Type .. ":" .. Meta .. ")" );
return true ;
end
end
2013-02-06 18:22:30 +00:00
2013-02-06 22:29:29 +00:00
2013-02-09 11:03:22 +00:00
-- Rclk with a diamond to test block area cropping and expanding
2013-02-06 18:22:30 +00:00
if ( Player : GetEquippedItem (). m_ItemType == E_ITEM_DIAMOND ) then
local Area = cBlockArea ();
Area : Read ( Player : GetWorld (),
2013-02-09 11:03:22 +00:00
BlockX - 19 , BlockX + 19 ,
2013-02-06 18:22:30 +00:00
BlockY - 7 , BlockY + 7 ,
2013-02-09 11:03:22 +00:00
BlockZ - 19 , BlockZ + 19
2013-02-06 18:22:30 +00:00
);
LOG ( "Size before cropping: " .. Area : GetSizeX () .. " x " .. Area : GetSizeY () .. " x " .. Area : GetSizeZ ());
Area : DumpToRawFile ( "crop0.dat" );
2013-02-09 11:03:22 +00:00
2013-02-06 18:22:30 +00:00
Area : Crop ( 2 , 3 , 0 , 0 , 0 , 0 );
LOG ( "Size after cropping 1: " .. Area : GetSizeX () .. " x " .. Area : GetSizeY () .. " x " .. Area : GetSizeZ ());
Area : DumpToRawFile ( "crop1.dat" );
2013-02-09 11:03:22 +00:00
2013-02-06 18:22:30 +00:00
Area : Crop ( 2 , 3 , 0 , 0 , 0 , 0 );
LOG ( "Size after cropping 2: " .. Area : GetSizeX () .. " x " .. Area : GetSizeY () .. " x " .. Area : GetSizeZ ());
Area : DumpToRawFile ( "crop2.dat" );
2013-02-09 11:03:22 +00:00
Area : Expand ( 2 , 3 , 0 , 0 , 0 , 0 );
LOG ( "Size after expanding 1: " .. Area : GetSizeX () .. " x " .. Area : GetSizeY () .. " x " .. Area : GetSizeZ ());
Area : DumpToRawFile ( "expand1.dat" );
Area : Expand ( 3 , 2 , 1 , 1 , 0 , 0 );
LOG ( "Size after expanding 2: " .. Area : GetSizeX () .. " x " .. Area : GetSizeY () .. " x " .. Area : GetSizeZ ());
Area : DumpToRawFile ( "expand2.dat" );
2013-02-06 18:22:30 +00:00
Area : Crop ( 0 , 0 , 0 , 0 , 3 , 2 );
LOG ( "Size after cropping 3: " .. Area : GetSizeX () .. " x " .. Area : GetSizeY () .. " x " .. Area : GetSizeZ ());
Area : DumpToRawFile ( "crop3.dat" );
2013-02-09 11:03:22 +00:00
2013-02-06 18:22:30 +00:00
Area : Crop ( 0 , 0 , 3 , 2 , 0 , 0 );
LOG ( "Size after cropping 4: " .. Area : GetSizeX () .. " x " .. Area : GetSizeY () .. " x " .. Area : GetSizeZ ());
Area : DumpToRawFile ( "crop4.dat" );
LOG ( "Crop test done" );
2013-02-09 11:03:22 +00:00
Player : SendMessage ( "Crop / expand test done." );
2013-02-06 18:22:30 +00:00
return false ;
end
2013-02-06 22:29:29 +00:00
-- Rclk with an eye of ender places a predefined schematic at the cursor
if ( Player : GetEquippedItem (). m_ItemType == E_ITEM_EYE_OF_ENDER ) then
local Area = cBlockArea ();
if not ( Area : LoadFromSchematicFile ( "schematics/test.schematic" )) then
LOG ( "Loading failed" );
return false ;
end
LOG ( "Schematic loaded, placing now." );
Area : Write ( Player : GetWorld (), BlockX , BlockY , BlockZ );
LOG ( "Done." );
return false ;
end
2013-02-07 10:09:42 +00:00
2013-02-07 10:45:30 +00:00
-- Rclk with an ender pearl saves a predefined area around the cursor into a .schematic file. Also tests area copying
2013-02-07 10:09:42 +00:00
if ( Player : GetEquippedItem (). m_ItemType == E_ITEM_ENDER_PEARL ) then
local Area = cBlockArea ();
if not ( Area : Read ( Player : GetWorld (),
BlockX - 8 , BlockX + 8 , BlockY - 8 , BlockY + 8 , BlockZ - 8 , BlockZ + 8 )
) then
LOG ( "LUA: Area couldn't be read" );
return false ;
end
2013-02-07 10:45:30 +00:00
LOG ( "LUA: Area read, copying now." );
local Area2 = cBlockArea ();
Area2 : CopyFrom ( Area );
LOG ( "LUA: Copied, now saving." );
if not ( Area2 : SaveToSchematicFile ( "schematics/test.schematic" )) then
2013-02-07 10:09:42 +00:00
LOG ( "LUA: Cannot save schematic file." );
return false ;
end
LOG ( "LUA: Done." );
return false ;
end
2012-10-16 08:20:45 +00:00
end
2012-12-21 11:22:46 +00:00
function OnTakeDamage ( Receiver , TDI )
-- Receiver is cPawn
-- TDI is TakeDamageInfo
LOG ( Receiver : GetClass () .. " was dealt RawDamage " .. TDI.RawDamage .. ", FinalDamage " .. TDI.FinalDamage .. " (that is, " .. ( TDI.RawDamage - TDI.FinalDamage ) .. " HPs covered by armor)" );
end
2013-02-08 20:57:42 +00:00
function OnChunkGenerated ( World , ChunkX , ChunkZ , ChunkDesc )
-- Test ChunkDesc / BlockArea interaction
local BlockArea = cBlockArea ();
ChunkDesc : ReadBlockArea ( BlockArea , 0 , 15 , 50 , 70 , 0 , 15 );
2013-02-09 11:03:22 +00:00
-- BlockArea:SaveToSchematicFile("ChunkBlocks_" .. ChunkX .. "_" .. ChunkZ .. ".schematic");
2013-02-08 20:57:42 +00:00
ChunkDesc : WriteBlockArea ( BlockArea , 5 , 115 , 5 );
return false ;
end