summaryrefslogtreecommitdiffstats
path: root/Plugins/Core/onblockplace.lua
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-15 14:16:42 +0100
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-02-15 14:16:42 +0100
commit5e1033c567064ffc4a81ac5a2f916db98e3a50ee (patch)
tree8409761d37e1bc62ea21faa4689dd85f6bcc5063 /Plugins/Core/onblockplace.lua
parentSlight cleanup - removed old code, some additional comments on dangerous functions (diff)
downloadcuberite-5e1033c567064ffc4a81ac5a2f916db98e3a50ee.tar
cuberite-5e1033c567064ffc4a81ac5a2f916db98e3a50ee.tar.gz
cuberite-5e1033c567064ffc4a81ac5a2f916db98e3a50ee.tar.bz2
cuberite-5e1033c567064ffc4a81ac5a2f916db98e3a50ee.tar.lz
cuberite-5e1033c567064ffc4a81ac5a2f916db98e3a50ee.tar.xz
cuberite-5e1033c567064ffc4a81ac5a2f916db98e3a50ee.tar.zst
cuberite-5e1033c567064ffc4a81ac5a2f916db98e3a50ee.zip
Diffstat (limited to 'Plugins/Core/onblockplace.lua')
-rw-r--r--Plugins/Core/onblockplace.lua67
1 files changed, 32 insertions, 35 deletions
diff --git a/Plugins/Core/onblockplace.lua b/Plugins/Core/onblockplace.lua
index 45d9a082e..64ab54920 100644
--- a/Plugins/Core/onblockplace.lua
+++ b/Plugins/Core/onblockplace.lua
@@ -1,5 +1,3 @@
-local BlockData = {}
-
function OnBlockPlace( Block, Player )
-- dont check if the direction is in the air
@@ -12,8 +10,39 @@ function OnBlockPlace( Block, Player )
if( Y >= 128 or Y < 0 ) then
return true
end
+
+ local CheckCollision = function( Player )
+ -- drop the decimals, we only care about the full block X,Y,Z
+ local PlayerX = math.floor(Player:GetPosX(), 0)
+ local PlayerY = math.floor(Player:GetPosY(), 0)
+ local PlayerZ = math.floor(Player:GetPosZ(), 0)
+
+ local BlockX = Block.m_PosX
+ local BlockY = Block.m_PosY
+ local BlockZ = Block.m_PosZ
+
+ -- player height is 2 blocks, so we check the position and then offset it up one
+ -- so they can't place a block on there face
+
+ local collision = false
+ if Block.m_Direction == 0 then if PlayerY == BlockY-2 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
+ if Block.m_Direction == 1 then if PlayerY == BlockY+1 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
- BlockData = Block
+ if Block.m_Direction == 2 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
+ if Block.m_Direction == 2 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
+
+ if Block.m_Direction == 3 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
+ if Block.m_Direction == 3 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
+
+ if Block.m_Direction == 4 then if PlayerY == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
+ if Block.m_Direction == 4 then if PlayerY+1 == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
+
+ if Block.m_Direction == 5 then if PlayerY == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
+ if Block.m_Direction == 5 then if PlayerY+1 == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
+
+ return collision
+ end
+
if( Player:GetWorld():ForEachPlayer( CheckCollision ) == false ) then
return true
else
@@ -24,36 +53,4 @@ function OnBlockPlace( Block, Player )
return false
-end
-
-function CheckCollision( Player )
- -- drop the decimals, we only care about the full block X,Y,Z
- local PlayerX = math.floor(Player:GetPosX(), 0)
- local PlayerY = math.floor(Player:GetPosY(), 0)
- local PlayerZ = math.floor(Player:GetPosZ(), 0)
-
- local BlockX = BlockData.m_PosX
- local BlockY = BlockData.m_PosY
- local BlockZ = BlockData.m_PosZ
-
- -- player height is 2 blocks, so we check the position and then offset it up one
- -- so they can't place a block on there face
-
- local collision = false
- if BlockData.m_Direction == 0 then if PlayerY == BlockY-2 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
- if BlockData.m_Direction == 1 then if PlayerY == BlockY+1 and PlayerX == BlockX and PlayerZ == BlockZ then collision = true end end
-
- if BlockData.m_Direction == 2 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
- if BlockData.m_Direction == 2 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ-1 then collision = true end end
-
- if BlockData.m_Direction == 3 then if PlayerY == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
- if BlockData.m_Direction == 3 then if PlayerY+1 == BlockY and PlayerX == BlockX and PlayerZ == BlockZ+1 then collision = true end end
-
- if BlockData.m_Direction == 4 then if PlayerY == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
- if BlockData.m_Direction == 4 then if PlayerY+1 == BlockY and PlayerX == BlockX-1 and PlayerZ == BlockZ then collision = true end end
-
- if BlockData.m_Direction == 5 then if PlayerY == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
- if BlockData.m_Direction == 5 then if PlayerY+1 == BlockY and PlayerX == BlockX+1 and PlayerZ == BlockZ then collision = true end end
-
- return collision
end \ No newline at end of file