1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#pragma once
#include "BlockEntity.h"
#include "../BlockEntities/MobHeadEntity.h"
class cBlockMobHeadHandler :
public cBlockEntityHandler
{
public:
cBlockMobHeadHandler(BLOCKTYPE a_BlockType):
cBlockEntityHandler(a_BlockType)
{
}
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
// The drop spawn is in the OnDestroyedByPlayer method
}
virtual void OnDestroyedByPlayer(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ) override
{
if (a_Player->IsGameModeCreative())
{
// No drops in creative mode
return;
}
class cCallback : public cBlockEntityCallback
{
virtual bool Item(cBlockEntity * a_BlockEntity)
{
if (a_BlockEntity->GetBlockType() != E_BLOCK_HEAD)
{
return false;
}
cMobHeadEntity * MobHeadEntity = static_cast<cMobHeadEntity*>(a_BlockEntity);
cItems Pickups;
Pickups.Add(E_ITEM_HEAD, 1, (short) MobHeadEntity->GetType());
MTRand r1;
// Mid-block position first
double MicroX, MicroY, MicroZ;
MicroX = MobHeadEntity->GetPosX() + 0.5;
MicroY = MobHeadEntity->GetPosY() + 0.5;
MicroZ = MobHeadEntity->GetPosZ() + 0.5;
// Add random offset second
MicroX += r1.rand(1) - 0.5;
MicroZ += r1.rand(1) - 0.5;
MobHeadEntity->GetWorld()->SpawnItemPickups(Pickups, MicroX, MicroY, MicroZ);
return false;
}
} Callback;
a_WorldInterface.DoWithBlockEntityAt(a_BlockX, a_BlockY, a_BlockZ, Callback);
}
} ;
|