summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-05-14 11:42:08 +0200
committerGitHub <noreply@github.com>2021-05-14 11:42:08 +0200
commitd92509a6e755271f629dffc79ee35636df7f6a27 (patch)
treec447234aa0db6154d2654ea1171cd0797832f3d4 /src
parentWindows: remove extra newlines in backtrace (#5218) (diff)
downloadcuberite-d92509a6e755271f629dffc79ee35636df7f6a27.tar
cuberite-d92509a6e755271f629dffc79ee35636df7f6a27.tar.gz
cuberite-d92509a6e755271f629dffc79ee35636df7f6a27.tar.bz2
cuberite-d92509a6e755271f629dffc79ee35636df7f6a27.tar.lz
cuberite-d92509a6e755271f629dffc79ee35636df7f6a27.tar.xz
cuberite-d92509a6e755271f629dffc79ee35636df7f6a27.tar.zst
cuberite-d92509a6e755271f629dffc79ee35636df7f6a27.zip
Diffstat (limited to '')
-rw-r--r--src/Blocks/BlockBed.h8
-rw-r--r--src/Blocks/BlockDropSpenser.h4
-rw-r--r--src/Blocks/BlockObserver.h4
-rw-r--r--src/Blocks/BlockPiston.h4
-rw-r--r--src/Blocks/Mixins.h36
-rw-r--r--src/Items/ItemDropSpenser.h2
-rw-r--r--src/Items/ItemObserver.h2
-rw-r--r--src/Items/ItemPiston.h2
8 files changed, 36 insertions, 26 deletions
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h
index d9f37b365..a6b2814b9 100644
--- a/src/Blocks/BlockBed.h
+++ b/src/Blocks/BlockBed.h
@@ -4,17 +4,21 @@
#pragma once
#include "BlockEntity.h"
-#include "Mixins.h"
#include "ChunkInterface.h"
+#include "Entities/Player.h"
+#include "Mixins.h"
+
+
+
class cEntity;
-class cPlayer;
class cWorldInterface;
+
class cBlockBedHandler final :
public cYawRotator<cBlockEntityHandler, 0x03, 0x02, 0x03, 0x00, 0x01>
{
diff --git a/src/Blocks/BlockDropSpenser.h b/src/Blocks/BlockDropSpenser.h
index 0f6863ea4..050adf0f1 100644
--- a/src/Blocks/BlockDropSpenser.h
+++ b/src/Blocks/BlockDropSpenser.h
@@ -12,9 +12,9 @@
class cBlockDropSpenserHandler final :
- public cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>
+ public cDisplacementYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>
{
- using Super = cPitchYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>;
+ using Super = cDisplacementYawRotator<cClearMetaOnDrop<cBlockEntityHandler>, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>;
public:
diff --git a/src/Blocks/BlockObserver.h b/src/Blocks/BlockObserver.h
index b2ac955f9..13ffa4631 100644
--- a/src/Blocks/BlockObserver.h
+++ b/src/Blocks/BlockObserver.h
@@ -6,9 +6,9 @@
class cBlockObserverHandler final :
- public cClearMetaOnDrop<cPitchYawRotator<cBlockHandler>>
+ public cClearMetaOnDrop<cDisplacementYawRotator<cBlockHandler>>
{
- using Super = cClearMetaOnDrop<cPitchYawRotator<cBlockHandler>>;
+ using Super = cClearMetaOnDrop<cDisplacementYawRotator<cBlockHandler>>;
public:
diff --git a/src/Blocks/BlockPiston.h b/src/Blocks/BlockPiston.h
index 42fcca3b8..4afeb4767 100644
--- a/src/Blocks/BlockPiston.h
+++ b/src/Blocks/BlockPiston.h
@@ -16,9 +16,9 @@ class cWorld;
class cBlockPistonHandler final :
- public cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>
+ public cClearMetaOnDrop<cDisplacementYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>
{
- using Super = cClearMetaOnDrop<cPitchYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>;
+ using Super = cClearMetaOnDrop<cDisplacementYawRotator<cBlockHandler, 0x07, 0x03, 0x04, 0x02, 0x05, 0x01, 0x00>>;
public:
diff --git a/src/Blocks/Mixins.h b/src/Blocks/Mixins.h
index 23a4be225..fa8985737 100644
--- a/src/Blocks/Mixins.h
+++ b/src/Blocks/Mixins.h
@@ -10,7 +10,6 @@ class cBlockLadder: public cMetaRotator<cClearMetaOnDrop, ...>
#pragma once
#include "../Item.h"
-#include "../Entities/Player.h"
@@ -169,7 +168,7 @@ public:
/** Converts the rotation value as returned by cPlayer::GetYaw() to the appropriate metadata
- value for a block placed by a player facing that way */
+ value for a block placed by a player facing that way. */
static NIBBLETYPE YawToMetaData(double a_Rotation)
{
if ((a_Rotation >= -135) && (a_Rotation < -45))
@@ -199,8 +198,8 @@ protected:
-/** Mixin for blocks whose meta on placement depends on the pitch and yaw of the player placing the block. BitMask
-selects the direction bits from the block's meta values. */
+/** Mixin for blocks whose meta on placement depends on the relative position of the player to the block in
+addition to the yaw of the player placing the block. BitMask selects the direction bits from the block's meta values. */
template <
class Base,
NIBBLETYPE BitMask = 0x07,
@@ -211,7 +210,7 @@ template <
NIBBLETYPE Up = 0x00,
NIBBLETYPE Down = 0x01
>
-class cPitchYawRotator:
+class cDisplacementYawRotator:
public cYawRotator<Base, BitMask, North, East, South, West>
{
using Super = cYawRotator<Base, BitMask, North, East, South, West>;
@@ -221,17 +220,24 @@ public:
using Super::Super;
- /** Converts the rotation and pitch values as returned by cPlayer::GetYaw() and cPlayer::GetPitch()
- respectively to the appropriate metadata value for a block placed by a player facing that way */
- static NIBBLETYPE PitchYawToMetaData(double a_Rotation, double a_Pitch)
+ /** Converts the placement position, eye position as returned by cPlayer::GetEyePosition(), and
+ rotation value as returned by cPlayer::GetYaw() to the appropriate metadata value for a block placed by a player facing that way. */
+ static NIBBLETYPE DisplacementYawToMetaData(const Vector3d a_PlacePosition, const Vector3d a_EyePosition, const double a_Rotation)
{
- if (a_Pitch >= 50)
- {
- return Up;
- }
- else if (a_Pitch <= -50)
+ if (
+ const auto Displacement = a_EyePosition - a_PlacePosition.addedXZ(0.5, 0.5);
+ (std::abs(Displacement.x) < 2) && (std::abs(Displacement.z) < 2)
+ )
{
- return Down;
+ if (Displacement.y > 2)
+ {
+ return Up;
+ }
+
+ if (Displacement.y < 0)
+ {
+ return Down;
+ }
}
return Super::YawToMetaData(a_Rotation);
@@ -239,7 +245,7 @@ public:
protected:
- ~cPitchYawRotator() = default;
+ ~cDisplacementYawRotator() = default;
virtual NIBBLETYPE MetaMirrorXZ(NIBBLETYPE a_Meta) const override
diff --git a/src/Items/ItemDropSpenser.h b/src/Items/ItemDropSpenser.h
index d226436db..a06f67569 100644
--- a/src/Items/ItemDropSpenser.h
+++ b/src/Items/ItemDropSpenser.h
@@ -21,6 +21,6 @@ private:
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
{
- return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockDropSpenserHandler::PitchYawToMetaData(a_Player.GetYaw(), a_Player.GetPitch()));
+ return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockDropSpenserHandler::DisplacementYawToMetaData(a_PlacePosition, a_Player.GetEyePosition(), a_Player.GetYaw()));
}
};
diff --git a/src/Items/ItemObserver.h b/src/Items/ItemObserver.h
index b95882ae0..9047386bd 100644
--- a/src/Items/ItemObserver.h
+++ b/src/Items/ItemObserver.h
@@ -21,6 +21,6 @@ private:
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
{
- return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_OBSERVER, cBlockObserverHandler::PitchYawToMetaData(a_Player.GetYaw(), a_Player.GetPitch()));
+ return a_Player.PlaceBlock(a_PlacePosition, E_BLOCK_OBSERVER, cBlockObserverHandler::DisplacementYawToMetaData(a_PlacePosition, a_Player.GetEyePosition(), a_Player.GetYaw()));
}
};
diff --git a/src/Items/ItemPiston.h b/src/Items/ItemPiston.h
index 659300924..097c26d78 100644
--- a/src/Items/ItemPiston.h
+++ b/src/Items/ItemPiston.h
@@ -21,6 +21,6 @@ private:
virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) override
{
- return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockPistonHandler::PitchYawToMetaData(a_Player.GetYaw(), a_Player.GetPitch()));
+ return a_Player.PlaceBlock(a_PlacePosition, static_cast<BLOCKTYPE>(a_HeldItem.m_ItemType), cBlockPistonHandler::DisplacementYawToMetaData(a_PlacePosition, a_Player.GetEyePosition(), a_Player.GetYaw()));
}
};