the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 250 lines 6.2 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.h" 3#include "net.minecraft.world.level.h" 4#include "net.minecraft.world.level.dimension.h" 5#include "net.minecraft.world.item.h" 6#include "PortalTile.h" 7#include "FireTile.h" 8 9PortalTile::PortalTile(int id) : HalfTransparentTile(id, L"portal", Material::portal, false) 10{ 11 setTicking(true); 12} 13 14void PortalTile::tick(Level *level, int x, int y, int z, Random *random) 15{ 16 HalfTransparentTile::tick(level, x, y, z, random); 17 18 if (level->dimension->isNaturalDimension() && random->nextInt(2000) < level->difficulty) 19 { 20 // locate floor 21 int y0 = y; 22 while (!level->isTopSolidBlocking(x, y0, z) && y0 > 0) 23 { 24 y0--; 25 } 26 if (y0 > 0 && !level->isSolidBlockingTile(x, y0 + 1, z)) 27 { 28 // spawn a pig man here 29 int iResult = 0; 30 shared_ptr<Entity> entity = SpawnEggItem::spawnMobAt(level, 57, x + .5, y0 + 1.1, z + .5, &iResult); 31 if (entity != NULL) 32 { 33 entity->changingDimensionDelay = entity->getDimensionChangingDelay(); 34 } 35 } 36 } 37} 38 39AABB *PortalTile::getAABB(Level *level, int x, int y, int z) 40{ 41 return NULL; 42} 43 44void PortalTile::updateShape(LevelSource *level, int x, int y, int z, int forceData, shared_ptr<TileEntity> forceEntity) // 4J added forceData, forceEntity param 45{ 46 if (level->getTile(x - 1, y, z) == id || level->getTile(x + 1, y, z) == id) 47 { 48 float xr = 8 / 16.0f; 49 float yr = 2 / 16.0f; 50 setShape(0.5f - xr, 0, 0.5f - yr, 0.5f + xr, 1, 0.5f + yr); 51 } 52 else 53 { 54 float xr = 2 / 16.0f; 55 float yr = 8 / 16.0f; 56 setShape(0.5f - xr, 0, 0.5f - yr, 0.5f + xr, 1, 0.5f + yr); 57 } 58} 59 60bool PortalTile::isSolidRender(bool isServerLevel) 61{ 62 return false; 63} 64 65bool PortalTile::isCubeShaped() 66{ 67 return false; 68} 69 70bool PortalTile::trySpawnPortal(Level *level, int x, int y, int z, bool actuallySpawn) 71{ 72 int xd = 0; 73 int zd = 0; 74 if (level->getTile(x - 1, y, z) == Tile::obsidian_Id || level->getTile(x + 1, y, z) == Tile::obsidian_Id) xd = 1; 75 if (level->getTile(x, y, z - 1) == Tile::obsidian_Id || level->getTile(x, y, z + 1) == Tile::obsidian_Id) zd = 1; 76 77 if (xd == zd) return false; 78 79 if (level->getTile(x - xd, y, z - zd) == 0) 80 { 81 x -= xd; 82 z -= zd; 83 } 84 85 for (int xx = -1; xx <= 2; xx++) 86 { 87 for (int yy = -1; yy <= 3; yy++) 88 { 89 bool edge = (xx == -1) || (xx == 2) || (yy == -1) || (yy == 3); 90 if ((xx == -1 || xx == 2) && (yy == -1 || yy == 3)) continue; 91 92 int t = level->getTile(x + xd * xx, y + yy, z + zd * xx); 93 94 if (edge) 95 { 96 if (t != Tile::obsidian_Id) return false; 97 } 98 else 99 { 100 if (t != 0 && t != Tile::fire_Id) return false; 101 } 102 } 103 } 104 105 if( !actuallySpawn ) 106 return true; 107 108 for (int xx = 0; xx < 2; xx++) 109 { 110 for (int yy = 0; yy < 3; yy++) 111 { 112 level->setTileAndData(x + xd * xx, y + yy, z + zd * xx, Tile::portalTile_Id, 0, Tile::UPDATE_CLIENTS); 113 } 114 } 115 116 return true; 117 118} 119 120void PortalTile::neighborChanged(Level *level, int x, int y, int z, int type) 121{ 122 int xd = 0; 123 int zd = 1; 124 if (level->getTile(x - 1, y, z) == id || level->getTile(x + 1, y, z) == id) 125 { 126 xd = 1; 127 zd = 0; 128 } 129 130 int yBottom = y; 131 while (level->getTile(x, yBottom - 1, z) == id) 132 yBottom--; 133 134 if (level->getTile(x, yBottom - 1, z) != Tile::obsidian_Id) 135 { 136 level->removeTile(x, y, z); 137 return; 138 } 139 140 int height = 1; 141 while (height < 4 && level->getTile(x, yBottom + height, z) == id) 142 height++; 143 144 if (height != 3 || level->getTile(x, yBottom + height, z) != Tile::obsidian_Id) 145 { 146 level->removeTile(x, y, z); 147 return; 148 } 149 150 bool we = level->getTile(x - 1, y, z) == id || level->getTile(x + 1, y, z) == id; 151 bool ns = level->getTile(x, y, z - 1) == id || level->getTile(x, y, z + 1) == id; 152 if (we && ns) 153 { 154 level->removeTile(x, y, z); 155 return; 156 } 157 158 if (!(// 159 (level->getTile(x + xd, y, z + zd) == Tile::obsidian_Id && level->getTile(x - xd, y, z - zd) == id) || // 160 (level->getTile(x - xd, y, z - zd) == Tile::obsidian_Id && level->getTile(x + xd, y, z + zd) == id)// 161 )) 162 { 163 level->removeTile(x, y, z); 164 return; 165 } 166 167} 168 169bool PortalTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face) 170{ 171 if (level->getTile(x, y, z) == id) return false; 172 173 bool w = level->getTile(x - 1, y, z) == id && level->getTile(x - 2, y, z) != id; 174 bool e = level->getTile(x + 1, y, z) == id && level->getTile(x + 2, y, z) != id; 175 176 bool n = level->getTile(x, y, z - 1) == id && level->getTile(x, y, z - 2) != id; 177 bool s = level->getTile(x, y, z + 1) == id && level->getTile(x, y, z + 2) != id; 178 179 bool we = w || e; 180 bool ns = n || s; 181 182 if (we && face == 4) return true; 183 if (we && face == 5) return true; 184 if (ns && face == 2) return true; 185 if (ns && face == 3) return true; 186 187 return false; 188} 189 190int PortalTile::getResourceCount(Random *random) 191{ 192 return 0; 193} 194 195int PortalTile::getRenderLayer() 196{ 197 return 1; 198} 199 200void PortalTile::entityInside(Level *level, int x, int y, int z, shared_ptr<Entity> entity) 201{ 202 if (entity->GetType() == eTYPE_EXPERIENCEORB ) return; // 4J added 203 204 if (entity->riding == NULL && entity->rider.lock() == NULL) entity->handleInsidePortal(); 205} 206 207void PortalTile::animateTick(Level *level, int xt, int yt, int zt, Random *random) 208{ 209 if (random->nextInt(100) == 0) 210 { 211 level->playLocalSound(xt + 0.5, yt + 0.5, zt + 0.5, eSoundType_PORTAL_PORTAL, 0.5f, random->nextFloat() * 0.4f + 0.8f, false); 212 } 213 for (int i = 0; i < 4; i++) 214 { 215 double x = xt + random->nextFloat(); 216 double y = yt + random->nextFloat(); 217 double z = zt + random->nextFloat(); 218 double xa = 0; 219 double ya = 0; 220 double za = 0; 221 int flip = random->nextInt(2) * 2 - 1; 222 xa = (random->nextFloat() - 0.5) * 0.5; 223 ya = (random->nextFloat() - 0.5) * 0.5; 224 za = (random->nextFloat() - 0.5) * 0.5; 225 if (level->getTile(xt - 1, yt, zt) == id || level->getTile(xt + 1, yt, zt) == id) 226 { 227 z = zt + 0.5 + (0.25) * flip; 228 za = (random->nextFloat() * 2) * flip; 229 } 230 else 231 { 232 x = xt + 0.5 + (0.25) * flip; 233 xa = (random->nextFloat() * 2) * flip; 234 } 235 236 level->addParticle(eParticleType_netherportal, x, y, z, xa, ya, za); 237 } 238} 239 240int PortalTile::cloneTileId(Level *level, int x, int y, int z) 241{ 242 return 0; 243} 244 245// 4J Added - We cannot collect the portal tile, so don't consider it as a hit result 246// Bug #754 - Riding a minecart into a portal will trap the player 247bool PortalTile::mayPick() 248{ 249 return false; 250}