added some vanilla block props, some changes for block placement

This commit is contained in:
GameHerobrine 2026-04-28 15:46:03 +03:00
parent cf4dc73a6c
commit 8f9a9debc5
9 changed files with 178 additions and 63 deletions

View file

@ -36,15 +36,27 @@ class LadderBlock extends TransparentBlock{
$this->breakTime = 0.4;
$this->material = Material::$decoration;
}
public function getPlacementDataValue(Level $level, $x, $y, $z, $side){
$v = 0; //getLevelDataForAuxValue($item_aux_value); - should be 0
if(($v == 0 || $side == 2) && $level->isSolidBlockingTile($x, $y, $z + 1)) $v = 2;
if(($v == 0 || $side == 3) && $level->isSolidBlockingTile($x, $y, $z - 1)) $v = 3;
if(($v == 0 || $side == 4) && $level->isSolidBlockingTile($x + 1, $y, $z)) $v = 4;
if(($v == 0 || $side == 5) && $level->isSolidBlockingTile($x - 1, $y, $z)) $v = 5;
return $v; //should never happen due to previous check in ::place
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($face === 0 || $face === 1){
return false; //fix of placing invalid ids without array
}
if($target->isTransparent === false){
$this->meta = $face;
$x = $block->x;
$y = $block->y;
$z = $block->z;
$level = $block->level;
if($level->isSolidBlockingTile($x - 1, $y, $z) || $level->isSolidBlockingTile($x + 1, $y, $z) || $level->isSolidBlockingTile($x, $y, $z - 1) || $level->isSolidBlockingTile($x, $y, $z+1)){
$this->meta = static::getPlacementDataValue($level, $x, $y, $z, $face);
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}

View file

@ -19,40 +19,85 @@ class TorchBlock extends FlowableBlock implements LightingBlock{
}
public static function neighborChanged(Level $level, $x, $y, $z, $nX, $nY, $nZ, $oldID){
$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);
if(static::checkCanSurvive($level, $x, $y, $z)){
$data = $level->level->getBlockDamage($x, $y, $z);
$destroy = !$level->isSolidBlockingTile($x-1, $y, $z) && $data == 1;
if(!$level->isSolidBlockingTile($x+1, $y, $z) && $data == 2) $destroy = true;
if(!$level->isSolidBlockingTile($x, $y, $z-1) && $data == 3) $destroy = true;
if(!$level->isSolidBlockingTile($x, $y, $z+1) && $data == 4) $destroy = true;
if((!static::isConnection($level, $x, $y-1, $z) && $data == 5) || $destroy){
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->isTransparent === false and $face !== 0){
$faces = array(
1 => 5,
2 => 4,
3 => 3,
4 => 2,
5 => 1,
);
$this->meta = $faces[$face];
$this->level->setBlock($block, $this, true, false, true);
public static function isConnection(Level $level, $x, $y, $z){
if($level->isSolidBlockingTile($x, $y, $z)){
return true;
}elseif($this->getSide(0)->isTransparent === false or $this->getSide(0)->getID() === FENCE or $this->getSide(0)->getID() === STONE_WALL){
$this->meta = 0;
}
$id = $level->level->getBlockID($x, $y, $z);
return $id == FENCE || $id == GLASS || $id == COBBLE_WALL;
}
public static function getPlacementDataValue(Level $level, $x, $y, $z, $side){
$def = 0;
if($side == 1){
if(static::isConnection($level, $x, $y-1, $z)) return 5;
}else if($side == 2){
if($level->isSolidBlockingTile($x, $y, $z+1)) return 4;
}
if($side == 5){
if($level->isSolidBlockingTile($x-1, $y, $z)) return 1;
}else if($side == 3){
if($level->isSolidBlockingTile($x, $y, $z-1)) return 3;
}else if($side == 4){
if($level->isSolidBlockingTile($x+1, $y, $z)) return 2;
}
return $def;
}
public static function checkCanSurvive(Level $level, $x, $y, $z){
if(static::mayPlace($level, $x, $y, $z)) return true;
if($level->level->getBlockID($x, $y, $z) == TORCH){
ServerAPI::request()->api->entity->drop(new Position($x, $y, $z, $level), BlockAPI::getItem(TORCH, 0, 1));
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
return false;
}
public static function onPlace(Level $level, $x, $y, $z){
if($level->level->getBlockDamage($x, $y, $z) == 0){
if($level->isSolidBlockingTile($x-1, $y, $z)) $level->fastSetBlockUpdateMeta($x, $y, $z, 1);
if($level->isSolidBlockingTile($x+1, $y, $z)) $level->fastSetBlockUpdateMeta($x, $y, $z, 2);
if($level->isSolidBlockingTile($x, $y, $z-1)) $level->fastSetBlockUpdateMeta($x, $y, $z, 3);
if($level->isSolidBlockingTile($x, $y, $z+1)) $level->fastSetBlockUpdateMeta($x, $y, $z, 4);
if(static::isConnection($level, $x, $y-1, $z)) $level->fastSetBlockUpdateMeta($x, $y, $z, 5);
}
static::checkCanSurvive($level, $x, $y, $z);
}
public static function mayPlace(Level $level, $x, $y, $z){
return $level->isSolidBlockingTile($x - 1, $y, $z) || $level->isSolidBlockingTile($x + 1, $y, $z) || $level->isSolidBlockingTile($x, $y, $z - 1) || $level->isSolidBlockingTile($x, $y, $z+1) || static::isConnection($level, $x, $y-1, $z);
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$x = $block->x;
$y = $block->y;
$z = $block->z;
$level = $block->level;
if(static::mayPlace($level, $x, $y, $z)){
$this->meta = static::getPlacementDataValue($level, $x, $y, $z, $face);
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
return array(
array($this->id, 0, 1),

View file

@ -14,10 +14,13 @@ class TrapdoorBlock extends TransparentBlock{
$this->breakTime = 3;
$this->material = Material::$wood;
}
public function canAttachTo(Block $target){
$id = $target->getID();
return $id === SLAB || $id === GLOWSTONE || $id === SLAB || $id === WOOD_SLAB || (!$target->isTransparent || $target instanceof StairBlock);
public static function attachesTo($id){
if($id <= 0) return false;
//check for non existent tiles is here - not needed?
//image using tile->getRenderShape() == 10 to check is stairs </3
return StaticBlock::getMaterial($id)->isSolidBlocking() && StaticBlock::getIsCubeShaped($id) || $id == GLOWSTONE || $id == SLAB || $id == WOODEN_SLAB || (StaticBlock::getBlock($id) instanceof StairBlock);
}
public static function isOpen($meta){
@ -59,18 +62,29 @@ class TrapdoorBlock extends TransparentBlock{
}
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if(($this->canAttachTo($target)) and $face !== 0 and $face !== 1){
$faces = array(
2 => 0,
3 => 1,
4 => 2,
5 => 3,
);
$this->meta = $faces[$face] & 0x03;
$this->level->setBlock($block, $this, true, false, true);
return true;
}
if($face == 0 || $face == 1) return false;
$level = $block->level;
$xx = $block->x;
$y = $block->y;
$zz = $block->z;
if($face == 2) ++$zz;
if($face == 3) --$zz;
if($face == 4) ++$xx;
if($face == 5) --$xx;
if(static::attachesTo($level->level->getBlockID($xx, $y, $zz))){
$this->meta = match($face){
3 => 1,
4 => 2,
5 => 3,
default => 0
};
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
return array(
@ -97,4 +111,15 @@ class TrapdoorBlock extends TransparentBlock{
$this->level->setBlock($this, $this, true, false, true);
return true;
}
/**
* @deprecated use TrapdoorBlock::attachesTo($target->getID());
* @param Block $target
* @return boolean
*/
public function canAttachTo(Block $target){
$id = $target->getID();
return static::attachesTo($id);
}
}

View file

@ -14,6 +14,10 @@ class BaseMushroomBlock extends FlowableBlock{
$level->fastSetBlockUpdate($x, $y, $z, 0, 0);
}
}
public static function canSurvive(Level $level, $x, $y, $z){
return $level->getRawBrightness($x, $y, $z) <= 12 && StaticBlock::getIsSolid($level->level->getBlockID($x, $y-1, $z));
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(Block::$mushroomSpread && mt_rand(0, 24) == 0){
@ -46,11 +50,11 @@ class BaseMushroomBlock extends FlowableBlock{
}
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;
if($block->getID() == 0 || $block->material->replaceable){ //Tile::mayPlace
if(static::canSurvive($block->level, $block->x, $block->y, $block->z)){
$this->level->setBlock($block, $this, true, false, true);
return true;
}
}
return false;
}
}

View file

@ -8,6 +8,7 @@ class StoneBlock extends SolidBlock{
$this->breakTime = 1.5;
$this->material = Material::$stone;
$this->lightBlock = 255;
$this->vIsSolid = true;
}
public function getBreakTime(Item $item, Player $player){