onUpdate is now static, disabled rail, water and lava updates to rework.

This commit is contained in:
GameHerobrine 2024-05-20 13:16:48 +03:00
parent 3c37dc446e
commit ee989ef556
38 changed files with 329 additions and 367 deletions

View file

@ -1,13 +1,6 @@
<?php
class LadderBlock extends TransparentBlock{
public static $faces = [
3 => 2,
2 => 3,
5 => 4,
4 => 5,
];
public static function getAABB(Level $level, $x, $y, $z){
[$id, $meta] = $level->level->getBlock($x, $y, $z);
@ -47,15 +40,21 @@ class LadderBlock extends TransparentBlock{
return false;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
$side = $level->level->getBlockDamage($x, $y, $z);
if($type === BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata();
if($this->getSide(self::$faces[$side]) instanceof AirBlock){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
return BLOCK_UPDATE_NORMAL;
}
$attached = match($side){
3 => $level->level->getBlockID($x, $y, $z - 1),
2 => $level->level->getBlockID($x, $y, $z + 1),
5 => $level->level->getBlockID($x - 1, $y, $z),
4 => $level->level->getBlockID($x + 1, $y, $z),
default => 0 //TODO
};
if($attached == AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(LADDER, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true);
return BLOCK_UPDATE_NORMAL;
}
return false;
}

View file

@ -33,13 +33,12 @@ class SignPostBlock extends TransparentBlock{
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if($this->getSide(0)->getID() === AIR){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SIGN, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, true, true);
return BLOCK_UPDATE_NORMAL;
}
public static function onUpdate(Level $level, $x, $y, $z, $type){ //TODO remove $type
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));
//$this->level->setBlock($this, new AirBlock(), true, true, true);
$level->fastSetBlockUpdate($x, $y, $z, 0, 0, true, true);
return BLOCK_UPDATE_NORMAL;
}
return false;
}

View file

@ -14,22 +14,20 @@ class TorchBlock extends FlowableBlock implements LightingBlock{
return null;
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata();
$faces = array(
1 => 4,
2 => 5,
3 => 2,
4 => 3,
5 => 0,
6 => 0,
0 => 0,
);
if($this->getSide($faces[$side])->isTransparent === true and !($side === 0 and $this->getSide(0)->getID() === FENCE)){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
$side = $level->level->getBlockDamage($x, $y, $z);
$attach = match($side){
1 => $level->level->getBlockID($x - 1, $y, $z),
2 => $level->level->getBlockID($x + 1, $y, $z),
3 => $level->level->getBlockID($x, $y, $z - 1),
4 => $level->level->getBlockID($x, $y, $z + 1),
default => $level->level->getBlockID($x, $y - 1, $z)
};
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));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
return BLOCK_UPDATE_NORMAL;
}
}

View file

@ -74,22 +74,20 @@ class TrapdoorBlock extends TransparentBlock{
array($this->id, 0, 1),
);
}
public function onUpdate($type){
public static function onUpdate(Level $level, $x, $y, $z, $type){
if($type === BLOCK_UPDATE_NORMAL){
$faces = array( //meta => side
0 => 3,
4 => 3, //activated
1 => 2,
5 => 2, //activated
2 => 5,
6 => 5, //activated
3 => 4,
7 => 4, //activated
);
$side = $faces[$this->meta];
if($this->getSide($side) instanceof AirBlock){ //Replace with common break method
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id, 0, 1));
$this->level->setBlock($this, new AirBlock(), true, false, true);
$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
};
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;
}
}

View file

@ -5,25 +5,24 @@ require_once("SignPostBlock.php");
/***REM_END***/
class WallSignBlock extends SignPostBlock{
public static $meta2side = [
2 => 3,
3 => 2,
4 => 5,
5 => 4
];
public function __construct($meta = 0){
TransparentBlock::__construct(WALL_SIGN, $meta, "Wall Sign");
$this->isSolid = false;
}
public function onUpdate($type){
$attached = $this->getSide(self::$meta2side[$this->meta] ?? -1);
if(!($attached instanceof Block) || (!$attached->isSolid && $attached->getID() != SIGN_POST && $attached->getID() != WALL_SIGN)){
$this->level->setBlock($this, new AirBlock(), true, true, true);
(ServerAPI::request())->api->entity->drop(new Position($this->x + 0.5, $this->y + 0.5, $this->z + 0.5, $this->level), BlockAPI::getItem(SIGN, 0, 1));
public static function onUpdate(Level $level, $x, $y, $z, $type){
$attached = match($level->level->getBlockDamage($x, $y, $z)){
2 => $level->level->getBlockID($x, $y, $z + 1),
3 => $level->level->getBlockID($x, $y, $z - 1),
4 => $level->level->getBlockID($x + 1, $y, $z),
5 => $level->level->getBlockID($x - 1, $y, $z),
default => WALL_SIGN
};
if(!StaticBlock::getIsSolid($attached) && $attached != SIGN_POST && $attached != WALL_SIGN){
$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));
}
return false;