mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 20:19:44 +00:00
separated neighbor updates and scheduled updates
This commit is contained in:
parent
ee989ef556
commit
2ebc482e3d
36 changed files with 197 additions and 262 deletions
|
|
@ -457,7 +457,8 @@ class BlockAPI{
|
||||||
return $this->cancelAction($block, $player);
|
return $this->cancelAction($block, $player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->blockUpdate($target, BLOCK_UPDATE_TOUCH);
|
|
||||||
|
StaticBlock::getBlock($target->getID())::interact($target->level, $target->x, $target->y, $target->z, $player);
|
||||||
|
|
||||||
if($target->isActivable === true){
|
if($target->isActivable === true){
|
||||||
if($this->server->api->dhandle("player.block.activate", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== false and $target->onActivate($item, $player) === true){
|
if($this->server->api->dhandle("player.block.activate", ["player" => $player, "block" => $block, "target" => $target, "item" => $item]) !== false and $target->onActivate($item, $player) === true){
|
||||||
|
|
@ -532,13 +533,21 @@ class BlockAPI{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$level = $block::onUpdate($pos->level, $pos->x, $pos->y, $pos->z, $type);
|
$level = $block::onUpdate($pos->level, $pos->x, $pos->y, $pos->z, $type);
|
||||||
if($level === BLOCK_UPDATE_NORMAL){
|
|
||||||
$this->blockUpdateAround($block, $level);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $level;
|
return $level;
|
||||||
}
|
}
|
||||||
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){
|
public function blockUpdateAround(Position $pos, $type = BLOCK_UPDATE_NORMAL, $delay = false){
|
||||||
|
|
||||||
|
if($type == BLOCK_UPDATE_NORMAL){
|
||||||
|
try{
|
||||||
|
throw new Exception("Deprecated: tried updating $pos using BLOCK_UPDATE_NORMAL.");
|
||||||
|
}catch(Exception $e){
|
||||||
|
ConsoleAPI::error($e->getMessage());
|
||||||
|
ConsoleAPI::error($e->getTraceAsString());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if($delay !== false){
|
if($delay !== false){
|
||||||
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
|
$this->scheduleBlockUpdate($pos->getSide(0), $delay, $type);
|
||||||
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
|
$this->scheduleBlockUpdate($pos->getSide(1), $delay, $type);
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,9 @@ abstract class Block extends Position{
|
||||||
public $y = 0;
|
public $y = 0;
|
||||||
public $z = 0;
|
public $z = 0;
|
||||||
public $slipperiness;
|
public $slipperiness;
|
||||||
|
public static function interact(Level $level, $x, $y, $z, Player $player){}
|
||||||
|
|
||||||
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){}
|
||||||
|
|
||||||
public static function getAABB(Level $level, $x, $y, $z){
|
public static function getAABB(Level $level, $x, $y, $z){
|
||||||
return StaticBlock::getAABB($level, $x, $y, $z);
|
return StaticBlock::getAABB($level, $x, $y, $z);
|
||||||
|
|
|
||||||
|
|
@ -106,23 +106,19 @@ class DoorBlock extends TransparentBlock{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
||||||
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
$id = $level->level->getBlockID($x, $y, $z);
|
||||||
$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));
|
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));
|
elseif($id == 71) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(330, 0, 1));
|
||||||
|
|
||||||
$top = $level->level->getBlockID($x, $y + 1, $z);
|
$top = $level->level->getBlockID($x, $y + 1, $z);
|
||||||
if($top == IRON_DOOR_BLOCK || $top == DOOR_BLOCK){
|
if($top == IRON_DOOR_BLOCK || $top == DOOR_BLOCK){
|
||||||
$level->fastSetBlockUpdate($x, $y + 1, $z, 0, 0);
|
$level->fastSetBlockUpdate($x, $y + 1, $z, 0, 0);
|
||||||
}
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ class FallableBlock extends SolidBlock{
|
||||||
*/
|
*/
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
$ret = $this->level->setBlock($this, $this, true, false, true);
|
$ret = $this->level->setBlock($this, $this, true, false, true);
|
||||||
ServerAPI::request()->api->block->blockUpdate(clone $this, BLOCK_UPDATE_NORMAL);
|
$clz = StaticBlock::getBlock($this->getID());
|
||||||
|
$clz::neighborChanged($this->level, $this->x, $this->y, $this->z, 0, 0, 0, 0); //TODO move to another method
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,14 +52,14 @@ class GenericBlock extends Block{
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||||
if(StaticBlock::getHasPhysics($id) and $type === BLOCK_UPDATE_NORMAL){ //TODO move from here to different class
|
if(StaticBlock::getHasPhysics($id)){ //TODO move from here to different class
|
||||||
$down = $level->level->getBlockID($x, $y - 1, $z);
|
$down = $level->level->getBlockID($x, $y - 1, $z);
|
||||||
if($down == AIR || StaticBlock::getIsLiquid($down)){
|
if($down == AIR || StaticBlock::getIsLiquid($down)){
|
||||||
$data = array(
|
$data = array(
|
||||||
"x" => $x + 0.5,
|
"x" => $x + 0.5,
|
||||||
"y" => $y,
|
"y" => $y - 0.5,
|
||||||
"z" => $z + 0.5,
|
"z" => $z + 0.5,
|
||||||
"Tile" => $id,
|
"Tile" => $id,
|
||||||
);
|
);
|
||||||
|
|
@ -68,9 +68,7 @@ class GenericBlock extends Block{
|
||||||
$e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data);
|
$e = $server->api->entity->add($level, ENTITY_FALLING, FALLING_SAND, $data);
|
||||||
$server->api->entity->spawnToAll($e);
|
$server->api->entity->spawnToAll($e);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class LadderBlock extends TransparentBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
$side = $level->level->getBlockDamage($x, $y, $z);
|
$side = $level->level->getBlockDamage($x, $y, $z);
|
||||||
|
|
||||||
$attached = match($side){
|
$attached = match($side){
|
||||||
|
|
@ -54,9 +54,7 @@ class LadderBlock extends TransparentBlock{
|
||||||
if($attached == AIR){ //Replace with common break method
|
if($attached == AIR){ //Replace with common break method
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(LADDER, 0, 1));
|
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(LADDER, 0, 1));
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,12 @@ class SignPostBlock extends TransparentBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){ //TODO remove $type
|
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){ //Replace with common break method
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SIGN, 0, 1));
|
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SIGN, 0, 1));
|
||||||
//$this->level->setBlock($this, new AirBlock(), true, true, true);
|
//$this->level->setBlock($this, new AirBlock(), true, true, true);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onBreak(Item $item, Player $player){
|
public function onBreak(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -14,24 +14,20 @@ class TorchBlock extends FlowableBlock implements LightingBlock{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
$side = $level->level->getBlockDamage($x, $y, $z);
|
||||||
$side = $level->level->getBlockDamage($x, $y, $z);
|
$attach = match($side){
|
||||||
$attach = match($side){
|
1 => $level->level->getBlockID($x - 1, $y, $z),
|
||||||
1 => $level->level->getBlockID($x - 1, $y, $z),
|
2 => $level->level->getBlockID($x + 1, $y, $z),
|
||||||
2 => $level->level->getBlockID($x + 1, $y, $z),
|
3 => $level->level->getBlockID($x, $y, $z - 1),
|
||||||
3 => $level->level->getBlockID($x, $y, $z - 1),
|
4 => $level->level->getBlockID($x, $y, $z + 1),
|
||||||
4 => $level->level->getBlockID($x, $y, $z + 1),
|
default => $level->level->getBlockID($x, $y - 1, $z)
|
||||||
default => $level->level->getBlockID($x, $y - 1, $z)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
if(StaticBlock::getIsTransparent($attach) && !($side === 0 && $attach === FENCE)){ //Replace with common break method
|
if(StaticBlock::getIsTransparent($attach) && !($side === 0 && $attach === FENCE)){ //Replace with common break method
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1));
|
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1));
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
|
|
||||||
|
|
@ -74,24 +74,21 @@ class TrapdoorBlock extends TransparentBlock{
|
||||||
array($this->id, 0, 1),
|
array($this->id, 0, 1),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
$attach = match($level->level->getBlockDamage($x, $y, $z)){
|
||||||
|
0, 4 => $level->level->getBlockID($x, $y, $z + 1),
|
||||||
|
1, 5 => $level->level->getBlockID($x, $y, $z - 1),
|
||||||
|
2, 6 => $level->level->getBlockID($x + 1, $y, $z),
|
||||||
|
3, 7 => $level->level->getBlockID($x - 1, $y, $z),
|
||||||
|
default => 0
|
||||||
|
};
|
||||||
|
|
||||||
$attach = match($level->level->getBlockDamage($x, $y, $z)){
|
if($attach == AIR){ //Replace with common break method
|
||||||
0, 4 => $level->level->getBlockID($x, $y, $z + 1),
|
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TRAPDOOR, 0, 1));
|
||||||
1, 5 => $level->level->getBlockID($x, $y, $z - 1),
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
2, 6 => $level->level->getBlockID($x + 1, $y, $z),
|
|
||||||
3, 7 => $level->level->getBlockID($x - 1, $y, $z),
|
|
||||||
default => 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if($attach == AIR){ //Replace with common break method
|
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TRAPDOOR, 0, 1));
|
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
$this->meta ^= 0x04;
|
$this->meta ^= 0x04;
|
||||||
$this->level->setBlock($this, $this, true, false, true);
|
$this->level->setBlock($this, $this, true, false, true);
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@ class WallSignBlock extends SignPostBlock{
|
||||||
$this->isSolid = false;
|
$this->isSolid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
|
|
||||||
$attached = match($level->level->getBlockDamage($x, $y, $z)){
|
$attached = match($level->level->getBlockDamage($x, $y, $z)){
|
||||||
2 => $level->level->getBlockID($x, $y, $z + 1),
|
2 => $level->level->getBlockID($x, $y, $z + 1),
|
||||||
3 => $level->level->getBlockID($x, $y, $z - 1),
|
3 => $level->level->getBlockID($x, $y, $z - 1),
|
||||||
|
|
@ -24,7 +23,5 @@ class WallSignBlock extends SignPostBlock{
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true);
|
$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));
|
(ServerAPI::request())->api->entity->drop(new Position($x + 0.5, $y + 0.5, $z + 0.5, $level), BlockAPI::getItem(SIGN, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -36,27 +36,28 @@ class FireBlock extends FlowableBlock implements LightingBlock{
|
||||||
public function getMaxLightValue(){
|
public function getMaxLightValue(){
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
|
$b = $level->level->getBlockID($x, $y - 1, $z);
|
||||||
|
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
||||||
|
$b = $level->level->getBlockID($x, $y - 1, $z);
|
||||||
|
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
||||||
|
|
||||||
|
$b = $level->level->getBlockID($x - 1, $y, $z);
|
||||||
|
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
||||||
|
$b = $level->level->getBlockID($x + 1, $y, $z);
|
||||||
|
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
||||||
|
|
||||||
|
$b = $level->level->getBlockID($x, $y, $z - 1);
|
||||||
|
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
||||||
|
$b = $level->level->getBlockID($x, $y, $z + 1);
|
||||||
|
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
||||||
|
|
||||||
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($type === BLOCK_UPDATE_SCHEDULED){
|
||||||
|
|
||||||
$b = $level->level->getBlockID($x, $y - 1, $z);
|
|
||||||
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
|
||||||
$b = $level->level->getBlockID($x, $y - 1, $z);
|
|
||||||
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
|
||||||
|
|
||||||
$b = $level->level->getBlockID($x - 1, $y, $z);
|
|
||||||
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
|
||||||
$b = $level->level->getBlockID($x + 1, $y, $z);
|
|
||||||
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
|
||||||
|
|
||||||
$b = $level->level->getBlockID($x, $y, $z - 1);
|
|
||||||
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
|
||||||
$b = $level->level->getBlockID($x, $y, $z + 1);
|
|
||||||
if($b != AIR && StaticBlock::getIsLiquid($b)) return false;
|
|
||||||
|
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}else if($type === BLOCK_UPDATE_SCHEDULED){ //TODO get rid of it
|
|
||||||
$idBelow = $level->level->getBlockID($x, $y - 1, $z);
|
$idBelow = $level->level->getBlockID($x, $y - 1, $z);
|
||||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||||
$alwaysBurn = $idBelow == NETHERRACK;
|
$alwaysBurn = $idBelow == NETHERRACK;
|
||||||
|
|
@ -83,7 +84,6 @@ class FireBlock extends FlowableBlock implements LightingBlock{
|
||||||
|
|
||||||
$level->scheduleBlockUpdate(new Position($x, $y, $z, $level), 30, BLOCK_UPDATE_SCHEDULED); //TODO looks like it also adds mt_rand(0, 9) to it
|
$level->scheduleBlockUpdate(new Position($x, $y, $z, $level), 30, BLOCK_UPDATE_SCHEDULED); //TODO looks like it also adds mt_rand(0, 9) to it
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz);
|
parent::place($item, $player, $block, $target, $face, $fx, $fy, $fz);
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,10 @@ class CakeBlock extends TransparentBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
||||||
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -35,15 +35,11 @@ class CarpetBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
||||||
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem($id, $meta));
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem($id, $meta));
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -58,14 +58,10 @@ class FarmlandBlock extends TransparentBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){
|
||||||
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z))){
|
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, DIRT, 0, true);
|
|
||||||
return $type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBlockID($x, $y, $z){
|
public function getBlockID($x, $y, $z){
|
||||||
|
|
|
||||||
|
|
@ -26,33 +26,23 @@ abstract class RailBaseBlock extends FlowableBlock //TODO move some methods here
|
||||||
|
|
||||||
public function updateState(){}
|
public function updateState(){}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
if($id === POWERED_RAIL){
|
||||||
if($id === POWERED_RAIL){
|
$meta &= 7;
|
||||||
$meta &= 7;
|
}
|
||||||
}
|
if(
|
||||||
if(
|
($level->level->getBlockID($x, $y - 1, $z) === 0) ||
|
||||||
($level->level->getBlockID($x, $y - 1, $z) === 0) ||
|
(($meta == 2) && $level->level->getBlockID($x + 1, $y, $z) === 0) ||
|
||||||
(($meta == 2) && $level->level->getBlockID($x + 1, $y, $z) === 0) ||
|
(($meta == 3) && $level->level->getBlockID($x - 1, $y, $z) === 0) ||
|
||||||
(($meta == 3) && $level->level->getBlockID($x - 1, $y, $z) === 0) ||
|
(($meta == 4) && $level->level->getBlockID($x, $y, $z - 1) === 0) ||
|
||||||
(($meta == 4) && $level->level->getBlockID($x, $y, $z - 1) === 0) ||
|
(($meta == 5) && $level->level->getBlockID($x, $y, $z + 1) === 0)
|
||||||
(($meta == 5) && $level->level->getBlockID($x, $y, $z + 1) === 0)
|
){
|
||||||
){
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem($id, $meta, 1));
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem($id, $meta, 1));
|
}else{
|
||||||
}else{
|
//TODO fix me pls $this->updateState();
|
||||||
//TODO fix me pls $this->updateState();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//if($this->getSide(0)->getID() === AIR){//Replace with common break method
|
|
||||||
// ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, $this->meta, 1));
|
|
||||||
// $this->level->setBlock($this, new AirBlock(), true, false, true);
|
|
||||||
//}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,14 +20,10 @@ class SnowLayerBlock extends FlowableBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
||||||
if($level->level->getBlockID($x, $y - 1, $z) == AIR){ //Replace with common break method
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,11 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
|
||||||
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
|
parent::__construct(GLOWING_REDSTONE_ORE, 0, "Glowing Redstone Ore");
|
||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||||
$level->setBlock(new Position($x, $y, $z, $level), BlockAPI::get(REDSTONE_ORE, $level->level->getBlockDamage($x, $y, $z)), false, false, true);
|
$level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0);
|
||||||
}
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
|
||||||
if($type === BLOCK_UPDATE_SCHEDULED){ //TODO replace with BLOCK_UPDATE_NORMAL
|
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, REDSTONE_ORE, 0);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMaxLightValue(){
|
public function getMaxLightValue(){
|
||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,8 @@ class RedstoneOreBlock extends SolidBlock{
|
||||||
$this->hardness = 15;
|
$this->hardness = 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function interact(Level $level, $x, $y, $z, Player $player){
|
||||||
if($type === BLOCK_UPDATE_NORMAL || $type === BLOCK_UPDATE_TOUCH){ //TODO remove BLOCK_UPDATE_TOUCH
|
$level->fastSetBlockUpdate($x, $y, $z, GLOWING_REDSTONE_ORE, 0);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, GLOWING_REDSTONE_ORE, 0);
|
|
||||||
$level->scheduleBlockUpdate(new Position($x, $y, $z, $level), Utils::getRandomUpdateTicks(), BLOCK_UPDATE_RANDOM);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -39,15 +39,11 @@ class BeetrootBlock extends FlowableBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
|
||||||
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(BEETROOT_SEEDS, 0, 1));
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(BEETROOT_SEEDS, 0, 1));
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,11 @@ class BrownMushroomBlock extends FlowableBlock{
|
||||||
$this->hardness = 0;
|
$this->hardness = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
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
|
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));
|
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);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ class CactusBlock extends TransparentBlock{
|
||||||
for($yy = 1; $yy < 3; ++$yy){
|
for($yy = 1; $yy < 3; ++$yy){
|
||||||
$bID = $level->level->getBlockID($x, $y + $yy, $z);
|
$bID = $level->level->getBlockID($x, $y + $yy, $z);
|
||||||
if($bID === AIR){
|
if($bID === AIR){
|
||||||
$level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0);
|
$level->fastSetBlockUpdate($x, $y + $yy, $z, CACTUS, 0, true);
|
||||||
CactusBlock::onUpdate($level, $x, $y + $yy, $z, BLOCK_UPDATE_NORMAL); //TODO rewrite ticking
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -39,20 +38,16 @@ class CactusBlock extends TransparentBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
$down = $level->level->getBlockID($x, $y, $z);
|
||||||
$down = $level->level->getBlockID($x, $y, $z);
|
$b0 = $level->level->getBlockID($x, $y, $z - 1);
|
||||||
$b0 = $level->level->getBlockID($x, $y, $z - 1);
|
$b1 = $level->level->getBlockID($x, $y, $z + 1);
|
||||||
$b1 = $level->level->getBlockID($x, $y, $z + 1);
|
$b2 = $level->level->getBlockID($x - 1, $y, $z);
|
||||||
$b2 = $level->level->getBlockID($x - 1, $y, $z);
|
$b3 = $level->level->getBlockID($x + 1, $y, $z);
|
||||||
$b3 = $level->level->getBlockID($x + 1, $y, $z);
|
if(!StaticBlock::getIsFlowable($b0) || !StaticBlock::getIsFlowable($b1) || !StaticBlock::getIsFlowable($b2) || !StaticBlock::getIsFlowable($b3) || ($down !== SAND and $down !== CACTUS)){ //Replace with common break method
|
||||||
if(!StaticBlock::getIsFlowable($b0) || !StaticBlock::getIsFlowable($b1) || !StaticBlock::getIsFlowable($b2) || !StaticBlock::getIsFlowable($b3) || ($down !== SAND and $down !== CACTUS)){ //Replace with common break method
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS));
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CACTUS));
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
|
|
||||||
|
|
@ -41,15 +41,11 @@ class CarrotBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
|
||||||
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(CARROT, 0, 1));
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(CARROT, 0, 1));
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,15 @@ class CyanFlowerBlock extends FlowableBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
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
|
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(CYAN_FLOWER));
|
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(CYAN_FLOWER));
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
|
if($item->getID() === DYE and $item->getMetadata() === 0x0F){
|
||||||
if(($player->gamemode & 0x01) === 0){
|
if(($player->gamemode & 0x01) === 0){
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,11 @@ class DandelionBlock extends FlowableBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
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
|
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(DANDELION));
|
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);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,10 @@ class DeadBushBlock extends FlowableBlock{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
|
||||||
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,11 @@ class MelonStemBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
|
||||||
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);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -41,15 +41,11 @@ class PotatoBlock extends FlowableBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
|
||||||
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(POTATO, 0, 1));
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(POTATO, 0, 1));
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -43,15 +43,11 @@ class PumpkinStemBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
|
||||||
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);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onActivate(Item $item, Player $player){
|
public function onActivate(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,11 @@ class RedMushroomBlock extends FlowableBlock{
|
||||||
$this->hardness = 0;
|
$this->hardness = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
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
|
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));
|
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);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,12 @@ class SaplingBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
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
|
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
|
||||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem($id, $meta));
|
ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem($id, $meta));
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||||
if(mt_rand(1,7) === 1){
|
if(mt_rand(1,7) === 1){
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class SugarcaneBlock extends FlowableBlock{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
$down = $level->level->getBlockID($x, $y - 1, $z);
|
$down = $level->level->getBlockID($x, $y - 1, $z);
|
||||||
if($down == GRASS or $down == DIRT or $down == SAND){
|
if($down == GRASS or $down == DIRT or $down == SAND){
|
||||||
$b0 = $level->level->getBlockID($x, $y - 1, $z - 1);
|
$b0 = $level->level->getBlockID($x, $y - 1, $z - 1);
|
||||||
|
|
@ -46,15 +46,12 @@ class SugarcaneBlock extends FlowableBlock{
|
||||||
if($b0 != WATER && $b0 != STILL_WATER && $b1 != WATER && $b1 != STILL_WATER && $b2 != WATER && $b2 != STILL_WATER && $b3 != WATER && $b3 != STILL_WATER){
|
if($b0 != WATER && $b0 != STILL_WATER && $b1 != WATER && $b1 != STILL_WATER && $b2 != WATER && $b2 != STILL_WATER && $b3 != WATER && $b3 != STILL_WATER){
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SUGARCANE));
|
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(SUGARCANE));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(StaticBlock::getIsTransparent($down) && $down != SUGARCANE_BLOCK){ //Replace with common break method
|
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);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public static function onRandomTick(Level $level, $x, $y, $z){
|
public static function onRandomTick(Level $level, $x, $y, $z){
|
||||||
$aboveID = $level->level->getBlockID($x, $y + 1, $z);
|
$aboveID = $level->level->getBlockID($x, $y + 1, $z);
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,11 @@ class TallGrassBlock extends FlowableBlock{
|
||||||
$this->hardness = 0;
|
$this->hardness = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
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
|
if(StaticBlock::getIsTransparent($level->level->getBlockID($x, $y - 1, $z))){ //Replace with common break method
|
||||||
if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(WHEAT_SEEDS));
|
if(Utils::chance(15)) ServerAPI::request()->api->entity->drop(new Position($x+0.5, $y, $z+0.5, $level), BlockAPI::getItem(WHEAT_SEEDS));
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getAABB(Level $level, $x, $y, $z){
|
public static function getAABB(Level $level, $x, $y, $z){
|
||||||
|
|
|
||||||
|
|
@ -41,15 +41,11 @@ class WheatBlock extends FlowableBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
if($type === BLOCK_UPDATE_NORMAL){
|
if($level->level->getBlockID($x, $y - 1, $z) != FARMLAND){
|
||||||
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(WHEAT_SEEDS, 0, 1));
|
||||||
ServerAPI::request()->api->entity->drop(new Position($x + 0.5, $y, $z + 0.5, $level), BlockAPI::getItem(WHEAT_SEEDS, 0, 1));
|
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
|
|
||||||
return BLOCK_UPDATE_NORMAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item, Player $player){
|
public function getDrops(Item $item, Player $player){
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class IceBlock extends TransparentBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){ /*Taken from https://github.com/PocketMine/PocketMine-MP/issues/3249*/
|
//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){
|
/*if($type === BLOCK_UPDATE_RANDOM){
|
||||||
$light = $this->scanForNearbyLightSources(3,3,3);
|
$light = $this->scanForNearbyLightSources(3,3,3);
|
||||||
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
|
if(LightUtils::getLightValueFromNearbySource($light,$this) > 12){
|
||||||
|
|
@ -52,7 +52,7 @@ class IceBlock extends TransparentBlock{
|
||||||
return BLOCK_UPDATE_RANDOM;
|
return BLOCK_UPDATE_RANDOM;
|
||||||
}
|
}
|
||||||
return false;*/ //TODO ice melting(after light?)
|
return false;*/ //TODO ice melting(after light?)
|
||||||
}
|
//}
|
||||||
public function getBreakTime(Item $item, Player $player){
|
public function getBreakTime(Item $item, Player $player){
|
||||||
if(($player->gamemode & 0x01) === 0x01){
|
if(($player->gamemode & 0x01) === 0x01){
|
||||||
return 0.20;
|
return 0.20;
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,12 @@ class LeavesBlock extends TransparentBlock{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static function onUpdate(Level $level, $x, $y, $z, $type){
|
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
|
||||||
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
[$id, $meta] = $level->level->getBlock($x, $y, $z);
|
||||||
if(($meta & 0b00001100) === 0){
|
if(($meta & 0b00001100) === 0){
|
||||||
$meta |= 0x08;
|
$meta |= 0x08;
|
||||||
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta); //TODO maybe use $level->level->setBlock directly, the client doesnt need to know thism info.
|
$level->fastSetBlockUpdate($x, $y, $z, $id, $meta); //TODO maybe use $level->level->setBlock directly, the client doesnt need to know thism info.
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||||
|
|
|
||||||
|
|
@ -459,22 +459,42 @@ class Level{
|
||||||
}
|
}
|
||||||
public function fastSetBlockUpdateMeta($x, $y, $z, $meta, $updateBlock = false){
|
public function fastSetBlockUpdateMeta($x, $y, $z, $meta, $updateBlock = false){
|
||||||
$this->level->setBlockDamage($x, $y, $z, $meta);
|
$this->level->setBlockDamage($x, $y, $z, $meta);
|
||||||
$this->addBlockToSendQueue($x, $y, $z, $this->level->getBlockID($x, $y, $z), $meta);
|
$id = $this->level->getBlockID($x, $y, $z);
|
||||||
|
$this->addBlockToSendQueue($x, $y, $z, $id, $meta);
|
||||||
if($updateBlock){
|
if($updateBlock){
|
||||||
$this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1);
|
$this->updateNeighborsAt($x, $y, $z, $id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function updateNeighborsAt($x, $y, $z, $oldID){
|
||||||
|
$block = $this->level->getBlockID($x - 1, $y, $z);
|
||||||
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x - 1, $y, $z, $x, $y, $z, $oldID);
|
||||||
|
$block = $this->level->getBlockID($x + 1, $y, $z);
|
||||||
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x + 1, $y, $z, $x, $y, $z, $oldID);
|
||||||
|
|
||||||
|
$block = $this->level->getBlockID($x, $y - 1, $z);
|
||||||
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y - 1, $z, $x, $y, $z, $oldID);
|
||||||
|
$block = $this->level->getBlockID($x, $y + 1, $z);
|
||||||
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y + 1, $z, $x, $y, $z, $oldID);
|
||||||
|
|
||||||
|
$block = $this->level->getBlockID($x, $y, $z - 1);
|
||||||
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z - 1, $x, $y, $z, $oldID);
|
||||||
|
$block = $this->level->getBlockID($x, $y, $z + 1);
|
||||||
|
if($block) StaticBlock::getBlock($block)::neighborChanged($this, $x, $y, $z + 1, $x, $y, $z, $oldID);
|
||||||
|
}
|
||||||
|
|
||||||
public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){
|
public function fastSetBlockUpdate($x, $y, $z, $id, $meta, $updateBlocksAround = false, $tiles = false){
|
||||||
|
$oldID = $this->level->getBlockID($x, $y, $z);
|
||||||
|
|
||||||
$this->level->setBlock($x, $y, $z, $id, $meta);
|
$this->level->setBlock($x, $y, $z, $id, $meta);
|
||||||
$this->addBlockToSendQueue($x, $y, $z, $id, $meta);
|
|
||||||
if($updateBlocksAround){
|
|
||||||
$this->server->api->block->blockUpdateAround(new Position($x, $y, $z, $this), BLOCK_UPDATE_NORMAL, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($tiles && ($t = $this->server->api->tile->getXYZ($this, $x, $y, $z)) != false){ //TODO rewrite
|
if($tiles && ($t = $this->server->api->tile->getXYZ($this, $x, $y, $z)) != false){ //TODO rewrite
|
||||||
$t->close();
|
$t->close();
|
||||||
}
|
}
|
||||||
|
if($updateBlocksAround){
|
||||||
|
self::updateNeighborsAt($x, $y, $z, $oldID);
|
||||||
|
}
|
||||||
|
$this->addBlockToSendQueue($x, $y, $z, $id, $meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onTick(PocketMinecraftServer $server, $currentTime){
|
public function onTick(PocketMinecraftServer $server, $currentTime){
|
||||||
|
|
@ -683,6 +703,7 @@ class Level{
|
||||||
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
|
if(!isset($this->level) or (($pos instanceof Position) and $pos->level !== $this) or $pos->x < 0 or $pos->y < 0 or $pos->z < 0){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
$oldID = $this->level->getBlockID($pos->x, $pos->y, $pos->z);
|
||||||
$ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata());
|
$ret = $this->level->setBlock($pos->x, $pos->y, $pos->z, $block->getID(), $block->getMetadata());
|
||||||
if($ret === true){
|
if($ret === true){
|
||||||
if(!($pos instanceof Position)){
|
if(!($pos instanceof Position)){
|
||||||
|
|
@ -701,14 +722,16 @@ class Level{
|
||||||
++$this->changedCount[$i];
|
++$this->changedCount[$i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if($update === true){
|
|
||||||
$this->server->api->block->blockUpdateAround($pos, BLOCK_UPDATE_NORMAL, 1);
|
|
||||||
}
|
|
||||||
if($tiles === true){
|
if($tiles === true){
|
||||||
if(($t = $this->server->api->tile->get($pos)) !== false){
|
if(($t = $this->server->api->tile->get($pos)) !== false){
|
||||||
$t->close();
|
$t->close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($update === true){
|
||||||
|
$this->updateNeighborsAt($pos->x, $pos->y, $pos->z, $oldID);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue