Adding new blocks

This commit is contained in:
ArkQuark 2023-02-26 15:16:34 +03:00
parent 37bbfe2d81
commit 4a861c0f5d
11 changed files with 135 additions and 6 deletions

View file

@ -7,6 +7,7 @@ class LadderBlock extends TransparentBlock{
$this->isFullBlock = false;
$this->hardness = 2;
}
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
@ -20,7 +21,6 @@ class LadderBlock extends TransparentBlock{
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
$side = $this->getMetadata();
$faces = array( //magical tranformation

View file

@ -2,14 +2,15 @@
class StoneWallBlock extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(STONE_WALL, $meta & 0x01, $meta === 1 ? "Mossy Cobblestone Wall" : "Cobblestone Wall");
parent::__construct(COBBLESTONE_WALL, $meta & 0x01, $meta === 1 ? "Mossy Cobblestone Wall" : "Cobblestone Wall");
$this->isFullBlock = false;
$this->isSolid = false;
$this->hardness = 30;
}
public function getDrops(Item $item, Player $player){
if($item->isPickaxe()){
return [[STONE_WALL, $this->getMetadata(),1]];
return [[COBBLESTONE_WALL, $this->getMetadata(), 1]];
}
return [];
}

View file

@ -0,0 +1,71 @@
<?php
class CocoaBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(COCOA, $meta, "tile.cocoa.name<");
$this->isActivable = true;
$this->hardness = 0;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
if($target->getID() === WOOD and ($target->getMetadata() & 0x03) === 0x03){
//$this->meta = $face;
$this->level->setBlock($block, $this, true, false, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta++;
if($this->meta > 0x02){
$this->meta = 0x02;
}
$this->level->setBlock($this, $this, true, false, true);
if(($player->gamemode & 0x01) === 0){
$player->removeItem(DYE, 0x0F, 1);
}
return true;
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
/*$side = $this->getMetadata();
$faces = array( //magical tranformation
3 => 2,
2 => 3,
5 => 4,
4 => 5,
);
if($this->getSide($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;
}*/
}elseif($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x03){
++$this->meta;
$this->level->setBlock($this, $this, true, false, true);
return BLOCK_UPDATE_RANDOM;
}
}else{
return BLOCK_UPDATE_RANDOM;
}
}
return false;
}
public function getDrops(Item $item, Player $player){
$drops = [];
if($this->meta >= 0x02){
$drops[] = [DYE, 3, mt_rand(1, 4)];
}else{
$drops[] = [DYE, 3, 1];
}
return $drops;
}
}

View file

@ -0,0 +1,19 @@
<?php
class BrownMushroomSolidBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(BROWN_MUSHROOM_BLOCK, $meta, "Mushroom");
$this->hardness = 0.2;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
//todo
$this->level->setBlock($this, $this, true, false, true);
}
public function getDrops(Item $item, Player $player){
return [
[BROWN_MUSHROOM, 0, mt_rand(0, 2)]
];
}
}

View file

@ -0,0 +1,12 @@
<?php
class MonsterSpawnerBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(MONSTER_SPAWNER, $meta, "Monster Spawner");
$this->hardness = 5;
}
public function getDrops(Item $item, Player $player){
return [];
}
}

View file

@ -0,0 +1,19 @@
<?php
class RedMushroomSolidBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(RED_MUSHROOM_BLOCK, $meta, "Mushroom");
$this->hardness = 0.2;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
//todo
$this->level->setBlock($this, $this, true, false, true);
}
public function getDrops(Item $item, Player $player){
return [
[RED_MUSHROOM, 0, mt_rand(0, 2)]
];
}
}