ソースを参照

fix negative block address calculation

Kolja Strohm 3 年 前
コミット
3a0adc87e1
3 ファイル変更13 行追加5 行削除
  1. 11 3
      FactoryCraft/Dimension.cpp
  2. 1 1
      FactoryCraft/Dimension.h
  3. 1 1
      FactoryCraft/Game.cpp

+ 11 - 3
FactoryCraft/Dimension.cpp

@@ -62,11 +62,19 @@ Chunk *Dimension::zChunk( Punkt wPos ) const
     return chunks->z( addr, 9 );
 }
 
-Block *Dimension::zBlock( Vec3<int> location )
+Block *Dimension::zBlock( Vec3<int> location, const Game *zGame )
 {
-    Chunk *c = zChunk( Punkt( location.x, location.y ) );
+    Chunk *c = zChunk( zGame->getChunkCenter( location.x, location.y ) );
     if( c )
-        return c->zBlockAt( Vec3<int>( location.x % CHUNK_SIZE, location.y % CHUNK_SIZE, location.z ) );
+    {
+        int x = location.x % CHUNK_SIZE;
+        int y = location.y % CHUNK_SIZE;
+        if( x < 0 )
+            x += CHUNK_SIZE;
+        if( y < 0 )
+            y += CHUNK_SIZE;
+        return c->zBlockAt( Vec3<int>( x, y, location.z ) );
+    }
     return 0;
 }
 

+ 1 - 1
FactoryCraft/Dimension.h

@@ -22,7 +22,7 @@ public:
     void api( Framework::StreamReader *zRequest, NetworkResponse *zResponse );
     void tickEntities( Game *zGame );
 
-    Block *zBlock( Framework::Vec3<int> location );
+    Block *zBlock( Framework::Vec3<int> location, const Game *zGame );
     void addEntity( Entity *entity );
     void addChunk( Chunk *chunk );
     void save( Framework::Text worldDir ) const;

+ 1 - 1
FactoryCraft/Game.cpp

@@ -339,7 +339,7 @@ Block *Game::zBlockAt( Framework::Vec3<int> location, int dimension ) const
 {
     Dimension *dim = zDimension( dimension );
     if( dim )
-        return dim->zBlock( location );
+        return dim->zBlock( location, this );
     return 0;
 }