Skip to content

Instantly share code, notes, and snippets.

@Muqsit
Last active July 18, 2017 22:23
Show Gist options
  • Save Muqsit/90e0fd0bdacf1fd1b152bf7c846f0be6 to your computer and use it in GitHub Desktop.
Save Muqsit/90e0fd0bdacf1fd1b152bf7c846f0be6 to your computer and use it in GitHub Desktop.
<?php
/**
* This code is licensed under WTFPL
* (Do What The Fuck You Want To Public License)
* http://www.wtfpl.net/
*
* WARNING: PLEASE READ the 'Caution' section at
* http://php.net/manual/en/function.eval.php before
* using or modifying this code.
*/
use pocketmine\block\Block;
use pocketmine\item\Item;
class haak {
/**
* Registers Teracotta Block. Use this as is
* only if you are never going to use
* getName() function on this block. I was
* lazy to type in the block names.
*/
public function registerTeracottaBlock(){
eval('class TeracottaBlock extends \pocketmine\block\Solid {
public function __construct($meta = 0)
{
$this->id = (int) substr(get_class($this), strlen("TeracottaBlock"));
$this->meta = 0;
}
public function place(\pocketmine\item\Item $item, \pocketmine\block\Block $block, \pocketmine\block\Block $target, $face, $fx, $fy, $fz, \pocketmine\Player $player = null)
{
$faces = [
0 => 4,
1 => 3,
2 => 5,
3 => 2
];
$this->meta = $faces[(~($player->getDirection() - 1)) & 0x03];//source: https://github.com/pmmp/PocketMine-MP/blob/fb44bad728e2133577189bfebb96446de25fefba/src/pocketmine/block/GlazedTerracotta.php#L57
$this->getLevel()->setBlock($block, $this, true, true);
}
};');
foreach (array_merge(range(219, 229), range(231, 235)) as $k => $bid) {
$cname = 'TeracottaBlock'.$bid;
eval("class $cname extends TeracottaBlock{};");
$this->registerBlock($bid, $cname);
Item::$list[$bid] = $cname;
Item::addCreativeItem(Item::get($bid, 0, 1));
}
}
/**
* Registers block so as to make it possible
* to place it.
*
* @param int $id
* @param string $class
*/
private static function registerBlock(int $id, string $class)
{
Block::$list[$id] = $class;
$block = new $class(0);
for($data = 0; $data < 16; ++$data){
Block::$fullList[($id << 4) | $data] = new $class($data);
}
/** @var Block $block */
Block::$solid[$id] = $block->isSolid();
Block::$transparent[$id] = $block->isTransparent();
Block::$hardness[$id] = $block->getHardness();
Block::$light[$id] = $block->getLightLevel();
Block::$lightFilter[$id] = 1;//TODO!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment