diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-18 11:56:28 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-18 11:56:28 +0200 |
commit | 2691e8daed826e944ca38f4787c77273edbf9404 (patch) | |
tree | 3f9fca349df2253c2c314abf2e0c22e8af7f9604 /Plugins | |
parent | Added Core files to the VC2008 project (so that they can be opened from the IDE there, nothing more) (diff) | |
download | cuberite-2691e8daed826e944ca38f4787c77273edbf9404.tar cuberite-2691e8daed826e944ca38f4787c77273edbf9404.tar.gz cuberite-2691e8daed826e944ca38f4787c77273edbf9404.tar.bz2 cuberite-2691e8daed826e944ca38f4787c77273edbf9404.tar.lz cuberite-2691e8daed826e944ca38f4787c77273edbf9404.tar.xz cuberite-2691e8daed826e944ca38f4787c77273edbf9404.tar.zst cuberite-2691e8daed826e944ca38f4787c77273edbf9404.zip |
Diffstat (limited to '')
-rw-r--r-- | Plugins/Core/onblockdig.lua | 7 | ||||
-rw-r--r-- | Plugins/Core/onblockplace.lua | 93 |
2 files changed, 51 insertions, 49 deletions
diff --git a/Plugins/Core/onblockdig.lua b/Plugins/Core/onblockdig.lua index 0fe671ad6..65e48576c 100644 --- a/Plugins/Core/onblockdig.lua +++ b/Plugins/Core/onblockdig.lua @@ -1,9 +1,8 @@ -function OnBlockDig( Block, Player )
-
+function OnBlockDig(Player, BlockX, BlockY, BlockZ, BlockFace, Status, OldBlockType, OldBlockMeta)
-- dont check if the direction is in the air
- if Block.m_Direction ~= -1 then
+ if (BlockFace ~= -1) then
- if( Player:HasPermission("core.build") == false ) then
+ if (Player:HasPermission("core.build") == false) then
return true
end
end
diff --git a/Plugins/Core/onblockplace.lua b/Plugins/Core/onblockplace.lua index 12b536e7a..9032f8207 100644 --- a/Plugins/Core/onblockplace.lua +++ b/Plugins/Core/onblockplace.lua @@ -1,60 +1,63 @@ -function OnBlockPlace( Block, Player )
+function OnBlockPlace(Player, BlockX, BlockY, BlockZ, BlockFace, HeldItem)
-- dont check if the direction is in the air
- if Block.m_Direction ~= -1 then
+ if (BlockFace == -1) then
+ return false
+ end
- if( Player:HasPermission("core.build") == false ) then
- return true
- end
+ if( Player:HasPermission("core.build") == false ) then
+ return true
+ end
+
+ -- TODO: If the placed block is not a block (torch etc.), allow it without checking for collisions
+
+ local X = BlockX
+ local Y = BlockY
+ local Z = BlockZ
+ X, Y, Z = AddDirection(X, Y, Z, BlockFace)
+ if (Y >= 256 or Y < 0) then
+ return true
+ end
- local X = Block.m_PosX
- local Y = Block.m_PosY
- local Z = Block.m_PosZ
- X, Y, Z = AddDirection( X, Y, Z, Block.m_Direction )
- if( Y >= 256 or Y < 0 ) then
- return true
+ 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)
+
+ -- player height is 2 blocks, so we check the position and then offset it up one
+ -- so they can't place a block in anyone's face
+
+ local collision = false
+ if ((BlockFace == BLOCK_FACE_TOP) and (PlayerY == BlockY - 2) and (PlayerX == BlockX) and (PlayerZ == BlockZ)) then
+ collision = 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
+ if ((BlockFace == BLOCK_FACE_BOTTOM) and (PlayerY == BlockY + 1) and (PlayerX == BlockX) and (PlayerZ == BlockZ)) then
+ collision = true
+ end
- 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 ((BlockFace == BLOCK_FACE_NORTH) and (PlayerX == BlockX) and (PlayerZ == BlockZ - 1)) then
+ if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) 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 ((BlockFace == BLOCK_FACE_SOUTH) and (PlayerX == BlockX) and (PlayerZ == BlockZ + 1)) then
+ if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) 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 ((BlockFace == BLOCK_FACE_WEST) and (PlayerX == BlockX - 1) and (PlayerZ == BlockZ)) then
+ if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) 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
+ if ((BlockFace == BLOCK_FACE_EAST) and (PlayerX == BlockX + 1) and (PlayerZ == BlockZ)) then
+ if ((PlayerY == BlockY) or (PlayerY + 1 == BlockY)) then collision = true end
end
- if( Player:GetWorld():ForEachPlayer( CheckCollision ) == false ) then
- return true
- else
- return false
- end
-
+ return collision
+ end
+
+ if (Player:GetWorld():ForEachPlayer(CheckCollision) == false) then
+ return true
end
-
return false
-
end
\ No newline at end of file |