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.phys.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.tile.h"
5#include "net.minecraft.world.item.h"
6#include "net.minecraft.world.entity.item.h"
7#include "SharedConstants.h"
8#include "JavaMath.h"
9#include "EyeOfEnderSignal.h"
10
11void EyeOfEnderSignal::_init()
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 // Initialisors
18 shakeTime = 0;
19 tx = ty = tz = 0.0;
20 life = 0;
21 surviveAfterDeath = false;
22}
23
24EyeOfEnderSignal::EyeOfEnderSignal(Level *level) : Entity(level)
25{
26 _init();
27 setSize(0.25f, 0.25f);
28}
29
30void EyeOfEnderSignal::defineSynchedData()
31{
32}
33
34bool EyeOfEnderSignal::shouldRenderAtSqrDistance(double distance)
35{
36 double size = bb->getSize() * 4;
37 size *= 64.0f;
38 return distance < size * size;
39}
40
41EyeOfEnderSignal::EyeOfEnderSignal(Level *level, double x, double y, double z) : Entity(level)
42{
43 _init();
44 life = 0;
45
46 setSize(0.25f, 0.25f);
47
48 setPos(x, y, z);
49 heightOffset = 0;
50}
51
52void EyeOfEnderSignal::signalTo(double tx, int ty, double tz)
53{
54
55
56 double dx = tx - x, dz = tz - z;
57 float dist = sqrt(dx * dx + dz * dz);
58
59 if (dist > 12)
60 {
61 this->tx = x + (dx / dist) * 12;
62 this->tz = z + (dz / dist) * 12;
63 this->ty = y + 8;
64 }
65 else
66 {
67 this->tx = tx;
68 this->ty = ty;
69 this->tz = tz;
70 }
71
72 life = 0;
73 surviveAfterDeath = random->nextInt(5) > 0;
74}
75
76void EyeOfEnderSignal::lerpMotion(double xd, double yd, double zd)
77{
78 this->xd = xd;
79 this->yd = yd;
80 this->zd = zd;
81 if (xRotO == 0 && yRotO == 0)
82 {
83 float sd = (float) sqrt(xd * xd + zd * zd);
84 yRotO = yRot = (float) (atan2(xd, zd) * 180 / PI);
85 xRotO = xRot = (float) (atan2(yd, (double)sd) * 180 / PI);
86 }
87}
88
89void EyeOfEnderSignal::tick()
90{
91 xOld = x;
92 yOld = y;
93 zOld = z;
94 Entity::tick();
95
96 x += xd;
97 y += yd;
98 z += zd;
99
100 float sd = (float) sqrt(xd * xd + zd * zd);
101 yRot = (float) (atan2(xd, zd) * 180 / PI);
102 xRot = (float) (atan2(yd, (double)sd) * 180 / PI);
103
104 while (xRot - xRotO < -180)
105 xRotO -= 360;
106 while (xRot - xRotO >= 180)
107 xRotO += 360;
108
109 while (yRot - yRotO < -180)
110 yRotO -= 360;
111 while (yRot - yRotO >= 180)
112 yRotO += 360;
113
114 xRot = xRotO + (xRot - xRotO) * 0.2f;
115 yRot = yRotO + (yRot - yRotO) * 0.2f;
116
117 if (!level->isClientSide)
118 {
119 double dx = tx - x, dz = tz - z;
120 float tdist = (float) sqrt(dx * dx + dz * dz);
121 float angle = (float) atan2(dz, dx);
122 double tspeed = (sd + (tdist - sd) * .0025);
123 if (tdist < 1)
124 {
125 tspeed *= .8;
126 yd *= .8;
127 }
128 xd = cos(angle) * tspeed;
129 zd = sin(angle) * tspeed;
130
131 if (y < ty)
132 {
133 yd = yd + (1 - yd) * .015f;
134 }
135 else
136 {
137 yd = yd + (-1 - yd) * .015f;
138 }
139
140 }
141
142 float s = 1 / 4.0f;
143 if (isInWater())
144 {
145 for (int i = 0; i < 4; i++)
146 {
147 level->addParticle(eParticleType_bubble, x - xd * s, y - yd * s, z - zd * s, xd, yd, zd);
148 }
149 }
150 else
151 {
152 level->addParticle(eParticleType_ender, x - xd * s + random->nextDouble() * .6 - .3, y - yd * s - .5, z - zd * s + random->nextDouble() * .6 - .3, xd, yd, zd);
153 }
154
155 if (!level->isClientSide)
156 {
157 setPos(x, y, z);
158
159
160 life++;
161 if (life > SharedConstants::TICKS_PER_SECOND * 4 && !level->isClientSide)
162 {
163 remove();
164 if (surviveAfterDeath)
165 {
166 level->addEntity(shared_ptr<ItemEntity>( new ItemEntity(level, x, y, z, shared_ptr<ItemInstance>(new ItemInstance(Item::eyeOfEnder)))));
167 }
168 else
169 {
170 level->levelEvent(LevelEvent::PARTICLES_EYE_OF_ENDER_DEATH, (int) Math::round(x), (int) Math::round(y), (int) Math::round(z), 0);
171 }
172 }
173 }
174}
175
176void EyeOfEnderSignal::addAdditonalSaveData(CompoundTag *tag)
177{
178}
179
180void EyeOfEnderSignal::readAdditionalSaveData(CompoundTag *tag)
181{
182}
183
184float EyeOfEnderSignal::getShadowHeightOffs()
185{
186 return 0;
187}
188
189float EyeOfEnderSignal::getBrightness(float a)
190{
191 return 1.0f;
192}
193
194int EyeOfEnderSignal::getLightColor(float a)
195{
196 return 15 << 20 | 15 << 4;
197}
198
199bool EyeOfEnderSignal::isAttackable()
200{
201 return false;
202}