Another blocks

This commit is contained in:
ArkQuark 2023-02-21 22:58:54 +03:00
parent f2c1329ce5
commit 4f8ec638c1
7 changed files with 149 additions and 25 deletions

View file

@ -132,6 +132,15 @@ abstract class Block extends Position{
INFO_UPDATE => "InfoUpdateBlock",
INFO_UPDATE2 => "InfoUpdate2Block",
RESERVED6 => "Reserved6Block",
ACACIA_WOOD_STAIRS => "AcaciaWoodStairsBlock",
DARK_OAK_WOOD_STAIRS => "DarkOakWoodStairsBlock",
EMERALD_ORE => "EmeraldOreBlock",
EMERALD_BLOCK => "EmeraldBlock",
END_STONE => "EndStoneBlock",
HARDENED_CLAY => "HardenedClayBlock",
LOG2 => "Log2Block",
LEAVES2 => "Leaves2Block",
);
protected $id;
protected $meta;

View file

@ -1,18 +1,8 @@
<?php
class CyanFlowerBlock extends FlowableBlock{
const POPPY = 0;
const BLUE_ORCHID = 1;
const ALLIUM = 2;
const AZURE_BLUET = 3;
const RED_TULIP = 4;
const ORANGE_TULIP = 5;
const WHITE_TULIP = 6;
const PINK_TULIP = 7;
const OXEYE_DAISY = 8;
public function __construct(){
parent::__construct(CYAN_FLOWER, 0, "Poppy");
public function __construct($meta = 0){
parent::__construct(CYAN_FLOWER, $meta, "Poppy");
$this->hardness = 0;
$names = array(
0 => "Poppy",

View file

@ -0,0 +1,86 @@
<?php
class Leaves2Block extends TransparentBlock{
public function __construct($meta = 0){
parent::__construct(LEAVES2, $meta, "Leaves2");
$names = array(
0 => "Acacia Leaves",
1 => "Dark Oak Leaves",
);
$this->name = $names[$this->meta & 0x02];
$this->hardness = 1;
}
private function createIndex($x, $y, $z){
return $index = $x.".".$y.".".$z;
}
private function findLog(Block $pos, array $visited, $distance){ //port from newest pocketmine
$index = $this->createIndex($pos->x, $pos->y, $pos->z);
if(isset($visited[$index])){
return false;
}
$visited[$index] = true;
$block = $this->level->getBlock($pos);
if($block instanceof WoodBlock or $block instanceof Log2Block){ //type doesn't matter
return true;
}
if($block->getId() === $this->getId() && $distance <= 4){
foreach(range(2, 5) as $side){
if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ //recursion i guess?
return true;
}
}
}
return false;
}
public function onUpdate($type){
if($type === BLOCK_UPDATE_NORMAL){
if(($this->meta & 0b00001100) === 0){
$this->meta |= 0x08;
$this->level->setBlock($this, $this, false, false, true);
return BLOCK_UPDATE_RANDOM;
}
}elseif($type === BLOCK_UPDATE_RANDOM){
if(($this->meta & 0b00001100) === 0x08){
$this->meta &= 0x02;
$visited = array();
$check = 0;
if($this->findLog($this, $visited, 0) !== true){
$this->level->setBlock($this, new AirBlock(), false, false, true);
if(mt_rand(1, 20) === 1){ //Saplings
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta + 2 & 0x05, 1));
}
if(($this->meta & 0x02) === 1 and mt_rand(1, 200) === 1){ //Apples
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
}
return BLOCK_UPDATE_NORMAL;
}
}
}
return false;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$this->meta |= 0x04;
$this->level->setBlock($this, $this, true, false, true);
}
public function getDrops(Item $item, Player $player){
$drops = array();
if($item->isShears()){
$drops[] = array(LEAVES2, $this->meta & 0x03, 1);
}else{
if(mt_rand(1, 20) === 1){ //Saplings
$drops[] = array(SAPLING, $this->meta + 2 & 0x05, 1);
}
if(($this->meta & 0x03) === 1 and mt_rand(1, 100) === 1){ //Apples
$drops[] = array(APPLE, 0, 1);
}
}
return $drops;
}
}

View file

@ -1,23 +1,22 @@
<?php
class LeavesBlock extends TransparentBlock{
const OAK = 0;
const SPRUCE = 1;
const BIRCH = 2;
public function __construct($meta = 0){
parent::__construct(LEAVES, $meta, "Leaves");
$names = array(
LeavesBlock::OAK => "Oak Leaves",
LeavesBlock::SPRUCE => "Spruce Leaves",
LeavesBlock::BIRCH => "Birch Leaves",
3 => "",
WoodBlock::OAK => "Oak Leaves",
WoodBlock::SPRUCE => "Spruce Leaves",
WoodBlock::BIRCH => "Birch Leaves",
WoodBlock::JUNGLE => "Jungle Leaves",
);
$this->name = $names[$this->meta & 0x03];
$this->hardness = 1;
}
private function createIndex($x, $y, $z){
return $index = $x.".".$y.".".$z;
}
private function findLog(Block $pos, array $visited, $distance){ //port from newest pocketmine
$index = $this->createIndex($pos->x, $pos->y, $pos->z);
if(isset($visited[$index])){
@ -31,7 +30,7 @@ class LeavesBlock extends TransparentBlock{
}
if($block->getId() === $this->getId() && $distance <= 4){
foreach(array(2,3,4,5) as $side){
foreach(range(2, 5) as $side){
if($this->findLog($pos->getSide($side), $visited, $distance + 1)){ //recursion i guess?
return true;
}
@ -54,10 +53,10 @@ class LeavesBlock extends TransparentBlock{
$check = 0;
if($this->findLog($this, $visited, 0) !== true){
$this->level->setBlock($this, new AirBlock(), false, false, true);
if(mt_rand(1,20) === 1){ //Saplings
if(mt_rand(1, 20) === 1){ //Saplings
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(SAPLING, $this->meta & 0x03, 1));
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,200) === 1){ //Apples
if(($this->meta & 0x03) === WoodBlock::OAK and mt_rand(1, 200) === 1){ //Apples
ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem(APPLE, 0, 1));
}
return BLOCK_UPDATE_NORMAL;
@ -80,7 +79,7 @@ class LeavesBlock extends TransparentBlock{
if(mt_rand(1,20) === 1){ //Saplings
$drops[] = array(SAPLING, $this->meta & 0x03, 1);
}
if(($this->meta & 0x03) === LeavesBlock::OAK and mt_rand(1,100) === 1){ //Apples
if(($this->meta & 0x03) === WoodBlock::OAK and mt_rand(1,100) === 1){ //Apples
$drops[] = array(APPLE, 0, 1);
}
}

View file

@ -0,0 +1,34 @@
<?php
class Log2Block extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(LOG2, $meta, "Log2");
$names = array(
0 => "Acacia Log",
1 => "Dark Oak Log",
);
$this->name = $names[$this->meta & 0x02];
$this->hardness = 10;
}
public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
$faces = array(
0 => 0,
1 => 0,
2 => 0b1000,
3 => 0b1000,
4 => 0b0100,
5 => 0b0100,
);
$this->meta = ($this->meta & 0x02) | $faces[$face];
$this->level->setBlock($block, $this, true, false, true);
return true;
}
public function getDrops(Item $item, Player $player){
return array(
array($this->id, $this->meta & 0x02, 1),
);
}
}

View file

@ -4,6 +4,7 @@ class StoneBlock extends SolidBlock{
public function __construct($meta = 0){
parent::__construct(STONE, $meta, "Stone");
$names = array(
0 => "Stone",
1 => "Granite",
2 => "Polished Granite",
3 => "Diorite",