Merge branch 'master' into mcpe-1.2

This commit is contained in:
Dylan K. Taylor 2017-08-19 21:42:33 +01:00
commit 159b2e3d5e
71 changed files with 286 additions and 219 deletions

View File

@ -2587,7 +2587,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
$block = $target->getSide($packet->face); $block = $target->getSide($packet->face);
if($block->getId() === Block::FIRE){ if($block->getId() === Block::FIRE){
$this->level->setBlock($block, new Air()); $this->level->setBlock($block, Block::get(Block::AIR));
break; break;
} }

View File

@ -30,4 +30,6 @@ class ActivatorRail extends Rail{
public function getName() : string{ public function getName() : string{
return "Activator Rail"; return "Activator Rail";
} }
//TODO
} }

View File

@ -377,12 +377,7 @@ class Block extends Position implements BlockIds, Metadatable{
*/ */
public static function get(int $id, int $meta = 0, Position $pos = null) : Block{ public static function get(int $id, int $meta = 0, Position $pos = null) : Block{
try{ try{
$block = self::$fullList[($id << 4) | $meta]; $block = clone self::$fullList[($id << 4) | $meta];
if($block !== null){
$block = clone $block;
}else{
$block = new UnknownBlock($id, $meta);
}
}catch(\RuntimeException $e){ }catch(\RuntimeException $e){
//TODO: this probably should return null (out of bounds IDs may cause unexpected behaviour) //TODO: this probably should return null (out of bounds IDs may cause unexpected behaviour)
$block = new UnknownBlock($id, $meta); $block = new UnknownBlock($id, $meta);
@ -398,8 +393,9 @@ class Block extends Position implements BlockIds, Metadatable{
return $block; return $block;
} }
/** @var int */
protected $id; protected $id;
/** @var int */
protected $meta = 0; protected $meta = 0;
/** @var string */ /** @var string */
protected $fallbackName; protected $fallbackName;
@ -460,6 +456,19 @@ class Block extends Position implements BlockIds, Metadatable{
$this->meta = $meta & 0x0f; $this->meta = $meta & 0x0f;
} }
/**
* Bitmask to use to remove superfluous information from block meta when getting its item form or name.
* This defaults to -1 (don't remove any data). Used to remove rotation data and bitflags from block drops.
*
* If your block should not have any meta value when it's dropped as an item, override this to return 0 in
* descendent classes.
*
* @return int
*/
public function getVariantBitmask() : int{
return -1;
}
/** /**
* Places the Block, using block space and block target, and side. Returns if the block has been placed. * Places the Block, using block space and block target, and side. Returns if the block has been placed.
* *
@ -497,7 +506,7 @@ class Block extends Position implements BlockIds, Metadatable{
* @return bool * @return bool
*/ */
public function onBreak(Item $item) : bool{ public function onBreak(Item $item) : bool{
return $this->getLevel()->setBlock($this, new Air(), true, true); return $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
} }
/** /**
@ -658,7 +667,7 @@ class Block extends Position implements BlockIds, Metadatable{
*/ */
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
return [ return [
Item::get($this->getItemId(), $this->getDamage(), 1), Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1),
]; ];
} }

View File

@ -44,4 +44,10 @@ class BrewingStand extends Transparent{
public function getToolType() : int{ public function getToolType() : int{
return Tool::TYPE_PICKAXE; return Tool::TYPE_PICKAXE;
} }
public function getVariantBitmask() : int{
return 0;
}
//TODO
} }

View File

@ -67,7 +67,7 @@ class BrownMushroom extends Flowable{
return false; return false;
} }
public function getBoundingBox(){ protected function recalculateBoundingBox(){
return null; return null;
} }

View File

@ -118,11 +118,13 @@ class BurningFurnace extends Solid{
return true; return true;
} }
public function getVariantBitmask() : int{
return 0;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), 0, 1)
];
} }
return []; return [];

View File

@ -90,7 +90,7 @@ class Cactus extends Transparent{
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getId() === self::AIR){ if($b->getId() === self::AIR){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Cactus())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, Block::get(Block::CACTUS)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true); $this->getLevel()->setBlock($b, $ev->getNewState(), true);
} }
@ -125,9 +125,7 @@ class Cactus extends Transparent{
return false; return false;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
} }

View File

@ -76,7 +76,7 @@ class Cake extends Transparent implements FoodSource{
public function onUpdate(int $type){ public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), true); $this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
return Level::BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }
@ -114,7 +114,7 @@ class Cake extends Transparent implements FoodSource{
$clone = clone $this; $clone = clone $this;
$clone->meta++; $clone->meta++;
if($clone->meta >= 0x06){ if($clone->meta >= 0x06){
$clone = new Air(); $clone = Block::get(Block::AIR);
} }
return $clone; return $clone;
} }

View File

@ -129,7 +129,7 @@ class Chest extends Transparent{
if($t instanceof TileChest){ if($t instanceof TileChest){
$t->unpair(); $t->unpair();
} }
$this->getLevel()->setBlock($this, new Air(), true, true); $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
return true; return true;
} }
@ -169,10 +169,8 @@ class Chest extends Transparent{
return true; return true;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
public function getFuelTime() : int{ public function getFuelTime() : int{

View File

@ -34,4 +34,6 @@ class CocoaBlock extends Solid{
public function getName() : string{ public function getName() : string{
return "Cocoa Block"; return "Cocoa Block";
} }
//TODO
} }

View File

@ -42,4 +42,6 @@ class DaylightSensor extends Transparent{
public function getFuelTime() : int{ public function getFuelTime() : int{
return 300; return 300;
} }
//TODO
} }

View File

@ -30,4 +30,6 @@ class DetectorRail extends Rail{
public function getName() : string{ public function getName() : string{
return "Detector Rail"; return "Detector Rail";
} }
//TODO
} }

View File

@ -204,9 +204,9 @@ abstract class Door extends Transparent{
public function onUpdate(int $type){ public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), false); $this->getLevel()->setBlock($this, Block::get(Block::AIR), false);
if($this->getSide(Vector3::SIDE_UP) instanceof Door){ if($this->getSide(Vector3::SIDE_UP) instanceof Door){
$this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), new Air(), false); $this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), Block::get(Block::AIR), false);
} }
return Level::BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
@ -250,15 +250,15 @@ abstract class Door extends Transparent{
if(($this->getDamage() & 0x08) === 0x08){ if(($this->getDamage() & 0x08) === 0x08){
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === $this->getId()){ if($down->getId() === $this->getId()){
$this->getLevel()->setBlock($down, new Air(), true); $this->getLevel()->setBlock($down, Block::get(Block::AIR), true);
} }
}else{ }else{
$up = $this->getSide(Vector3::SIDE_UP); $up = $this->getSide(Vector3::SIDE_UP);
if($up->getId() === $this->getId()){ if($up->getId() === $this->getId()){
$this->getLevel()->setBlock($up, new Air(), true); $this->getLevel()->setBlock($up, Block::get(Block::AIR), true);
} }
} }
$this->getLevel()->setBlock($this, new Air(), true); $this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
return true; return true;
} }
@ -282,4 +282,8 @@ abstract class Door extends Transparent{
return true; return true;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -104,6 +104,10 @@ class DoublePlant extends Flowable{
return false; return false;
} }
public function getVariantBitmask() : int{
return 0x07;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern if(!$item->isShears() and ($this->meta === 2 or $this->meta === 3)){ //grass or fern
if(mt_rand(0, 24) === 0){ if(mt_rand(0, 24) === 0){
@ -115,8 +119,6 @@ class DoublePlant extends Flowable{
return []; return [];
} }
return [ return parent::getDrops($item);
Item::get($this->getItemId(), $this->getDamage() & 0x07, 1)
];
} }
} }

View File

@ -92,9 +92,7 @@ class EnchantingTable extends Transparent{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), 0, 1)
];
} }
return []; return [];

View File

@ -19,8 +19,9 @@
* *
*/ */
namespace pocketmine\block; declare(strict_types=1);
namespace pocketmine\block;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\math\AxisAlignedBB; use pocketmine\math\AxisAlignedBB;
@ -97,10 +98,7 @@ class EndRod extends Flowable{
return null; return null;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getId(), 0, 1)
];
} }
} }

View File

@ -75,10 +75,8 @@ class FenceGate extends Transparent{
return true; return true;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{

View File

@ -87,14 +87,14 @@ class Fire extends Flowable{
return false; return false;
} }
} }
$this->getLevel()->setBlock($this, new Air(), true); $this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
return Level::BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
}elseif($type === Level::BLOCK_UPDATE_RANDOM){ }elseif($type === Level::BLOCK_UPDATE_RANDOM){
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::NETHERRACK){ if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::NETHERRACK){
if(mt_rand(0, 2) === 0){ if(mt_rand(0, 2) === 0){
if($this->meta === 0x0F){ if($this->meta === 0x0F){
$this->level->setBlock($this, new Air()); $this->level->setBlock($this, Block::get(Block::AIR));
}else{ }else{
$this->meta++; $this->meta++;
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);

View File

@ -52,11 +52,13 @@ class GlazedTerracotta extends Solid{
return $this->getLevel()->setBlock($block, $this, true, true); return $this->getLevel()->setBlock($block, $this, true, true);
} }
public function getVariantBitmask() : int{
return 0;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), 0, 1)
];
} }
return []; return [];

View File

@ -105,12 +105,12 @@ class Grass extends Solid{
return true; return true;
}elseif($item->isHoe()){ }elseif($item->isHoe()){
$item->useOn($this); $item->useOn($this);
$this->getLevel()->setBlock($this, new Farmland()); $this->getLevel()->setBlock($this, Block::get(Block::FARMLAND));
return true; return true;
}elseif($item->isShovel() and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){ }elseif($item->isShovel() and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){
$item->useOn($this); $item->useOn($this);
$this->getLevel()->setBlock($this, new GrassPath()); $this->getLevel()->setBlock($this, Block::get(Block::GRASS_PATH));
return true; return true;
} }

View File

@ -53,9 +53,7 @@ class Gravel extends Fallable{
]; ];
} }
return [ return parent::getDrops($item);
Item::get(Item::GRAVEL, 0, 1)
];
} }
} }

View File

@ -58,10 +58,7 @@ class HayBale extends Solid{
return true; return true;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0x03;
Item::get($this->getItemId(), 0, 1)
];
} }
} }

View File

@ -52,7 +52,7 @@ class Ice extends Transparent{
} }
public function onBreak(Item $item) : bool{ public function onBreak(Item $item) : bool{
$this->getLevel()->setBlock($this, new Water(), true); $this->getLevel()->setBlock($this, Block::get(Block::WATER), true);
return true; return true;
} }

View File

@ -46,11 +46,13 @@ class IronBars extends Thin{
return Tool::TYPE_PICKAXE; return Tool::TYPE_PICKAXE;
} }
public function getVariantBitmask() : int{
return 0;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), 0, 1)
];
} }
return []; return [];

View File

@ -139,10 +139,7 @@ class ItemFrame extends Flowable{
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
} }

View File

@ -149,9 +149,7 @@ class Ladder extends Transparent{
return Tool::TYPE_AXE; return Tool::TYPE_AXE;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
} }

View File

@ -241,7 +241,7 @@ abstract class Liquid extends Transparent{
if($k !== $decay){ if($k !== $decay){
$decay = $k; $decay = $k;
if($decay < 0){ if($decay < 0){
$this->getLevel()->setBlock($this, new Air(), true, true); $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
}else{ }else{
$this->getLevel()->setBlock($this, Block::get($this->id, $decay), true, true); $this->getLevel()->setBlock($this, Block::get($this->id, $decay), true, true);
$this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate());
@ -442,7 +442,7 @@ abstract class Liquid extends Transparent{
} }
} }
public function getBoundingBox(){ protected function recalculateBoundingBox(){
return null; return null;
} }

View File

@ -68,7 +68,7 @@ class MelonStem extends Crops{
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(Vector3::SIDE_DOWN); $d = $side->getSide(Vector3::SIDE_DOWN);
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Melon())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, Block::get(Block::MELON_BLOCK)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true); $this->getLevel()->setBlock($side, $ev->getNewState(), true);
} }

View File

@ -23,8 +23,6 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool;
class MossyCobblestone extends Cobblestone{ class MossyCobblestone extends Cobblestone{

View File

@ -65,7 +65,7 @@ class Mycelium extends Solid{
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z)); $block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
if($block->getId() === Block::DIRT){ if($block->getId() === Block::DIRT){
if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){ if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, new Mycelium())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, Block::get(Block::MYCELIUM)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($block, $ev->getNewState()); $this->getLevel()->setBlock($block, $ev->getNewState());
} }

View File

@ -29,6 +29,10 @@ class NetherBrickStairs extends Stair{
protected $id = self::NETHER_BRICK_STAIRS; protected $id = self::NETHER_BRICK_STAIRS;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{ public function getName() : string{
return "Nether Brick Stairs"; return "Nether Brick Stairs";
} }
@ -41,8 +45,4 @@ class NetherBrickStairs extends Stair{
return Tool::TYPE_PICKAXE; return Tool::TYPE_PICKAXE;
} }
public function __construct(int $meta = 0){
$this->meta = $meta;
}
} }

View File

@ -55,11 +55,13 @@ class Prismarine extends Solid{
return Tool::TYPE_PICKAXE; return Tool::TYPE_PICKAXE;
} }
public function getVariantBitmask() : int{
return 0x03;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
];
} }
return []; return [];

View File

@ -56,4 +56,7 @@ class Pumpkin extends Solid{
return true; return true;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -68,7 +68,7 @@ class PumpkinStem extends Crops{
$side = $this->getSide(mt_rand(2, 5)); $side = $this->getSide(mt_rand(2, 5));
$d = $side->getSide(Vector3::SIDE_DOWN); $d = $side->getSide(Vector3::SIDE_DOWN);
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){ if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, new Pumpkin())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, Block::get(Block::PUMPKIN)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($side, $ev->getNewState(), true); $this->getLevel()->setBlock($side, $ev->getNewState(), true);
} }

View File

@ -57,11 +57,13 @@ class Quartz extends Solid{
return Tool::TYPE_PICKAXE; return Tool::TYPE_PICKAXE;
} }
public function getVariantBitmask() : int{
return 0x03;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
];
} }
return []; return [];

View File

@ -75,4 +75,8 @@ class Rail extends Flowable{
return false; return false;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -55,11 +55,13 @@ class Sandstone extends Solid{
return Tool::TYPE_PICKAXE; return Tool::TYPE_PICKAXE;
} }
public function getVariantBitmask() : int{
return 0x03;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
];
} }
return []; return [];

View File

@ -55,7 +55,7 @@ class SignPost extends Transparent{
return "Sign Post"; return "Sign Post";
} }
public function getBoundingBox(){ protected function recalculateBoundingBox(){
return null; return null;
} }
@ -114,4 +114,8 @@ class SignPost extends Transparent{
public function getToolType() : int{ public function getToolType() : int{
return Tool::TYPE_AXE; return Tool::TYPE_AXE;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -24,16 +24,11 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper; use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\item\Item;
class StainedGlass extends Glass{ class StainedGlass extends Glass{
protected $id = self::STAINED_GLASS; protected $id = self::STAINED_GLASS;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{ public function getName() : string{
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Glass"; return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Glass";
} }

View File

@ -24,16 +24,11 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\block\utils\ColorBlockMetaHelper; use pocketmine\block\utils\ColorBlockMetaHelper;
use pocketmine\item\Item;
class StainedGlassPane extends GlassPane{ class StainedGlassPane extends GlassPane{
protected $id = self::STAINED_GLASS_PANE; protected $id = self::STAINED_GLASS_PANE;
public function __construct(int $meta = 0){
$this->meta = $meta;
}
public function getName() : string{ public function getName() : string{
return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Glass Pane"; return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Glass Pane";
} }

View File

@ -145,11 +145,13 @@ abstract class Stair extends Transparent{
return true; return true;
} }
public function getVariantBitmask() : int{
return 0;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), 0, 1)
];
} }
return []; return [];

View File

@ -58,9 +58,7 @@ class StoneBricks extends Solid{
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isPickaxe() >= Tool::TIER_WOODEN){ if($item->isPickaxe() >= Tool::TIER_WOODEN){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
];
} }
return []; return [];

View File

@ -38,4 +38,8 @@ class StoneButton extends Flowable{
public function getHardness() : float{ public function getHardness() : float{
return 0.5; return 0.5;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -42,4 +42,8 @@ class StonePressurePlate extends Transparent{
public function getHardness() : float{ public function getHardness() : float{
return 0.5; return 0.5;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -50,7 +50,7 @@ class Sugarcane extends Flowable{
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getId() === self::AIR){ if($b->getId() === self::AIR){
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, new Sugarcane())); Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, Block::get(Block::SUGARCANE_BLOCK)));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->getLevel()->setBlock($b, $ev->getNewState(), true); $this->getLevel()->setBlock($b, $ev->getNewState(), true);
} }
@ -84,7 +84,7 @@ class Sugarcane extends Flowable{
for($y = 1; $y < 3; ++$y){ for($y = 1; $y < 3; ++$y){
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z)); $b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
if($b->getId() === self::AIR){ if($b->getId() === self::AIR){
$this->getLevel()->setBlock($b, new Sugarcane(), true); $this->getLevel()->setBlock($b, Block::get(Block::SUGARCANE_BLOCK), true);
break; break;
} }
} }
@ -105,7 +105,7 @@ class Sugarcane extends Flowable{
public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{
$down = $this->getSide(Vector3::SIDE_DOWN); $down = $this->getSide(Vector3::SIDE_DOWN);
if($down->getId() === self::SUGARCANE_BLOCK){ if($down->getId() === self::SUGARCANE_BLOCK){
$this->getLevel()->setBlock($block, new Sugarcane(), true); $this->getLevel()->setBlock($block, Block::get(Block::SUGARCANE_BLOCK), true);
return true; return true;
}elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){ }elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){
@ -114,7 +114,7 @@ class Sugarcane extends Flowable{
$block2 = $down->getSide(Vector3::SIDE_WEST); $block2 = $down->getSide(Vector3::SIDE_WEST);
$block3 = $down->getSide(Vector3::SIDE_EAST); $block3 = $down->getSide(Vector3::SIDE_EAST);
if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){ if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){
$this->getLevel()->setBlock($block, new Sugarcane(), true); $this->getLevel()->setBlock($block, Block::get(Block::SUGARCANE_BLOCK), true);
return true; return true;
} }
@ -122,4 +122,8 @@ class Sugarcane extends Flowable{
return false; return false;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -60,7 +60,7 @@ class TNT extends Solid{
} }
public function ignite(int $fuse = 80){ public function ignite(int $fuse = 80){
$this->getLevel()->setBlock($this, new Air(), true); $this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
$mot = (new Random())->nextSignedFloat() * M_PI * 2; $mot = (new Random())->nextSignedFloat() * M_PI * 2;
$tnt = Entity::createEntity("PrimedTNT", $this->getLevel(), new CompoundTag("", [ $tnt = Entity::createEntity("PrimedTNT", $this->getLevel(), new CompoundTag("", [

View File

@ -64,7 +64,7 @@ class TallGrass extends Flowable{
public function onUpdate(int $type){ public function onUpdate(int $type){
if($type === Level::BLOCK_UPDATE_NORMAL){ if($type === Level::BLOCK_UPDATE_NORMAL){
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ //Replace with common break method if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ //Replace with common break method
$this->getLevel()->setBlock($this, new Air(), true, true); $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
return Level::BLOCK_UPDATE_NORMAL; return Level::BLOCK_UPDATE_NORMAL;
} }

View File

@ -93,9 +93,7 @@ class Torch extends Flowable{
return false; return false;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
} }

View File

@ -140,10 +140,8 @@ class Trapdoor extends Transparent{
return true; return true;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{

View File

@ -34,4 +34,10 @@ class TripwireHook extends Flowable{
public function getName() : string{ public function getName() : string{
return "Tripwire Hook"; return "Tripwire Hook";
} }
public function getVariantBitmask() : int{
return 0;
}
//TODO
} }

View File

@ -174,11 +174,13 @@ class Vine extends Transparent{
return false; return false;
} }
public function getVariantBitmask() : int{
return 0;
}
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
if($item->isShears()){ if($item->isShears()){
return [ return parent::getDrops($item);
Item::get($this->getItemId(), 0, 1)
];
} }
return []; return [];

View File

@ -80,9 +80,7 @@ class WaterLily extends Flowable{
return false; return false;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0;
Item::get($this->getItemId(), 0, 1)
];
} }
} }

View File

@ -42,4 +42,8 @@ class WeightedPressurePlateLight extends Transparent{
public function getHardness() : float{ public function getHardness() : float{
return 0.5; return 0.5;
} }
public function getVariantBitmask() : int{
return 0;
}
} }

View File

@ -69,10 +69,8 @@ class Wood extends Solid{
return true; return true;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0x03;
Item::get($this->getItemId(), $this->getDamage() & 0x03, 1)
];
} }
public function getToolType() : int{ public function getToolType() : int{

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace pocketmine\block; namespace pocketmine\block;
use pocketmine\item\Item;
use pocketmine\item\Tool; use pocketmine\item\Tool;
class WoodenDoor extends Door{ class WoodenDoor extends Door{
@ -35,10 +34,4 @@ class WoodenDoor extends Door{
public function getToolType() : int{ public function getToolType() : int{
return Tool::TYPE_AXE; return Tool::TYPE_AXE;
} }
public function getDrops(Item $item) : array{
return [
Item::get($this->getItemId(), 0, 1)
];
}
} }

View File

@ -129,10 +129,8 @@ class WoodenSlab extends Transparent{
return Tool::TYPE_AXE; return Tool::TYPE_AXE;
} }
public function getDrops(Item $item) : array{ public function getVariantBitmask() : int{
return [ return 0x07;
Item::get($this->getItemId(), $this->getDamage() & 0x07, 1)
];
} }
public function getFuelTime() : int{ public function getFuelTime() : int{

View File

@ -41,8 +41,9 @@ class WoodenStairs extends Stair{
} }
public function getDrops(Item $item) : array{ public function getDrops(Item $item) : array{
//TODO: Hierarchy problem (base class is for stone stairs)
return [ return [
Item::get($this->getItemId(), 0, 1) Item::get($this->getItemId(), $this->getDamage() & $this->getVariantBitmask(), 1)
]; ];
} }
} }

View File

@ -28,6 +28,9 @@ use pocketmine\event\Cancellable;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\Player; use pocketmine\Player;
/**
* Called when a player destroys a block somewhere in the world.
*/
class BlockBreakEvent extends BlockEvent implements Cancellable{ class BlockBreakEvent extends BlockEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
@ -42,30 +45,56 @@ class BlockBreakEvent extends BlockEvent implements Cancellable{
/** @var Item[] */ /** @var Item[] */
protected $blockDrops = []; protected $blockDrops = [];
public function __construct(Player $player, Block $block, Item $item, $instaBreak = false){ public function __construct(Player $player, Block $block, Item $item, bool $instaBreak = false){
$this->block = $block; parent::__construct($block);
$this->item = $item; $this->item = $item;
$this->player = $player; $this->player = $player;
$this->instaBreak = (bool) $instaBreak;
$this->blockDrops = $player->isSurvival() ? $block->getDrops($item) : []; $this->instaBreak = $instaBreak;
if($player->isSurvival()){
$this->setDrops($block->getDrops($item));
}
} }
public function getPlayer(){ /**
* Returns the player who is destroying the block.
* @return Player
*/
public function getPlayer() : Player{
return $this->player; return $this->player;
} }
public function getItem(){ /**
* Returns the item used to destroy the block.
* @return Item
*/
public function getItem() : Item{
return $this->item; return $this->item;
} }
public function getInstaBreak(){ /**
* Returns whether the block may be broken in less than the amount of time calculated. This is usually true for
* creative players.
*
* @return bool
*/
public function getInstaBreak() : bool{
return $this->instaBreak; return $this->instaBreak;
} }
/**
* @param bool $instaBreak
*/
public function setInstaBreak(bool $instaBreak){
$this->instaBreak = $instaBreak;
}
/** /**
* @return Item[] * @return Item[]
*/ */
public function getDrops(){ public function getDrops() : array{
return $this->blockDrops; return $this->blockDrops;
} }
@ -73,13 +102,15 @@ class BlockBreakEvent extends BlockEvent implements Cancellable{
* @param Item[] $drops * @param Item[] $drops
*/ */
public function setDrops(array $drops){ public function setDrops(array $drops){
$this->blockDrops = $drops; $this->setDropsVariadic(...$drops);
} }
/** /**
* @param bool $instaBreak * Variadic hack for easy array member type enforcement.
*
* @param Item[] ...$drops
*/ */
public function setInstaBreak($instaBreak){ public function setDropsVariadic(Item ...$drops){
$this->instaBreak = (bool) $instaBreak; $this->blockDrops = $drops;
} }
} }

View File

@ -43,7 +43,7 @@ abstract class BlockEvent extends Event{
/** /**
* @return Block * @return Block
*/ */
public function getBlock(){ public function getBlock() : Block{
return $this->block; return $this->block;
} }
} }

View File

@ -26,6 +26,9 @@ namespace pocketmine\event\block;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
/**
* Called when plants or crops grow.
*/
class BlockGrowEvent extends BlockEvent implements Cancellable{ class BlockGrowEvent extends BlockEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
@ -40,7 +43,7 @@ class BlockGrowEvent extends BlockEvent implements Cancellable{
/** /**
* @return Block * @return Block
*/ */
public function getNewState(){ public function getNewState() : Block{
return $this->newState; return $this->newState;
} }

View File

@ -40,36 +40,46 @@ class BlockPlaceEvent extends BlockEvent implements Cancellable{
/** @var Item */ /** @var Item */
protected $item; protected $item;
/** @var Block */
protected $blockReplace; protected $blockReplace;
/** @var Block */
protected $blockAgainst; protected $blockAgainst;
public function __construct(Player $player, Block $blockPlace, Block $blockReplace, Block $blockAgainst, Item $item){ public function __construct(Player $player, Block $blockPlace, Block $blockReplace, Block $blockAgainst, Item $item){
$this->block = $blockPlace; parent::__construct($blockPlace);
$this->blockReplace = $blockReplace; $this->blockReplace = $blockReplace;
$this->blockAgainst = $blockAgainst; $this->blockAgainst = $blockAgainst;
$this->item = $item; $this->item = $item;
$this->player = $player; $this->player = $player;
} }
public function getPlayer(){ /**
* Returns the player who is placing the block.
* @return Player
*/
public function getPlayer() : Player{
return $this->player; return $this->player;
} }
/** /**
* Gets the item in hand * Gets the item in hand
* * @return Item
* @return mixed
*/ */
public function getItem(){ public function getItem() : Item{
return $this->item; return $this->item;
} }
public function getBlockReplaced(){ /**
* @return Block
*/
public function getBlockReplaced() : Block{
return $this->blockReplace; return $this->blockReplace;
} }
public function getBlockAgainst(){ /**
* @return Block
*/
public function getBlockAgainst() : Block{
return $this->blockAgainst; return $this->blockAgainst;
} }
} }

View File

@ -25,6 +25,9 @@ namespace pocketmine\event\block;
use pocketmine\block\Block; use pocketmine\block\Block;
/**
* Called when a block spreads to another block, such as grass spreading to nearby dirt blocks.
*/
class BlockSpreadEvent extends BlockFormEvent{ class BlockSpreadEvent extends BlockFormEvent{
public static $handlerList = null; public static $handlerList = null;
@ -39,7 +42,7 @@ class BlockSpreadEvent extends BlockFormEvent{
/** /**
* @return Block * @return Block
*/ */
public function getSource(){ public function getSource() : Block{
return $this->source; return $this->source;
} }

View File

@ -23,14 +23,12 @@ declare(strict_types=1);
namespace pocketmine\event\block; namespace pocketmine\event\block;
use pocketmine\block\Block;
use pocketmine\event\Cancellable; use pocketmine\event\Cancellable;
/**
* Called when leaves decay due to not being attached to wood.
*/
class LeavesDecayEvent extends BlockEvent implements Cancellable{ class LeavesDecayEvent extends BlockEvent implements Cancellable{
public static $handlerList = null; public static $handlerList = null;
public function __construct(Block $block){
parent::__construct($block);
}
} }

View File

@ -52,14 +52,14 @@ class SignChangeEvent extends BlockEvent implements Cancellable{
/** /**
* @return Player * @return Player
*/ */
public function getPlayer(){ public function getPlayer() : Player{
return $this->player; return $this->player;
} }
/** /**
* @return string[] * @return string[]
*/ */
public function getLines(){ public function getLines() : array{
return $this->lines; return $this->lines;
} }
@ -67,16 +67,21 @@ class SignChangeEvent extends BlockEvent implements Cancellable{
* @param int $index 0-3 * @param int $index 0-3
* *
* @return string * @return string
*
* @throws \InvalidArgumentException if the index is out of bounds
*/ */
public function getLine($index){ public function getLine(int $index) : string{
if($index < 0 or $index > 3){ if($index < 0 or $index > 3){
throw new \InvalidArgumentException("Index must be in the range 0-3!"); throw new \InvalidArgumentException("Index must be in the range 0-3!");
} }
return $this->lines[$index]; return $this->lines[$index];
} }
/** /**
* @param string[] $lines * @param string[] $lines
*
* @throws \InvalidArgumentException if there are more or less than 4 lines in the passed array
*/ */
public function setLines(array $lines){ public function setLines(array $lines){
if(count($lines) !== 4){ if(count($lines) !== 4){
@ -88,8 +93,10 @@ class SignChangeEvent extends BlockEvent implements Cancellable{
/** /**
* @param int $index 0-3 * @param int $index 0-3
* @param string $line * @param string $line
*
* @throws \InvalidArgumentException if the index is out of bounds
*/ */
public function setLine($index, $line){ public function setLine(int $index, string $line){
if($index < 0 or $index > 3){ if($index < 0 or $index > 3){
throw new \InvalidArgumentException("Index must be in the range 0-3!"); throw new \InvalidArgumentException("Index must be in the range 0-3!");
} }

View File

@ -56,7 +56,7 @@ class Bucket extends Item{
$result->setDamage($target->getId()); $result->setDamage($target->getId());
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result)); $player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$player->getLevel()->setBlock($target, new Air(), true, true); $player->getLevel()->setBlock($target, Block::get(Block::AIR), true, true);
if($player->isSurvival()){ if($player->isSurvival()){
$player->getInventory()->setItemInHand($ev->getItem()); $player->getInventory()->setItemInHand($ev->getItem());
} }

View File

@ -36,7 +36,7 @@ class FlintSteel extends Tool{
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($block->getId() === self::AIR and ($target instanceof Solid)){ if($block->getId() === self::AIR and ($target instanceof Solid)){
$level->setBlock($block, new Fire(), true); $level->setBlock($block, Block::get(Block::FIRE), true);
if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){ if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){
if($this->getDamage() >= $this->getMaxDurability()){ if($this->getDamage() >= $this->getMaxDurability()){
$player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0)); $player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));

View File

@ -1652,7 +1652,7 @@ class Level implements ChunkManager, Metadatable{
$above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z)); $above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
if($above !== null){ if($above !== null){
if($above->getId() === Item::FIRE){ if($above->getId() === Item::FIRE){
$this->setBlock($above, new Air(), true); $this->setBlock($above, Block::get(Block::AIR), true);
} }
} }

View File

@ -23,17 +23,11 @@ declare(strict_types=1);
namespace pocketmine\level\generator; namespace pocketmine\level\generator;
use pocketmine\block\CoalOre; use pocketmine\block\Block;
use pocketmine\block\DiamondOre;
use pocketmine\block\Dirt;
use pocketmine\block\GoldOre;
use pocketmine\block\Gravel;
use pocketmine\block\IronOre;
use pocketmine\block\LapisOre;
use pocketmine\block\RedstoneOre;
use pocketmine\item\Item; use pocketmine\item\Item;
use pocketmine\level\ChunkManager; use pocketmine\level\ChunkManager;
use pocketmine\level\format\Chunk; use pocketmine\level\format\Chunk;
use pocketmine\level\generator\object\OreType;
use pocketmine\level\generator\populator\Ore; use pocketmine\level\generator\populator\Ore;
use pocketmine\level\generator\populator\Populator; use pocketmine\level\generator\populator\Populator;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -67,14 +61,14 @@ class Flat extends Generator{
if(isset($this->options["decoration"])){ if(isset($this->options["decoration"])){
$ores = new Ore(); $ores = new Ore();
$ores->setOreTypes([ $ores->setOreTypes([
new object\OreType(new CoalOre(), 20, 16, 0, 128), new OreType(Block::get(Block::COAL_ORE), 20, 16, 0, 128),
new object\OreType(new IronOre(), 20, 8, 0, 64), new OreType(Block::get(Block::IRON_ORE), 20, 8, 0, 64),
new object\OreType(new RedstoneOre(), 8, 7, 0, 16), new OreType(Block::get(Block::REDSTONE_ORE), 8, 7, 0, 16),
new object\OreType(new LapisOre(), 1, 6, 0, 32), new OreType(Block::get(Block::LAPIS_ORE), 1, 6, 0, 32),
new object\OreType(new GoldOre(), 2, 8, 0, 32), new OreType(Block::get(Block::GOLD_ORE), 2, 8, 0, 32),
new object\OreType(new DiamondOre(), 1, 7, 0, 16), new OreType(Block::get(Block::DIAMOND_ORE), 1, 7, 0, 16),
new object\OreType(new Dirt(), 20, 32, 0, 128), new OreType(Block::get(Block::DIRT), 20, 32, 0, 128),
new object\OreType(new Gravel(), 10, 16, 0, 128) new OreType(Block::get(Block::GRAVEL), 10, 16, 0, 128)
]); ]);
$this->populators[] = $ores; $this->populators[] = $ores;
} }

View File

@ -24,14 +24,6 @@ declare(strict_types=1);
namespace pocketmine\level\generator\normal; namespace pocketmine\level\generator\normal;
use pocketmine\block\Block; use pocketmine\block\Block;
use pocketmine\block\CoalOre;
use pocketmine\block\DiamondOre;
use pocketmine\block\Dirt;
use pocketmine\block\GoldOre;
use pocketmine\block\Gravel;
use pocketmine\block\IronOre;
use pocketmine\block\LapisOre;
use pocketmine\block\RedstoneOre;
use pocketmine\level\ChunkManager; use pocketmine\level\ChunkManager;
use pocketmine\level\generator\biome\Biome; use pocketmine\level\generator\biome\Biome;
use pocketmine\level\generator\biome\BiomeSelector; use pocketmine\level\generator\biome\BiomeSelector;
@ -179,14 +171,14 @@ class Normal extends Generator{
$ores = new Ore(); $ores = new Ore();
$ores->setOreTypes([ $ores->setOreTypes([
new OreType(new CoalOre(), 20, 16, 0, 128), new OreType(Block::get(Block::COAL_ORE), 20, 16, 0, 128),
new OreType(New IronOre(), 20, 8, 0, 64), new OreType(Block::get(Block::IRON_ORE), 20, 8, 0, 64),
new OreType(new RedstoneOre(), 8, 7, 0, 16), new OreType(Block::get(Block::REDSTONE_ORE), 8, 7, 0, 16),
new OreType(new LapisOre(), 1, 6, 0, 32), new OreType(Block::get(Block::LAPIS_ORE), 1, 6, 0, 32),
new OreType(new GoldOre(), 2, 8, 0, 32), new OreType(Block::get(Block::GOLD_ORE), 2, 8, 0, 32),
new OreType(new DiamondOre(), 1, 7, 0, 16), new OreType(Block::get(Block::DIAMOND_ORE), 1, 7, 0, 16),
new OreType(new Dirt(), 20, 32, 0, 128), new OreType(Block::get(Block::DIRT), 20, 32, 0, 128),
new OreType(new Gravel(), 10, 16, 0, 128) new OreType(Block::get(Block::GRAVEL), 10, 16, 0, 128)
]); ]);
$this->populators[] = $ores; $this->populators[] = $ores;
} }

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\level\generator\populator; namespace pocketmine\level\generator\populator;
use pocketmine\block\Block;
use pocketmine\block\Water; use pocketmine\block\Water;
use pocketmine\level\ChunkManager; use pocketmine\level\ChunkManager;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
@ -38,7 +39,7 @@ class Pond extends Populator{
$x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16); $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
$y = $random->nextBoundedInt(128); $y = $random->nextBoundedInt(128);
$z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16); $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
$pond = new \pocketmine\level\generator\object\Pond($random, new Water()); $pond = new \pocketmine\level\generator\object\Pond($random, Block::get(Block::WATER));
if($pond->canPlaceObject($level, $v = new Vector3($x, $y, $z))){ if($pond->canPlaceObject($level, $v = new Vector3($x, $y, $z))){
$pond->placeObject($level, $v); $pond->placeObject($level, $v);
} }

View File

@ -61,7 +61,7 @@ class ExplodePacket extends DataPacket{
$this->putUnsignedVarInt(count($this->records)); $this->putUnsignedVarInt(count($this->records));
if(count($this->records) > 0){ if(count($this->records) > 0){
foreach($this->records as $record){ foreach($this->records as $record){
$this->putSignedBlockPosition($record->x, $record->y, $record->z); $this->putSignedBlockPosition((int) $record->x, (int) $record->y, (int) $record->z);
} }
} }
} }
@ -70,4 +70,4 @@ class ExplodePacket extends DataPacket{
return $session->handleExplode($this); return $session->handleExplode($this);
} }
} }