Improved Falling blocks physics, entity kill, chunk unserialize, fixed flat generator color, fixed nbt tags __toString(), fixed explosion offsets, fixed increased player interaction range in creative

This commit is contained in:
Shoghi Cervantes
2015-05-13 12:18:59 +02:00
parent f3bdef7513
commit b1edfd7631
14 changed files with 84 additions and 52 deletions

View File

@ -130,7 +130,7 @@ class Explosion{
public function explodeB(){
$send = [];
$source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->round();
$source = (new Vector3($this->source->x, $this->source->y, $this->source->z))->floor();
$yield = (1 / $this->size) * 100;
if($this->what instanceof Entity){

View File

@ -953,12 +953,12 @@ class Level implements ChunkManager, Metadatable{
* @return AxisAlignedBB[]
*/
public function getCollisionCubes(Entity $entity, AxisAlignedBB $bb, $entities = true){
$minX = Math::floorFloat($bb->minX);
$minY = Math::floorFloat($bb->minY);
$minZ = Math::floorFloat($bb->minZ);
$maxX = Math::ceilFloat($bb->maxX);
$maxY = Math::ceilFloat($bb->maxY);
$maxZ = Math::ceilFloat($bb->maxZ);
$minX = (int) $bb->minX;
$minY = (int) $bb->minY;
$minZ = (int) $bb->minZ;
$maxX = (int) ($bb->maxX + 1);
$maxY = (int) ($bb->maxY + 1);
$maxZ = (int) ($bb->maxZ + 1);
$collides = [];
$v = $this->temporalVector;

View File

@ -66,6 +66,8 @@ abstract class BaseFullChunk implements FullChunk{
protected $hasChanged = false;
private $isInit = false;
/**
* @param LevelProvider $provider
* @param int $x
@ -106,7 +108,7 @@ abstract class BaseFullChunk implements FullChunk{
}
public function initChunk(){
if($this->getProvider() instanceof LevelProvider and $this->NBTentities !== null){
if($this->getProvider() instanceof LevelProvider and !$this->isInit and $this->NBTentities !== null){
$this->getProvider()->getLevel()->timings->syncChunkLoadEntitiesTimer->startTiming();
foreach($this->NBTentities as $nbt){
if($nbt instanceof Compound){
@ -154,8 +156,8 @@ abstract class BaseFullChunk implements FullChunk{
$this->NBTentities = null;
$this->NBTtiles = null;
$this->hasChanged = false;
$this->isInit = true;
}
if(!$this->isLightPopulated() and $this->isPopulated()){
@ -280,14 +282,14 @@ abstract class BaseFullChunk implements FullChunk{
public function addEntity(Entity $entity){
$this->entities[$entity->getId()] = $entity;
if(!($entity instanceof Player)){
if(!($entity instanceof Player) and $this->isInit){
$this->hasChanged = true;
}
}
public function removeEntity(Entity $entity){
unset($this->entities[$entity->getId()]);
if(!($entity instanceof Player)){
if(!($entity instanceof Player) and $this->isInit){
$this->hasChanged = true;
}
}
@ -298,13 +300,17 @@ abstract class BaseFullChunk implements FullChunk{
$this->tileList[$index]->close();
}
$this->tileList[$index] = $tile;
$this->hasChanged = true;
if($this->isInit){
$this->hasChanged = true;
}
}
public function removeTile(Tile $tile){
unset($this->tiles[$tile->getId()]);
unset($this->tileList[(($tile->z & 0x0f) << 12) | (($tile->x & 0x0f) << 8) | ($tile->y & 0xff)]);
$this->hasChanged = true;
if($this->isInit){
$this->hasChanged = true;
}
}
public function getEntities(){

View File

@ -247,7 +247,7 @@ class Chunk extends BaseFullChunk{
if($provider instanceof LevelDB){
$nbt = new NBT(NBT::LITTLE_ENDIAN);
$entityData = $provider->getDatabase()->get(substr($data, 0, 8) . "\x32");
$entityData = $provider->getDatabase()->get(substr($data, 0, 8) . LevelDB::ENTRY_ENTITIES);
if($entityData !== false and strlen($entityData) > 0){
$nbt->read($entityData, true);
$entities = $nbt->getData();
@ -255,7 +255,7 @@ class Chunk extends BaseFullChunk{
$entities = [$entities];
}
}
$tileData = $provider->getDatabase()->get(substr($data, 0, 8) . "\x31");
$tileData = $provider->getDatabase()->get(substr($data, 0, 8) . LevelDB::ENTRY_TILES);
if($tileData !== false and strlen($tileData) > 0){
$nbt->read($tileData, true);
$tiles = $nbt->getData();
@ -302,9 +302,9 @@ class Chunk extends BaseFullChunk{
}
if(count($entities) > 0){
$provider->getDatabase()->put($chunkIndex . "\x32", implode($entities));
$provider->getDatabase()->put($chunkIndex . LevelDB::ENTRY_ENTITIES, implode($entities));
}else{
$provider->getDatabase()->delete($chunkIndex . "\x32");
$provider->getDatabase()->delete($chunkIndex . LevelDB::ENTRY_ENTITIES);
}
@ -318,9 +318,9 @@ class Chunk extends BaseFullChunk{
}
if(count($tiles) > 0){
$provider->getDatabase()->put($chunkIndex . "\x31", implode($tiles));
$provider->getDatabase()->put($chunkIndex . LevelDB::ENTRY_TILES, implode($tiles));
}else{
$provider->getDatabase()->delete($chunkIndex . "\x31");
$provider->getDatabase()->delete($chunkIndex . LevelDB::ENTRY_TILES);
}

View File

@ -32,6 +32,7 @@ use pocketmine\block\RedstoneOre;
use pocketmine\item\Item;
use pocketmine\level\ChunkManager;
use pocketmine\level\format\FullChunk;
use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\populator\Ore;
use pocketmine\level\generator\populator\Populator;
use pocketmine\math\Vector3;
@ -110,10 +111,15 @@ class Flat extends Generator{
$this->chunk = clone $this->level->getChunk($chunkX, $chunkZ);
$this->chunk->setGenerated();
$c = Biome::getBiome($biome)->getColor();
$R = $c >> 16;
$G = ($c >> 8) & 0xff;
$B = $c & 0xff;
for($Z = 0; $Z < 16; ++$Z){
for($X = 0; $X < 16; ++$X){
$this->chunk->setBiomeId($X, $Z, $biome);
$this->chunk->setBiomeColor($X, $Z, $R, $G, $B);
for($y = 0; $y < 128; ++$y){
$this->chunk->setBlock($X, $y, $Z, ...$this->structure[$y]);
}