the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 224 lines 6.3 kB view raw
1#include "stdafx.h" 2#include "LiquidTile_SPU.h" 3#include "Facing_SPU.h" 4#include "ChunkRebuildData.h" 5 6#ifdef SN_TARGET_PS3_SPU 7#include "..\Common\spu_assert.h" 8#endif 9 10// const wstring LiquidTile::TEXTURE_LAVA_STILL = L"lava"; 11// const wstring LiquidTile::TEXTURE_WATER_STILL = L"water"; 12// const wstring LiquidTile::TEXTURE_WATER_FLOW = L"water_flow"; 13// const wstring LiquidTile::TEXTURE_LAVA_FLOW = L"lava_flow"; 14 15#define MATH_PI (3.141592654f) 16 17 18int LiquidTile_SPU::getColor(ChunkRebuildData *level, int x, int y, int z) 19{ 20 21 return getColor(level, x, y, z, 0); 22} 23 24int LiquidTile_SPU::getColor(ChunkRebuildData *level, int x, int y, int z, int d) 25{ 26 // MGH - TODO 27 if (getMaterial()->getID() == Material_SPU::water_Id) 28 { 29 // Biome b = level.getBiomeSource().getBiome(x, z); 30 // return b.waterColor; 31 32 int totalRed = 0; 33 int totalGreen = 0; 34 int totalBlue = 0; 35 36 for (int oz = -1; oz <= 1; oz++) 37 { 38 for (int ox = -1; ox <= 1; ox++) 39 { 40 int waterColor = level->getWaterColor(x + ox, z + oz); 41 42 totalRed += (waterColor & 0xff0000) >> 16; 43 totalGreen += (waterColor & 0xff00) >> 8; 44 totalBlue += (waterColor & 0xff); 45 } 46 } 47 48 // return level.getBiomeSource().getBiome(x, z).getGrassColor(level, x, y, z); 49 return (((totalRed / 9) & 0xFF) << 16) | (((totalGreen / 9) & 0xFF) << 8) | (((totalBlue / 9) & 0xFF)); 50 } 51 return 0xffffff; 52} 53 54float LiquidTile_SPU::getHeight(int d) 55{ 56 // if (d == 0) d++; 57 if (d >= 8) d = 0; 58 return (d + 1) / 9.0f; 59} 60 61Icon_SPU *LiquidTile_SPU::getTexture(int face, int data) 62{ 63 if (face == Facing::DOWN || face == Facing::UP) 64 { 65 if(id == water_Id || id == calmWater_Id) 66 return &ms_pTileData->liquidTile_iconWaterStill; 67 else //(id == lava_Id || id == calmLava_Id) 68 return &ms_pTileData->liquidTile_iconLavaStill; 69 } 70 else 71 { 72 if(id == water_Id || id == calmWater_Id) 73 return &ms_pTileData->liquidTile_iconWaterFlow; 74 else //(id == lava_Id || id == calmLava_Id) 75 return &ms_pTileData->liquidTile_iconLavaFlow; 76 } 77} 78 79int LiquidTile_SPU::getDepth(ChunkRebuildData *level, int x, int y, int z) 80{ 81 if (level->getMaterial(x, y, z)->getID() != getMaterial()->getID()) return -1; 82 else return -1;; 83} 84 85int LiquidTile_SPU::getRenderedDepth(ChunkRebuildData *level, int x, int y, int z) 86{ 87 if (level->getMaterial(x, y, z)->getID() != getMaterial()->getID()) return -1; 88 int d = level->getData(x, y, z); 89 if (d >= 8) d = 0; 90 return d; 91} 92 93 94bool LiquidTile_SPU::isSolidRender(bool isServerLevel) 95{ 96 return false; 97} 98 99bool LiquidTile_SPU::isSolidFace(ChunkRebuildData *level, int x, int y, int z, int face) 100{ 101 Material_SPU *m = level->getMaterial(x, y, z); 102 if (m->getID() == this->getMaterial()->getID()) return false; 103 if (face == Facing::UP) return true; 104 if (m->getID() == Material_SPU::ice_Id) return false; 105 106 return Tile_SPU::isSolidFace(level, x, y, z, face); 107} 108 109bool LiquidTile_SPU::shouldRenderFace(ChunkRebuildData *level, int x, int y, int z, int face) 110{ 111 Material_SPU *m = level->getMaterial(x, y, z); 112 if (m->getID() == this->getMaterial()->getID()) return false; 113 if (face == Facing::UP) return true; 114 if (m->getID() == Material_SPU::ice_Id) return false; 115 return Tile_SPU::shouldRenderFace(level, x, y, z, face); 116} 117 118int LiquidTile_SPU::getRenderShape() 119{ 120 return Tile_SPU::SHAPE_WATER; 121} 122 123 124Vec3_SPU LiquidTile_SPU::getFlow(ChunkRebuildData *level, int x, int y, int z) 125{ 126 Vec3_SPU flow = Vec3_SPU(0,0,0); 127 int mid = getRenderedDepth(level, x, y, z); 128 for (int d = 0; d < 4; d++) 129 { 130 131 int xt = x; 132 int yt = y; 133 int zt = z; 134 135 if (d == 0) xt--; 136 if (d == 1) zt--; 137 if (d == 2) xt++; 138 if (d == 3) zt++; 139 140 int t = getRenderedDepth(level, xt, yt, zt); 141 if (t < 0) 142 { 143 if (!level->getMaterial(xt, yt, zt)->blocksMotion()) 144 { 145 t = getRenderedDepth(level, xt, yt - 1, zt); 146 if (t >= 0) 147 { 148 int dir = t - (mid - 8); 149 flow = flow.add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir); 150 } 151 } 152 } else 153 { 154 if (t >= 0) 155 { 156 int dir = t - mid; 157 flow = flow.add((xt - x) * dir, (yt - y) * dir, (zt - z) * dir); 158 } 159 } 160 161 } 162 if (level->getData(x, y, z) >= 8) 163 { 164 bool ok = false; 165 if (ok || isSolidFace(level, x, y, z - 1, 2)) ok = true; 166 if (ok || isSolidFace(level, x, y, z + 1, 3)) ok = true; 167 if (ok || isSolidFace(level, x - 1, y, z, 4)) ok = true; 168 if (ok || isSolidFace(level, x + 1, y, z, 5)) ok = true; 169 if (ok || isSolidFace(level, x, y + 1, z - 1, 2)) ok = true; 170 if (ok || isSolidFace(level, x, y + 1, z + 1, 3)) ok = true; 171 if (ok || isSolidFace(level, x - 1, y + 1, z, 4)) ok = true; 172 if (ok || isSolidFace(level, x + 1, y + 1, z, 5)) ok = true; 173 if (ok) flow = flow.normalize().add(0, -6, 0); 174 } 175 flow = flow.normalize(); 176 return flow; 177} 178 179 180// 4J - change brought forward from 1.8.2 181int LiquidTile_SPU::getLightColor(ChunkRebuildData *level, int x, int y, int z) 182{ 183 int a = level->getLightColor(x, y, z, 0); 184 int b = level->getLightColor(x, y + 1, z, 0); 185 186 int aa = a & 0xff; 187 int ba = b & 0xff; 188 int ab = (a >> 16) & 0xff; 189 int bb = (b >> 16) & 0xff; 190 191 return (aa > ba ? aa : ba) | ((ab > bb ? ab : bb) << 16); 192} 193 194float LiquidTile_SPU::getBrightness(ChunkRebuildData *level, int x, int y, int z) 195{ 196 float a = level->getBrightness(x, y, z); 197 float b = level->getBrightness(x, y + 1, z); 198 return a > b ? a : b; 199} 200 201 202int LiquidTile_SPU::getRenderLayer() 203{ 204 return getMaterial()->getID() == Material_SPU::water_Id ? 1 : 0; 205} 206 207 208double LiquidTile_SPU::getSlopeAngle(ChunkRebuildData *level, int x, int y, int z, Material_SPU *m) 209{ 210 Vec3_SPU flow = Vec3_SPU(0,0,0); 211 if (m->getID() == Material_SPU::water_Id) 212 { 213 TileRef_SPU tRef(Tile_SPU::water_Id); 214 flow = ((LiquidTile_SPU*)tRef.getPtr())->getFlow(level, x, y, z); 215 } 216 if (m->getID() == Material_SPU::lava_Id) 217 { 218 TileRef_SPU tRef(Tile_SPU::lava_Id); 219 flow = ((LiquidTile_SPU*)tRef.getPtr())->getFlow(level, x, y, z); 220 } 221 if (flow.x == 0 && flow.z == 0) return -1000; 222 return atan2(flow.z, flow.x) - MATH_PI / 2; 223} 224