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 "PistonMovingPiece.h"
3#include "PistonPieceEntity.h"
4#include "net.minecraft.world.level.h"
5#include "net.minecraft.world.h"
6#include "Facing.h"
7#include "AABB.h"
8
9PistonMovingPiece::PistonMovingPiece(int id) : BaseEntityTile(id, Material::piston, isSolidRender() )
10{
11 setDestroyTime(INDESTRUCTIBLE_DESTROY_TIME);
12}
13
14shared_ptr<TileEntity> PistonMovingPiece::newTileEntity(Level *level)
15{
16 return nullptr;
17}
18
19void PistonMovingPiece::onPlace(Level *level, int x, int y, int z)
20{
21}
22
23void PistonMovingPiece::onRemove(Level *level, int x, int y, int z, int id, int data)
24{
25 shared_ptr<TileEntity> tileEntity = level->getTileEntity(x, y, z);
26 if (tileEntity != NULL && dynamic_pointer_cast<PistonPieceEntity>(tileEntity) != NULL)
27 {
28 dynamic_pointer_cast<PistonPieceEntity>(tileEntity)->finalTick();
29 }
30 else
31 {
32 BaseEntityTile::onRemove(level, x, y, z, id, data);
33 }
34}
35
36bool PistonMovingPiece::mayPlace(Level *level, int x, int y, int z)
37{
38 return false;
39}
40
41bool PistonMovingPiece::mayPlace(Level *level, int x, int y, int z, int face)
42{
43 return false;
44}
45
46int PistonMovingPiece::getRenderShape()
47{
48 return SHAPE_INVISIBLE;
49}
50
51bool PistonMovingPiece::isSolidRender(bool isServerLevel)
52{
53 return false;
54}
55
56bool PistonMovingPiece::isCubeShaped()
57{
58 return false;
59}
60
61bool PistonMovingPiece::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
62{
63 if( soundOnly) return false;
64 // this is a special case in order to help removing invisible, unbreakable, blocks in the world
65 if (!level->isClientSide && level->getTileEntity(x, y, z) == NULL)
66 {
67 // this block is no longer valid
68 level->removeTile(x, y, z);
69 return true;
70 }
71 return false;
72}
73
74int PistonMovingPiece::getResource(int data, Random *random, int playerBonusLevel)
75{
76 return 0;
77}
78
79void PistonMovingPiece::spawnResources(Level *level, int x, int y, int z, int data, float odds, int playerBonus)
80{
81 if (level->isClientSide) return;
82
83 shared_ptr<PistonPieceEntity> entity = getEntity(level, x, y, z);
84 if (entity == NULL)
85 {
86 return;
87 }
88
89 Tile::tiles[entity->getId()]->spawnResources(level, x, y, z, entity->getData(), 0);
90}
91
92void PistonMovingPiece::neighborChanged(Level *level, int x, int y, int z, int type)
93{
94 if (!level->isClientSide)
95 {
96 level->getTileEntity(x, y, z) == NULL;
97 }
98}
99
100shared_ptr<TileEntity> PistonMovingPiece::newMovingPieceEntity(int block, int data, int facing, bool extending, bool isSourcePiston)
101{
102 return shared_ptr<TileEntity>(new PistonPieceEntity(block, data, facing, extending, isSourcePiston));
103}
104
105AABB *PistonMovingPiece::getAABB(Level *level, int x, int y, int z)
106{
107 shared_ptr<PistonPieceEntity> entity = getEntity(level, x, y, z);
108 if (entity == NULL)
109 {
110 return NULL;
111 }
112
113 // move the aabb depending on the animation
114 float progress = entity->getProgress(0);
115 if (entity->isExtending())
116 {
117 progress = 1.0f - progress;
118 }
119 return getAABB(level, x, y, z, entity->getId(), progress, entity->getFacing());
120}
121
122void PistonMovingPiece::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param
123{
124 shared_ptr<PistonPieceEntity> entity = dynamic_pointer_cast<PistonPieceEntity>(forceEntity);
125 if( entity == NULL ) entity = getEntity(level, x, y, z);
126 if (entity != NULL)
127 {
128 Tile *tile = Tile::tiles[entity->getId()];
129 if (tile == NULL || tile == this)
130 {
131 return;
132 }
133 tile->updateShape(level, x, y, z);
134
135 float progress = entity->getProgress(0);
136 if (entity->isExtending())
137 {
138 progress = 1.0f - progress;
139 }
140 int facing = entity->getFacing();
141 ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape);
142 tls->xx0 = tile->getShapeX0() - Facing::STEP_X[facing] * progress;
143 tls->yy0 = tile->getShapeY0() - Facing::STEP_Y[facing] * progress;
144 tls->zz0 = tile->getShapeZ0() - Facing::STEP_Z[facing] * progress;
145 tls->xx1 = tile->getShapeX1() - Facing::STEP_X[facing] * progress;
146 tls->yy1 = tile->getShapeY1() - Facing::STEP_Y[facing] * progress;
147 tls->zz1 = tile->getShapeZ1() - Facing::STEP_Z[facing] * progress;
148 }
149}
150
151AABB *PistonMovingPiece::getAABB(Level *level, int x, int y, int z, int tile, float progress, int facing)
152{
153 if (tile == 0 || tile == id)
154 {
155 return NULL;
156 }
157 AABB *aabb = Tile::tiles[tile]->getAABB(level, x, y, z);
158
159 if (aabb == NULL)
160 {
161 return NULL;
162 }
163
164 // move the aabb depending on the animation
165 if (Facing::STEP_X[facing] < 0)
166 {
167 aabb->x0 -= Facing::STEP_X[facing] * progress;
168 }
169 else
170 {
171 aabb->x1 -= Facing::STEP_X[facing] * progress;
172 }
173 if (Facing::STEP_Y[facing] < 0)
174 {
175 aabb->y0 -= Facing::STEP_Y[facing] * progress;
176 }
177 else
178 {
179 aabb->y1 -= Facing::STEP_Y[facing] * progress;
180 }
181 if (Facing::STEP_Z[facing] < 0)
182 {
183 aabb->z0 -= Facing::STEP_Z[facing] * progress;
184 }
185 else
186 {
187 aabb->z1 -= Facing::STEP_Z[facing] * progress;
188 }
189 return aabb;
190}
191
192shared_ptr<PistonPieceEntity> PistonMovingPiece::getEntity(LevelSource *level, int x, int y, int z)
193{
194 shared_ptr<TileEntity> tileEntity = level->getTileEntity(x, y, z);
195 if (tileEntity != NULL && dynamic_pointer_cast<PistonPieceEntity>(tileEntity) != NULL)
196 {
197 return dynamic_pointer_cast<PistonPieceEntity>(tileEntity);
198 }
199 return nullptr;
200}
201
202void PistonMovingPiece::registerIcons(IconRegister *iconRegister)
203{
204 // don't register null, register piston top instead (to get proper
205 // particle effect)
206 icon = iconRegister->registerIcon(L"piston_top");
207}
208
209int PistonMovingPiece::cloneTileId(Level *level, int x, int y, int z)
210{
211 return 0;
212}