the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.level.h"
3#include "net.minecraft.world.level.tile.h"
4#include "net.minecraft.world.entity.h"
5#include "net.minecraft.world.entity.boss.enderdragon.h"
6#include "EnderCrystal.h"
7#include "DamageSource.h"
8
9
10
11void EnderCrystal::_init(Level *level)
12{
13 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
14 // the derived version of the function is called
15 this->defineSynchedData();
16
17 blocksBuilding = true;
18 setSize(2.0f, 2.0f);
19 heightOffset = bbHeight / 2.0f;
20 life = MAX_LIFE;
21
22 time = random->nextInt(100000);
23}
24
25EnderCrystal::EnderCrystal(Level *level) : Entity( level )
26{
27 _init(level);
28
29}
30
31EnderCrystal::EnderCrystal(Level *level, double x, double y, double z) : Entity( level )
32{
33 _init(level);
34 setPos(x, y, z);
35
36}
37
38bool EnderCrystal::makeStepSound()
39{
40 return false;
41}
42
43void EnderCrystal::defineSynchedData()
44{
45 entityData->define(DATA_REMAINING_LIFE, life);
46}
47
48void EnderCrystal::tick()
49{
50 xo = x;
51 yo = y;
52 zo = z;
53 time++;
54
55 entityData->set(DATA_REMAINING_LIFE, life);
56
57 // Don't set the tile directly on the client, as this can end up in the updatesToReset queue in the MultiPlayerLevel, and the perpetually end up removing/adding these fire tiles causing timing
58 // glitches from the lighting changes requried.
59 if (!level->isClientSide)
60 {
61 int xt = Mth::floor(x);
62 int yt = Mth::floor(y);
63 int zt = Mth::floor(z);
64 if (level->getTile(xt, yt, zt) != Tile::fire_Id)
65 {
66 level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
67 }
68 }
69}
70
71
72void EnderCrystal::addAdditonalSaveData(CompoundTag *tag)
73{
74}
75
76void EnderCrystal::readAdditionalSaveData(CompoundTag *tag)
77{
78}
79
80
81float EnderCrystal::getShadowHeightOffs()
82{
83 return 0;
84}
85
86bool EnderCrystal::isPickable()
87{
88 return true;
89}
90
91bool EnderCrystal::hurt(DamageSource *source, float damage)
92{
93 if (isInvulnerable()) return false;
94
95 // 4J-PB - if the owner of the source is the enderdragon, then ignore it (where the dragon's fireball hits an endercrystal)
96 if ( source->getEntity() != NULL && source->getEntity()->instanceof(eTYPE_ENDERDRAGON) )
97 {
98 return false;
99 }
100
101 if (!removed && !level->isClientSide)
102 {
103 life = 0;
104 if (life <= 0)
105 {
106 remove();
107 if (!level->isClientSide)
108 {
109 level->explode(nullptr, x, y, z, 6, true);
110
111 vector<shared_ptr<Entity> > entities = level->getAllEntities();
112 shared_ptr<EnderDragon> dragon = nullptr;
113 AUTO_VAR(itEnd, entities.end());
114 for (AUTO_VAR(it, entities.begin()); it != itEnd; it++)
115 {
116 shared_ptr<Entity> e = *it; //entities->at(i);
117 dragon = dynamic_pointer_cast<EnderDragon>(e);
118 if(dragon != NULL)
119 {
120 dragon->handleCrystalDestroyed(source);
121 break;
122 }
123 }
124 }
125 }
126 }
127 return true;
128}