the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 179 lines 4.3 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.level.h" 3#include "net.minecraft.world.entity.boss.enderdragon.h" 4#include "net.minecraft.world.level.tile.h" 5#include "SpikeFeature.h" 6 7SpikeFeature::SpikeFeature(int tile) 8{ 9 this->tile = tile; 10 //m_iIndex=0; 11} 12 13bool SpikeFeature::place(Level *level, Random *random, int x, int y, int z) 14{ 15 if (!(level->isEmptyTile(x, y, z) && level->getTile(x, y - 1, z) == tile)) 16 { 17 return false; 18 } 19 int hh = random->nextInt(32) + 6; 20 int r = random->nextInt(4) + 1; 21 22 for (int xx = x - r; xx <= x + r; xx++) 23 for (int zz = z - r; zz <= z + r; zz++) 24 { 25 int xd = xx - x; 26 int zd = zz - z; 27 if (xd * xd + zd * zd <= r * r + 1) 28 { 29 if (level->getTile(xx, y - 1, zz) != tile) 30 { 31 return false; 32 } 33 } 34 } 35 36 for (int yy = y; yy < y + hh; yy++) 37 { 38 if (yy < Level::genDepth) 39 { 40 for (int xx = x - r; xx <= x + r; xx++) 41 for (int zz = z - r; zz <= z + r; zz++) 42 { 43 int xd = xx - x; 44 int zd = zz - z; 45 if (xd * xd + zd * zd <= r * r + 1) 46 { 47 level->setTileAndData(xx, yy, zz, Tile::obsidian_Id, 0, Tile::UPDATE_CLIENTS); 48 } 49 } 50 } else break; 51 } 52 53 shared_ptr<EnderCrystal> enderCrystal = shared_ptr<EnderCrystal>(new EnderCrystal(level)); 54 enderCrystal->moveTo(x + 0.5f, y + hh, z + 0.5f, random->nextFloat() * 360, 0); 55 level->addEntity(enderCrystal); 56 level->setTileAndData(x, y + hh, z, Tile::unbreakable_Id, 0, Tile::UPDATE_CLIENTS); 57 58 return true; 59} 60 61bool SpikeFeature::placeWithIndex(Level *level, Random *random, int x, int y, int z,int iIndex, int iRadius) 62{ 63 app.DebugPrintf("Spike - %d,%d,%d - index %d\n",x,y,z,iIndex); 64 65 int hh = 12 + (iIndex*3); 66 67 // fill any tiles below the spike 68 69 for (int xx = x - iRadius; xx <= x + iRadius; xx++) 70 { 71 for (int zz = z - iRadius; zz <= z + iRadius; zz++) 72 { 73 int xd = xx - x; 74 int zd = zz - z; 75 if (xd * xd + zd * zd <= iRadius * iRadius + 1) 76 { 77 int iTileBelow=1; 78 79 while((y-iTileBelow>-10) && level->getTile(xx, y - iTileBelow, zz) != tile) 80 { 81 if(level->isEmptyTile(xx, y - iTileBelow, zz)) 82 { 83 // empty tile 84 level->setTileAndData(xx, y - iTileBelow, zz, Tile::obsidian_Id, 0, Tile::UPDATE_CLIENTS); 85 } 86 else 87 { 88 level->setTileAndData(xx, y - iTileBelow, zz, Tile::obsidian_Id, 0, Tile::UPDATE_CLIENTS); 89 } 90 iTileBelow++; 91 } 92 } 93 } 94 } 95 96 for (int yy = y; yy < y + hh; yy++) 97 { 98 if (yy < Level::genDepth) 99 { 100 for (int xx = x - iRadius; xx <= x + iRadius; xx++) 101 { 102 for (int zz = z - iRadius; zz <= z + iRadius; zz++) 103 { 104 int xd = xx - x; 105 int zd = zz - z; 106 int iVal = xd * xd + zd * zd; 107 if ( iVal <= iRadius * iRadius + 1) 108 { 109 //level->setTile(xx, yy, zz, Tile::obsidian_Id); 110 placeBlock(level, xx, yy, zz, Tile::obsidian_Id, 0); 111 } 112 } 113 } 114 } 115 else 116 { 117 app.DebugPrintf("Breaking out of spike feature\n"); 118 break; 119 } 120 } 121 122 // cap the last spikes with a fence to stop lucky arrows hitting the crystal 123 124 if(iIndex>5) 125 { 126 for (int yy = y; yy < y + hh; yy++) 127 { 128 if (yy < Level::genDepth) 129 { 130 for (int xx = x - 2; xx <= x + 2; xx++) 131 { 132 for (int zz = z - 2; zz <= z + 2; zz++) 133 { 134 int xd = xx - x; 135 int zd = zz - z; 136 int iVal = xd * xd + zd * zd; 137 if ( iVal >= 2 * 2) 138 { 139 if(yy==(y + hh - 1)) 140 { 141 placeBlock(level, xx, y + hh, zz, Tile::ironFence_Id, 0); 142 placeBlock(level, xx, y + hh +1, zz, Tile::ironFence_Id, 0); 143 placeBlock(level, xx, y + hh +2, zz, Tile::ironFence_Id, 0); 144 } 145 } 146 } 147 } 148 } 149 else 150 { 151 app.DebugPrintf("Breaking out of spike feature\n"); 152 break; 153 } 154 } 155 156 // and cap off the top 157 int yy = y + hh + 3; 158 159 if (yy < Level::genDepth) 160 { 161 for (int xx = x - 2; xx <= x + 2; xx++) 162 { 163 for (int zz = z - 2; zz <= z + 2; zz++) 164 { 165 placeBlock(level, xx, yy, zz, Tile::ironFence_Id, 0); 166 } 167 } 168 } 169 } 170 171 shared_ptr<EnderCrystal> enderCrystal = shared_ptr<EnderCrystal>(new EnderCrystal(level)); 172 enderCrystal->moveTo(x + 0.5f, y + hh, z + 0.5f, random->nextFloat() * 360, 0); 173 level->addEntity(enderCrystal); 174 placeBlock(level, x, y + hh, z, Tile::unbreakable_Id, 0); 175 //level->setTile(x, y + hh, z, Tile::unbreakable_Id); 176 177 return true; 178} 179