Skip to content

Commit

Permalink
Support for v2.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
larryTheCoder committed Dec 16, 2023
1 parent 94cc55a commit 70c500b
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions src/muqsit/vanillagenerator/Loader.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace muqsit\vanillagenerator;

use muqsit\vanillagenerator\generator\OverworldGenerator;
use OverworldGenerator as Generator;
use pocketmine\block\Block;
use pocketmine\block\BlockTypeIds;
use pocketmine\block\Liquid;
use pocketmine\block\VanillaBlocks;
use pocketmine\plugin\PluginBase;
use pocketmine\world\generator\GeneratorManager;
use ReflectionMethod;
use Throwable;
use ReflectionProperty;

final class Loader extends PluginBase {
final class Loader extends PluginBase
{

private const EXT_MCGENERATOR_VERSION = "2.1.5";
private const EXT_MCGENERATOR_VERSION = "2.1.7";

public function onLoad(): void{
if(!extension_loaded('vanillagenerator')){
public function onLoad(): void
{
if (!extension_loaded('vanillagenerator')) {
$this->getLogger()->critical("Unable to find the vanillagenerator extension.");
$this->getServer()->getPluginManager()->disablePlugin($this);

return;
}elseif(($phpver = phpversion('vanillagenerator')) < self::EXT_MCGENERATOR_VERSION){
} elseif (($phpver = phpversion('vanillagenerator')) < self::EXT_MCGENERATOR_VERSION) {
$this->getLogger()->critical("vanillagenerator extension version " . self::EXT_MCGENERATOR_VERSION . " is required, you have $phpver.");
$this->getServer()->getPluginManager()->disablePlugin($this);

Expand All @@ -36,36 +40,43 @@ public function onLoad(): void{
$generatorManager->addGenerator(OverworldGenerator::class, "vanilla_overworld", fn() => null);
}

private function registerBlocks(): void{
private function registerBlocks(): void
{
$blocks = VanillaBlocks::getAll();

foreach($blocks as $blockSelection){
foreach($blockSelection->generateStatePermutations() as $block){
foreach ($blocks as $blockSelection) {
$blockTypeId = $blockSelection->getIdInfo()->getBlockTypeId();

$r = new ReflectionProperty(Block::class, 'stateIdXorMask');
$r->setAccessible(true);

Generator::registerMask($blockTypeId, $r->getValue($blockSelection));

foreach ($blockSelection->generateStatePermutations() as $block) {
// "state" is a fancy word for "meta"
$r = new ReflectionMethod(Block::class, 'encodeFullState');
$r->setAccessible(true);

try{
$blockMeta = $r->invoke($block);
$blockMeta = $r->invoke($block);

// 1st bit = solid state
// 2nd bit = transparent state
// 3rd bit = flowable state
// 4th bit = liquid state
// 5th bit = light level (require 4 bits, 0-15)
// 1st bit = solid state
// 2nd bit = transparent state
// 3rd bit = flowable state
// 4th bit = liquid state
// 5th bit = light level (require 4 bits, 0-15)

$value = 0;
if($block->isSolid()) $value |= (1 << 0);
if($block->isTransparent()) $value |= (1 << 1);
if($block->canBeFlowedInto()) $value |= (1 << 2);
if($block instanceof Liquid) $value |= (1 << 3);
$value = 0;
if ($block->isSolid()) $value |= (1 << 0);
if ($block->isTransparent()) $value |= (1 << 1);
if ($block->canBeFlowedInto()) $value |= (1 << 2);
if ($block instanceof Liquid) $value |= (1 << 3);

$value |= ($block->getLightLevel() << 4);
$value |= ($block->getLightLevel() << 4);

\OverworldGenerator::registerBlock($block->getIdInfo()->getBlockTypeId(), $blockMeta, $value);
}catch(Throwable){
}
Generator::registerBlock($blockTypeId, $blockMeta, $value);
}
}

Generator::registerBlock(BlockTypeIds::AIR, 716, 0);
}
}

0 comments on commit 70c500b

Please sign in to comment.