the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 146 lines 4.1 kB view raw
1#include "stdafx.h" 2#include "..\Minecraft.Client\Minecraft.h" 3#include "GrassTile.h" 4#include "net.minecraft.world.level.h" 5#include "net.minecraft.world.level.biome.h" 6#include "net.minecraft.h" 7#include "net.minecraft.world.h" 8 9// AP - included for PSVita Alpha cut out optimisation 10#include "IntBuffer.h" 11#include "..\Minecraft.Client\Tesselator.h" 12 13GrassTile::GrassTile(int id) : Tile(id, Material::grass) 14{ 15 iconTop = NULL; 16 iconSnowSide = NULL; 17 iconSideOverlay = NULL; 18 19 setTicking(true); 20} 21 22Icon *GrassTile::getTexture(int face, int data) 23{ 24 if (face == Facing::UP) return iconTop; 25 if (face == Facing::DOWN) return Tile::dirt->getTexture(face); 26 return icon; 27} 28 29Icon *GrassTile::getTexture(LevelSource *level, int x, int y, int z, int face) 30{ 31 if (face == Facing::UP) return iconTop; 32 if (face == Facing::DOWN) return Tile::dirt->getTexture(face); 33 Material *above = level->getMaterial(x, y + 1, z); 34 if (above == Material::topSnow || above == Material::snow) return iconSnowSide; 35 else return icon; 36} 37 38void GrassTile::registerIcons(IconRegister *iconRegister) 39{ 40 icon = iconRegister->registerIcon(L"grass_side"); 41 iconTop = iconRegister->registerIcon(L"grass_top"); 42 iconSnowSide = iconRegister->registerIcon(L"snow_side"); 43 iconSideOverlay = iconRegister->registerIcon(L"grass_side_overlay"); 44} 45 46int GrassTile::getColor() const 47{ 48 // 4J Replaced 49 //double temp = 0.5; 50 //double rain = 1.0; 51 52 //return GrassColor::get(temp, rain); 53 54 return Minecraft::GetInstance()->getColourTable()->getColor( eMinecraftColour_Grass_Common ); 55} 56 57int GrassTile::getColor(int auxData) 58{ 59 return getColor(); 60} 61 62int GrassTile::getColor(LevelSource *level, int x, int y, int z) 63{ 64 return getColor( level, x, y, z, level->getData( x, y, z ) ); 65} 66 67// 4J - changed interface to have data passed in, and put existing interface as wrapper above 68int GrassTile::getColor(LevelSource *level, int x, int y, int z, int data) 69{ 70 //return level->getBiomeSource()->getBiome(x, z)->getGrassColor(level, x, y, z); 71 72 int totalRed = 0; 73 int totalGreen = 0; 74 int totalBlue = 0; 75 76 for (int oz = -1; oz <= 1; oz++) 77 { 78 for (int ox = -1; ox <= 1; ox++) 79 { 80 int grassColor = level->getBiome(x + ox, z + oz)->getGrassColor(); 81 82 totalRed += (grassColor & 0xff0000) >> 16; 83 totalGreen += (grassColor & 0xff00) >> 8; 84 totalBlue += (grassColor & 0xff); 85 } 86 } 87 88 return (((totalRed / 9) & 0xFF) << 16) | (((totalGreen / 9) & 0xFF) << 8) | (((totalBlue / 9) & 0xFF)); 89} 90 91void GrassTile::tick(Level *level, int x, int y, int z, Random *random) 92{ 93 if (level->isClientSide) return; 94 95 if (level->getRawBrightness(x, y + 1, z) < MIN_BRIGHTNESS && Tile::lightBlock[level->getTile(x, y + 1, z)] > 2) 96 { 97 level->setTileAndUpdate(x, y, z, Tile::dirt_Id); 98 } 99 else 100 { 101 if (level->getRawBrightness(x, y + 1, z) >= Level::MAX_BRIGHTNESS - 6) 102 { 103 for (int i = 0; i < 4; i++) 104 { 105 int xt = x + random->nextInt(3) - 1; 106 int yt = y + random->nextInt(5) - 3; 107 int zt = z + random->nextInt(3) - 1; 108 int above = level->getTile(xt, yt + 1, zt); 109 if (level->getTile(xt, yt, zt) == Tile::dirt_Id && level->getRawBrightness(xt, yt + 1, zt) >= MIN_BRIGHTNESS && Tile::lightBlock[above] <= 2) 110 { 111 level->setTileAndUpdate(xt, yt, zt, Tile::grass_Id); 112 } 113 } 114 } 115 } 116} 117 118int GrassTile::getResource(int data, Random *random, int playerBonusLevel) 119{ 120 return Tile::dirt->getResource(0, random, playerBonusLevel); 121} 122 123Icon *GrassTile::getSideTextureOverlay() 124{ 125#ifdef __PSVITA__ 126 // AP - alpha cut out is expensive on vita. Because of the way grass sides are treated as special case we need to set the alpha flag here 127 // this would normally happen in TileRenderer::getTextureOrMissing 128 Tesselator* t = Tesselator::getInstance(); 129 t->setAlphaCutOut( true ); 130#endif 131 132 return Tile::grass->iconSideOverlay; 133} 134 135bool GrassTile::shouldTileTick(Level *level, int x,int y,int z) 136{ 137 bool should = false; 138 139 if( (level->getRawBrightness(x, y + 1, z) < MIN_BRIGHTNESS && Tile::lightBlock[level->getTile(x, y + 1, z)] > 2) || 140 (level->getRawBrightness(x, y + 1, z) >= Level::MAX_BRIGHTNESS - 6) ) 141 { 142 should = true; 143 } 144 145 return should; 146}