summaryrefslogtreecommitdiffstats
path: root/MCServer/Plugins
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-06 19:01:01 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-10-06 19:01:01 +0200
commit04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec (patch)
treecd9b1831bd1f47b8938c936ee0ab98206f1a3557 /MCServer/Plugins
parentBlockArea writing support (BlockTypes with BlockMeta only) (diff)
downloadcuberite-04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec.tar
cuberite-04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec.tar.gz
cuberite-04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec.tar.bz2
cuberite-04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec.tar.lz
cuberite-04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec.tar.xz
cuberite-04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec.tar.zst
cuberite-04c43ac8f52c367817bd1a71b9e5c2efb6b4f3ec.zip
Diffstat (limited to 'MCServer/Plugins')
-rw-r--r--MCServer/Plugins/DiamondMover/DiamondMover.lua83
1 files changed, 83 insertions, 0 deletions
diff --git a/MCServer/Plugins/DiamondMover/DiamondMover.lua b/MCServer/Plugins/DiamondMover/DiamondMover.lua
new file mode 100644
index 000000000..075268fa4
--- /dev/null
+++ b/MCServer/Plugins/DiamondMover/DiamondMover.lua
@@ -0,0 +1,83 @@
+
+-- DiamondMover.lua
+
+-- An example Lua plugin using the cBlockArea object
+-- When a player rclks with a diamond in their hand, an area around the clicked block is moved in the direction the player is facing
+
+
+
+
+
+-- Global variables
+PLUGIN = {} -- Reference to own plugin object
+MOVER_SIZE_X = 4;
+MOVER_SIZE_Y = 4;
+MOVER_SIZE_Z = 4;
+
+
+
+
+
+function Initialize(Plugin)
+ PLUGIN = Plugin;
+
+ Plugin:SetName("DiamondMover");
+ Plugin:SetVersion(1);
+
+ PluginManager = cRoot:Get():GetPluginManager();
+ PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_PLACE);
+ return true;
+end
+
+
+
+
+
+function OnBlockPlace(Player, BlockX, BlockY, BlockZ, BlockFace, HeldItem)
+
+ -- Don't check if the direction is in the air
+ if (BlockFace == -1) then
+ return false;
+ end;
+
+ if (Player:HasPermission("diamondmover.move") == false) then
+ return true;
+ end;
+
+ -- Rclk with a diamond to push in the direction the player is facing
+ if (Player:GetEquippedItem().m_ItemType == E_ITEM_DIAMOND) then
+ local Area = cBlockArea();
+ Area:Read(Player:GetWorld(),
+ BlockX - MOVER_SIZE_X, BlockX + MOVER_SIZE_X,
+ BlockY - MOVER_SIZE_Y, BlockY + MOVER_SIZE_Y,
+ BlockZ - MOVER_SIZE_Z, BlockZ + MOVER_SIZE_Z
+ );
+
+ local PlayerPitch = Player:GetPitch();
+ if (PlayerPitch < -70) then -- looking up
+ BlockY = BlockY + 1;
+ else
+ if (PlayerPitch > 70) then -- looking down
+ BlockY = BlockY - 1;
+ else
+ local PlayerRot = Player:GetRotation() + 180; -- Convert [-180, 180] into [0, 360] for simpler conditions
+ if ((PlayerRot < 45) or (PlayerRot > 315)) then
+ BlockZ = BlockZ - 1;
+ else
+ if (PlayerRot < 135) then
+ BlockX = BlockX + 1;
+ else
+ if (PlayerRot < 225) then
+ BlockZ = BlockZ + 1;
+ else
+ BlockX = BlockX - 1;
+ end;
+ end;
+ end;
+ end;
+ end;
+
+ Area:Write(Player:GetWorld(), BlockX - MOVER_SIZE_X, BlockY - MOVER_SIZE_Y, BlockZ - MOVER_SIZE_Z);
+ return false;
+ end
+end \ No newline at end of file