summaryrefslogtreecommitdiffstats
path: root/MCServer
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-25 14:03:20 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2013-05-25 14:03:20 +0200
commit41db106a8f72f62b4da736c053c1cc1808535730 (patch)
tree62ade47824fdeae1494bbc03223b5ae7d7220bb4 /MCServer
parentFixed WindowOwner implementation (diff)
downloadcuberite-41db106a8f72f62b4da736c053c1cc1808535730.tar
cuberite-41db106a8f72f62b4da736c053c1cc1808535730.tar.gz
cuberite-41db106a8f72f62b4da736c053c1cc1808535730.tar.bz2
cuberite-41db106a8f72f62b4da736c053c1cc1808535730.tar.lz
cuberite-41db106a8f72f62b4da736c053c1cc1808535730.tar.xz
cuberite-41db106a8f72f62b4da736c053c1cc1808535730.tar.zst
cuberite-41db106a8f72f62b4da736c053c1cc1808535730.zip
Diffstat (limited to 'MCServer')
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.deproj6
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua292
2 files changed, 194 insertions, 104 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.deproj b/MCServer/Plugins/Debuggers/Debuggers.deproj
new file mode 100644
index 000000000..5d25c5815
--- /dev/null
+++ b/MCServer/Plugins/Debuggers/Debuggers.deproj
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+ <file>
+ <filename>Debuggers.lua</filename>
+ </file>
+</project>
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 3f6dcfb7e..571f1f185 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -3,6 +3,9 @@
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
+
@@ -14,12 +17,14 @@ function Initialize(Plugin)
Plugin:SetVersion(1)
PluginManager = cRoot:Get():GetPluginManager()
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_BLOCK);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_TICK);
- 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("/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");
-- Enable the following line for BlockArea / Generator interface testing:
-- PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
@@ -244,6 +249,140 @@ end
+function OnUsingBlazeRod(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
+ -- Magic rod of query: show block types and metas for both neighbors of the pointed face
+ local Type, Meta, Valid = Player:GetWorld():GetBlockTypeMeta(BlockX, BlockY, BlockZ, Type, Meta);
+
+ 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, Y, Z = AddFaceDirection(BlockX, BlockY, BlockZ, BlockFace);
+ Valid, Type, Meta = Player:GetWorld():GetBlockTypeMeta(X, Y, Z, Type, Meta);
+ 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 .. ")");
+ end
+ return false;
+end
+
+
+
+
+
+function OnUsingDiamond(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
+ -- Rclk with a diamond to test block area cropping and expanding
+ local Area = cBlockArea();
+ Area:Read(Player:GetWorld(),
+ BlockX - 19, BlockX + 19,
+ BlockY - 7, BlockY + 7,
+ BlockZ - 19, BlockZ + 19
+ );
+
+ LOG("Size before cropping: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
+ Area:DumpToRawFile("crop0.dat");
+
+ 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");
+
+ 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");
+
+ 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");
+
+ 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");
+
+ 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");
+ Player:SendMessage("Crop / expand test done.");
+ return false;
+end
+
+
+
+
+
+function OnUsingEyeOfEnder(Player, BlockX, BlockY, BlockZ)
+ -- Rclk with an eye of ender places a predefined schematic at the cursor
+ 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
+
+
+
+
+
+function OnUsingEnderPearl(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
+ -- Rclk with an ender pearl saves a predefined area around the cursor into a .schematic file. Also tests area copying
+ 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
+ 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
+ LOG("LUA: Cannot save schematic file.");
+ return false;
+ end
+ LOG("LUA: Done.");
+ return false;
+end
+
+
+
+
+
+function OnUsingRedstoneTorch(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
+ -- 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});
+ 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});
+ Player:SendMessage("Dropper at {" .. BlockX .. ", " .. BlockY .. ", " .. BlockZ .. "} discharging");
+ return true;
+ else
+ Player:SendMessage("Neither a dispenser nor a dropper at {" .. BlockX .. ", " .. BlockY .. ", " .. BlockZ .. "}: " .. BlockType);
+ end
+ return false;
+end
+
+
+
+
+
function OnPlayerUsingItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
-- dont check if the direction is in the air
@@ -252,122 +391,41 @@ function OnPlayerUsingItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, C
end
local HeldItem = Player:GetEquippedItem();
+ local HeldItemType = HeldItem.m_ItemType;
-
- if (HeldItem.m_ItemType == E_ITEM_STICK) then
+ if (HeldItemType == 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
+ elseif (HeldItemType == E_ITEM_BLAZE_ROD) then
+ return OnUsingBlazeRod(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ);
+ elseif (HeldItemType == E_ITEM_DIAMOND) then
+ return OnUsingDiamond(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ);
+ elseif (HeldItemType == E_ITEM_EYE_OF_ENDER) then
+ return OnUsingEyeOfEnder(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ);
+ elseif (HeldItemType == E_ITEM_ENDER_PEARL) then
+ return OnUsingEnderPearl(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ);
end
+ return false;
+end
- 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;
- local Valid = false;
- Valid, Type, Meta = Player:GetWorld():GetBlockTypeMeta(BlockX, BlockY, BlockZ, Type, Meta);
-
- 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;
- X, Y, Z = AddFaceDirection(BlockX, BlockY, BlockZ, BlockFace);
- Valid, Type, Meta = Player:GetWorld():GetBlockTypeMeta(X, Y, Z, Type, Meta);
- 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
- -- Rclk with a diamond to test block area cropping and expanding
- if (Player:GetEquippedItem().m_ItemType == E_ITEM_DIAMOND) then
- local Area = cBlockArea();
- Area:Read(Player:GetWorld(),
- BlockX - 19, BlockX + 19,
- BlockY - 7, BlockY + 7,
- BlockZ - 19, BlockZ + 19
- );
-
- LOG("Size before cropping: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
- Area:DumpToRawFile("crop0.dat");
-
- 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");
-
- 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");
-
- 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");
-
- 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");
-
- 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");
- Player:SendMessage("Crop / expand test done.");
- return false;
+function OnPlayerUsingBlock(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ, BlockType, BlockMeta)
+ -- dont check if the direction is in the air
+ if (BlockFace == BLOCK_FACE_NONE) then
+ return false
end
+ local HeldItem = Player:GetEquippedItem();
+ local HeldItemType = HeldItem.m_ItemType;
- -- 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
-
-
- -- Rclk with an ender pearl saves a predefined area around the cursor into a .schematic file. Also tests area copying
- 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
- 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
- LOG("LUA: Cannot save schematic file.");
- return false;
- end
- LOG("LUA: Done.");
- return false;
+ if (HeldItemType == E_BLOCK_REDSTONE_TORCH_ON) then
+ return OnUsingRedstoneTorch(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ);
end
-
end
@@ -379,6 +437,32 @@ function OnTakeDamage(Receiver, TDI)
-- TDI is TakeDamageInfo
LOG(Receiver:GetClass() .. " was dealt RawDamage " .. TDI.RawDamage .. ", FinalDamage " .. TDI.FinalDamage .. " (that is, " .. (TDI.RawDamage - TDI.FinalDamage) .. " HPs covered by armor)");
+ return false;
+end
+
+
+
+
+
+function OnTick()
+ -- Activate all dispensers in the g_DispensersToActivate list:
+ local ActivateDisp = function(Dispenser)
+ if (Dispenser:GetContents():GetFirstUsedSlot() == -1) then
+ return true;
+ end
+ Dispenser:Activate();
+ return false;
+ end
+
+ local idx = #g_DispensersToActivate;
+ 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);
+ end
+ end
+
+ return false;
end