diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-14 20:14:23 +0100 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-14 20:14:23 +0100 |
commit | e7ea352f41b867dad83d170b7382b22a46f25c49 (patch) | |
tree | e37ed55018238c84445eb60302c825726ebaf4e9 /Plugins/Core/onblockplace.lua | |
parent | Makefile cleanup - read COMPILING for details on *nix compilation (diff) | |
download | cuberite-e7ea352f41b867dad83d170b7382b22a46f25c49.tar cuberite-e7ea352f41b867dad83d170b7382b22a46f25c49.tar.gz cuberite-e7ea352f41b867dad83d170b7382b22a46f25c49.tar.bz2 cuberite-e7ea352f41b867dad83d170b7382b22a46f25c49.tar.lz cuberite-e7ea352f41b867dad83d170b7382b22a46f25c49.tar.xz cuberite-e7ea352f41b867dad83d170b7382b22a46f25c49.tar.zst cuberite-e7ea352f41b867dad83d170b7382b22a46f25c49.zip |
Diffstat (limited to 'Plugins/Core/onblockplace.lua')
-rw-r--r-- | Plugins/Core/onblockplace.lua | 69 |
1 files changed, 34 insertions, 35 deletions
diff --git a/Plugins/Core/onblockplace.lua b/Plugins/Core/onblockplace.lua index ba75bf5c2..45d9a082e 100644 --- a/Plugins/Core/onblockplace.lua +++ b/Plugins/Core/onblockplace.lua @@ -1,3 +1,5 @@ +local BlockData = {}
+
function OnBlockPlace( Block, Player )
-- dont check if the direction is in the air
@@ -11,50 +13,47 @@ function OnBlockPlace( Block, Player ) return true
end
- local collision = false
- local World = Player:GetWorld()
- local PlayerList = World:GetAllPlayers()
-
- -- check if a player occupies the placement location
- for i, Player in ipairs( PlayerList ) do
-
- -- 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
+ BlockData = Block
+ if( Player:GetWorld():ForEachPlayer( CheckCollision ) == false ) then
+ return true
+ else
+ return false
+ end
- -- 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
+ end
- 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
+ return false
- 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
+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
+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)
- 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
+ local BlockX = BlockData.m_PosX
+ local BlockY = BlockData.m_PosY
+ local BlockZ = BlockData.m_PosZ
- 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
+ -- 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
- end
+ 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 collision then
- return true
- else
- return false
- 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
- 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
- return false
+ 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 |