Merge branch 'master'

# Conflicts:
#	src/API/AchievementAPI.php
#	src/API/BanAPI.php
#	src/API/BlockAPI.php
#	src/API/EntityAPI.php
#	src/API/PlayerAPI.php
#	src/Player.php
#	src/PocketMinecraftServer.php
#	src/config.php
#	src/entity/Animal.php
#	src/entity/Breedable.php
#	src/entity/Creature.php
#	src/entity/Entity.php
#	src/entity/animal/Sheep.php
#	src/entity/monster/Creeper.php
#	src/entity/monster/Zombie.php
#	src/entity/object/Arrow.php
#	src/entity/object/FallingSand.php
#	src/entity/object/ItemEntity.php
#	src/entity/object/Minecart.php
#	src/entity/object/Painting.php
#	src/entity/object/PrimedTNT.php
#	src/material/Block.php
#	src/material/Item.php
#	src/material/Material.php
#	src/material/StaticBlock.php
#	src/material/block/DoorBlock.php
#	src/material/block/GenericBlock.php
#	src/material/block/attachable/WallSignBlock.php
#	src/material/block/liquid/LiquidBlockDynamic.php
#	src/material/block/misc/AirBlock.php
#	src/material/block/misc/BedBlock.php
#	src/material/block/misc/TNTBlock.php
#	src/material/block/nonfull/CarpetBlock.php
#	src/material/block/nonfull/FenceBlock.php
#	src/material/block/nonfull/PoweredRailBlock.php
#	src/material/block/nonfull/RailBlock.php
#	src/material/block/nonfull/SnowLayerBlock.php
#	src/material/block/nonfull/WoodSlabBlock.php
#	src/material/block/plant/BrownMushroomBlock.php
#	src/material/block/plant/DandelionBlock.php
#	src/material/block/plant/MelonStemBlock.php
#	src/material/block/plant/PumpkinStemBlock.php
#	src/material/block/plant/RedMushroomBlock.php
#	src/material/block/plant/SugarcaneBlock.php
#	src/material/block/solid/GrassBlock.php
#	src/material/block/solid/IceBlock.php
#	src/material/block/solid/LeavesBlock.php
#	src/material/block/solid/ObsidianBlock.php
#	src/material/block/solid/PumpkinBlock.php
#	src/material/block/solid/WoolBlock.php
#	src/material/item/base/ItemHoe.php
#	src/material/item/base/ItemTool.php
#	src/material/item/generic/DyeItem.php
#	src/material/item/generic/SpawnEggItem.php
#	src/material/item/tool/FlintSteelItem.php
#	src/material/item/tool/ShearsItem.php
#	src/math/AxisAlignedBB.php
#	src/network/MinecraftInterface.php
#	src/network/UDPSocket.php
#	src/network/protocol/packet/AddItemEntityPacket.php
#	src/network/protocol/packet/ContainerSetContentPacket.php
#	src/network/raknet/RakNetDataPacket.php
#	src/network/raknet/RakNetParser.php
#	src/pmf/PMFLevel.php
#	src/utils/Utils.php
#	src/world/Explosion.php
#	src/world/Level.php
#	src/world/MobSpawner.php
This commit is contained in:
yefengeeeeeeeeeee 2026-04-04 14:52:08 +08:00
commit 3fbab46e60
245 changed files with 6118 additions and 3408 deletions

View file

@ -86,13 +86,14 @@ class DoorBlock extends TransparentBlock{
}
break;
}
return [$aabb->offset($x, $y, $z)];
}
public static function getCompositeData(Level $level, $x, $y, $z){
$myMeta = $level->level->getBlockDamage($x, $y, $z);
if(($myMeta & 8) != 0){
$metaLower = $level->level->getBlockDamage($x, $y - 1, $z);
$metaUpper = $myMeta;
@ -100,18 +101,22 @@ class DoorBlock extends TransparentBlock{
$metaLower = $myMeta;
$metaUpper = $level->level->getBlockDamage($x, $y + 1, $z);
}
return $metaLower & 7 | (($myMeta & 8) != 0 ? 8 : 0) | (($metaUpper & 1 != 0) ? 16 : 0);
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
if($level->level->getBlockID($x, $y - 1, $z) == AIR){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
$id = $level->level->getBlockID($x, $y, $z);
if($id == 64) ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(324, 0, 1));
elseif($id == 71) ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(330, 0, 1));
if(($meta & 8) == 0){
if($id == DOOR_BLOCK) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(WOODEN_DOOR, 0, 1));
elseif($id == IRON_DOOR_BLOCK) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(IRON_DOOR, 0, 1));
}
$top = $level->level->getBlockID($x, $y + 1, $z);
if($top == IRON_DOOR_BLOCK || $top == DOOR_BLOCK){
$level->fastSetBlockUpdate($x, $y + 1, $z, 0, 0);
@ -119,7 +124,12 @@ class DoorBlock extends TransparentBlock{
}
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
@ -135,12 +145,12 @@ class DoorBlock extends TransparentBlock{
return false;
}
$direction = $player->entity->getDirection();
$face = [
$face = array(
0 => 3,
1 => 4,
2 => 2,
3 => 5,
];
);
$next = $this->getSide($face[(($direction + 2) % 4)]);
$next2 = $this->getSide($face[$direction]);
$metaUp = 0x08;
@ -148,15 +158,17 @@ class DoorBlock extends TransparentBlock{
$metaUp |= 0x01;
}
$this->level->setBlock($blockUp, BlockAPI::get($this->id, $metaUp), true, false, true); //Top
$this->meta = $direction & 0x03;
$this->level->setBlock($block, $this, true, false, true); //Bottom
return true;
return true;
}
return false;
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
@ -177,6 +189,8 @@ class DoorBlock extends TransparentBlock{
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
@ -194,7 +208,7 @@ class DoorBlock extends TransparentBlock{
$pk->z = $this->z;
$pk->evid = 1003;
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
ServerAPI::request()->api->player->broadcastPacket($players, $pk); //TODO use block queue?
return true;
}
return false;

View file

@ -1,5 +1,6 @@
<?php
class GenericBlock extends Block{
/**
* @param int $id
@ -11,6 +12,10 @@ class GenericBlock extends Block{
}
/**
* @param Item $item
* @param Player $player
* @param Block $block
* @param Block $target
* @param integer $face
* @param integer $fx
* @param integer $fy
@ -23,6 +28,8 @@ class GenericBlock extends Block{
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/
@ -31,6 +38,8 @@ class GenericBlock extends Block{
}
/**
* @param Item $item
* @param Player $player
*
* @return mixed
*/
@ -46,24 +55,28 @@ class GenericBlock extends Block{
parent::onPlace($level, $x, $y, $z);
}
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$down = $level->level->getBlockID($x, $y - 1, $z);
if($down == AIR || StaticBlock::getIsLiquid($down)){
$data = [
"x" => $x + 0.5,
"y" => $y,
"z" => $z + 0.5,
"Tile" => $id,
];
$server = ServerAPI::request();
$e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data);
$server->api->entity->spawnToAll($e);
if(StaticBlock::getHasPhysics($id)){
$down = $level->level->getBlockID($x, $y - 1, $z);
if($down == AIR || StaticBlock::getIsLiquid($down)){
$data = array(
"x" => $x + 0.5,
"y" => $y,
"z" => $z + 0.5,
"Tile" => $id,
);
$server = ServerAPI::request();
$e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data);
$server->api->entity->spawnToAll($e);
}
}
}
/**
* @param integer $type
*
* @return boolean
*/
@ -75,6 +88,8 @@ class GenericBlock extends Block{
}
/**
* @param Item $item
* @param Player $player
*
* @return boolean
*/

View file

@ -23,11 +23,18 @@ class LadderBlock extends TransparentBlock{
return parent::getAABB($level, $x, $y, $z);
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];
}
public function __construct($meta = 0){
parent::__construct(LADDER, $meta, "Ladder");
$this->isSolid = false;
$this->isFullBlock = false;
$this->hardness = 2;
$this->breakTime = 0.4;
$this->material = Material::$decoration;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($face === 0 || $face === 1){

View file

@ -16,10 +16,12 @@ class SignPostBlock extends TransparentBlock{
$this->isSolid = false;
$this->isFullBlock = false;
$this->hardness = 5;
$this->breakTime = 1;
$this->material = Material::$wood;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($target->isSolid || $target->getID() === SIGN_POST || $target->getID() === WALL_SIGN) && $face !== 0){
if(($target->isSolid || $target->getID() === SIGN_POST || $target->getID() === WALL_SIGN || $target->getID() === GLASS_PANE || $target->getID() === IRON_BARS || $target->getID() === STONE_WALL) && $face !== 0){
if(!isset(self::$faces[$face])){
$this->meta = floor((($player->entity->yaw + 180) * 16 / 360) + 0.5) & 0x0F;
$this->level->setBlock($block, BlockAPI::get(SIGN_POST, $this->meta), true, false, true);

View file

@ -5,6 +5,9 @@ class TorchBlock extends FlowableBlock implements LightingBlock{
public function __construct($meta = 0){
parent::__construct(TORCH, $meta, "Torch");
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$decoration;
$this->lightEmission = 14;
}
public function getMaxLightValue(){

View file

@ -11,6 +11,8 @@ class TrapdoorBlock extends TransparentBlock{
$this->isFullBlock = true;
}
$this->hardness = 15;
$this->breakTime = 3;
$this->material = Material::$wood;
}
public function canAttachTo(Block $target){

View file

@ -9,8 +9,11 @@ class WallSignBlock extends SignPostBlock{
public function __construct($meta = 0){
TransparentBlock::__construct(WALL_SIGN, $meta, "Wall Sign");
$this->isSolid = false;
$this->breakTime = 1;
$this->hardness = 5;
$this->material = Material::$wood;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$attached = match($level->level->getBlockDamage($x, $y, $z)){
2 => $level->level->getBlockID($x, $y, $z + 1),
@ -19,8 +22,8 @@ class WallSignBlock extends SignPostBlock{
5 => $level->level->getBlockID($x - 1, $y, $z),
default => WALL_SIGN
};
if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN){
if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN && $attached != GLASS_PANE && $attached != IRON_BARS && $attached != STONE_WALL){
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true);
(ServerAPI::request())->api->entity->drop(new Position($x + 0.5, $y + 0.5, $z + 0.5, $level), BlockAPI::getItem(SIGN, 0, 1));
}

View file

@ -6,7 +6,11 @@ class LavaBlock extends LiquidBlockDynamic implements LightingBlock{
public static $blockID = LAVA;
public function __construct($meta = 0){
parent::__construct(LAVA, $meta, "Lava");
$this->hardness = 500;
$this->hardness = 500; //0 in vanilla
$this->breakTime = -1; //in vanilla it is 0, but you cant interact with the block so it is not possible to destroy it
$this->material = Material::$lava;
$this->lightEmission = 15;
$this->lightBlock = 255;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -4,55 +4,55 @@ class LiquidBlockDynamic extends LiquidBlock{
public function __construct($id, $meta = 0, $name = "Unknown"){
parent::__construct($id, $meta, $name);
}
public static $blockID = 0;
public static $sourcesAround = 0;
public static $spread = [0, 0, 0, 0];
public static function getHighest(Level $level, $x, $y, $z, $highest){
$depth = static::getDepth($level, $x, $y, $z);
if($depth < 0) return $highest;
if($depth == 0) ++static::$sourcesAround;
if($depth >= 8) $depth = 0;
return $highest >= 0 && $depth >= $highest ? $highest : $depth;
}
public static function setStatic(Level $level, $x, $y, $z){
$meta = $level->level->getBlockDamage($x, $y, $z);
$level->fastSetBlockUpdate($x, $y, $z, static::$blockID + 1, $meta);
}
public static function isWaterBlocking(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);
if($id == AIR) return false;
if($id == DOOR_BLOCK || $id == SIGN_POST || $id == WALL_SIGN || $id == LADDER || $id == SUGARCANE_BLOCK) return true;
if($id == CARPET || $id == SNOW_LAYER || $id == RAIL || $id == POWERED_RAIL) return false; //TODO Tile::getThickness() > 0
//TODO materials
//if(!StaticBlock::getIsFlowable($id)) return true;
return StaticBlock::getIsSolid($id);
$mat = StaticBlock::getMaterial($id);
if($mat->blocksMotion) return true;
return $mat->isSolid;
}
public static function canSpreadTo(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);
if($id == LAVA || $id == STILL_LAVA) return false;
if((static::$blockID == WATER) && ($id == WATER || $id == STILL_WATER)) return false;
return static::isWaterBlocking($level, $x, $y, $z) ^ 1;
}
public static function getSpread(Level $level, $x, $y, $z){
for($i = 0; $i < 4; ++$i){
static::$spread[$i] = 1000;
$xs = $x;
$ys = $y;
$zs = $z;
switch($i){
case 0:
--$xs;
@ -67,13 +67,13 @@ class LiquidBlockDynamic extends LiquidBlock{
++$zs;
break;
}
if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue;
[$id, $meta] = $level->level->getBlock($xs, $ys, $zs);
if(((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) || (static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) && $meta == 0){
continue;
}
if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) static::$spread[$i] = 0;
else static::$spread[$i] = static::getSlopeDistance($level, $xs, $ys, $zs, 1, $i);
}
@ -85,18 +85,18 @@ class LiquidBlockDynamic extends LiquidBlock{
for($i = 0; $i < 4; ++$i) $ba[$i] = ($i1 == static::$spread[$i]);
return $ba;
}
public static function getSlopeDistance(Level $level, $x, $y, $z, $l, $i1){
$j1 = 1000;
for($k1 = 0; $k1 < 4; ++$k1){
if($k1 == 0 && $i1 == 1 || $k1 == 1 && $i1 == 0 || $k1 == 2 && $i1 == 3 || $k1 == 3 && $i1 == 2){
if($k1 == 0 && $i1 == 1 || $k1 == 1 && $i1 == 0 || $k1 == 2 && $i1 == 3 || $k1 == 3 && $i1 == 2){
continue;
}
$xs = $x;
$ys = $y;
$zs = $z;
switch($k1){
case 0:
--$xs;
@ -111,10 +111,10 @@ class LiquidBlockDynamic extends LiquidBlock{
++$zs;
break;
}
if(static::isWaterBlocking($level, $xs, $ys, $zs)) continue;
[$id, $meta] = $level->level->getBlock($xs, $ys, $zs);
if(
((static::$blockID == WATER && ($id == WATER || $id == STILL_WATER)) ||
(static::$blockID == LAVA && ($id == LAVA || $id == STILL_LAVA))) &&
@ -122,20 +122,20 @@ class LiquidBlockDynamic extends LiquidBlock{
){
continue;
}
if(!static::isWaterBlocking($level, $xs, $ys - 1, $zs)) return $l;
if($l >= 4) continue;
$k2 = static::getSlopeDistance($level, $xs, $ys, $zs, $l + 1, $k1);
if($k2 < $j1) $j1 = $k2;
}
return $j1;
}
public static function trySpreadTo(Level $level, $x, $y, $z, $meta){
if(static::canSpreadTo($level, $x, $y, $z)){
[$id, $meta2] = $level->level->getBlock($x, $y, $z);
if($id > 0){
if(($id == LAVA || $id == STILL_LAVA) && (static::$blockID == LAVA || static::$blockID == STILL_LAVA)); //fizz
else{
@ -147,23 +147,23 @@ class LiquidBlockDynamic extends LiquidBlock{
}
}
}
$level->fastSetBlockUpdate($x, $y, $z, static::$blockID, $meta, true);
}
}
public static function onPlace(Level $level, $x, $y, $z){
static::updateLiquid($level, $x, $y, $z);
$id = $level->level->getBlockID($x, $y, $z);
if($id == static::$blockID) ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay());
}
public static function onUpdate(Level $level, $x, $y, $z, $type){
$id = $level->level->getBlockID($x, $y, $z);
$depth = static::getDepth($level, $x, $y, $z);
$flowAdd = (static::$blockID == LAVA) ? 2 : 1;
$flag = true;
if($depth > 0){
static::$sourcesAround = 0;
$highest = static::getHighest($level, $x - 1, $y, $z, -100);
@ -174,19 +174,19 @@ class LiquidBlockDynamic extends LiquidBlock{
if($j1 >= 8 || $highest < 0) $j1 = -1;
$l1 = static::getDepth($level, $x, $y + 1, $z);
if($l1 >= 0) $j1 = ($l1 >= 8 ? $l1 : $l1 + 8);
if(static::$sourcesAround >= 2 && static::$blockID == WATER){
$idBot = $level->level->getBlockID($x, $y - 1, $z);
if($idBot > 0){
if(StaticBlock::getIsSolid($idBot) || (($idBot == WATER || $idBot == STILL_WATER) && $level->level->getBlockDamage($x, $y, $z) == 0)) $j1 = 0;
}
}
//if(static::$blockID == LAVA && $depth < 8 && $j1 < 8 && $j1 > $depth && mt_rand(0, 4) != 0){ TODO fix later
// $j1 = $depth;
// $flag = false;
//}
if($j1 != $depth){
$depth = $j1;
if($depth < 0) $level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
@ -195,16 +195,16 @@ class LiquidBlockDynamic extends LiquidBlock{
ServerAPI::request()->api->block->scheduleBlockUpdateXYZ($level, $x, $y, $z, BLOCK_UPDATE_SCHEDULED, static::getTickDelay());
$level->updateNeighborsAt($x, $y, $z, static::$blockID); //TODO check is needed
}
}elseif($flag){
}else if($flag){
static::setStatic($level, $x, $y, $z);
}
}else{
static::setStatic($level, $x, $y, $z);
}
if(static::canSpreadTo($level, $x, $y - 1, $z)){
$level->fastSetBlockUpdate($x, $y - 1, $z, static::$blockID, ($depth >= 8 ? $depth : $depth + 8) & 0xf, true);
}elseif($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){
}else if($depth >= 0 && ($depth == 0 || static::isWaterBlocking($level, $x, $y - 1, $z))){
$flags = static::getSpread($level, $x, $y, $z);
$k1 = $depth >= 8 ? 1 : ($depth + $flowAdd);
if($k1 >= 8) return;

View file

@ -7,6 +7,10 @@ class StillLavaBlock extends LiquidBlockStatic{
public function __construct($meta = 0){
parent::__construct(STILL_LAVA, $meta, "Still Lava");
$this->hardness = 500;
$this->breakTime = -1; //in vanilla it is 100, but you cant interact with the block so it is not possible to destroy it
$this->material = Material::$lava;
$this->lightEmission = 15;
$this->lightBlock = 255;
}
public static function getTickDelay(){

View file

@ -11,6 +11,9 @@ class StillWaterBlock extends LiquidBlockStatic{
public function __construct($meta = 0){
LiquidBlock::__construct(STILL_WATER, $meta, "Still Water");
$this->hardness = 500;
$this->breakTime = -1; //in vanilla it is 100, but you cant interact with the block so it is not possible to destroy it
$this->material = Material::$water;
$this->lightBlock = 3;
}
public static function getTickDelay(){

View file

@ -8,6 +8,9 @@ class WaterBlock extends LiquidBlockDynamic{
public function __construct($meta = 0){
parent::__construct(WATER, $meta, "Water");
$this->hardness = 500;
$this->breakTime = -1; //in vanilla it is 100, but you cant interact with the block so it is not possible to destroy it
$this->material = Material::$water;
$this->lightBlock = 3;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -2,7 +2,7 @@
class AirBlock extends TransparentBlock{
public static $blockID;
public function __construct(){
parent::__construct(AIR, 0, "Air");
$this->isActivable = false;
@ -15,7 +15,8 @@ class AirBlock extends TransparentBlock{
$this->isSolid = false;
$this->isFullBlock = true;
$this->hardness = 0;
$this->material = Material::$air;
}
}

View file

@ -14,43 +14,47 @@ class BedBlock extends TransparentBlock{
[0, -1],
[1, 0]
];
const PLAYER_BED_OFFS_X = [0.5, 0.1, 0.5, 0.9];
const PLAYER_BED_OFFS_Z = [0.9, 0.5, 0.1, 0.5];
public function __construct($type = 0){
parent::__construct(BED_BLOCK, $type, "Bed Block");
$this->isActivable = true;
$this->isFullBlock = false;
$this->hardness = 1;
$this->breakTime = 0.2;
$this->material = Material::$cloth;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$meta = $level->level->getBlockDamage($x, $y, $z);
$dir = $meta & 3;
$isHead = ($meta >> 3) & 1;
$offX = self::HEAD_DIRECTION_OFFSETS[$dir][0];
$offZ = self::HEAD_DIRECTION_OFFSETS[$dir][1];
if($isHead){
if($level->level->getBlockID($x - $offX, $y, $z - $offZ) != BED_BLOCK){
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
}
}elseif($level->level->getBlockID($x + $offX, $y, $z + $offZ) != BED_BLOCK){
}else if($level->level->getBlockID($x + $offX, $y, $z + $offZ) != BED_BLOCK){
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
ServerAPI::request()->api->entity->dropRawPos(
$level,
$x + (lcg_value() * 0.7) + 0.15,
$y + (lcg_value() * 0.7) + 0.15,
$z + (lcg_value() * 0.7) + 0.15,
BlockAPI::getItem(BED, 0, 1),
$level,
$x + (lcg_value() * 0.7) + 0.15,
$y + (lcg_value() * 0.7) + 0.15,
$z + (lcg_value() * 0.7) + 0.15,
BlockAPI::getItem(BED, 0, 1),
lcg_value() * 0.2 - 0.1, 0.2, lcg_value() * 0.2 - 0.1
);
}
}
public static function findStandUpPosition(Level $level, $x, $y, $z){
$blockMeta = $level->level->getBlockDamage($x, $y, $z);
@ -60,63 +64,48 @@ class BedBlock extends TransparentBlock{
$minZ = $z - self::HEAD_DIRECTION_OFFSETS[$direction][1] * $v7 - 1;
$maxX = $minX + 2;
$maxZ = $minZ + 2;
for($xCheck = $minX; $xCheck <= $maxX; ++$xCheck){
for($zCheck = $minZ; $zCheck <= $maxZ; ++$zCheck){
$idCheck = $level->level->getBlockID($xCheck, $y - 1, $zCheck);
if(!StaticBlock::getIsTransparent($idCheck) && $level->level->getBlockID($xCheck, $y, $zCheck) == 0 && $level->level->getBlockID($xCheck, $y + 1, $zCheck) == 0){
return new Vector3($xCheck, $y, $zCheck);
return new Position($xCheck, $y, $zCheck, $level);
}
}
}
}
return null;
}
public function onActivate(Item $item, Player $player){
if(ServerAPI::request()->api->time->getPhase($player->level) !== "night"){
$pk = new ChatPacket;
$pk->message = "You can only sleep at night";
$player->dataPacket($pk);
$player->sendChat("You can only sleep at night");
return true;
}
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
$b = $this;
}else{ //Bottom Part of Bed
if($blockNorth->getID() === $this->id and ($blockNorth->meta & 0x08) === 0x08){
$b = $blockNorth;
}elseif($blockSouth->getID() === $this->id and ($blockSouth->meta & 0x08) === 0x08){
$b = $blockSouth;
}elseif($blockEast->getID() === $this->id and ($blockEast->meta & 0x08) === 0x08){
$b = $blockEast;
}elseif($blockWest->getID() === $this->id and ($blockWest->meta & 0x08) === 0x08){
$b = $blockWest;
}else{
$pk = new ChatPacket;
$pk->message = "This bed is incomplete";
$player->dataPacket($pk);
$dir = ($this->meta & 3);
$o = BedBlock::HEAD_DIRECTION_OFFSETS[$dir];
$b = $this->level->getBlockWithoutVector($this->x + $o[0], $this->y, $this->z + $o[1]);
if($b->getID() != BED_BLOCK){
$player->sendChat("This bed is incomplete");
return true;
}
}
if($player->sleepOn($b) === false){
$pk = new ChatPacket;
$pk->message = "This bed is occupied";
$player->dataPacket($pk);
$player->sendChat("This bed is occupied");
}
return true;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$d = $player->entity->getDirection();
$next = $this->getSide(self::$faces[(($d + 3) % 4)]);
$downNext = $next->getSide(0);
@ -128,15 +117,15 @@ class BedBlock extends TransparentBlock{
}
}
return false;
}
}
public function onBreak(Item $item, Player $player){
$blockNorth = $this->getSide(2); //Gets the blocks around them
$blockSouth = $this->getSide(3);
$blockEast = $this->getSide(5);
$blockWest = $this->getSide(4);
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
if(($this->meta & 0x08) === 0x08){ //This is the Top part of bed
switch($this->meta & 0x7){
case 0:
if($blockNorth->id === $this->id) $this->level->setBlock($blockNorth, new AirBlock(), true, false, true);
@ -170,11 +159,11 @@ class BedBlock extends TransparentBlock{
$this->level->setBlock($this, new AirBlock(), true, false, true);
return true;
}
public function getDrops(Item $item, Player $player){
return [
[BED, 0, 1],
];
return array(
array(BED, 0, 1),
);
}
}

View file

@ -11,6 +11,9 @@ class FireBlock extends FlowableBlock implements LightingBlock{
$this->breakable = false;
$this->isFullBlock = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$fire;
$this->lightEmission = 15;
}
public static function getAABB(Level $level, $x, $y, $z){
return null;

View file

@ -6,6 +6,10 @@ class NetherReactorBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(NETHER_REACTOR, $meta, "Nether Reactor");
$this->isActivable = true;
$this->hardness = 15;
$this->breakTime = 3;
$this->material = Material::$metal;
$this->lightBlock = 255;
}
public function onActivate(Item $item, Player $player){

View file

@ -5,21 +5,22 @@ class TNTBlock extends SolidBlock{
public function __construct(){
parent::__construct(TNT, 0, "TNT");
$this->hardness = 0;
$this->breakTime = 0;
$this->isActivable = true;
$this->material = Material::$explosive;
$this->lightBlock = 255;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === FLINT_STEEL){
if(($player->gamemode & 0x01) === 0){
$item->useOn($this);
}
$data = [
$item->hurtAndBreak(1, $player);
$data = array(
"x" => $this->x + 0.5,
"y" => $this->y,
"z" => $this->z + 0.5,
"power" => 3,
"fuse" => 20 * 4, //4 seconds
];
);
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, 0, 0, true);
$e = ServerAPI::request()->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data);
ServerAPI::request()->api->entity->spawnToAll($e);

View file

@ -8,6 +8,8 @@ class CakeBlock extends TransparentBlock{
$this->isActivable = true;
$this->meta = $meta & 0x07;
$this->hardness = 2.5;
$this->breakTime = 0.5;
$this->material = Material::$cake;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){

View file

@ -4,7 +4,7 @@ class CarpetBlock extends FlowableBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(CARPET, $meta, "Carpet");
$names = [
$names = array(
0 => "White Carpet",
1 => "Orange Carpet",
2 => "Magenta Carpet",
@ -21,11 +21,13 @@ class CarpetBlock extends FlowableBlock{
13 => "Green Carpet",
14 => "Red Carpet",
15 => "Black Carpet",
];
);
$this->name = $names[$this->meta];
$this->hardness = 0;
$this->isFullBlock = false;
$this->hardness = 0.5;
$this->breakTime = 0.1;
$this->isFullBlock = false;
$this->isSolid = true;
$this->material = Material::$cloth;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [static::getAABB($level, $x, $y, $z)];

View file

@ -7,6 +7,8 @@ class ChestBlock extends TransparentBlock{
$this->isActivable = true;
$this->isFullBlock = false;
$this->hardness = 15;
$this->breakTime = 2.5;
$this->material = Material::$wood;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [new AxisAlignedBB($x + 0.025, $y, $z + 0.025, $x + 0.975, $y + 0.95, $z + 0.975)];

View file

@ -6,7 +6,10 @@ class CobwebBlock extends FlowableBlock{
parent::__construct(COBWEB, 0, "Cobweb");
$this->isSolid = true;
$this->isFullBlock = false;
$this->hardness = 25;
$this->hardness = 30;
$this->breakTime = 4;
$this->material = Material::$web;
$this->lightBlock = 1;
}
public static function getAABB(Level $level, $x, $y, $z){

View file

@ -5,6 +5,8 @@ class FarmlandBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(FARMLAND, $meta, "Farmland");
$this->hardness = 3;
$this->breakTime = 0.6;
$this->material = Material::$dirt;
}
public function getDrops(Item $item, Player $player){
return [
@ -24,7 +26,7 @@ class FarmlandBlock extends TransparentBlock{
public static function fallOn(Level $level, $x, $y, $z, Entity $entity, $fallDistance){
$rv = lcg_value();
if($rv < ($fallDistance - 0.5)){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0);
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true);
}
}

View file

@ -6,17 +6,26 @@ class FenceBlock extends TransparentBlock{
parent::__construct(FENCE, 0, "Fence");
$this->isFullBlock = false;
$this->hardness = 15;
$this->breakTime = 2;
$this->material = Material::$wood;
}
public static function canConnectTo(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);
/*if($id == FENCE || $id == FENCE_GATE) return true;
if($id == 0) return false;
$mat = StaticBlock::getMaterial($id);
if($mat->isSolidBlocking() && tile->isCubeShaped()){ //TODO tile->isCubeShaped
return $mat != Material::$vegetable;
}
return false;*/
if($id != FENCE && $id != FENCE_GATE){
return StaticBlock::getIsSolid($id) && $id != PUMPKIN; //TODO check var6 != null && var6.blockMaterial.isOpaque() && var6.renderAsNormalBlock() ? var6.blockMaterial != Material.pumpkin : false;
return StaticBlock::getIsSolid($id) && $id != PUMPKIN;
}
return true;
}
public static function getAABB(Level $level, $x, $y, $z){
$v9 = self::canConnectTo($level, $x, $y, $z - 1);
$v10 = self::canConnectTo($level, $x, $y, $z + 1);
@ -29,7 +38,7 @@ class FenceBlock extends TransparentBlock{
StaticBlock::setBlockBounds(static::$blockID, $minX, 0, $minZ, $maxX, 1.5, $maxZ);
return parent::getAABB($level, $x, $y, $z);
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
$v8 = self::canConnectTo($level, $x, $y, $z - 1);
$v9 = self::canConnectTo($level, $x, $y, $z + 1);
@ -47,11 +56,11 @@ class FenceBlock extends TransparentBlock{
$v15 = 0.625;
if($v10) $v12 = 0;
if($v11) $v13 = 1;
if($v10 || $v11 || !$v8 && !$v9){
$arr[] = new AxisAlignedBB($x + $v12, $y + 0, $z + $v14, $x + $v13, $y + 1.5, $z + $v15);
}
return $arr;
}
}

View file

@ -31,6 +31,8 @@ class FenceGateBlock extends TransparentBlock{
$this->isFullBlock = false;
}
$this->hardness = 15;
$this->breakTime = 2;
$this->material = Material::$wood;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = [
@ -73,7 +75,7 @@ class FenceGateBlock extends TransparentBlock{
$pk->z = $this->z;
$pk->evid = 1003;
$pk->data = 0;
ServerAPI::request()->api->player->broadcastPacket($players, $pk);
ServerAPI::request()->api->player->broadcastPacket($players, $pk); //TODO use blok queue?
return true;
}
}

View file

@ -6,6 +6,9 @@ class GlassPaneBlock extends TransparentBlock{
parent::__construct(GLASS_PANE, 0, "Glass Pane");
$this->isFullBlock = false;
$this->isSolid = false;
$this->breakTime = 0.3;
$this->hardness = 0.3*5;
$this->material = Material::$glass;
}
public static function updateShape(Level $level, $x, $y, $z){
$id = $level->level->getBlockID($x, $y, $z);

View file

@ -6,6 +6,9 @@ class IronBarsBlock extends TransparentBlock{
parent::__construct(IRON_BARS, 0, "Iron Bars");
$this->isFullBlock = false;
$this->isSolid = false;
$this->breakTime = 5;
$this->hardness = 30;
$this->material = Material::$metal;
}
public static function updateShape(Level $level, $x, $y, $z){

View file

@ -6,6 +6,8 @@ class IronDoorBlock extends DoorBlock{
parent::__construct(IRON_DOOR_BLOCK, $meta, "Iron Door Block");
//$this->isActivable = true;
$this->hardness = 25;
$this->breakTime = 5;
$this->material = Material::$metal;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -1,13 +1,14 @@
<?php
require_once("RailBaseBlock.php");
class PoweredRailBlock extends RailBaseBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(POWERED_RAIL, 0, "PoweredRailBlock");
$this->hardness = 0.7;
$this->isFullBlock = false;
$this->isFullBlock = false;
$this->isSolid = false;
$this->hardness = 3.5;
$this->breakTime = 0.7;
$this->material = Material::$decoration;
}
}

View file

@ -1,20 +1,21 @@
<?php
require_once("RailBaseBlock.php");
class RailBlock extends RailBaseBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(RAIL, $meta, "Rail");
$this->hardness = 0.7;
$this->isFullBlock = false;
$this->hardness = 0.7*5;
$this->breakTime = 0.7;
$this->isFullBlock = false;
$this->isSolid = false;
$this->material = Material::$decoration;
}
public function updateState(){
$logic = (new RailLogic($this));
if($logic->countPotentialConnections() == 3){
$logic->place(false, false);
}
}
}

View file

@ -22,6 +22,8 @@ class SlabBlock extends TransparentBlock{
$this->isFullBlock = false;
}
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$stone;
}
public static function updateShape(Level $level, $x, $y, $z){

View file

@ -8,6 +8,8 @@ class SnowLayerBlock extends FlowableBlock{
$this->isSolid = false;
$this->isFullBlock = false;
$this->hardness = 0.5;
$this->breakTime = 0.1;
$this->material = Material::$topSnow;
}
public static function getAABB(Level $level, $x, $y, $z){
return null;
@ -20,20 +22,26 @@ class SnowLayerBlock extends FlowableBlock{
}
return false;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
}
}
public static function onRandomTick(Level $level, $x, $y, $z){
if($level->level->getBlockLight($x, $y, $z) > 11){
$level->fastSetBlockUpdate($x, $y, $z, 0, true);
}
}
public function getDrops(Item $item, Player $player){
if($item->isShovel() !== false){
return [
[SNOWBALL, 0, 1],
];
return array(
array(SNOWBALL, 0, 1),
);
}
return [];
return array();
}
}

View file

@ -7,7 +7,9 @@ class StoneWallBlock extends TransparentBlock{
parent::__construct(STONE_WALL, $meta & 0x01, $meta === 1 ? "Mossy Cobblestone Wall" : "Cobblestone Wall");
$this->isFullBlock = false;
$this->isSolid = false;
$this->hardness = 30;
$this->hardness = 50;
$this->breakTime = 10;
$this->material = Material::$stone;
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe()){

View file

@ -6,6 +6,8 @@ class WoodDoorBlock extends DoorBlock{
parent::__construct(WOOD_DOOR_BLOCK, $meta, "Wood Door Block");
$this->isActivable = true;
$this->hardness = 15;
$this->breakTime = 3;
$this->material = Material::$wood;
}
public function getDrops(Item $item, Player $player){

View file

@ -1,29 +1,30 @@
<?php
//TODO make it extend SlabBlock
class WoodSlabBlock extends TransparentBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(WOOD_SLAB, $meta, "Wooden Slab");
$names = [
$names = array(
0 => "Oak",
1 => "Spruce",
2 => "Birch",
3 => "Jungle",
];
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Wooden Slab";
);
$this->name = (($this->meta & 0x08) === 0x08 ? "Upper ":"") . $names[$this->meta & 0x07] . " Wooden Slab";
if(($this->meta & 0x08) === 0x08){
$this->isFullBlock = true;
}else{
$this->isFullBlock = false;
}
$this->hardness = 15;
}
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$wood;
}
public static function updateShape(Level $level, $x, $y, $z){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if($meta & 0x08 == 0x08){
StaticBlock::setBlockBounds($id, 0, 0, 0, 1, 1, 1);
}else{
@ -32,11 +33,11 @@ class WoodSlabBlock extends TransparentBlock{
else StaticBlock::setBlockBounds($id, 0, 0.5, 0, 1, 1, 1);
}
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
self::updateShape($level, $x, $y, $z);
$id = $level->level->getBlockID($x, $y, $z);
return [
new AxisAlignedBB(
$x + StaticBlock::$minXs[$id], $y + StaticBlock::$minYs[$id], $z + StaticBlock::$minZs[$id],
@ -44,7 +45,7 @@ class WoodSlabBlock extends TransparentBlock{
)
];
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta &= 0x07;
if($face === 0){
@ -91,7 +92,9 @@ class WoodSlabBlock extends TransparentBlock{
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
return match ($item->isAxe()) {
if(!$item->isAxe()) return 3;
return match ($item->getLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
@ -100,10 +103,10 @@ class WoodSlabBlock extends TransparentBlock{
default => 3,
};
}
public function getDrops(Item $item, Player $player){
return [
[$this->id, $this->meta & 0x07, 1],
];
return array(
array($this->id, $this->meta & 0x07, 1),
);
}
}

View file

@ -4,6 +4,9 @@ class BirchWoodStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(BIRCH_WOOD_STAIRS, $meta, "Birch Wood Stairs");
$this->hardness = 15;
$this->breakTime = 2;
$this->material = Material::$wood;
}
public function getDrops(Item $item, Player $player){

View file

@ -4,6 +4,9 @@ class BrickStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(BRICK_STAIRS, $meta, "Brick Stairs");
$this->breakTime = 2;
$this->hardness = 30;
$this->material = Material::$stone;
}
}

View file

@ -4,6 +4,9 @@ class CobblestoneStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(COBBLESTONE_STAIRS, $meta, "Cobblestone Stairs");
$this->breakTime = 2;
$this->hardness = 30;
$this->material = Material::$stone;
}
}

View file

@ -4,6 +4,9 @@ class JungleWoodStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(JUNGLE_WOOD_STAIRS, $meta, "Jungle Wood Stairs");
$this->hardness = 15;
$this->breakTime = 2;
$this->material = Material::$wood;
}
public function getDrops(Item $item, Player $player){

View file

@ -4,6 +4,9 @@ class NetherBricksStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(NETHER_BRICKS_STAIRS, $meta, "Nether Bricks Stairs");
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$stone;
}
}

View file

@ -4,6 +4,9 @@ class QuartzStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(QUARTZ_STAIRS, $meta, "Quartz Stairs");
$this->breakTime = 0.8;
$this->hardness = 4;
$this->material = Material::$stone;
}
}

View file

@ -4,6 +4,9 @@ class SandstoneStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(SANDSTONE_STAIRS, $meta, "Sandstone Stairs");
$this->hardness = 0.8*5;
$this->breakTime = 0.8;
$this->material = Material::$stone;
}
}

View file

@ -4,6 +4,9 @@ class SpruceWoodStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(SPRUCE_WOOD_STAIRS, $meta, "Spruce Wood Stairs");
$this->hardness = 15;
$this->breakTime = 2;
$this->material = Material::$wood;
}
public function getDrops(Item $item, Player $player){

View file

@ -4,6 +4,9 @@ class StoneBrickStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(STONE_BRICK_STAIRS, $meta, "Stone Brick Stairs");
$this->hardness = 30;
$this->breakTime = 1.5;
$this->material = Material::$stone;
}
}

View file

@ -4,13 +4,17 @@ class WoodStairsBlock extends StairBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(WOOD_STAIRS, $meta, "Wood Stairs");
$this->breakTime = 2;
$this->material = Material::$wood;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
return match ($item->isAxe()) {
if(!$item->isAxe()) return 3;
return match ($item->getLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,

View file

@ -5,6 +5,9 @@ class CoalOreBlock extends SolidBlock{
public function __construct(){
parent::__construct(COAL_ORE, 0, "Coal Ore");
$this->hardness = 15;
$this->breakTime = 3.0;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class DiamondOreBlock extends SolidBlock{
public function __construct(){
parent::__construct(DIAMOND_ORE, 0, "Diamond Ore");
$this->hardness = 15;
$this->breakTime = 3;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,10 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
public function __construct(){
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
$this->hardness = 15;
$this->breakTime = 3;
$this->material = Material::$stone;
$this->lightBlock = 255;
$this->lightEmission = 9;
}
public static function onRandomTick(Level $level, $x, $y, $z){

View file

@ -5,6 +5,9 @@ class GoldOreBlock extends SolidBlock{
public function __construct(){
parent::__construct(GOLD_ORE, 0, "Gold Ore");
$this->hardness = 15;
$this->breakTime = 3.0;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class IronOreBlock extends SolidBlock{
public function __construct(){
parent::__construct(IRON_ORE, 0, "Iron Ore");
$this->hardness = 15;
$this->breakTime = 3.0;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class LapisOreBlock extends SolidBlock{
public function __construct(){
parent::__construct(LAPIS_ORE, 0, "Lapis Ore");
$this->hardness = 15;
$this->breakTime = 3.0;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class RedstoneOreBlock extends SolidBlock{
public function __construct(){
parent::__construct(REDSTONE_ORE, 0, "Redstone Ore");
$this->hardness = 15;
$this->breakTime = 3;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public static function interact(Level $level, $x, $y, $z, Player $player){

View file

@ -0,0 +1,56 @@
<?php
class BaseMushroomBlock extends FlowableBlock{
public function __construct($id, $meta, $name){
parent::__construct($id, $meta, $name);
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(static::$blockID, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(Block::$mushroomSpread && mt_rand(0, 24) == 0){
$maxcnt = 5;
for($xx = $x-4; $xx <= $x+4; ++$xx){
for($zz = $z-4; $zz <= $z+4; ++$zz){
for($yy = $y-1; $yy <= $y+1; ++$yy){
if($level->level->getBlockID($xx, $yy, $zz) == static::$blockID){
if(--$maxcnt <= 0) return;
}
}
}
}
for($att = 0; $att < 4; ++$att){
$nx = $x + mt_rand(-1, 1);
$ny = $y + mt_rand(-1, 1);
$nz = $z + mt_rand(-1, 1);
if($ny < 127 && $ny > 0 && $level->level->getBlockID($nx, $ny, $nz) == 0){
$idb = $level->level->getBlockID($nx, $ny-1, $nz);
if(!StaticBlock::getIsTransparent($idb)){ //TODO better canSurvive check
if($level->getRawBrightness($nx, $ny, $nz) <= 12){
$level->fastSetBlockUpdate($nx, $ny, $nz, static::$blockID, 0);
return;
}
}
}
}
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
}

View file

@ -6,13 +6,14 @@ class BeetrootBlock extends FlowableBlock{
parent::__construct(BEETROOT_BLOCK, $meta, "Beetroot Block");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
@ -32,9 +33,7 @@ class BeetrootBlock extends FlowableBlock{
$this->meta = 7;
}
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;

View file

@ -1,25 +1,9 @@
<?php
class BrownMushroomBlock extends FlowableBlock{
require_once("BaseMushroomBlock.php");
class BrownMushroomBlock extends BaseMushroomBlock{
public static $blockID;
public function __construct(){
parent::__construct(BROWN_MUSHROOM, 0, "Brown Mushroom");
$this->hardness = 0;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(BROWN_MUSHROOM));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
$this->lightEmission = 1;
}
}

View file

@ -6,6 +6,8 @@ class CactusBlock extends TransparentBlock{
parent::__construct(CACTUS, $meta, "Cactus");
$this->isFullBlock = false;
$this->hardness = 2;
$this->breakTime = 0.4;
$this->material = Material::$cactus;
}
public static function onEntityCollidedWithBlock(Level $level, $x, $y, $z, Entity $entity){
@ -60,7 +62,6 @@ class CactusBlock extends TransparentBlock{
$block3 = $this->getSide(5);
if($block0->isFlowable === true and $block1->isFlowable === true and $block2->isFlowable === true and $block3->isFlowable === true){
$this->level->setBlock($this, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL);
return true;
}

View file

@ -6,13 +6,14 @@ class CarrotBlock extends FlowableBlock{
parent::__construct(CARROT_BLOCK, $meta, "Carrot Block");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
@ -25,9 +26,7 @@ class CarrotBlock extends FlowableBlock{
$this->meta = 7;
}
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;

View file

@ -6,6 +6,8 @@ class CyanFlowerBlock extends FlowableBlock{
parent::__construct(CYAN_FLOWER, 0, "Cyan Flower");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public static function getAABB(Level $level, $x, $y, $z){
@ -31,11 +33,9 @@ class CyanFlowerBlock extends FlowableBlock{
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$random = new Random();
self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2);
$player->consumeSingleItem(send:true);
return true;
}
return false;

View file

@ -6,6 +6,8 @@ class DandelionBlock extends FlowableBlock{
parent::__construct(DANDELION, 0, "Dandelion");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public static function getAABB(Level $level, $x, $y, $z){
return null;
@ -22,18 +24,16 @@ class DandelionBlock extends FlowableBlock{
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$downId = $level->level->getBlockID($x, $y - 1, $z);
if(StaticBlock::getIsTransparent($downId) and $downId !== FARMLAND){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CYAN_FLOWER));
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(DANDELION));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$random = new Random();
self::placeFlowers($this->level, new Vector3($this->x, $this->y, $this->z), $random, $random->nextRange(2, 5), 2);
$player->consumeSingleItem(send:true);
return true;
}
return false;

View file

@ -6,6 +6,8 @@ class DeadBushBlock extends FlowableBlock{
parent::__construct(DEAD_BUSH, 0, "Dead Bush");
//$this->isReplaceable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$replaceable_plant;
}
public static function getAABB(Level $level, $x, $y, $z){

View file

@ -6,51 +6,97 @@ class MelonStemBlock extends FlowableBlock{
parent::__construct(MELON_STEM, $meta, "Melon Stem");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
}
public static function getGrowthSpeed(Level $level, $x, $y, $z){
$zneg = $level->level->getBlockID($x, $y, $z-1);
$zpos = $level->level->getBlockID($x, $y, $z+1);
$xneg = $level->level->getBlockID($x-1, $y, $z);
$xpos = $level->level->getBlockID($x+1, $y, $z);
$znxn = $level->level->getBlockID($x-1, $y, $z-1);
$znxp = $level->level->getBlockID($x+1, $y, $z-1);
$zpxp = $level->level->getBlockID($x+1, $y, $z+1);
$zpxn = $level->level->getBlockID($x-1, $y, $z+1);
$xEqual = $xneg == MELON_STEM || $xpos == MELON_STEM;
$zEqual = $zneg == MELON_STEM || $zpos == MELON_STEM;
$xzEqual = $znxn == MELON_STEM || $znxp == MELON_STEM || $zpxn == MELON_STEM || $zpxp == MELON_STEM;
$speed = 1;
for($xx = $x-1; $xx >= $x+1; ++$xx){
for($zz = $z-1; $zz >= $z+1; ++$zz){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
$v18 = 0;
if($id == FARMLAND) $v18 = $meta > 0 ? 3 : 1;
if($xx != $x || $zz != $z) $v18 *= 0.25;
$speed += $v18;
}
}
if($xzEqual || ($xEqual && $zEqual)) return $speed*0.5;
return $speed;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}else{
$position = new AirBlock(); //feke block
$position->x = $x;
$position->y = $y;
$position->z = $z;
$position->level = $level;
for($side = 2; $side <= 5; ++$side){
$b = $position->getSide($side);
if($b->getID() === MELON_BLOCK){
return;
}
}
$side = $position->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$level->setBlock($side, new MelonBlock(), true, false, true);
}
//TODO checkAlive
//if ( Level::getRawBrightness(a2, a3, a4 + 1, a5) > 8 ) TODO - skylight
$growSpeed = static::getGrowthSpeed($level, $x, $y, $z);
$rand = mt_rand(0, (int)(25/$growSpeed));
if($rand != 0) return;
$meta = $level->level->getBlockDamage($x, $y, $z);
if($meta <= 6){
$level->fastSetBlockUpdateMeta($x, $y, $z, $meta+1);
return;
}
$xn = $level->level->getBlockID($x-1, $y, $z);
$xp = $level->level->getBlockID($x+1, $y, $z);
$zn = $level->level->getBlockID($x, $y, $z-1);
$zp = $level->level->getBlockID($x, $y, $z+1);
if($xn != MELON_BLOCK && $xp != MELON_BLOCK && $zn != MELON_BLOCK && $zp != MELON_BLOCK){
$below = $level->level->getBlockID($x-1, $y-1, $z);
if($level->level->getBlockID($x-1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x-1, $y, $z, MELON_BLOCK, 0);
return;
}
$below = $level->level->getBlockID($x+1, $y-1, $z);
if($level->level->getBlockID($x+1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x+1, $y, $z, MELON_BLOCK, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z-1);
if($level->level->getBlockID($x, $y, $z-1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z-1, MELON_BLOCK, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z+1);
if($level->level->getBlockID($x, $y, $z+1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z+1, MELON_BLOCK, 0);
return;
}
}
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(MELON_SEEDS, 0, mt_rand(0, 2)));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta += mt_rand(0, 3) + 2;
@ -58,24 +104,16 @@ class MelonStemBlock extends FlowableBlock{
$this->meta = 7;
}
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
$drops = [];
if($this->meta >= 0x07){
$drops[] = [MELON_SEEDS, 0, mt_rand(1, 2)];
}
elseif($this->meta >= 0x01 and $this->meta <= 0x07){
$drops[] = [MELON_SEEDS, 0, 1];
}
else{
$drops[] = [MELON_SEEDS, 0, 0];
for($i = 0; $i < 3; ++$i){
if(mt_rand(0, 15) <= $this->meta) $drops[] = [MELON_SEEDS, 0, 1];
}
return $drops;
}

View file

@ -6,13 +6,14 @@ class PotatoBlock extends FlowableBlock{
parent::__construct(POTATO_BLOCK, $meta, "Potato Block");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
@ -34,9 +35,7 @@ class PotatoBlock extends FlowableBlock{
$this->meta = 7;
}
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;

View file

@ -6,51 +6,96 @@ class PumpkinStemBlock extends FlowableBlock{
parent::__construct(PUMPKIN_STEM, $meta, "Pumpkin Stem");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public static function getGrowthSpeed(Level $level, $x, $y, $z){
$zneg = $level->level->getBlockID($x, $y, $z-1);
$zpos = $level->level->getBlockID($x, $y, $z+1);
$xneg = $level->level->getBlockID($x-1, $y, $z);
$xpos = $level->level->getBlockID($x+1, $y, $z);
$znxn = $level->level->getBlockID($x-1, $y, $z-1);
$znxp = $level->level->getBlockID($x+1, $y, $z-1);
$zpxp = $level->level->getBlockID($x+1, $y, $z+1);
$zpxn = $level->level->getBlockID($x-1, $y, $z+1);
$xEqual = $xneg == PUMPKIN_STEM || $xpos == PUMPKIN_STEM;
$zEqual = $zneg == PUMPKIN_STEM || $zpos == PUMPKIN_STEM;
$xzEqual = $znxn == PUMPKIN_STEM || $znxp == PUMPKIN_STEM || $zpxn == PUMPKIN_STEM || $zpxp == PUMPKIN_STEM;
$speed = 1;
for($xx = $x-1; $xx >= $x+1; ++$xx){
for($zz = $z-1; $zz >= $z+1; ++$zz){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if($id == FARMLAND) $v18 = $meta > 0 ? 3 : 1;
else $v18 = 0;
if($xx != $x || $zz != $z) $v18 *= 0.25;
$speed += $v18;
}
}
if($xzEqual || ($xEqual && $zEqual)) return $speed*0.5;
return $speed;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(mt_rand(0, 2) == 1){
$block = $level->level->getBlock($x, $y, $z);
if($block[1] < 0x07){
//++$this->meta;
//$this->level->setBlock($this, $this, true, false, true);
$level->fastSetBlockUpdate($x, $y, $z, $block[0], $block[1] + 1);
}else{
$position = new AirBlock(); //feke block
$position->x = $x;
$position->y = $y;
$position->z = $z;
$position->level = $level;
for($side = 2; $side <= 5; ++$side){
$b = $position->getSide($side);
if($b->getID() === PUMPKIN){
return;
}
}
$side = $position->getSide(mt_rand(2,5));
$d = $side->getSide(0);
if($side->getID() === AIR and ($d->getID() === FARMLAND or $d->getID() === GRASS or $d->getID() === DIRT)){
$level->setBlock($side, new PumpkinBlock(), true, false, true);
}
//TODO checkAlive
//if ( Level::getRawBrightness(a2, a3, a4 + 1, a5) > 8 ) TODO - skylight
$growSpeed = static::getGrowthSpeed($level, $x, $y, $z);
$rand = mt_rand(0, (int)(25/$growSpeed));
if($rand != 0) return;
$meta = $level->level->getBlockDamage($x, $y, $z);
if($meta <= 6){
$level->fastSetBlockUpdateMeta($x, $y, $z, $meta+1);
return;
}
$xn = $level->level->getBlockID($x-1, $y, $z);
$xp = $level->level->getBlockID($x+1, $y, $z);
$zn = $level->level->getBlockID($x, $y, $z-1);
$zp = $level->level->getBlockID($x, $y, $z+1);
if($xn != PUMPKIN && $xp != PUMPKIN && $zn != PUMPKIN && $zp != PUMPKIN){
$below = $level->level->getBlockID($x-1, $y-1, $z);
if($level->level->getBlockID($x-1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x-1, $y, $z, PUMPKIN, 0);
return;
}
$below = $level->level->getBlockID($x+1, $y-1, $z);
if($level->level->getBlockID($x+1, $y, $z) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x+1, $y, $z, PUMPKIN, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z-1);
if($level->level->getBlockID($x, $y, $z-1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z-1, PUMPKIN, 0);
return;
}
$below = $level->level->getBlockID($x, $y-1, $z+1);
if($level->level->getBlockID($x, $y, $z+1) == 0 && ($below == FARMLAND || $below == DIRT || $below == GRASS)){
$level->fastSetBlockUpdate($x, $y, $z+1, PUMPKIN, 0);
return;
}
}
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(PUMPKIN_SEEDS, 0, mt_rand(0, 2)));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta += mt_rand(0, 3) + 2;
@ -58,24 +103,16 @@ class PumpkinStemBlock extends FlowableBlock{
$this->meta = 7;
}
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
$drops = [];
if($this->meta >= 0x07){
$drops[] = [PUMPKIN_SEEDS, 0, mt_rand(1, 2)];
}
elseif($this->meta >= 0x01 and $this->meta <= 0x07){
$drops[] = [PUMPKIN_SEEDS, 0, 1];
}
else{
$drops[] = [PUMPKIN_SEEDS, 0, 0];
for($i = 0; $i < 3; ++$i){
if(mt_rand(0, 15) <= $this->meta) $drops[] = [PUMPKIN_SEEDS, 0, 1];
}
return $drops;
}

View file

@ -1,25 +1,9 @@
<?php
require_once("BaseMushroomBlock.php");
class RedMushroomBlock extends FlowableBlock{
class RedMushroomBlock extends BaseMushroomBlock{
public static $blockID;
public function __construct(){
parent::__construct(RED_MUSHROOM, 0, "Red Mushroom");
$this->hardness = 0;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(RED_MUSHROOM));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->isTransparent === false){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
}

View file

@ -19,6 +19,8 @@ class SaplingBlock extends FlowableBlock{
];
$this->name = $names[$this->meta & 0x03];
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public static function getAABB(Level $level, $x, $y, $z){
return null;
@ -27,7 +29,6 @@ class SaplingBlock extends FlowableBlock{
$down = $this->getSide(0);
if($down->getID() === GRASS or $down->getID() === DIRT or $down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
@ -36,9 +37,7 @@ class SaplingBlock extends FlowableBlock{
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x03);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;

View file

@ -6,8 +6,10 @@ class SugarcaneBlock extends FlowableBlock{
parent::__construct(SUGARCANE_BLOCK, $meta, "Sugarcane");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public function getDrops(Item $item, Player $player){
return [
[SUGARCANE, 0, 1],
@ -28,10 +30,8 @@ class SugarcaneBlock extends FlowableBlock{
$this->meta = 0;
$this->level->fastSetBlockUpdateMeta($this->x, $this->y, $this->z, $this->meta, true);
}
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;
@ -50,7 +50,7 @@ class SugarcaneBlock extends FlowableBlock{
}
}
if(StaticBlock::getIsTransparent($down) && $down != SUGARCANE_BLOCK){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(SUGARCANE));
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(SUGARCANE));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
}
}
@ -80,7 +80,7 @@ class SugarcaneBlock extends FlowableBlock{
$x = $this->x;
$y = $this->y;
$z = $this->z;
$b0 = $level->level->getBlockID($x, $y - 1, $z - 1);
$b1 = $level->level->getBlockID($x, $y - 1, $z + 1);
$b2 = $level->level->getBlockID($x - 1, $y - 1, $z);

View file

@ -12,6 +12,8 @@ class TallGrassBlock extends FlowableBlock{
];
$this->name = $names[$this->meta & 0x03];
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$replaceable_plant;
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){

View file

@ -6,13 +6,14 @@ class WheatBlock extends FlowableBlock{
parent::__construct(WHEAT_BLOCK, $meta, "Wheat Block");
$this->isActivable = true;
$this->hardness = 0;
$this->breakTime = 0;
$this->material = Material::$plant;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$down = $this->getSide(0);
if($down->getID() === FARMLAND){
$this->level->setBlock($block, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return true;
}
return false;
@ -25,9 +26,7 @@ class WheatBlock extends FlowableBlock{
$this->meta = 7;
}
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
return true;
}
return false;

View file

@ -6,6 +6,9 @@ class BedrockBlock extends SolidBlock{
parent::__construct(BEDROCK, 0, "Bedrock");
$this->breakable = false;
$this->hardness = 18000000;
$this->breakTime = -1;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function isBreakable(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class BookshelfBlock extends SolidBlock{
public function __construct(){
parent::__construct(BOOKSHELF, 0, "Bookshelf");
$this->hardness = 7.5;
$this->breakTime = 1.5;
$this->material = Material::$wood;
$this->lightBlock = 255;
}
}

View file

@ -5,6 +5,9 @@ class BricksBlock extends SolidBlock{
public function __construct(){
parent::__construct(BRICKS_BLOCK, 0, "Bricks");
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -6,6 +6,10 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
parent::__construct(BURNING_FURNACE, $meta, "Burning Furnace");
$this->isActivable = true;
$this->hardness = 17.5;
$this->breakTime = 3.5;
$this->material = Material::$stone;
$this->lightBlock = 255;
$this->lightEmission = 13;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -5,6 +5,9 @@ class ClayBlock extends SolidBlock{
public function __construct(){
parent::__construct(CLAY_BLOCK, 0, "Clay Block");
$this->hardness = 3;
$this->breakTime = 0.6;
$this->material = Material::$clay;
$this->lightBlock = 255;
}
public function getDrops(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class CoalBlock extends SolidBlock{
public function __construct(){
parent::__construct(COAL_BLOCK, 0, "Coal Block");
$this->hardness = 30;
$this->breakTime = 5;
$this->material = Material::$metal;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class CobblestoneBlock extends SolidBlock{
public function __construct(){
parent::__construct(COBBLESTONE, 0, "Cobblestone");
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class DiamondBlock extends SolidBlock{
public function __construct(){
parent::__construct(DIAMOND_BLOCK, 0, "Diamond Block");
$this->hardness = 30;
$this->breakTime = 5;
$this->material = Material::$metal;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -6,16 +6,15 @@ class DirtBlock extends SolidBlock{
parent::__construct(DIRT, 0, "Dirt");
$this->isActivable = true;
$this->hardness = 2.5;
$this->breakTime = 0.5;
$this->material = Material::$dirt;
$this->lightBlock = 255;
}
public function onActivate(Item $item, Player $player){
if($item->isHoe()){
if($this->getSide(1)->isTransparent === false) return false;
if(($player->gamemode & 0x01) === 0){
$item->useOn($this);
if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false);
else $player->setSlot($player->slot, $item, true);
}
$item->hurtAndBreak(1, $player); //TODO move to ItemHoe
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true);
return true;
}

View file

@ -16,6 +16,9 @@ class DoubleSlabBlock extends SolidBlock{
];
$this->name = "Double " . $names[$this->meta & 0x07] . " Slab";
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -11,14 +11,19 @@ class DoubleWoodSlabBlock extends SolidBlock{
3 => "Jungle",
];
$this->name = "Double " . $names[$this->meta & 0x07] . " Wooden Slab";
$this->hardness = 15;
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$wood;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
return match ($item->isAxe()) {
if(!$item->isAxe()) return 3;
return match ($item->getLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,

View file

@ -11,5 +11,8 @@ class FurnaceBlock extends BurningFurnaceBlock{
$this->id = FURNACE;
$this->name = "Furnace";
$this->isActivable = true;
$this->material = Material::$stone;
$this->lightBlock = 255;
$this->lightEmission = 0;
}
}

View file

@ -5,6 +5,8 @@ class GlassBlock extends TransparentBlock{
public function __construct(){
parent::__construct(GLASS, 0, "Glass");
$this->hardness = 1.5;
$this->breakTime = 0.3;
$this->material = Material::$glass;
}
public function getDrops(Item $item, Player $player){

View file

@ -4,6 +4,11 @@ class GlowingObsidianBlock extends SolidBlock implements LightingBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(GLOWING_OBSIDIAN, $meta, "Glowing Obsidian");
$this->hardness = 6000;
$this->breakTime = 10;
$this->material = Material::$stone;
$this->lightBlock = 255;
$this->lightEmission = 13;
}
public function getMaxLightValue(){

View file

@ -5,6 +5,10 @@ class GlowstoneBlock extends TransparentBlock implements LightingBlock{
public function __construct(){
parent::__construct(GLOWSTONE_BLOCK, 0, "Glowstone");
$this->hardness = 1.5;
$this->breakTime = 0.3;
$this->material = Material::$glass;
$this->lightBlock = 255;
$this->lightEmission = 15;
}
public function getMaxLightValue(){

View file

@ -5,6 +5,9 @@ class GoldBlock extends SolidBlock{
public function __construct(){
parent::__construct(GOLD_BLOCK, 0, "Gold Block");
$this->hardness = 30;
$this->breakTime = 3;
$this->material = Material::$metal;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -6,58 +6,55 @@ class GrassBlock extends SolidBlock{
parent::__construct(GRASS, 0, "Grass");
$this->isActivable = true;
$this->hardness = 3;
$this->breakTime = 0.6;
$this->material = Material::$dirt;
$this->lightBlock = 255;
}
public function getDrops(Item $item, Player $player){
return [
[DIRT, 0, 1],
];
return array(
array(DIRT, 0, 1),
);
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE,0x0F,1);
}
$player->consumeSingleItem(send:true);
TallGrassObject::growGrass($this->level, $this, new Random(), 8, 2);
return true;
}elseif($item->isHoe()){
if($this->getSide(1)->isTransparent === false) return false;
if(($player->gamemode & 0x01) === 0){
$item->useOn($this);
if($item->getMetadata() >= $item->getMaxDurability()) $player->setSlot($player->slot, new Item(AIR, 0, 0), false);
else $player->setSlot($player->slot, $item, true);
}
$item->hurtAndBreak(1, $player); //TODO move to ItemHoe
$this->level->fastSetBlockUpdate($this->x, $this->y, $this->z, FARMLAND, 0, true);
$this->seedsDrop();
return true;
}
return false;
}
public function seedsDrop(){
$chance = lcg_value() * 100;
if($chance <= 1){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y + 1, $this->z + 0.5, $this->level), BlockAPI::getItem(BEETROOT_SEEDS,0,1), 10);
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(BEETROOT_SEEDS,0,1), 10);
}elseif($chance > 1 and $chance <= 16){
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y + 1, $this->z + 0.5, $this->level), BlockAPI::getItem(SEEDS,0,1), 10);
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(SEEDS,0,1), 10);
}
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z)) && mt_rand(0, 2) == 1){
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0);
}else{
for($cnt = 0; $cnt < 4; ++$cnt){
$x = $x + mt_rand(0, 2) - 1;
$y = $y + mt_rand(0, 4) - 3;
$z = $z + mt_rand(0, 2) - 1;
$blockUp = $level->level->getBlockID($x, $y + 1, $z);
if(StaticBlock::getIsTransparent($blockUp) && !StaticBlock::getIsLiquid($blockUp) && !($blockUp === 60) && $level->level->getBlockID($x, $y, $z) === DIRT){
$level->fastSetBlockUpdate($x, $y, $z, GRASS, 0);
}
//for($cnt = 0; $cnt < 4; ++$cnt){
$x = $x + mt_rand(0, 2) - 1;
$y = $y + mt_rand(0, 4) - 3;
$z = $z + mt_rand(0, 2) - 1;
$blockUp = $level->level->getBlockID($x, $y + 1, $z);
if(StaticBlock::getIsTransparent($blockUp) && !StaticBlock::getIsLiquid($blockUp) && !($blockUp == FARMLAND) && $level->level->getBlockID($x, $y, $z) === DIRT){
$level->fastSetBlockUpdate($x, $y, $z, GRASS, 0);
}
//}
}
}

View file

@ -5,6 +5,9 @@ class GravelBlock extends FallableBlock{
public function __construct(){
parent::__construct(GRAVEL, 0, "Gravel");
$this->hardness = 3;
$this->breakTime = 0.6;
$this->material = Material::$sand;
$this->lightBlock = 255;
}
public function getDrops(Item $item, Player $player){

View file

@ -4,7 +4,10 @@ class HayBaleBlock extends SolidBlock{
public static $blockID;
public function __construct($meta = 0){
parent::__construct(HAY_BALE, $meta, "Hay Bale");
$this->hardness = 10;
$this->hardness = 2.5;
$this->breakTime = 0.5;
$this->material = Material::$dirt;
$this->lightBlock = 255;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){

View file

@ -5,19 +5,21 @@ class IceBlock extends TransparentBlock{
public function __construct(){
parent::__construct(ICE, 0, "Ice");
$this->hardness = 2.5;
$this->breakTime = 0.5;
$this->slipperiness = 0.98;
$this->material = Material::$ice;
$this->lightBlock = 3;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)];
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$ret = $this->level->setBlock($this, $this, true, false, true);
$this->level->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
return $ret;
}
public function onBreak(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0){
$this->level->setBlock($this, new WaterBlock(), true, false, true);
@ -28,32 +30,12 @@ class IceBlock extends TransparentBlock{
return true;
}
private function scanForNearbyLightSources($offsetX, $offsetY, $offsetZ){
for($x = -$offsetX; $x <= $offsetX; ++$x){ //i hope it is possible to optimize it
for($z = -$offsetZ; $z <= $offsetZ; ++$z){
for($y = -$offsetY; $y <= $offsetY; ++$y){
$pX = $this->x + $x;
$pY = $this->y + $y;
$pZ = $this->z + $z;
$block = $this->level->getBlock(new Vector3($pX, $pY, $pZ)); //D= slow what was u thinking of gameherobrine from 2022
if($block instanceof LightingBlock){ //idk is it possible to make it better
return $block;
}
}
}
public static function onRandomTick(Level $level, $x, $y, $z){
if($level->level->getBlockLight($x, $y, $z) > 11 - StaticBlock::$lightBlock[ICE]){
$level->fastSetBlockUpdate($x, $y, $z, STILL_WATER, true);
}
}
//public static function onUpdate(Level $level, $x, $y, $z, $type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/
/*if($type === BLOCK_UPDATE_RANDOM){
$light = $this->scanForNearbyLightSources(3,3,3);
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
$this->level->setBlock($this, new WaterBlock(), true);
ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($this, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); //additional request for update
}
return BLOCK_UPDATE_RANDOM;
}
return false;*/ //TODO ice melting(after light?)
//}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
@ -69,6 +51,6 @@ class IceBlock extends TransparentBlock{
}
public function getDrops(Item $item, Player $player){
return [];
return array();
}
}

View file

@ -5,7 +5,10 @@ class InfoUpdate2Block extends SolidBlock{
public function __construct(){
parent::__construct(INFO_UPDATE2, 0, "tile.info_update2.name<");
$this->breakable = true;
$this->hardness = 0;
$this->hardness = 5;
$this->breakTime = 1;
$this->material = Material::$dirt;
$this->lightBlock = 255;
}
}

View file

@ -5,7 +5,10 @@ class InfoUpdateBlock extends SolidBlock{
public function __construct(){
parent::__construct(INFO_UPDATE, 0, "tile.info_update.name<");
$this->breakable = true;
$this->hardness = 0;
$this->hardness = 5;
$this->breakTime = 1;
$this->material = Material::$dirt;
$this->lightBlock = 255;
}
}

View file

@ -5,7 +5,10 @@ class InvisibleBedrockBlock extends SolidBlock{
public function __construct(){
parent::__construct(INVISIBLE_BEDROCK, 0, ".name<");
$this->breakable = false;
$this->hardness = 3600000;
$this->hardness = 18000000;
$this->breakTime = -1;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function isBreakable(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class IronBlock extends SolidBlock{
public function __construct(){
parent::__construct(IRON_BLOCK, 0, "Iron Block");
$this->hardness = 30;
$this->breakTime = 5;
$this->material = Material::$metal;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class LapisBlock extends SolidBlock{
public function __construct(){
parent::__construct(LAPIS_BLOCK, 0, "Lapis Block");
$this->hardness = 15;
$this->breakTime = 3.0;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -7,87 +7,134 @@ class LeavesBlock extends TransparentBlock{
const BIRCH = 2;
public function __construct($meta = 0){
parent::__construct(LEAVES, $meta, "Leaves");
$names = [
$names = array(
LeavesBlock::OAK => "Oak Leaves",
LeavesBlock::SPRUCE => "Spruce Leaves",
LeavesBlock::BIRCH => "Birch Leaves",
3 => "",
];
);
$this->name = $names[$this->meta & 0x03];
$this->hardness = 1;
$this->breakTime = 0.2;
$this->material = Material::$leaves;
$this->lightBlock = 1;
}
public static function getCollisionBoundingBoxes(Level $level, $x, $y, $z, Entity $entity){
return [new AxisAlignedBB($x, $y, $z, $x + 1, $y + 1, $z + 1)];
}
public static function createIndex($x, $y, $z){
return $x.".".$y.".".$z;
return "$x.$y.$z";
}
public static function findLog(Level $level, $x, $y, $z, array $visited, $distance){ //port from newest pocketmine
/**
* @deprecated leaf decay was rewritten
*/
public static function findLog(Level $level, $x, $y, $z, array &$visited, $distance){ //port from newest pocketmine
$index = self::createIndex($x, $y, $z);
if(isset($visited[$index])){
return false;
return $visited[$index];
}
$visited[$index] = true;
$block = $level->level->getBlockID($x, $y, $z);
if($block === WOOD){ //type doesn't matter
return true;
return ($visited[$index] = true);
}
if($block === LEAVES && $distance <= 4){
if(self::findLog($level, $x - 1, $y, $z, $visited, $distance + 1)) return true;
if(self::findLog($level, $x + 1, $y, $z, $visited, $distance + 1)) return true;
if(self::findLog($level, $x, $y, $z - 1, $visited, $distance + 1)) return true;
if(self::findLog($level, $x, $y, $z + 1, $visited, $distance + 1)) return true;
if(self::findLog($level, $x - 1, $y, $z, $visited, $distance + 1)) return ($visited[$index] = true);
if(self::findLog($level, $x + 1, $y, $z, $visited, $distance + 1)) return ($visited[$index] = true);
if(self::findLog($level, $x, $y, $z - 1, $visited, $distance + 1)) return ($visited[$index] = true);
if(self::findLog($level, $x, $y, $z + 1, $visited, $distance + 1)) return ($visited[$index] = true);
}
return false;
return ($visited[$index] = false);
}
private static $treeBlocksNearby = null;
public static function onRandomTick(Level $level, $x, $y, $z){
$b = $level->level->getBlock($x, $y, $z);
$id = $b[0];
$meta = $b[1];
if(($meta & 0b00001100) === 0x08){
$meta &= 0x03;
$visited = [];
if(!self::findLog($level, $x, $y, $z, $visited, 0)){
//$this->level->setBlock($this, new AirBlock(), false, false, true);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
//TODO MCPE uses 0x04 for detecting updates
if(($meta & 0b1100) == 0b1000){
if(self::$treeBlocksNearby == null) self::$treeBlocksNearby = array_fill(0, 32*32*32, 0);
for ($xx = - 4; $xx <= 4; $xx ++) {
for ($yy = - 4; $yy <= 4; $yy ++) {
for ($zz = - 4; $zz <= 4; $zz ++) {
$k3 = $level->level->getBlockID($x + $xx, $y + $yy, $z + $zz);
if ($k3 == TRUNK) {
self::$treeBlocksNearby[($xx + 16) * 1024 + ($yy + 16) * 32 + ($zz + 16)] = 0;
} else if ($k3 == LEAVES) {
self::$treeBlocksNearby[($xx + 16) * 1024 + ($yy + 16) * 32 + ($zz + 16)] = - 2;
} else {
self::$treeBlocksNearby[($xx + 16) * 1024 + ($yy + 16) * 32 + ($zz + 16)] = - 1;
}
}
}
}
for ($i2 = 1; $i2 <= 4; $i2 ++) {
for ($l2 = - 4; $l2 <= 4; $l2 ++) {
for ($j3 = - 4; $j3 <= 4; $j3 ++) {
for ($l3 = - 4; $l3 <= 4; $l3 ++) {
if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] != $i2 - 1) continue;
if (self::$treeBlocksNearby[(($l2 + 16) - 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] == - 2) {
self::$treeBlocksNearby[(($l2 + 16) - 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] = $i2;
}
if (self::$treeBlocksNearby[($l2 + 16 + 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] == - 2) {
self::$treeBlocksNearby[($l2 + 16 + 1) * 1024 + ($j3 + 16) * 32 + ($l3 + 16)] = $i2;
}
if (self::$treeBlocksNearby[($l2 + 16) * 1024 + (($j3 + 16) - 1) * 32 + ($l3 + 16)] == - 2) {
self::$treeBlocksNearby[($l2 + 16) * 1024 + (($j3 + 16) - 1) * 32 + ($l3 + 16)] = $i2;
}
if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16 + 1) * 32 + ($l3 + 16)] == - 2) {
self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16 + 1) * 32 + ($l3 + 16)] = $i2;
}
if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + (($l3 + 16) - 1)] == - 2) {
self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + (($l3 + 16) - 1)] = $i2;
}
if (self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + ($l3 + 16 + 1)] == - 2) {
self::$treeBlocksNearby[($l2 + 16) * 1024 + ($j3 + 16) * 32 + ($l3 + 16 + 1)] = $i2;
}
}
}
}
}
$j2 = self::$treeBlocksNearby[(32/2) * (32*32) + (32/2) * 32 + (32/2)];
if($j2 >= 0)
{
$level->level->setBlockDamage($x, $y, $z, $meta & 0xf7);
} else
{
if(mt_rand(1,20) === 1){ //Saplings
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SAPLING, $meta & 0x03, 1));
}
if(($meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(APPLE, 0, 1));
}
}else{
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, false);
}
}
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
if(($meta & 0b00001100) === 0){
$meta |= 0x08;
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta); //TODO maybe use $level->level->setBlock directly, the client doesnt need to know thism info.
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta |= 0x04;
//TODO MCPE uses 0x08 for detecting was it placed by player or not
if($player instanceof Player && $player != PlayerNull::$INSTANCE) $this->meta |= 0x04;
$this->level->setBlock($this, $this, true, false, true);
}
public function getDrops(Item $item, Player $player){
$drops = [];
$drops = array();
if($item->isShears()){
$drops[] = [LEAVES, $this->meta & 0x03, 1];
$drops[] = array(LEAVES, $this->meta & 0x03, 1);
}else{
if(mt_rand(1,20) === 1){ //Saplings
$drops[] = [SAPLING, $this->meta & 0x03, 1];
$drops[] = array(SAPLING, $this->meta & 0x03, 1);
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,100) === 1){ //Apples
$drops[] = [APPLE, 0, 1];
$drops[] = array(APPLE, 0, 1);
}
}
return $drops;

View file

@ -12,6 +12,10 @@ class LitPumpkinBlock extends SolidBlock implements LightingBlock{
public function __construct($meta = 0){
parent::__construct(LIT_PUMPKIN, $meta, "Jack o'Lantern");
$this->hardness = 5;
$this->breakTime = 1.0;
$this->material = Material::$vegetable;
$this->lightBlock = 255;
$this->lightEmission = 15;
}
public function getMaxLightValue(){

View file

@ -5,6 +5,9 @@ class MelonBlock extends TransparentBlock{
public function __construct(){
parent::__construct(MELON_BLOCK, 0, "Melon Block");
$this->hardness = 5;
$this->breakTime = 1;
$this->material = Material::$vegetable;
$this->lightBlock = 255;
}
public function getDrops(Item $item, Player $player){
return [

View file

@ -5,6 +5,9 @@ class MossStoneBlock extends SolidBlock{
public function __construct(){
parent::__construct(MOSS_STONE, 0, "Moss Stone");
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class NetherBricksBlock extends SolidBlock{
public function __construct(){
parent::__construct(NETHER_BRICKS, 0, "Nether Bricks");
$this->hardness = 30;
$this->breakTime = 2;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,6 +5,9 @@ class NetherrackBlock extends SolidBlock{
public function __construct(){
parent::__construct(NETHERRACK, 0, "Netherrack");
$this->hardness = 2;
$this->breakTime = 0.4;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){

View file

@ -5,8 +5,11 @@ class ObsidianBlock extends SolidBlock{
public function __construct(){
parent::__construct(OBSIDIAN, 0, "Obsidian");
$this->hardness = 6000;
$this->breakTime = 10;
$this->material = Material::$stone;
$this->lightBlock = 255;
}
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
@ -17,7 +20,7 @@ class ObsidianBlock extends SolidBlock{
return 250;
}
}
public function getDrops(Item $item, Player $player){
if($item->getPickaxeLevel() >= 5){
return [

View file

@ -12,6 +12,9 @@ class PlanksBlock extends SolidBlock{
];
$this->name = $names[$this->meta & 0x03];
$this->hardness = 15;
$this->breakTime = 2;
$this->material = Material::$wood;
$this->lightBlock = 255;
}
}

Some files were not shown because too many files have changed in this diff Show more