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.phys.h"
5#include "LightningBolt.h"
6#include "SoundTypes.h"
7#include "..\Minecraft.Client\MinecraftServer.h"
8#include "..\Minecraft.Client\PlayerList.h"
9#include "net.minecraft.world.level.dimension.h"
10
11
12LightningBolt::LightningBolt(Level *level, double x, double y, double z) :
13 life( 0 ),
14 seed( 0 ),
15 flashes( 0 ),
16 GlobalEntity( level )
17{
18 // 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
19 // the derived version of the function is called
20 this->defineSynchedData();
21
22 moveTo(x, y, z, 0, 0);
23 life = START_LIFE;
24 seed = random->nextLong();
25 // 4J-PB - Microsoft request due to photosensitivity issue with multiple flashes of lightning
26 //flashes = random->nextInt(3) + 1;
27 flashes = 1;
28
29 // 4J - added clientside check
30 if( !level->isClientSide && level->getGameRules()->getBoolean(GameRules::RULE_DOFIRETICK)&&level->difficulty >= 2 && level->hasChunksAt( Mth::floor(x), Mth::floor(y), Mth::floor(z), 10))
31 {
32 {
33 int xt = Mth::floor(x);
34 int yt = Mth::floor(y);
35 int zt = Mth::floor(z);
36 // 4J added - don't go setting tiles if we aren't tracking them for network synchronisation
37 if( MinecraftServer::getInstance()->getPlayers()->isTrackingTile(xt, yt, zt, level->dimension->id) )
38 {
39 if (level->getTile(xt, yt, zt) == 0 && Tile::fire->mayPlace(level, xt, yt, zt)) level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
40 }
41 }
42
43 for (int i = 0; i < 4; i++)
44 {
45 int xt = Mth::floor(x) + random->nextInt(3) - 1;
46 int yt = Mth::floor(y) + random->nextInt(3) - 1;
47 int zt = Mth::floor(z) + random->nextInt(3) - 1;
48 // 4J added - don't go setting tiles if we aren't tracking them for network synchronisation
49 if( MinecraftServer::getInstance()->getPlayers()->isTrackingTile(xt, yt, zt, level->dimension->id) )
50 {
51 if (level->getTile(xt, yt, zt) == 0 && Tile::fire->mayPlace(level, xt, yt, zt)) level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
52 }
53 }
54 }
55}
56
57void LightningBolt::tick()
58{
59 GlobalEntity::tick();
60
61 if (life == START_LIFE) {
62 // 4J-PB - this volume seems off the scale! But the volume is used to check the distance from the camera player - (volume*32) squared
63 // so we'll limit the sound in the sound engine
64 level->playSound(x, y, z, eSoundType_AMBIENT_WEATHER_THUNDER, 10000, 0.8f + random->nextFloat() * 0.2f);
65 level->playSound(x, y, z, eSoundType_RANDOM_EXPLODE, 2, 0.5f + random->nextFloat() * 0.2f);
66 }
67
68 life--;
69 if (life < 0)
70 {
71 if (flashes == 0)
72 {
73 remove();
74 }
75 else if (life < -random->nextInt(10))
76 {
77 flashes--;
78 life = 1;
79
80 seed = random->nextLong();
81 if (!level->isClientSide && level->getGameRules()->getBoolean(GameRules::RULE_DOFIRETICK) && level->hasChunksAt( (int) floor(x), (int) floor(y), (int) floor(z), 10))
82 {
83 int xt = (int) floor(x);
84 int yt = (int) floor(y);
85 int zt = (int) floor(z);
86
87 // 4J added - don't go setting tiles if we aren't tracking them for network synchronisation
88 if( MinecraftServer::getInstance()->getPlayers()->isTrackingTile(xt, yt, zt, level->dimension->id) )
89 {
90 if (level->getTile(xt, yt, zt) == 0 && Tile::fire->mayPlace(level, xt, yt, zt)) level->setTileAndUpdate(xt, yt, zt, Tile::fire_Id);
91 }
92 }
93 }
94 }
95
96 if (life >= 0)
97 {
98 if (level->isClientSide)
99 {
100 level->skyFlashTime = 2;
101 }
102 else
103 {
104 double r = 3;
105 vector<shared_ptr<Entity> > *entities = level->getEntities(shared_from_this(), AABB::newTemp(x - r, y - r, z - r, x + r, y + 6 + r, z + r));
106 AUTO_VAR(itEnd, entities->end());
107 for (AUTO_VAR(it, entities->begin()); it != itEnd; it++)
108 {
109 shared_ptr<Entity> e = (*it); //entities->at(i);
110 e->thunderHit(this);
111 }
112 }
113 }
114}
115
116
117void LightningBolt::defineSynchedData()
118{
119}
120
121void LightningBolt::readAdditionalSaveData(CompoundTag *tag)
122{
123}
124
125void LightningBolt::addAdditonalSaveData(CompoundTag *tag)
126{
127}
128
129
130bool LightningBolt::shouldAlwaysRender()
131{
132 return true;
133}
134
135bool LightningBolt::shouldRender(Vec3 *c)
136{
137 return life >= 0;
138}