Added Vines and Mycelium blocks

This commit is contained in:
ArkQuark 2023-02-28 22:16:38 +03:00
parent 62e47bab13
commit 9118406d7d
6 changed files with 59 additions and 27 deletions

View file

@ -146,6 +146,8 @@ abstract class Block extends Position{
RED_MUSHROOM_BLOCK => "RedMushroomSolidBlock",
BROWN_MUSHROOM_BLOCK => "BrownMushroomSolidBlock",
MONSTER_SPAWNER => "MonsterSpawnerBlock",
VINES => "VinesBlock",
MYCELIUM => "MyceliumBlock",
);
protected $id;
protected $meta;

View file

@ -8,15 +8,23 @@ class CocoaBlock extends FlowableBlock{
}
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);
if($face === 0 || $face === 1){
return false; //fix of placing invalid ids without array
}
if($target->isTransparent === false){
$faces = array(
2 => 0x00,
3 => 0x00,
4 => 0x00,
5 => 0x00,
);
$this->level->setBlock($this, BlockAPI::get($this->id, $faces[$face]), true, false, true);
return true;
}
return false;
}
public function onActivate(Item $item, Player $player){
/*public function onActivate(Item $item, Player $player){
if($item->getID() === DYE and $item->getMetadata() === 0x0F){ //Bonemeal
$this->meta++;
if($this->meta > 0x02){
@ -32,20 +40,7 @@ class CocoaBlock extends FlowableBlock{
}
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($type === BLOCK_UPDATE_RANDOM){
if(mt_rand(0, 2) == 1){
if($this->meta < 0x03){
++$this->meta;
@ -57,11 +52,11 @@ class CocoaBlock extends FlowableBlock{
}
}
return false;
}
}*/
public function getDrops(Item $item, Player $player){
$drops = [];
if($this->meta >= 0x02){
if($this->meta >= 0x02){ //hum?
$drops[] = [DYE, 3, mt_rand(1, 4)];
}else{
$drops[] = [DYE, 3, 1];

View file

@ -0,0 +1,35 @@
<?php
class VinesBlock extends FlowableBlock{
public function __construct($meta = 0){
parent::__construct(VINES, $meta, "Vines");
$this->isSolid = false;
$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
}
if($target->isTransparent === false){
$faces = array(
2 => 0x01,
3 => 0x04,
4 => 0x08,
5 => 0x02,
);
$this->level->setBlock($this, BlockAPI::get($this->id, $faces[$face]), true, false, true);
return true;
}
return false;
}
public function getDrops(Item $item, Player $player){
$drops = array();
if($item->isShears()){
$drops[] = array($this->id, 0, 1);
}
return $drops;
}
}

View file

@ -7,16 +7,16 @@ class MyceliumBlock extends SolidBlock{
$this->hardness = 3;
}
public function getDrops(Item $item, Player $player){
return array(
array(DIRT, 0, 1),
);
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_RANDOM && !$this->getSide(1)->isTransparent && mt_rand(0, 2) == 1){
$this->level->setBlock($this, BlockAPI::get(DIRT, 0), true, false, true);
}
return BLOCK_UPDATE_RANDOM;
}
public function getDrops(Item $item, Player $player){
return array(
array(DIRT, 0, 1),
);
}
}