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 "EggTile.h"
3#include "net.minecraft.world.level.h"
4#include "net.minecraft.world.level.tile.h"
5#include "net.minecraft.world.entity.item.h"
6
7EggTile::EggTile(int id) : Tile(id, Material::egg, isSolidRender())
8{
9}
10
11void EggTile::onPlace(Level *level, int x, int y, int z)
12{
13 level->addToTickNextTick(x, y, z, id, getTickDelay(level));
14}
15
16void EggTile::neighborChanged(Level *level, int x, int y, int z, int type)
17{
18 level->addToTickNextTick(x, y, z, id, getTickDelay(level));
19}
20
21void EggTile::tick(Level *level, int x, int y, int z, Random *random)
22{
23 checkSlide(level, x, y, z);
24}
25
26void EggTile::checkSlide(Level *level, int x, int y, int z)
27{
28 if (HeavyTile::isFree(level, x, y - 1, z) && y >= 0)
29 {
30 int r = 32;
31 if (HeavyTile::instaFall || !level->hasChunksAt(x - r, y - r, z - r, x + r, y + r, z + r))
32 {
33 level->removeTile(x, y, z);
34 while (HeavyTile::isFree(level, x, y - 1, z) && y > 0)
35 y--;
36 if (y > 0)
37 {
38 level->setTileAndData(x, y, z, id, 0, Tile::UPDATE_CLIENTS);
39 }
40 }
41 else
42 {
43 shared_ptr<FallingTile> e = shared_ptr<FallingTile>(new FallingTile(level, x + 0.5f, y + 0.5f, z + 0.5f, id));
44 level->addEntity(e);
45 }
46 }
47}
48
49bool EggTile::use(Level *level, int x, int y, int z, shared_ptr<Player> player, int clickedFace, float clickX, float clickY, float clickZ, bool soundOnly/*=false*/) // 4J added soundOnly param
50{
51 if(soundOnly) return false;
52
53 teleport(level, x, y, z);
54 return true;
55}
56
57void EggTile::attack(Level *level, int x, int y, int z, shared_ptr<Player> player)
58{
59 teleport(level, x, y, z);
60}
61
62void EggTile::teleport(Level *level, int x, int y, int z)
63{
64 if (level->getTile(x, y, z) != id) return;
65
66 for (int i = 0; i < 1000; i++)
67 {
68 int xt = x + level->random->nextInt(16) - level->random->nextInt(16);
69 int yt = y + level->random->nextInt(8) - level->random->nextInt(8);
70 int zt = z + level->random->nextInt(16) - level->random->nextInt(16);
71 if (level->getTile(xt, yt, zt) == 0)
72 {
73 // Fix for TU9: Content: Art: Dragon egg teleport particle effect isn't present.
74 // Don't set tiles on client, and don't create particles on the server (matches later change in Java)
75 if(!level->isClientSide)
76 {
77 level->setTileAndData(xt, yt, zt, id, level->getData(x, y, z), Tile::UPDATE_CLIENTS);
78 level->removeTile(x, y, z);
79
80 // 4J Stu - The PC version is wrong as the particles calculated on the client side will point towards a different
81 // location to the one where the egg has actually moved. As the deltas are all small we can pack them into an int
82 // See generateTeleportParticles for unpacking
83 char deltaX = x-xt;
84 char deltaY = y-yt;
85 char deltaZ = z-zt;
86 int deltas = 0|(deltaX&0xFF)|((deltaY&0xFF)<<8)|((deltaZ&0xFF)<<16);
87
88 level->levelEvent(LevelEvent::END_EGG_TELEPORT,xt,yt,zt,deltas);
89 }
90
91 // 4J Stu - This code will not work correctly on the client as it will show the particles going in the wrong direction
92 // and only for the player who attacks the egg
93 // else
94 // {
95 // int count = 128;
96 // for (int j = 0; j < count; j++)
97 // {
98 // double d = level->random->nextDouble(); // j < count / 2 ? 0 :
99 //// 1;
100 // float xa = (level->random->nextFloat() - 0.5f) * 0.2f;
101 // float ya = (level->random->nextFloat() - 0.5f) * 0.2f;
102 // float za = (level->random->nextFloat() - 0.5f) * 0.2f;
103
104 // double _x = xt + (x - xt) * d + (level->random->nextDouble() - 0.5) * 1 + 0.5f;
105 // double _y = yt + (y - yt) * d + level->random->nextDouble() * 1 - 0.5f;
106 // double _z = zt + (z - zt) * d + (level->random->nextDouble() - 0.5) * 1 + 0.5f;
107 // level->addParticle(eParticleType_ender, _x, _y, _z, xa, ya, za);
108 // }
109 // }
110 return;
111 }
112 }
113}
114
115int EggTile::getTickDelay(Level *level)
116{
117 return 5;
118}
119
120bool EggTile::blocksLight()
121{
122 return false;
123}
124
125bool EggTile::isSolidRender(bool isServerLevel)
126{
127 return false;
128}
129
130bool EggTile::isCubeShaped()
131{
132 return false;
133}
134
135bool EggTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face)
136{
137 return true;
138}
139
140int EggTile::getRenderShape()
141{
142 return Tile::SHAPE_EGG;
143}
144
145int EggTile::cloneTileId(Level *level, int x, int y, int z)
146{
147 return 0;
148}
149
150// 4J Added for Fix for #77475 - TU9: Content: Art: Dragon egg teleport particle effect isn't present.
151void EggTile::generateTeleportParticles(Level *level,int xt,int yt, int zt,int deltas)
152{
153 int count = 128;
154
155 // See above for packing
156 char deltaX = deltas&0xFF;
157 char deltaY = (deltas>>8)&0xFF;
158 char deltaZ = (deltas>>16)&0xFF;
159
160 for (int j = 0; j < count; j++)
161 {
162 double d = level->random->nextDouble(); // j < count / 2 ? 0 :
163 // 1;
164 float xa = (level->random->nextFloat() - 0.5f) * 0.2f;
165 float ya = (level->random->nextFloat() - 0.5f) * 0.2f;
166 float za = (level->random->nextFloat() - 0.5f) * 0.2f;
167
168 double _x = xt + deltaX * d + (level->random->nextDouble() - 0.5) * 1 + 0.5f;
169 double _y = yt + deltaY * d + level->random->nextDouble() * 1 - 0.5f;
170 double _z = zt + deltaZ * d + (level->random->nextDouble() - 0.5) * 1 + 0.5f;
171 level->addParticle(eParticleType_ender, _x, _y, _z, xa, ya, za);
172 }
173}