diff options
Diffstat (limited to 'Minecraft.World/TopSnowTile.cpp')
| -rw-r--r-- | Minecraft.World/TopSnowTile.cpp | 75 |
1 files changed, 29 insertions, 46 deletions
diff --git a/Minecraft.World/TopSnowTile.cpp b/Minecraft.World/TopSnowTile.cpp index 9bcf5527..033b4eb2 100644 --- a/Minecraft.World/TopSnowTile.cpp +++ b/Minecraft.World/TopSnowTile.cpp @@ -9,14 +9,13 @@ #include "TopSnowTile.h" const int TopSnowTile::MAX_HEIGHT = 6; - const int TopSnowTile::HEIGHT_MASK = 7; // max 8 steps - TopSnowTile::TopSnowTile(int id) : Tile(id, Material::topSnow,isSolidRender()) { setShape(0, 0, 0, 1, 2 / 16.0f, 1); setTicking(true); + updateShape(0); } void TopSnowTile::registerIcons(IconRegister *iconRegister) @@ -27,12 +26,9 @@ void TopSnowTile::registerIcons(IconRegister *iconRegister) AABB *TopSnowTile::getAABB(Level *level, int x, int y, int z) { int height = level->getData(x, y, z) & HEIGHT_MASK; - if (height >= (MAX_HEIGHT / 2)) - { - ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); - return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + .5f, z + tls->zz1); - } - return NULL; + float offset = 2.0f / SharedConstants::WORLD_RESOLUTION; + ThreadStorage *tls = (ThreadStorage *)TlsGetValue(Tile::tlsIdxShape); + return AABB::newTemp(x + tls->xx0, y + tls->yy0, z + tls->zz0, x + tls->xx1, y + (height * offset), z + tls->zz1); } float TopSnowTile::getHeight(Level *level, int x, int y, int z) @@ -41,19 +37,16 @@ float TopSnowTile::getHeight(Level *level, int x, int y, int z) return 2 * (1 + height) / 16.0f; } - bool TopSnowTile::blocksLight() { return false; } - bool TopSnowTile::isSolidRender(bool isServerLevel) { return false; } - bool TopSnowTile::isCubeShaped() { return false; @@ -79,67 +72,57 @@ void TopSnowTile::updateShape(int data) bool TopSnowTile::mayPlace(Level *level, int x, int y, int z) { int t = level->getTile(x, y - 1, z); + if (t == 0) return false; + if (t == id && (level->getData(x, y - 1, z) & HEIGHT_MASK) == MAX_HEIGHT + 1) return true; // 4J Stu - Assume when placing that this is the server level and we don't care how it's going to be rendered // Fix for #9407 - Gameplay: Destroying a block of snow on top of trees, removes any adjacent snow. - if (t == 0 || (t != Tile::leaves_Id && !Tile::tiles[t]->isSolidRender(true))) return false; + if (t != Tile::leaves_Id && !Tile::tiles[t]->isSolidRender(true)) return false; return level->getMaterial(x, y - 1, z)->blocksMotion(); } - void TopSnowTile::neighborChanged(Level *level, int x, int y, int z, int type) { checkCanSurvive(level, x, y, z); } - bool TopSnowTile::checkCanSurvive(Level *level, int x, int y, int z) { if (!mayPlace(level, x, y, z)) { - this->spawnResources(level, x, y, z, level->getData(x, y, z), 0); - level->setTile(x, y, z, 0); + spawnResources(level, x, y, z, level->getData(x, y, z), 0); + level->removeTile(x, y, z); return false; } return true; } - void TopSnowTile::playerDestroy(Level *level, shared_ptr<Player> player, int x, int y, int z, int data) { int type = Item::snowBall->id; - float s = 0.7f; - double xo = level->random->nextFloat() * s + (1 - s) * 0.5; - double yo = level->random->nextFloat() * s + (1 - s) * 0.5; - double zo = level->random->nextFloat() * s + (1 - s) * 0.5; - shared_ptr<ItemEntity> item = shared_ptr<ItemEntity>( new ItemEntity(level, x + xo, y + yo, z + zo, shared_ptr<ItemInstance>( new ItemInstance(type, 1, 0) ) ) ); - item->throwTime = 10; - level->addEntity(item); - level->setTile(x, y, z, 0); + int height = data & HEIGHT_MASK; + popResource(level, x, y, z, shared_ptr<ItemInstance>( new ItemInstance(type, height + 1, 0))); + level->removeTile(x, y, z); } - int TopSnowTile::getResource(int data, Random *random, int playerBonusLevel) { return Item::snowBall->id; } - int TopSnowTile::getResourceCount(Random *random) { return 0; } - void TopSnowTile::tick(Level *level, int x, int y, int z, Random *random) { if (level->getBrightness(LightLayer::Block, x, y, z) > 11) { - this->spawnResources(level, x, y, z, level->getData(x, y, z), 0); - level->setTile(x, y, z, 0); + spawnResources(level, x, y, z, level->getData(x, y, z), 0); + level->removeTile(x, y, z); } } - bool TopSnowTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int face) { if (face == 1) return true; @@ -155,20 +138,20 @@ bool TopSnowTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int // offsetting by the face direction) switch(face) { - case 2: - zz += 1; - break; - case 3: - zz -= 1; - break; - case 4: - xx += 1; - break; - case 5: - xx -= 1; - break; - default: - break; + case 2: + zz += 1; + break; + case 3: + zz -= 1; + break; + case 4: + xx += 1; + break; + case 5: + xx -= 1; + break; + default: + break; } int h1 = level->getData(xx,yy,zz) & HEIGHT_MASK; if( h0 >= h1 ) return false; @@ -178,5 +161,5 @@ bool TopSnowTile::shouldRenderFace(LevelSource *level, int x, int y, int z, int bool TopSnowTile::shouldTileTick(Level *level, int x,int y,int z) { - return level->getBrightness(LightLayer::Block, x, y, z) > 11; + return level->getBrightness(LightLayer::Block, x, y, z) > 11; } |
