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.entity.h"
3#include "net.minecraft.world.item.h"
4#include "net.minecraft.world.level.h"
5#include "FireworksRocketEntity.h"
6
7FireworksRocketEntity::FireworksRocketEntity(Level *level) : Entity(level)
8{
9 defineSynchedData();
10
11 life = 0;
12 lifetime = 0;
13 setSize(0.25f, 0.25f);
14}
15
16void FireworksRocketEntity::defineSynchedData()
17{
18 entityData->defineNULL(DATA_ID_FIREWORKS_ITEM, NULL);
19}
20
21bool FireworksRocketEntity::shouldRenderAtSqrDistance(double distance)
22{
23 return distance < 64 * 64;
24}
25
26FireworksRocketEntity::FireworksRocketEntity(Level *level, double x, double y, double z, shared_ptr<ItemInstance> sourceItem) : Entity(level)
27{
28 defineSynchedData();
29
30 life = 0;
31
32 setSize(0.25f, 0.25f);
33
34 setPos(x, y, z);
35 heightOffset = 0;
36
37 int flightCount = 1;
38 if (sourceItem != NULL && sourceItem->hasTag())
39 {
40 entityData->set(DATA_ID_FIREWORKS_ITEM, sourceItem);
41
42 CompoundTag *tag = sourceItem->getTag();
43 CompoundTag *compound = tag->getCompound(FireworksItem::TAG_FIREWORKS);
44 if (compound != NULL)
45 {
46 flightCount += compound->getByte(FireworksItem::TAG_FLIGHT);
47 }
48 }
49 xd = random->nextGaussian() * .001;
50 zd = random->nextGaussian() * .001;
51 yd = 0.05;
52
53 lifetime = (SharedConstants::TICKS_PER_SECOND / 2) * flightCount + random->nextInt(6) + random->nextInt(7);
54}
55
56void FireworksRocketEntity::lerpMotion(double xd, double yd, double zd)
57{
58 xd = xd;
59 yd = yd;
60 zd = zd;
61 if (xRotO == 0 && yRotO == 0)
62 {
63 double sd = Mth::sqrt(xd * xd + zd * zd);
64 yRotO = yRot = (float) (atan2(xd, zd) * 180 / PI);
65 xRotO = xRot = (float) (atan2(yd, sd) * 180 / PI);
66 }
67}
68
69void FireworksRocketEntity::tick()
70{
71 xOld = x;
72 yOld = y;
73 zOld = z;
74 Entity::tick();
75
76 xd *= 1.15;
77 zd *= 1.15;
78 yd += .04;
79 move(xd, yd, zd);
80
81 double sd = Mth::sqrt(xd * xd + zd * zd);
82 yRot = (float) (atan2(xd, zd) * 180 / PI);
83 xRot = (float) (atan2(yd, sd) * 180 / PI);
84
85 while (xRot - xRotO < -180)
86 xRotO -= 360;
87 while (xRot - xRotO >= 180)
88 xRotO += 360;
89
90 while (yRot - yRotO < -180)
91 yRotO -= 360;
92 while (yRot - yRotO >= 180)
93 yRotO += 360;
94
95 xRot = xRotO + (xRot - xRotO) * 0.2f;
96 yRot = yRotO + (yRot - yRotO) * 0.2f;
97
98 if (!level->isClientSide )
99 {
100 if (life == 0)
101 {
102 level->playEntitySound(shared_from_this(), eSoundType_FIREWORKS_LAUNCH, 3, 1);
103 }
104 }
105
106 life++;
107 if (level->isClientSide && (life % 2) < 2)
108 {
109 level->addParticle(eParticleType_fireworksspark, x, y - .3, z, random->nextGaussian() * .05, -yd * .5, random->nextGaussian() * .05);
110 }
111 if (!level->isClientSide && life > lifetime)
112 {
113 level->broadcastEntityEvent(shared_from_this(), EntityEvent::FIREWORKS_EXPLODE);
114 remove();
115 }
116}
117
118void FireworksRocketEntity::handleEntityEvent(byte eventId)
119{
120 if (eventId == EntityEvent::FIREWORKS_EXPLODE && level->isClientSide)
121 {
122 shared_ptr<ItemInstance> sourceItem = entityData->getItemInstance(DATA_ID_FIREWORKS_ITEM);
123 CompoundTag *tag = NULL;
124 if (sourceItem != NULL && sourceItem->hasTag())
125 {
126 tag = sourceItem->getTag()->getCompound(FireworksItem::TAG_FIREWORKS);
127 }
128 level->createFireworks(x, y, z, xd, yd, zd, tag);
129 }
130 Entity::handleEntityEvent(eventId);
131}
132
133void FireworksRocketEntity::addAdditonalSaveData(CompoundTag *tag)
134{
135 tag->putInt(L"Life", life);
136 tag->putInt(L"LifeTime", lifetime);
137 shared_ptr<ItemInstance> itemInstance = entityData->getItemInstance(DATA_ID_FIREWORKS_ITEM);
138 if (itemInstance != NULL)
139 {
140 CompoundTag *itemTag = new CompoundTag();
141 itemInstance->save(itemTag);
142 tag->putCompound(L"FireworksItem", itemTag);
143 }
144
145}
146
147void FireworksRocketEntity::readAdditionalSaveData(CompoundTag *tag)
148{
149 life = tag->getInt(L"Life");
150 lifetime = tag->getInt(L"LifeTime");
151
152 CompoundTag *itemTag = tag->getCompound(L"FireworksItem");
153 if (itemTag != NULL)
154 {
155 shared_ptr<ItemInstance> fromTag = ItemInstance::fromTag(itemTag);
156 if (fromTag != NULL)
157 {
158 entityData->set(DATA_ID_FIREWORKS_ITEM, fromTag);
159 }
160 }
161}
162
163float FireworksRocketEntity::getShadowHeightOffs()
164{
165 return 0;
166}
167
168float FireworksRocketEntity::getBrightness(float a)
169{
170 return Entity::getBrightness(a);
171}
172
173int FireworksRocketEntity::getLightColor(float a)
174{
175 return Entity::getLightColor(a);
176}
177
178bool FireworksRocketEntity::isAttackable()
179{
180 return false;
181}