summaryrefslogtreecommitdiffstats
path: root/src/Blocks/BlockFence.h
diff options
context:
space:
mode:
authorLane Kolbly <lane@rscheme.org>2017-07-28 18:59:21 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2017-07-28 18:59:21 +0200
commit5402b214b31af60bc96cd4e47e9211715c3e99f5 (patch)
tree3d8b0fe5cc7a3f8c63e365afa9f118d755780ea2 /src/Blocks/BlockFence.h
parentTentative fix for player-limit race condition (#3862) (diff)
downloadcuberite-5402b214b31af60bc96cd4e47e9211715c3e99f5.tar
cuberite-5402b214b31af60bc96cd4e47e9211715c3e99f5.tar.gz
cuberite-5402b214b31af60bc96cd4e47e9211715c3e99f5.tar.bz2
cuberite-5402b214b31af60bc96cd4e47e9211715c3e99f5.tar.lz
cuberite-5402b214b31af60bc96cd4e47e9211715c3e99f5.tar.xz
cuberite-5402b214b31af60bc96cd4e47e9211715c3e99f5.tar.zst
cuberite-5402b214b31af60bc96cd4e47e9211715c3e99f5.zip
Diffstat (limited to 'src/Blocks/BlockFence.h')
-rw-r--r--src/Blocks/BlockFence.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/Blocks/BlockFence.h b/src/Blocks/BlockFence.h
new file mode 100644
index 000000000..92f52cbbe
--- /dev/null
+++ b/src/Blocks/BlockFence.h
@@ -0,0 +1,80 @@
+
+#pragma once
+
+#include "BlockHandler.h"
+#include "BlockID.h"
+#include "../BoundingBox.h"
+
+
+
+
+class cBlockFenceHandler :
+ public cBlockHandler
+{
+public:
+ // These are the min and max coordinates (X and Z) for a straight fence.
+ // 0.4 and 0.6 are really just guesses, but they seem pretty good.
+ // (0.4 to 0.6 is a fence that's 0.2 wide, down the center of the block)
+ const double MIN_COORD = 0.4;
+ const double MAX_COORD = 0.6;
+
+ cBlockFenceHandler(BLOCKTYPE a_BlockType)
+ : cBlockHandler(a_BlockType)
+ {
+ }
+
+ virtual cBoundingBox GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) override
+ {
+ bool XMSolid = cBlockInfo::IsSolid(a_XM);
+ bool XPSolid = cBlockInfo::IsSolid(a_XP);
+ bool ZMSolid = cBlockInfo::IsSolid(a_ZM);
+ bool ZPSolid = cBlockInfo::IsSolid(a_ZP);
+
+ double FENCE_HEIGHT = cBlockInfo::GetBlockHeight(m_BlockType);
+
+ // Entities can never be in the center
+ cBoundingBox PlacementBox(MIN_COORD, MAX_COORD, 0, FENCE_HEIGHT, MIN_COORD, MAX_COORD);
+
+ // For each solid neighbor, the hitbox extends that way
+ if (XMSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(0, 0.5, 0, FENCE_HEIGHT, MIN_COORD, MAX_COORD));
+ }
+ if (XPSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(0.5, 1.0, 0, FENCE_HEIGHT, MIN_COORD, MAX_COORD));
+ }
+ if (ZMSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(MIN_COORD, MAX_COORD, 0, FENCE_HEIGHT, 0.0, 0.5));
+ }
+ if (ZPSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(MIN_COORD, MAX_COORD, 0, FENCE_HEIGHT, 0.5, 1.0));
+ }
+
+ // For each corner, fill in the corner
+ if (XMSolid && ZMSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(0, 0.5, 0, FENCE_HEIGHT, 0, 0.5));
+ }
+ if (XPSolid && ZMSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(0.5, 1.0, 0, FENCE_HEIGHT, 0, 0.5));
+ }
+ if (XPSolid && ZPSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(0.5, 1.0, 0, FENCE_HEIGHT, 0.5, 1.0));
+ }
+ if (XMSolid && ZPSolid)
+ {
+ PlacementBox = PlacementBox.Union(cBoundingBox(0, 0.5, 0, FENCE_HEIGHT, 0.5, 1.0));
+ }
+
+ return PlacementBox;
+ }
+};
+
+
+
+