Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockDoor.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h"
3 #include "BlockDoor.h"
4 #include "../EffectID.h"
5 
6 
7 
8 
9 
11  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
12  Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType,
13  NIBBLETYPE a_OldBlockMeta,
14  const cEntity * a_Digger
15 ) const
16 {
17  UNUSED(a_Digger);
18  // A part of the multiblock door was broken; the relevant half will drop any pickups as required.
19  // All that is left to do is to delete the other half of the multiblock.
20 
21  if ((a_OldBlockMeta & 0x08) != 0)
22  {
23  const auto Lower = a_BlockPos.addedY(-1);
24  if ((Lower.y >= 0) && IsDoorBlockType(a_ChunkInterface.GetBlock(Lower)))
25  {
26  // Was upper part of door, remove lower:
27  a_ChunkInterface.SetBlock(Lower, E_BLOCK_AIR, 0);
28  }
29  }
30  else
31  {
32  const auto Upper = a_BlockPos.addedY(1);
33  if ((Upper.y < cChunkDef::Height) && IsDoorBlockType(a_ChunkInterface.GetBlock(Upper)))
34  {
35  // Was lower part, remove upper:
36  a_ChunkInterface.SetBlock(Upper, E_BLOCK_AIR, 0);
37  }
38  }
39 }
40 
41 
42 
43 
44 
46  cChunkInterface & a_ChunkInterface,
47  cWorldInterface & a_WorldInterface,
48  cPlayer & a_Player,
49  const Vector3i a_BlockPos,
50  eBlockFace a_BlockFace,
51  const Vector3i a_CursorPos
52 ) const
53 {
54  UNUSED(a_WorldInterface);
55  UNUSED(a_BlockFace);
56  UNUSED(a_CursorPos);
57 
58  switch (a_ChunkInterface.GetBlock(a_BlockPos))
59  {
60  default:
61  {
62  ASSERT(!"Unhandled door block type");
63  }
65  case E_BLOCK_BIRCH_DOOR:
69  case E_BLOCK_OAK_DOOR:
70  {
71  ChangeDoor(a_ChunkInterface, a_BlockPos);
73  break;
74  }
75  case E_BLOCK_IRON_DOOR:
76  {
77  // Prevent iron door from opening on player click (#2415):
78  OnCancelRightClick(a_ChunkInterface, a_WorldInterface, a_Player, a_BlockPos, a_BlockFace);
79 
80  // Allow placement actions to instead take place:
81  return false;
82  }
83  }
84 
85  return true;
86 }
87 
88 
89 
90 
91 
93  cChunkInterface & a_ChunkInterface,
94  cWorldInterface & a_WorldInterface,
95  cPlayer & a_Player,
96  const Vector3i a_BlockPos,
97  eBlockFace a_BlockFace
98 ) const
99 {
100  UNUSED(a_ChunkInterface);
101  UNUSED(a_BlockFace);
102 
103  a_WorldInterface.SendBlockTo(a_BlockPos, a_Player);
104  NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockPos);
105 
106  if (Meta & 0x08)
107  {
108  // Current block is top of the door, send the bottom part:
109  a_WorldInterface.SendBlockTo(a_BlockPos.addedY(-1), a_Player);
110  }
111  else
112  {
113  // Current block is bottom of the door, send the top part:
114  a_WorldInterface.SendBlockTo(a_BlockPos.addedY(1), a_Player);
115  }
116 }
117 
118 
119 
120 
121 
123 {
124  // Doors can be placed inside the player
125  return cBoundingBox(0, 0, 0, 0, 0, 0);
126 }
127 
128 
129 
130 
131 
133 {
134  if (a_Meta & 0x08)
135  {
136  // The meta doesn't change for the top block
137  return a_Meta;
138  }
139  else
140  {
141  // Rotate the bottom block
142  return Super::MetaRotateCCW(a_Meta);
143  }
144 }
145 
146 
147 
148 
149 
151 {
152  if (a_Meta & 0x08)
153  {
154  // The meta doesn't change for the top block
155  return a_Meta;
156  }
157  else
158  {
159  // Rotate the bottom block
160  return Super::MetaRotateCW(a_Meta);
161  }
162 }
163 
164 
165 
166 
167 
169 {
170  /*
171  Top bit (0x08) contains door block position (Top / Bottom). Only Bottom blocks contain position data
172  Return a_Meta if panel is a top panel (0x08 bit is set to 1)
173  */
174 
175  // Note: Currently, you can not properly mirror the hinges on a double door. The orientation of the door is stored
176  // in only the bottom tile while the hinge position is in the top tile. This function only operates on one tile at a time,
177  // so the function can only see either the hinge position or orientation, but not both, at any given time. The class itself
178  // needs extra datamembers.
179  if (a_Meta & 0x08)
180  {
181  return a_Meta;
182  }
183 
184  // Holds open / closed meta data. 0x0C == 1100.
185  NIBBLETYPE OtherMeta = a_Meta & 0x0C;
186 
187  // Mirrors according to a table. 0x03 == 0011.
188  switch (a_Meta & 0x03)
189  {
190  case 0x03: return 0x01 + OtherMeta; // South -> North
191  case 0x01: return 0x03 + OtherMeta; // North -> South
192  }
193 
194  // Not Facing North or South; No change.
195  return a_Meta;
196 }
197 
198 
199 
200 
201 
203 {
204  // Top bit (0x08) contains door panel type (Top / Bottom panel) Only Bottom panels contain position data
205  // Return a_Meta if panel is a top panel (0x08 bit is set to 1)
206 
207  // Note: Currently, you can not properly mirror the hinges on a double door. The orientation of the door is stored
208  // in only the bottom tile while the hinge position is in the top tile. This function only operates on one tile at a time,
209  // so the function can only see either the hinge position or orientation, but not both, at any given time.The class itself
210  // needs extra datamembers.
211 
212  if (a_Meta & 0x08)
213  {
214  return a_Meta;
215  }
216 
217  // Holds open / closed meta data. 0x0C == 1100.
218  NIBBLETYPE OtherMeta = a_Meta & 0x0C;
219 
220  // Mirrors according to a table. 0x03 == 0011.
221  switch (a_Meta & 0x03)
222  {
223  case 0x00: return 0x02 + OtherMeta; // West -> East
224  case 0x02: return 0x00 + OtherMeta; // East -> West
225  }
226 
227  // Not Facing North or South; No change.
228  return a_Meta;
229 }
230 
231 
232 
@ E_BLOCK_AIR
Definition: BlockType.h:10
@ E_BLOCK_SPRUCE_DOOR
Definition: BlockType.h:212
@ E_BLOCK_BIRCH_DOOR
Definition: BlockType.h:213
@ E_BLOCK_IRON_DOOR
Definition: BlockType.h:85
@ E_BLOCK_JUNGLE_DOOR
Definition: BlockType.h:214
@ E_BLOCK_OAK_DOOR
Definition: BlockType.h:77
@ E_BLOCK_DARK_OAK_DOOR
Definition: BlockType.h:216
@ E_BLOCK_ACACIA_DOOR
Definition: BlockType.h:215
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
@ SFX_RANDOM_WOODEN_DOOR_OPEN
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) const override
Definition: BlockDoor.cpp:202
virtual cBoundingBox GetPlacementCollisionBox(BLOCKTYPE a_XM, BLOCKTYPE a_XP, BLOCKTYPE a_YM, BLOCKTYPE a_YP, BLOCKTYPE a_ZM, BLOCKTYPE a_ZP) const override
Definition: BlockDoor.cpp:122
static void ChangeDoor(cChunkInterface &a_ChunkInterface, const Vector3i a_BlockPos)
Changes the door at the specified coords from open to close or vice versa.
Definition: BlockDoor.h:245
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const override
Definition: BlockDoor.cpp:45
virtual void OnCancelRightClick(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const override
Definition: BlockDoor.cpp:92
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) const override
Definition: BlockDoor.cpp:150
static bool IsDoorBlockType(BLOCKTYPE a_Block)
Returns true if the specified blocktype is any kind of door.
Definition: BlockDoor.h:61
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) const override
Definition: BlockDoor.cpp:168
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) const override
Definition: BlockDoor.cpp:132
virtual void OnBroken(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta, const cEntity *a_Digger) const override
Definition: BlockDoor.cpp:10
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
BLOCKTYPE GetBlock(Vector3i a_Pos)
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) const override
Definition: Mixins.h:74
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) const override
Definition: Mixins.h:95
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, const cPlayer &a_Player)=0
Sends the block on those coords to the player.
Represents two sets of coords, minimum and maximum for each direction.
Definition: BoundingBox.h:24
static const int Height
Definition: ChunkDef.h:125
Definition: Entity.h:76
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
Definition: Vector3.h:314
virtual void BroadcastSoundParticleEffect(const EffectID a_EffectID, Vector3i a_SrcPos, int a_Data, const cClientHandle *a_Exclude=nullptr) override