mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Move block registration to its own class
This commit is contained in:
parent
9451dd361e
commit
02f42eba48
@ -26,6 +26,7 @@ namespace pocketmine;
|
||||
use pocketmine\block\Air;
|
||||
use pocketmine\block\Bed;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\command\Command;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\entity\Arrow;
|
||||
@ -2493,7 +2494,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
}
|
||||
$block = $target->getSide($packet->face);
|
||||
if($block->getId() === Block::FIRE){
|
||||
$this->level->setBlock($block, Block::get(Block::AIR));
|
||||
$this->level->setBlock($block, BlockFactory::get(Block::AIR));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace pocketmine;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\command\CommandReader;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\ConsoleCommandSender;
|
||||
@ -81,8 +81,8 @@ use pocketmine\nbt\tag\StringTag;
|
||||
use pocketmine\network\CompressBatchedTask;
|
||||
use pocketmine\network\mcpe\protocol\BatchPacket;
|
||||
use pocketmine\network\mcpe\protocol\DataPacket;
|
||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||
use pocketmine\network\mcpe\protocol\PlayerListPacket;
|
||||
use pocketmine\network\mcpe\protocol\ProtocolInfo;
|
||||
use pocketmine\network\mcpe\RakLibInterface;
|
||||
use pocketmine\network\Network;
|
||||
use pocketmine\network\query\QueryHandler;
|
||||
@ -1583,7 +1583,7 @@ class Server{
|
||||
Entity::init();
|
||||
Tile::init();
|
||||
InventoryType::init();
|
||||
Block::init();
|
||||
BlockFactory::init();
|
||||
Enchantment::init();
|
||||
Item::init();
|
||||
Biome::init();
|
||||
|
@ -180,8 +180,8 @@ class Bed extends Transparent{
|
||||
$meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03;
|
||||
$next = $this->getSide(self::getOtherHalfSide($meta));
|
||||
if($next->canBeReplaced() === true and !$next->getSide(Vector3::SIDE_DOWN)->isTransparent()){
|
||||
$this->getLevel()->setBlock($block, Block::get($this->id, $meta), true, true);
|
||||
$this->getLevel()->setBlock($next, Block::get($this->id, $meta | self::BITFLAG_HEAD), true, true);
|
||||
$this->getLevel()->setBlock($block, BlockFactory::get($this->id, $meta), true, true);
|
||||
$this->getLevel()->setBlock($next, BlockFactory::get($this->id, $meta | self::BITFLAG_HEAD), true, true);
|
||||
|
||||
$nbt = new CompoundTag("", [
|
||||
new StringTag("id", Tile::BED),
|
||||
@ -206,7 +206,7 @@ class Bed extends Transparent{
|
||||
}
|
||||
|
||||
public function onBreak(Item $item) : bool{
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||
if(($other = $this->getOtherHalf()) !== null){
|
||||
$this->getLevel()->useBreakOn($other); //make sure tiles get removed
|
||||
}
|
||||
|
@ -41,360 +41,17 @@ use pocketmine\plugin\Plugin;
|
||||
|
||||
class Block extends Position implements BlockIds, Metadatable{
|
||||
|
||||
/** @var \SplFixedArray<Block> */
|
||||
public static $list = null;
|
||||
/** @var \SplFixedArray<Block> */
|
||||
public static $fullList = null;
|
||||
|
||||
/** @var \SplFixedArray<int> */
|
||||
public static $light = null;
|
||||
/** @var \SplFixedArray<int> */
|
||||
public static $lightFilter = null;
|
||||
/** @var \SplFixedArray<bool> */
|
||||
public static $solid = null;
|
||||
/** @var \SplFixedArray<float> */
|
||||
public static $hardness = null;
|
||||
/** @var \SplFixedArray<bool> */
|
||||
public static $transparent = null;
|
||||
/** @var \SplFixedArray<bool> */
|
||||
public static $diffusesSkyLight = null;
|
||||
/** @var \SplFixedArray<float> */
|
||||
public static $blastResistance = null;
|
||||
|
||||
/**
|
||||
* Initializes the block factory. By default this is called only once on server start, however you may wish to use
|
||||
* this if you need to reset the block factory back to its original defaults for whatever reason.
|
||||
* @deprecated This functionality has moved to {@link BlockFactory#get}
|
||||
*
|
||||
* @param bool $force
|
||||
*/
|
||||
public static function init(bool $force = false){
|
||||
if(self::$list === null or $force){
|
||||
self::$list = new \SplFixedArray(256);
|
||||
self::$fullList = new \SplFixedArray(4096);
|
||||
self::$light = new \SplFixedArray(256);
|
||||
self::$lightFilter = new \SplFixedArray(256);
|
||||
self::$solid = new \SplFixedArray(256);
|
||||
self::$hardness = new \SplFixedArray(256);
|
||||
self::$transparent = new \SplFixedArray(256);
|
||||
self::$diffusesSkyLight = new \SplFixedArray(256);
|
||||
self::$blastResistance = new \SplFixedArray(256);
|
||||
|
||||
self::registerBlock(new Air());
|
||||
self::registerBlock(new Stone());
|
||||
self::registerBlock(new Grass());
|
||||
self::registerBlock(new Dirt());
|
||||
self::registerBlock(new Cobblestone());
|
||||
self::registerBlock(new Planks());
|
||||
self::registerBlock(new Sapling());
|
||||
self::registerBlock(new Bedrock());
|
||||
self::registerBlock(new Water());
|
||||
self::registerBlock(new StillWater());
|
||||
self::registerBlock(new Lava());
|
||||
self::registerBlock(new StillLava());
|
||||
self::registerBlock(new Sand());
|
||||
self::registerBlock(new Gravel());
|
||||
self::registerBlock(new GoldOre());
|
||||
self::registerBlock(new IronOre());
|
||||
self::registerBlock(new CoalOre());
|
||||
self::registerBlock(new Wood());
|
||||
self::registerBlock(new Leaves());
|
||||
self::registerBlock(new Sponge());
|
||||
self::registerBlock(new Glass());
|
||||
self::registerBlock(new LapisOre());
|
||||
self::registerBlock(new Lapis());
|
||||
//TODO: DISPENSER
|
||||
self::registerBlock(new Sandstone());
|
||||
self::registerBlock(new NoteBlock());
|
||||
self::registerBlock(new Bed());
|
||||
self::registerBlock(new PoweredRail());
|
||||
self::registerBlock(new DetectorRail());
|
||||
//TODO: STICKY_PISTON
|
||||
self::registerBlock(new Cobweb());
|
||||
self::registerBlock(new TallGrass());
|
||||
self::registerBlock(new DeadBush());
|
||||
//TODO: PISTON
|
||||
//TODO: PISTONARMCOLLISION
|
||||
self::registerBlock(new Wool());
|
||||
|
||||
self::registerBlock(new Dandelion());
|
||||
self::registerBlock(new Flower());
|
||||
self::registerBlock(new BrownMushroom());
|
||||
self::registerBlock(new RedMushroom());
|
||||
self::registerBlock(new Gold());
|
||||
self::registerBlock(new Iron());
|
||||
self::registerBlock(new DoubleStoneSlab());
|
||||
self::registerBlock(new StoneSlab());
|
||||
self::registerBlock(new Bricks());
|
||||
self::registerBlock(new TNT());
|
||||
self::registerBlock(new Bookshelf());
|
||||
self::registerBlock(new MossyCobblestone());
|
||||
self::registerBlock(new Obsidian());
|
||||
self::registerBlock(new Torch());
|
||||
self::registerBlock(new Fire());
|
||||
self::registerBlock(new MonsterSpawner());
|
||||
self::registerBlock(new WoodenStairs(Block::OAK_STAIRS, 0, "Oak Stairs"));
|
||||
self::registerBlock(new Chest());
|
||||
//TODO: REDSTONE_WIRE
|
||||
self::registerBlock(new DiamondOre());
|
||||
self::registerBlock(new Diamond());
|
||||
self::registerBlock(new CraftingTable());
|
||||
self::registerBlock(new Wheat());
|
||||
self::registerBlock(new Farmland());
|
||||
self::registerBlock(new Furnace());
|
||||
self::registerBlock(new BurningFurnace());
|
||||
self::registerBlock(new SignPost());
|
||||
self::registerBlock(new WoodenDoor(Block::OAK_DOOR_BLOCK, 0, "Oak Door Block", Item::OAK_DOOR));
|
||||
self::registerBlock(new Ladder());
|
||||
self::registerBlock(new Rail());
|
||||
self::registerBlock(new CobblestoneStairs());
|
||||
self::registerBlock(new WallSign());
|
||||
self::registerBlock(new Lever());
|
||||
self::registerBlock(new StonePressurePlate());
|
||||
self::registerBlock(new IronDoor());
|
||||
self::registerBlock(new WoodenPressurePlate());
|
||||
self::registerBlock(new RedstoneOre());
|
||||
self::registerBlock(new GlowingRedstoneOre());
|
||||
self::registerBlock(new RedstoneTorchUnlit());
|
||||
self::registerBlock(new RedstoneTorch());
|
||||
self::registerBlock(new StoneButton());
|
||||
self::registerBlock(new SnowLayer());
|
||||
self::registerBlock(new Ice());
|
||||
self::registerBlock(new Snow());
|
||||
self::registerBlock(new Cactus());
|
||||
self::registerBlock(new Clay());
|
||||
self::registerBlock(new Sugarcane());
|
||||
|
||||
self::registerBlock(new Fence());
|
||||
self::registerBlock(new Pumpkin());
|
||||
self::registerBlock(new Netherrack());
|
||||
self::registerBlock(new SoulSand());
|
||||
self::registerBlock(new Glowstone());
|
||||
//TODO: PORTAL
|
||||
self::registerBlock(new LitPumpkin());
|
||||
self::registerBlock(new Cake());
|
||||
//TODO: REPEATER_BLOCK
|
||||
//TODO: POWERED_REPEATER
|
||||
//TODO: INVISIBLEBEDROCK
|
||||
self::registerBlock(new Trapdoor());
|
||||
//TODO: MONSTER_EGG
|
||||
self::registerBlock(new StoneBricks());
|
||||
//TODO: BROWN_MUSHROOM_BLOCK
|
||||
//TODO: RED_MUSHROOM_BLOCK
|
||||
self::registerBlock(new IronBars());
|
||||
self::registerBlock(new GlassPane());
|
||||
self::registerBlock(new Melon());
|
||||
self::registerBlock(new PumpkinStem());
|
||||
self::registerBlock(new MelonStem());
|
||||
self::registerBlock(new Vine());
|
||||
self::registerBlock(new FenceGate(Block::OAK_FENCE_GATE, 0, "Oak Fence Gate"));
|
||||
self::registerBlock(new BrickStairs());
|
||||
self::registerBlock(new StoneBrickStairs());
|
||||
self::registerBlock(new Mycelium());
|
||||
self::registerBlock(new WaterLily());
|
||||
self::registerBlock(new NetherBrick(Block::NETHER_BRICK_BLOCK, 0, "Nether Bricks"));
|
||||
self::registerBlock(new NetherBrickFence());
|
||||
self::registerBlock(new NetherBrickStairs());
|
||||
self::registerBlock(new NetherWartPlant());
|
||||
self::registerBlock(new EnchantingTable());
|
||||
self::registerBlock(new BrewingStand());
|
||||
//TODO: CAULDRON_BLOCK
|
||||
//TODO: END_PORTAL
|
||||
self::registerBlock(new EndPortalFrame());
|
||||
self::registerBlock(new EndStone());
|
||||
//TODO: DRAGON_EGG
|
||||
self::registerBlock(new RedstoneLamp());
|
||||
self::registerBlock(new LitRedstoneLamp());
|
||||
//TODO: DROPPER
|
||||
self::registerBlock(new ActivatorRail());
|
||||
self::registerBlock(new CocoaBlock());
|
||||
self::registerBlock(new SandstoneStairs());
|
||||
self::registerBlock(new EmeraldOre());
|
||||
//TODO: ENDER_CHEST
|
||||
self::registerBlock(new TripwireHook());
|
||||
self::registerBlock(new Tripwire());
|
||||
self::registerBlock(new Emerald());
|
||||
self::registerBlock(new WoodenStairs(Block::SPRUCE_STAIRS, 0, "Spruce Stairs"));
|
||||
self::registerBlock(new WoodenStairs(Block::BIRCH_STAIRS, 0, "Birch Stairs"));
|
||||
self::registerBlock(new WoodenStairs(Block::JUNGLE_STAIRS, 0, "Jungle Stairs"));
|
||||
//TODO: COMMAND_BLOCK
|
||||
//TODO: BEACON
|
||||
self::registerBlock(new CobblestoneWall());
|
||||
self::registerBlock(new FlowerPot());
|
||||
self::registerBlock(new Carrot());
|
||||
self::registerBlock(new Potato());
|
||||
self::registerBlock(new WoodenButton());
|
||||
self::registerBlock(new Skull());
|
||||
self::registerBlock(new Anvil());
|
||||
self::registerBlock(new TrappedChest());
|
||||
self::registerBlock(new WeightedPressurePlateLight());
|
||||
self::registerBlock(new WeightedPressurePlateHeavy());
|
||||
//TODO: COMPARATOR_BLOCK
|
||||
//TODO: POWERED_COMPARATOR
|
||||
self::registerBlock(new DaylightSensor());
|
||||
self::registerBlock(new Redstone());
|
||||
self::registerBlock(new NetherQuartzOre());
|
||||
//TODO: HOPPER_BLOCK
|
||||
self::registerBlock(new Quartz());
|
||||
self::registerBlock(new QuartzStairs());
|
||||
self::registerBlock(new DoubleWoodenSlab());
|
||||
self::registerBlock(new WoodenSlab());
|
||||
self::registerBlock(new StainedClay());
|
||||
self::registerBlock(new StainedGlassPane());
|
||||
self::registerBlock(new Leaves2());
|
||||
self::registerBlock(new Wood2());
|
||||
self::registerBlock(new WoodenStairs(Block::ACACIA_STAIRS, 0, "Acacia Stairs"));
|
||||
self::registerBlock(new WoodenStairs(Block::DARK_OAK_STAIRS, 0, "Dark Oak Stairs"));
|
||||
//TODO: SLIME
|
||||
|
||||
self::registerBlock(new IronTrapdoor());
|
||||
self::registerBlock(new Prismarine());
|
||||
self::registerBlock(new SeaLantern());
|
||||
self::registerBlock(new HayBale());
|
||||
self::registerBlock(new Carpet());
|
||||
self::registerBlock(new HardenedClay());
|
||||
self::registerBlock(new Coal());
|
||||
self::registerBlock(new PackedIce());
|
||||
self::registerBlock(new DoublePlant());
|
||||
|
||||
//TODO: DAYLIGHT_DETECTOR_INVERTED
|
||||
//TODO: RED_SANDSTONE
|
||||
//TODO: RED_SANDSTONE_STAIRS
|
||||
//TODO: DOUBLE_STONE_SLAB2
|
||||
//TODO: STONE_SLAB2
|
||||
self::registerBlock(new FenceGate(Block::SPRUCE_FENCE_GATE, 0, "Spruce Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::BIRCH_FENCE_GATE, 0, "Birch Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::JUNGLE_FENCE_GATE, 0, "Jungle Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::DARK_OAK_FENCE_GATE, 0, "Dark Oak Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::ACACIA_FENCE_GATE, 0, "Acacia Fence Gate"));
|
||||
//TODO: REPEATING_COMMAND_BLOCK
|
||||
//TODO: CHAIN_COMMAND_BLOCK
|
||||
|
||||
self::registerBlock(new WoodenDoor(Block::SPRUCE_DOOR_BLOCK, 0, "Spruce Door Block", Item::SPRUCE_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::BIRCH_DOOR_BLOCK, 0, "Birch Door Block", Item::BIRCH_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::JUNGLE_DOOR_BLOCK, 0, "Jungle Door Block", Item::JUNGLE_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::ACACIA_DOOR_BLOCK, 0, "Acacia Door Block", Item::ACACIA_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::DARK_OAK_DOOR_BLOCK, 0, "Dark Oak Door Block", Item::DARK_OAK_DOOR));
|
||||
self::registerBlock(new GrassPath());
|
||||
self::registerBlock(new ItemFrame());
|
||||
//TODO: CHORUS_FLOWER
|
||||
//TODO: PURPUR_BLOCK
|
||||
|
||||
//TODO: PURPUR_STAIRS
|
||||
|
||||
//TODO: END_BRICKS
|
||||
//TODO: FROSTED_ICE
|
||||
self::registerBlock(new EndRod());
|
||||
//TODO: END_GATEWAY
|
||||
|
||||
self::registerBlock(new Magma());
|
||||
self::registerBlock(new NetherWartBlock());
|
||||
self::registerBlock(new NetherBrick(Block::RED_NETHER_BRICK, 0, "Red Nether Bricks"));
|
||||
//TODO: BONE_BLOCK
|
||||
|
||||
//TODO: SHULKER_BOX
|
||||
self::registerBlock(new GlazedTerracotta(Block::PURPLE_GLAZED_TERRACOTTA, 0, "Purple Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::WHITE_GLAZED_TERRACOTTA, 0, "White Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::ORANGE_GLAZED_TERRACOTTA, 0, "Orange Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::MAGENTA_GLAZED_TERRACOTTA, 0, "Magenta Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::LIGHT_BLUE_GLAZED_TERRACOTTA, 0, "Light Blue Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::YELLOW_GLAZED_TERRACOTTA, 0, "Yellow Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::LIME_GLAZED_TERRACOTTA, 0, "Lime Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::PINK_GLAZED_TERRACOTTA, 0, "Pink Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::GRAY_GLAZED_TERRACOTTA, 0, "Grey Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::SILVER_GLAZED_TERRACOTTA, 0, "Light Grey Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::CYAN_GLAZED_TERRACOTTA, 0, "Cyan Glazed Terracotta"));
|
||||
|
||||
self::registerBlock(new GlazedTerracotta(Block::BLUE_GLAZED_TERRACOTTA, 0, "Blue Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::BROWN_GLAZED_TERRACOTTA, 0, "Brown Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::GREEN_GLAZED_TERRACOTTA, 0, "Green Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::RED_GLAZED_TERRACOTTA, 0, "Red Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::BLACK_GLAZED_TERRACOTTA, 0, "Black Glazed Terracotta"));
|
||||
//TODO: CONCRETE
|
||||
//TODO: CONCRETEPOWDER
|
||||
|
||||
//TODO: CHORUS_PLANT
|
||||
self::registerBlock(new StainedGlass());
|
||||
|
||||
self::registerBlock(new Podzol());
|
||||
self::registerBlock(new Beetroot());
|
||||
self::registerBlock(new Stonecutter());
|
||||
self::registerBlock(new GlowingObsidian());
|
||||
self::registerBlock(new NetherReactor());
|
||||
//TODO: INFO_UPDATE
|
||||
//TODO: INFO_UPDATE2
|
||||
//TODO: MOVINGBLOCK
|
||||
//TODO: OBSERVER
|
||||
|
||||
//TODO: RESERVED6
|
||||
|
||||
foreach(self::$list as $id => $block){
|
||||
if($block === null){
|
||||
self::registerBlock(new UnknownBlock($id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a block type into the index. Plugins may use this method to register new block types or override
|
||||
* existing ones.
|
||||
*
|
||||
* NOTE: If you are registering a new block type, you will need to add it to the creative inventory yourself - it
|
||||
* will not automatically appear there.
|
||||
*
|
||||
* @param Block $block
|
||||
* @param bool $override Whether to override existing registrations
|
||||
*
|
||||
* @throws \RuntimeException if something attempted to override an already-registered block without specifying the
|
||||
* $override parameter.
|
||||
*/
|
||||
public static function registerBlock(Block $block, bool $override = false){
|
||||
$id = $block->getId();
|
||||
|
||||
if(self::$list[$id] !== null and !(self::$list[$id] instanceof UnknownBlock) and !$override){
|
||||
throw new \RuntimeException("Trying to overwrite an already registered block");
|
||||
}
|
||||
|
||||
self::$list[$id] = clone $block;
|
||||
|
||||
for($meta = 0; $meta < 16; ++$meta){
|
||||
$variant = clone $block;
|
||||
$variant->setDamage($meta);
|
||||
self::$fullList[($id << 4) | $meta] = $variant;
|
||||
}
|
||||
|
||||
self::$solid[$id] = $block->isSolid();
|
||||
self::$transparent[$id] = $block->isTransparent();
|
||||
self::$hardness[$id] = $block->getHardness();
|
||||
self::$light[$id] = $block->getLightLevel();
|
||||
self::$lightFilter[$id] = $block->getLightFilter() + 1; //opacity plus 1 standard light filter
|
||||
self::$diffusesSkyLight[$id] = $block->diffusesSkyLight();
|
||||
self::$blastResistance[$id] = $block->getBlastResistance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param Position $pos
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param Position|null $pos
|
||||
*
|
||||
* @return Block
|
||||
*/
|
||||
public static function get(int $id, int $meta = 0, Position $pos = null) : Block{
|
||||
try{
|
||||
$block = clone self::$fullList[($id << 4) | $meta];
|
||||
}catch(\RuntimeException $e){
|
||||
//TODO: this probably should return null (out of bounds IDs may cause unexpected behaviour)
|
||||
$block = new UnknownBlock($id, $meta);
|
||||
}
|
||||
|
||||
if($pos !== null){
|
||||
$block->x = $pos->x;
|
||||
$block->y = $pos->y;
|
||||
$block->z = $pos->z;
|
||||
$block->level = $pos->level;
|
||||
}
|
||||
|
||||
return $block;
|
||||
return BlockFactory::get($id, $meta, $pos);
|
||||
}
|
||||
|
||||
/** @var int */
|
||||
@ -508,7 +165,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
* @return bool
|
||||
*/
|
||||
public function onBreak(Item $item) : bool{
|
||||
return $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
|
||||
return $this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -756,7 +413,7 @@ class Block extends Position implements BlockIds, Metadatable{
|
||||
return $this->getLevel()->getBlock(Vector3::getSide($side, $step));
|
||||
}
|
||||
|
||||
return Block::get(Block::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
|
||||
return BlockFactory::get(Block::AIR, 0, Position::fromObject(Vector3::getSide($side, $step)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
391
src/pocketmine/block/BlockFactory.php
Normal file
391
src/pocketmine/block/BlockFactory.php
Normal file
@ -0,0 +1,391 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block;
|
||||
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Position;
|
||||
|
||||
/**
|
||||
* Manages block registration and instance creation
|
||||
*/
|
||||
class BlockFactory{
|
||||
/** @var \SplFixedArray<Block> */
|
||||
public static $list = null;
|
||||
/** @var \SplFixedArray<Block> */
|
||||
public static $fullList = null;
|
||||
/** @var \SplFixedArray<bool> */
|
||||
public static $solid = null;
|
||||
/** @var \SplFixedArray<bool> */
|
||||
public static $transparent = null;
|
||||
/** @var \SplFixedArray<float> */
|
||||
public static $hardness = null;
|
||||
/** @var \SplFixedArray<int> */
|
||||
public static $light = null;
|
||||
/** @var \SplFixedArray<int> */
|
||||
public static $lightFilter = null;
|
||||
/** @var \SplFixedArray<bool> */
|
||||
public static $diffusesSkyLight = null;
|
||||
/** @var \SplFixedArray<float> */
|
||||
public static $blastResistance = null;
|
||||
|
||||
/**
|
||||
* Initializes the block factory. By default this is called only once on server start, however you may wish to use
|
||||
* this if you need to reset the block factory back to its original defaults for whatever reason.
|
||||
*
|
||||
* @param bool $force
|
||||
*/
|
||||
public static function init(bool $force = false){
|
||||
if(self::$list === null or $force){
|
||||
self::$list = new \SplFixedArray(256);
|
||||
self::$fullList = new \SplFixedArray(4096);
|
||||
self::$light = new \SplFixedArray(256);
|
||||
self::$lightFilter = new \SplFixedArray(256);
|
||||
self::$solid = new \SplFixedArray(256);
|
||||
self::$hardness = new \SplFixedArray(256);
|
||||
self::$transparent = new \SplFixedArray(256);
|
||||
self::$diffusesSkyLight = new \SplFixedArray(256);
|
||||
|
||||
self::registerBlock(new Air());
|
||||
self::registerBlock(new Stone());
|
||||
self::registerBlock(new Grass());
|
||||
self::registerBlock(new Dirt());
|
||||
self::registerBlock(new Cobblestone());
|
||||
self::registerBlock(new Planks());
|
||||
self::registerBlock(new Sapling());
|
||||
self::registerBlock(new Bedrock());
|
||||
self::registerBlock(new Water());
|
||||
self::registerBlock(new StillWater());
|
||||
self::registerBlock(new Lava());
|
||||
self::registerBlock(new StillLava());
|
||||
self::registerBlock(new Sand());
|
||||
self::registerBlock(new Gravel());
|
||||
self::registerBlock(new GoldOre());
|
||||
self::registerBlock(new IronOre());
|
||||
self::registerBlock(new CoalOre());
|
||||
self::registerBlock(new Wood());
|
||||
self::registerBlock(new Leaves());
|
||||
self::registerBlock(new Sponge());
|
||||
self::registerBlock(new Glass());
|
||||
self::registerBlock(new LapisOre());
|
||||
self::registerBlock(new Lapis());
|
||||
//TODO: DISPENSER
|
||||
self::registerBlock(new Sandstone());
|
||||
self::registerBlock(new NoteBlock());
|
||||
self::registerBlock(new Bed());
|
||||
self::registerBlock(new PoweredRail());
|
||||
self::registerBlock(new DetectorRail());
|
||||
//TODO: STICKY_PISTON
|
||||
self::registerBlock(new Cobweb());
|
||||
self::registerBlock(new TallGrass());
|
||||
self::registerBlock(new DeadBush());
|
||||
//TODO: PISTON
|
||||
//TODO: PISTONARMCOLLISION
|
||||
self::registerBlock(new Wool());
|
||||
|
||||
self::registerBlock(new Dandelion());
|
||||
self::registerBlock(new Flower());
|
||||
self::registerBlock(new BrownMushroom());
|
||||
self::registerBlock(new RedMushroom());
|
||||
self::registerBlock(new Gold());
|
||||
self::registerBlock(new Iron());
|
||||
self::registerBlock(new DoubleStoneSlab());
|
||||
self::registerBlock(new StoneSlab());
|
||||
self::registerBlock(new Bricks());
|
||||
self::registerBlock(new TNT());
|
||||
self::registerBlock(new Bookshelf());
|
||||
self::registerBlock(new MossyCobblestone());
|
||||
self::registerBlock(new Obsidian());
|
||||
self::registerBlock(new Torch());
|
||||
self::registerBlock(new Fire());
|
||||
self::registerBlock(new MonsterSpawner());
|
||||
self::registerBlock(new WoodenStairs(Block::OAK_STAIRS, 0, "Oak Stairs"));
|
||||
self::registerBlock(new Chest());
|
||||
//TODO: REDSTONE_WIRE
|
||||
self::registerBlock(new DiamondOre());
|
||||
self::registerBlock(new Diamond());
|
||||
self::registerBlock(new CraftingTable());
|
||||
self::registerBlock(new Wheat());
|
||||
self::registerBlock(new Farmland());
|
||||
self::registerBlock(new Furnace());
|
||||
self::registerBlock(new BurningFurnace());
|
||||
self::registerBlock(new SignPost());
|
||||
self::registerBlock(new WoodenDoor(Block::OAK_DOOR_BLOCK, 0, "Oak Door Block", Item::OAK_DOOR));
|
||||
self::registerBlock(new Ladder());
|
||||
self::registerBlock(new Rail());
|
||||
self::registerBlock(new CobblestoneStairs());
|
||||
self::registerBlock(new WallSign());
|
||||
self::registerBlock(new Lever());
|
||||
self::registerBlock(new StonePressurePlate());
|
||||
self::registerBlock(new IronDoor());
|
||||
self::registerBlock(new WoodenPressurePlate());
|
||||
self::registerBlock(new RedstoneOre());
|
||||
self::registerBlock(new GlowingRedstoneOre());
|
||||
self::registerBlock(new RedstoneTorchUnlit());
|
||||
self::registerBlock(new RedstoneTorch());
|
||||
self::registerBlock(new StoneButton());
|
||||
self::registerBlock(new SnowLayer());
|
||||
self::registerBlock(new Ice());
|
||||
self::registerBlock(new Snow());
|
||||
self::registerBlock(new Cactus());
|
||||
self::registerBlock(new Clay());
|
||||
self::registerBlock(new Sugarcane());
|
||||
|
||||
self::registerBlock(new Fence());
|
||||
self::registerBlock(new Pumpkin());
|
||||
self::registerBlock(new Netherrack());
|
||||
self::registerBlock(new SoulSand());
|
||||
self::registerBlock(new Glowstone());
|
||||
//TODO: PORTAL
|
||||
self::registerBlock(new LitPumpkin());
|
||||
self::registerBlock(new Cake());
|
||||
//TODO: REPEATER_BLOCK
|
||||
//TODO: POWERED_REPEATER
|
||||
//TODO: INVISIBLEBEDROCK
|
||||
self::registerBlock(new Trapdoor());
|
||||
//TODO: MONSTER_EGG
|
||||
self::registerBlock(new StoneBricks());
|
||||
//TODO: BROWN_MUSHROOM_BLOCK
|
||||
//TODO: RED_MUSHROOM_BLOCK
|
||||
self::registerBlock(new IronBars());
|
||||
self::registerBlock(new GlassPane());
|
||||
self::registerBlock(new Melon());
|
||||
self::registerBlock(new PumpkinStem());
|
||||
self::registerBlock(new MelonStem());
|
||||
self::registerBlock(new Vine());
|
||||
self::registerBlock(new FenceGate(Block::OAK_FENCE_GATE, 0, "Oak Fence Gate"));
|
||||
self::registerBlock(new BrickStairs());
|
||||
self::registerBlock(new StoneBrickStairs());
|
||||
self::registerBlock(new Mycelium());
|
||||
self::registerBlock(new WaterLily());
|
||||
self::registerBlock(new NetherBrick(Block::NETHER_BRICK_BLOCK, 0, "Nether Bricks"));
|
||||
self::registerBlock(new NetherBrickFence());
|
||||
self::registerBlock(new NetherBrickStairs());
|
||||
self::registerBlock(new NetherWartPlant());
|
||||
self::registerBlock(new EnchantingTable());
|
||||
self::registerBlock(new BrewingStand());
|
||||
//TODO: CAULDRON_BLOCK
|
||||
//TODO: END_PORTAL
|
||||
self::registerBlock(new EndPortalFrame());
|
||||
self::registerBlock(new EndStone());
|
||||
//TODO: DRAGON_EGG
|
||||
self::registerBlock(new RedstoneLamp());
|
||||
self::registerBlock(new LitRedstoneLamp());
|
||||
//TODO: DROPPER
|
||||
self::registerBlock(new ActivatorRail());
|
||||
self::registerBlock(new CocoaBlock());
|
||||
self::registerBlock(new SandstoneStairs());
|
||||
self::registerBlock(new EmeraldOre());
|
||||
//TODO: ENDER_CHEST
|
||||
self::registerBlock(new TripwireHook());
|
||||
self::registerBlock(new Tripwire());
|
||||
self::registerBlock(new Emerald());
|
||||
self::registerBlock(new WoodenStairs(Block::SPRUCE_STAIRS, 0, "Spruce Stairs"));
|
||||
self::registerBlock(new WoodenStairs(Block::BIRCH_STAIRS, 0, "Birch Stairs"));
|
||||
self::registerBlock(new WoodenStairs(Block::JUNGLE_STAIRS, 0, "Jungle Stairs"));
|
||||
//TODO: COMMAND_BLOCK
|
||||
//TODO: BEACON
|
||||
self::registerBlock(new CobblestoneWall());
|
||||
self::registerBlock(new FlowerPot());
|
||||
self::registerBlock(new Carrot());
|
||||
self::registerBlock(new Potato());
|
||||
self::registerBlock(new WoodenButton());
|
||||
self::registerBlock(new Skull());
|
||||
self::registerBlock(new Anvil());
|
||||
self::registerBlock(new TrappedChest());
|
||||
self::registerBlock(new WeightedPressurePlateLight());
|
||||
self::registerBlock(new WeightedPressurePlateHeavy());
|
||||
//TODO: COMPARATOR_BLOCK
|
||||
//TODO: POWERED_COMPARATOR
|
||||
self::registerBlock(new DaylightSensor());
|
||||
self::registerBlock(new Redstone());
|
||||
self::registerBlock(new NetherQuartzOre());
|
||||
//TODO: HOPPER_BLOCK
|
||||
self::registerBlock(new Quartz());
|
||||
self::registerBlock(new QuartzStairs());
|
||||
self::registerBlock(new DoubleWoodenSlab());
|
||||
self::registerBlock(new WoodenSlab());
|
||||
self::registerBlock(new StainedClay());
|
||||
self::registerBlock(new StainedGlassPane());
|
||||
self::registerBlock(new Leaves2());
|
||||
self::registerBlock(new Wood2());
|
||||
self::registerBlock(new WoodenStairs(Block::ACACIA_STAIRS, 0, "Acacia Stairs"));
|
||||
self::registerBlock(new WoodenStairs(Block::DARK_OAK_STAIRS, 0, "Dark Oak Stairs"));
|
||||
//TODO: SLIME
|
||||
|
||||
self::registerBlock(new IronTrapdoor());
|
||||
self::registerBlock(new Prismarine());
|
||||
self::registerBlock(new SeaLantern());
|
||||
self::registerBlock(new HayBale());
|
||||
self::registerBlock(new Carpet());
|
||||
self::registerBlock(new HardenedClay());
|
||||
self::registerBlock(new Coal());
|
||||
self::registerBlock(new PackedIce());
|
||||
self::registerBlock(new DoublePlant());
|
||||
|
||||
//TODO: DAYLIGHT_DETECTOR_INVERTED
|
||||
//TODO: RED_SANDSTONE
|
||||
//TODO: RED_SANDSTONE_STAIRS
|
||||
//TODO: DOUBLE_STONE_SLAB2
|
||||
//TODO: STONE_SLAB2
|
||||
self::registerBlock(new FenceGate(Block::SPRUCE_FENCE_GATE, 0, "Spruce Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::BIRCH_FENCE_GATE, 0, "Birch Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::JUNGLE_FENCE_GATE, 0, "Jungle Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::DARK_OAK_FENCE_GATE, 0, "Dark Oak Fence Gate"));
|
||||
self::registerBlock(new FenceGate(Block::ACACIA_FENCE_GATE, 0, "Acacia Fence Gate"));
|
||||
//TODO: REPEATING_COMMAND_BLOCK
|
||||
//TODO: CHAIN_COMMAND_BLOCK
|
||||
|
||||
self::registerBlock(new WoodenDoor(Block::SPRUCE_DOOR_BLOCK, 0, "Spruce Door Block", Item::SPRUCE_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::BIRCH_DOOR_BLOCK, 0, "Birch Door Block", Item::BIRCH_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::JUNGLE_DOOR_BLOCK, 0, "Jungle Door Block", Item::JUNGLE_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::ACACIA_DOOR_BLOCK, 0, "Acacia Door Block", Item::ACACIA_DOOR));
|
||||
self::registerBlock(new WoodenDoor(Block::DARK_OAK_DOOR_BLOCK, 0, "Dark Oak Door Block", Item::DARK_OAK_DOOR));
|
||||
self::registerBlock(new GrassPath());
|
||||
self::registerBlock(new ItemFrame());
|
||||
//TODO: CHORUS_FLOWER
|
||||
//TODO: PURPUR_BLOCK
|
||||
|
||||
//TODO: PURPUR_STAIRS
|
||||
|
||||
//TODO: END_BRICKS
|
||||
//TODO: FROSTED_ICE
|
||||
self::registerBlock(new EndRod());
|
||||
//TODO: END_GATEWAY
|
||||
|
||||
self::registerBlock(new Magma());
|
||||
self::registerBlock(new NetherWartBlock());
|
||||
self::registerBlock(new NetherBrick(Block::RED_NETHER_BRICK, 0, "Red Nether Bricks"));
|
||||
//TODO: BONE_BLOCK
|
||||
|
||||
//TODO: SHULKER_BOX
|
||||
self::registerBlock(new GlazedTerracotta(Block::PURPLE_GLAZED_TERRACOTTA, 0, "Purple Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::WHITE_GLAZED_TERRACOTTA, 0, "White Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::ORANGE_GLAZED_TERRACOTTA, 0, "Orange Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::MAGENTA_GLAZED_TERRACOTTA, 0, "Magenta Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::LIGHT_BLUE_GLAZED_TERRACOTTA, 0, "Light Blue Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::YELLOW_GLAZED_TERRACOTTA, 0, "Yellow Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::LIME_GLAZED_TERRACOTTA, 0, "Lime Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::PINK_GLAZED_TERRACOTTA, 0, "Pink Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::GRAY_GLAZED_TERRACOTTA, 0, "Grey Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::SILVER_GLAZED_TERRACOTTA, 0, "Light Grey Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::CYAN_GLAZED_TERRACOTTA, 0, "Cyan Glazed Terracotta"));
|
||||
|
||||
self::registerBlock(new GlazedTerracotta(Block::BLUE_GLAZED_TERRACOTTA, 0, "Blue Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::BROWN_GLAZED_TERRACOTTA, 0, "Brown Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::GREEN_GLAZED_TERRACOTTA, 0, "Green Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::RED_GLAZED_TERRACOTTA, 0, "Red Glazed Terracotta"));
|
||||
self::registerBlock(new GlazedTerracotta(Block::BLACK_GLAZED_TERRACOTTA, 0, "Black Glazed Terracotta"));
|
||||
//TODO: CONCRETE
|
||||
//TODO: CONCRETEPOWDER
|
||||
|
||||
//TODO: CHORUS_PLANT
|
||||
self::registerBlock(new StainedGlass());
|
||||
|
||||
self::registerBlock(new Podzol());
|
||||
self::registerBlock(new Beetroot());
|
||||
self::registerBlock(new Stonecutter());
|
||||
self::registerBlock(new GlowingObsidian());
|
||||
self::registerBlock(new NetherReactor());
|
||||
//TODO: INFO_UPDATE
|
||||
//TODO: INFO_UPDATE2
|
||||
//TODO: MOVINGBLOCK
|
||||
//TODO: OBSERVER
|
||||
|
||||
//TODO: RESERVED6
|
||||
|
||||
foreach(self::$list as $id => $block){
|
||||
if($block === null){
|
||||
self::registerBlock(new UnknownBlock($id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a block type into the index. Plugins may use this method to register new block types or override
|
||||
* existing ones.
|
||||
*
|
||||
* NOTE: If you are registering a new block type, you will need to add it to the creative inventory yourself - it
|
||||
* will not automatically appear there.
|
||||
*
|
||||
* @param Block $block
|
||||
* @param bool $override Whether to override existing registrations
|
||||
*
|
||||
* @throws \RuntimeException if something attempted to override an already-registered block without specifying the
|
||||
* $override parameter.
|
||||
*/
|
||||
public static function registerBlock(Block $block, bool $override = false){
|
||||
$id = $block->getId();
|
||||
|
||||
if(self::$list[$id] !== null and !(self::$list[$id] instanceof UnknownBlock) and !$override){
|
||||
throw new \RuntimeException("Trying to overwrite an already registered block");
|
||||
}
|
||||
|
||||
self::$list[$id] = clone $block;
|
||||
|
||||
for($meta = 0; $meta < 16; ++$meta){
|
||||
$variant = clone $block;
|
||||
$variant->setDamage($meta);
|
||||
self::$fullList[($id << 4) | $meta] = $variant;
|
||||
}
|
||||
|
||||
self::$solid[$id] = $block->isSolid();
|
||||
self::$transparent[$id] = $block->isTransparent();
|
||||
self::$hardness[$id] = $block->getHardness();
|
||||
self::$light[$id] = $block->getLightLevel();
|
||||
self::$lightFilter[$id] = $block->getLightFilter() + 1; //opacity plus 1 standard light filter
|
||||
self::$diffusesSkyLight[$id] = $block->diffusesSkyLight();
|
||||
self::$blastResistance[$id] = $block->getBlastResistance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param int $meta
|
||||
* @param Position $pos
|
||||
*
|
||||
* @return Block
|
||||
*/
|
||||
public static function get(int $id, int $meta = 0, Position $pos = null) : Block{
|
||||
try{
|
||||
$block = self::$fullList[($id << 4) | $meta];
|
||||
if($block !== null){
|
||||
$block = clone $block;
|
||||
}else{
|
||||
$block = new UnknownBlock($id, $meta);
|
||||
}
|
||||
}catch(\RuntimeException $e){
|
||||
//TODO: this probably should return null (out of bounds IDs may cause unexpected behaviour)
|
||||
$block = new UnknownBlock($id, $meta);
|
||||
}
|
||||
|
||||
if($pos !== null){
|
||||
$block->x = $pos->x;
|
||||
$block->y = $pos->y;
|
||||
$block->z = $pos->z;
|
||||
$block->level = $pos->level;
|
||||
}
|
||||
|
||||
return $block;
|
||||
}
|
||||
}
|
@ -90,7 +90,7 @@ class Cactus extends Transparent{
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getId() === self::AIR){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, Block::get(Block::CACTUS)));
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, BlockFactory::get(Block::CACTUS)));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ class Cake extends Transparent implements FoodSource{
|
||||
public function onUpdate(int $type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
@ -114,7 +114,7 @@ class Cake extends Transparent implements FoodSource{
|
||||
$clone = clone $this;
|
||||
$clone->meta++;
|
||||
if($clone->meta >= 0x06){
|
||||
$clone = Block::get(Block::AIR);
|
||||
$clone = BlockFactory::get(Block::AIR);
|
||||
}
|
||||
return $clone;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ class Chest extends Transparent{
|
||||
if($t instanceof TileChest){
|
||||
$t->unpair();
|
||||
}
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class Dirt extends Solid{
|
||||
public function onActivate(Item $item, Player $player = null) : bool{
|
||||
if($item->isHoe()){
|
||||
$item->useOn($this);
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::FARMLAND, 0), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND, 0), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -204,9 +204,9 @@ abstract class Door extends Transparent{
|
||||
public function onUpdate(int $type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ //Replace with common break method
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), false);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false);
|
||||
if($this->getSide(Vector3::SIDE_UP) instanceof Door){
|
||||
$this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), Block::get(Block::AIR), false);
|
||||
$this->getLevel()->setBlock($this->getSide(Vector3::SIDE_UP), BlockFactory::get(Block::AIR), false);
|
||||
}
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
@ -239,7 +239,7 @@ abstract class Door extends Transparent{
|
||||
|
||||
$this->setDamage($player->getDirection() & 0x03);
|
||||
$this->getLevel()->setBlock($block, $this, true, true); //Bottom
|
||||
$this->getLevel()->setBlock($blockUp, $b = Block::get($this->getId(), $metaUp), true); //Top
|
||||
$this->getLevel()->setBlock($blockUp, $b = BlockFactory::get($this->getId(), $metaUp), true); //Top
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -250,15 +250,15 @@ abstract class Door extends Transparent{
|
||||
if(($this->getDamage() & 0x08) === 0x08){
|
||||
$down = $this->getSide(Vector3::SIDE_DOWN);
|
||||
if($down->getId() === $this->getId()){
|
||||
$this->getLevel()->setBlock($down, Block::get(Block::AIR), true);
|
||||
$this->getLevel()->setBlock($down, BlockFactory::get(Block::AIR), true);
|
||||
}
|
||||
}else{
|
||||
$up = $this->getSide(Vector3::SIDE_UP);
|
||||
if($up->getId() === $this->getId()){
|
||||
$this->getLevel()->setBlock($up, Block::get(Block::AIR), true);
|
||||
$this->getLevel()->setBlock($up, BlockFactory::get(Block::AIR), true);
|
||||
}
|
||||
}
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -268,7 +268,7 @@ abstract class Door extends Transparent{
|
||||
$down = $this->getSide(Vector3::SIDE_DOWN);
|
||||
if($down->getId() === $this->getId()){
|
||||
$meta = $down->getDamage() ^ 0x04;
|
||||
$this->level->setBlock($down, Block::get($this->getId(), $meta), true);
|
||||
$this->level->setBlock($down, BlockFactory::get($this->getId(), $meta), true);
|
||||
$this->level->addSound(new DoorSound($this));
|
||||
return true;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ class DoublePlant extends Flowable{
|
||||
$id = $block->getSide(Vector3::SIDE_DOWN)->getId();
|
||||
if(($id === Block::GRASS or $id === Block::DIRT) and $block->getSide(Vector3::SIDE_UP)->canBeReplaced()){
|
||||
$this->getLevel()->setBlock($block, $this, false, false);
|
||||
$this->getLevel()->setBlock($block->getSide(Vector3::SIDE_UP), Block::get($this->id, $this->meta | self::BITFLAG_TOP), false, false);
|
||||
$this->getLevel()->setBlock($block->getSide(Vector3::SIDE_UP), BlockFactory::get($this->id, $this->meta | self::BITFLAG_TOP), false, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -98,7 +98,7 @@ class DoublePlant extends Flowable{
|
||||
|
||||
public function onBreak(Item $item) : bool{
|
||||
if(parent::onBreak($item) and $this->isValidHalfPlant()){
|
||||
return $this->getLevel()->setBlock($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), Block::get(Block::AIR));
|
||||
return $this->getLevel()->setBlock($this->getSide(($this->meta & self::BITFLAG_TOP) !== 0 ? Vector3::SIDE_DOWN : Vector3::SIDE_UP), BlockFactory::get(Block::AIR));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -39,7 +39,7 @@ abstract class Fallable extends Solid{
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
$down = $this->getSide(Vector3::SIDE_DOWN);
|
||||
if($down->getId() === self::AIR or ($down instanceof Liquid)){
|
||||
$this->level->setBlock($this, Block::get(Block::AIR), true, true);
|
||||
$this->level->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||
$fall = Entity::createEntity("FallingSand", $this->getLevel(), new CompoundTag("", [
|
||||
new ListTag("Pos", [
|
||||
new DoubleTag("", $this->x + 0.5),
|
||||
|
@ -87,14 +87,14 @@ class Fire extends Flowable{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||
if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::NETHERRACK){
|
||||
if(mt_rand(0, 2) === 0){
|
||||
if($this->meta === 0x0F){
|
||||
$this->level->setBlock($this, Block::get(Block::AIR));
|
||||
$this->level->setBlock($this, BlockFactory::get(Block::AIR));
|
||||
}else{
|
||||
$this->meta++;
|
||||
$this->level->setBlock($this, $this);
|
||||
|
@ -39,7 +39,7 @@ class GlowingRedstoneOre extends RedstoneOre{
|
||||
|
||||
public function onUpdate(int $type){
|
||||
if($type === Level::BLOCK_UPDATE_SCHEDULED or $type === Level::BLOCK_UPDATE_RANDOM){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::REDSTONE_ORE, $this->meta), false, false);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::REDSTONE_ORE, $this->meta), false, false);
|
||||
|
||||
return Level::BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
|
@ -61,9 +61,9 @@ class Grass extends Solid{
|
||||
public function onUpdate(int $type){
|
||||
if($type === Level::BLOCK_UPDATE_RANDOM){
|
||||
$lightAbove = $this->level->getFullLightAt($this->x, $this->y + 1, $this->z);
|
||||
if($lightAbove < 4 and Block::$lightFilter[$this->level->getBlockIdAt($this->x, $this->y + 1, $this->z)] >= 3){ //2 plus 1 standard filter amount
|
||||
if($lightAbove < 4 and BlockFactory::$lightFilter[$this->level->getBlockIdAt($this->x, $this->y + 1, $this->z)] >= 3){ //2 plus 1 standard filter amount
|
||||
//grass dies
|
||||
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this, $this, Block::get(Block::DIRT)));
|
||||
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this, $this, BlockFactory::get(Block::DIRT)));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->level->setBlock($this, $ev->getNewState(), false, false);
|
||||
}
|
||||
@ -79,12 +79,12 @@ class Grass extends Solid{
|
||||
if(
|
||||
$this->level->getBlockIdAt($vector->x, $vector->y, $vector->z) !== Block::DIRT or
|
||||
$this->level->getFullLightAt($vector->x, $vector->y + 1, $vector->z) < 4 or
|
||||
Block::$lightFilter[$this->level->getBlockIdAt($vector->x, $vector->y + 1, $vector->z)] >= 3
|
||||
BlockFactory::$lightFilter[$this->level->getBlockIdAt($vector->x, $vector->y + 1, $vector->z)] >= 3
|
||||
){
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this->level->getBlock($vector), $this, Block::get(Block::GRASS)));
|
||||
$this->level->getServer()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($this->level->getBlock($vector), $this, BlockFactory::get(Block::GRASS)));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->level->setBlock($vector, $ev->getNewState(), false, false);
|
||||
}
|
||||
@ -105,12 +105,12 @@ class Grass extends Solid{
|
||||
return true;
|
||||
}elseif($item->isHoe()){
|
||||
$item->useOn($this);
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::FARMLAND));
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FARMLAND));
|
||||
|
||||
return true;
|
||||
}elseif($item->isShovel() and $this->getSide(Vector3::SIDE_UP)->getId() === Block::AIR){
|
||||
$item->useOn($this);
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::GRASS_PATH));
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GRASS_PATH));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class Ice extends Transparent{
|
||||
}
|
||||
|
||||
public function onBreak(Item $item) : bool{
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::WATER), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::WATER), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -241,9 +241,9 @@ abstract class Liquid extends Transparent{
|
||||
if($k !== $decay){
|
||||
$decay = $k;
|
||||
if($decay < 0){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||
}else{
|
||||
$this->getLevel()->setBlock($this, Block::get($this->id, $decay), true, true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get($this->id, $decay), true, true);
|
||||
$this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate());
|
||||
}
|
||||
}elseif($flag){
|
||||
@ -257,10 +257,10 @@ abstract class Liquid extends Transparent{
|
||||
$bottomBlock = $this->level->getBlock($this->temporalVector->setComponents($this->x, $this->y - 1, $this->z));
|
||||
|
||||
if($this instanceof Lava and $bottomBlock instanceof Water){
|
||||
$this->getLevel()->setBlock($bottomBlock, Block::get(Block::STONE), true, true);
|
||||
$this->getLevel()->setBlock($bottomBlock, BlockFactory::get(Block::STONE), true, true);
|
||||
|
||||
}elseif($bottomBlock->canBeFlowedInto() or ($bottomBlock instanceof Liquid and ($bottomBlock->getDamage() & 0x07) !== 0)){
|
||||
$this->getLevel()->setBlock($bottomBlock, Block::get($this->id, $decay | 0x08), true, false);
|
||||
$this->getLevel()->setBlock($bottomBlock, BlockFactory::get($this->id, $decay | 0x08), true, false);
|
||||
$this->getLevel()->scheduleDelayedBlockUpdate($bottomBlock, $this->tickRate());
|
||||
|
||||
}elseif($decay >= 0 and ($decay === 0 or !$bottomBlock->canBeFlowedInto())){
|
||||
@ -305,7 +305,7 @@ abstract class Liquid extends Transparent{
|
||||
$this->getLevel()->useBreakOn($block);
|
||||
}
|
||||
|
||||
$this->getLevel()->setBlock($block, Block::get($this->getId(), $newFlowDecay), true, false);
|
||||
$this->getLevel()->setBlock($block, BlockFactory::get($this->getId(), $newFlowDecay), true, false);
|
||||
$this->getLevel()->scheduleDelayedBlockUpdate($block, $this->tickRate());
|
||||
}
|
||||
}
|
||||
@ -434,9 +434,9 @@ abstract class Liquid extends Transparent{
|
||||
|
||||
if($colliding){
|
||||
if($this->getDamage() === 0){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::OBSIDIAN), true, true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::OBSIDIAN), true, true);
|
||||
}elseif($this->getDamage() <= 4){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::COBBLESTONE), true, true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::COBBLESTONE), true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class MelonStem extends Crops{
|
||||
$side = $this->getSide(mt_rand(2, 5));
|
||||
$d = $side->getSide(Vector3::SIDE_DOWN);
|
||||
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, Block::get(Block::MELON_BLOCK)));
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::MELON_BLOCK)));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class Mycelium extends Solid{
|
||||
$block = $this->getLevel()->getBlock(new Vector3($x, $y, $z));
|
||||
if($block->getId() === Block::DIRT){
|
||||
if($block->getSide(Vector3::SIDE_UP) instanceof Transparent){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, Block::get(Block::MYCELIUM)));
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockSpreadEvent($block, $this, BlockFactory::get(Block::MYCELIUM)));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($block, $ev->getNewState());
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class PumpkinStem extends Crops{
|
||||
$side = $this->getSide(mt_rand(2, 5));
|
||||
$d = $side->getSide(Vector3::SIDE_DOWN);
|
||||
if($side->getId() === self::AIR and ($d->getId() === self::FARMLAND or $d->getId() === self::GRASS or $d->getId() === self::DIRT)){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, Block::get(Block::PUMPKIN)));
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($side, BlockFactory::get(Block::PUMPKIN)));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($side, $ev->getNewState(), true);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class RedstoneOre extends Solid{
|
||||
|
||||
public function onUpdate(int $type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL or $type === Level::BLOCK_UPDATE_TOUCH){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::GLOWING_REDSTONE_ORE, $this->meta));
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::GLOWING_REDSTONE_ORE, $this->meta));
|
||||
|
||||
return Level::BLOCK_UPDATE_WEAK;
|
||||
}
|
||||
|
@ -68,13 +68,13 @@ class SnowLayer extends Flowable{
|
||||
public function onUpdate(int $type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if(!$this->getSide(Vector3::SIDE_DOWN)->isSolid()){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), false, false);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false, false);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){
|
||||
if($this->level->getBlockLightAt($this->x, $this->y, $this->z) >= 12){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), false, false);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), false, false);
|
||||
|
||||
return Level::BLOCK_UPDATE_RANDOM;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class Sugarcane extends Flowable{
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getId() === self::AIR){
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, Block::get(Block::SUGARCANE_BLOCK)));
|
||||
Server::getInstance()->getPluginManager()->callEvent($ev = new BlockGrowEvent($b, BlockFactory::get(Block::SUGARCANE_BLOCK)));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($b, $ev->getNewState(), true);
|
||||
}
|
||||
@ -84,7 +84,7 @@ class Sugarcane extends Flowable{
|
||||
for($y = 1; $y < 3; ++$y){
|
||||
$b = $this->getLevel()->getBlock(new Vector3($this->x, $this->y + $y, $this->z));
|
||||
if($b->getId() === self::AIR){
|
||||
$this->getLevel()->setBlock($b, Block::get(Block::SUGARCANE_BLOCK), true);
|
||||
$this->getLevel()->setBlock($b, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,7 @@ class Sugarcane extends Flowable{
|
||||
public function place(Item $item, Block $block, Block $target, int $face, Vector3 $facePos, Player $player = null) : bool{
|
||||
$down = $this->getSide(Vector3::SIDE_DOWN);
|
||||
if($down->getId() === self::SUGARCANE_BLOCK){
|
||||
$this->getLevel()->setBlock($block, Block::get(Block::SUGARCANE_BLOCK), true);
|
||||
$this->getLevel()->setBlock($block, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
|
||||
|
||||
return true;
|
||||
}elseif($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::SAND){
|
||||
@ -114,7 +114,7 @@ class Sugarcane extends Flowable{
|
||||
$block2 = $down->getSide(Vector3::SIDE_WEST);
|
||||
$block3 = $down->getSide(Vector3::SIDE_EAST);
|
||||
if(($block0 instanceof Water) or ($block1 instanceof Water) or ($block2 instanceof Water) or ($block3 instanceof Water)){
|
||||
$this->getLevel()->setBlock($block, Block::get(Block::SUGARCANE_BLOCK), true);
|
||||
$this->getLevel()->setBlock($block, BlockFactory::get(Block::SUGARCANE_BLOCK), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class TNT extends Solid{
|
||||
}
|
||||
|
||||
public function ignite(int $fuse = 80){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true);
|
||||
|
||||
$mot = (new Random())->nextSignedFloat() * M_PI * 2;
|
||||
$tnt = Entity::createEntity("PrimedTNT", $this->getLevel(), new CompoundTag("", [
|
||||
|
@ -64,7 +64,7 @@ class TallGrass extends Flowable{
|
||||
public function onUpdate(int $type){
|
||||
if($type === Level::BLOCK_UPDATE_NORMAL){
|
||||
if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ //Replace with common break method
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::AIR), true, true);
|
||||
|
||||
return Level::BLOCK_UPDATE_NORMAL;
|
||||
}
|
||||
|
@ -86,11 +86,11 @@ class WoodenSlab extends Transparent{
|
||||
$this->meta &= 0x07;
|
||||
if($face === Vector3::SIDE_DOWN){
|
||||
if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === $this->meta){
|
||||
$this->getLevel()->setBlock($target, Block::get($this->doubleId, $this->meta), true);
|
||||
$this->getLevel()->setBlock($target, BlockFactory::get($this->doubleId, $this->meta), true);
|
||||
|
||||
return true;
|
||||
}elseif($block->getId() === $this->id and ($block->getDamage() & 0x07) === $this->meta){
|
||||
$this->getLevel()->setBlock($block, Block::get($this->doubleId, $this->meta), true);
|
||||
$this->getLevel()->setBlock($block, BlockFactory::get($this->doubleId, $this->meta), true);
|
||||
|
||||
return true;
|
||||
}else{
|
||||
@ -98,18 +98,18 @@ class WoodenSlab extends Transparent{
|
||||
}
|
||||
}elseif($face === Vector3::SIDE_UP){
|
||||
if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0 and ($target->getDamage() & 0x07) === $this->meta){
|
||||
$this->getLevel()->setBlock($target, Block::get($this->doubleId, $this->meta), true);
|
||||
$this->getLevel()->setBlock($target, BlockFactory::get($this->doubleId, $this->meta), true);
|
||||
|
||||
return true;
|
||||
}elseif($block->getId() === $this->id and ($block->getDamage() & 0x07) === $this->meta){
|
||||
$this->getLevel()->setBlock($block, Block::get($this->doubleId, $this->meta), true);
|
||||
$this->getLevel()->setBlock($block, BlockFactory::get($this->doubleId, $this->meta), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
}else{ //TODO: collision
|
||||
if($block->getId() === $this->id){
|
||||
if(($block->getDamage() & 0x07) === $this->meta){
|
||||
$this->getLevel()->setBlock($block, Block::get($this->doubleId, $this->meta), true);
|
||||
$this->getLevel()->setBlock($block, BlockFactory::get($this->doubleId, $this->meta), true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\command\defaults;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\command\CommandSender;
|
||||
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||
use pocketmine\event\TranslationContainer;
|
||||
@ -183,7 +183,7 @@ class ParticleCommand extends VanillaCommand{
|
||||
break;
|
||||
case "terrain":
|
||||
if($data !== null and $data !== 0){
|
||||
return new TerrainParticle($pos, Block::get($data));
|
||||
return new TerrainParticle($pos, BlockFactory::get($data));
|
||||
}
|
||||
break;
|
||||
case "heart":
|
||||
@ -211,7 +211,7 @@ class ParticleCommand extends VanillaCommand{
|
||||
}elseif(strpos($name, "blockcrack_") === 0){
|
||||
$d = explode("_", $name);
|
||||
if(count($d) === 2){
|
||||
return new TerrainParticle($pos, Block::get($d[1] & 0xff, $d[1] >> 12));
|
||||
return new TerrainParticle($pos, BlockFactory::get($d[1] & 0xff, $d[1] >> 12));
|
||||
}
|
||||
}elseif(strpos($name, "blockdust_") === 0){
|
||||
$d = explode("_", $name);
|
||||
|
@ -27,6 +27,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Water;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\event\entity\EntityDespawnEvent;
|
||||
@ -1011,13 +1012,13 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$diffY = $y - $j;
|
||||
$diffZ = $z - $k;
|
||||
|
||||
if(Block::$solid[$this->level->getBlockIdAt($i, $j, $k)]){
|
||||
$flag = !Block::$solid[$this->level->getBlockIdAt($i - 1, $j, $k)];
|
||||
$flag1 = !Block::$solid[$this->level->getBlockIdAt($i + 1, $j, $k)];
|
||||
$flag2 = !Block::$solid[$this->level->getBlockIdAt($i, $j - 1, $k)];
|
||||
$flag3 = !Block::$solid[$this->level->getBlockIdAt($i, $j + 1, $k)];
|
||||
$flag4 = !Block::$solid[$this->level->getBlockIdAt($i, $j, $k - 1)];
|
||||
$flag5 = !Block::$solid[$this->level->getBlockIdAt($i, $j, $k + 1)];
|
||||
if(BlockFactory::$solid[$this->level->getBlockIdAt($i, $j, $k)]){
|
||||
$flag = !BlockFactory::$solid[$this->level->getBlockIdAt($i - 1, $j, $k)];
|
||||
$flag1 = !BlockFactory::$solid[$this->level->getBlockIdAt($i + 1, $j, $k)];
|
||||
$flag2 = !BlockFactory::$solid[$this->level->getBlockIdAt($i, $j - 1, $k)];
|
||||
$flag3 = !BlockFactory::$solid[$this->level->getBlockIdAt($i, $j + 1, $k)];
|
||||
$flag4 = !BlockFactory::$solid[$this->level->getBlockIdAt($i, $j, $k - 1)];
|
||||
$flag5 = !BlockFactory::$solid[$this->level->getBlockIdAt($i, $j, $k + 1)];
|
||||
|
||||
$direction = -1;
|
||||
$limit = 9999;
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\event\entity\EntityBlockChangeEvent;
|
||||
use pocketmine\event\entity\EntityDamageEvent;
|
||||
use pocketmine\item\Item as ItemItem;
|
||||
@ -117,7 +117,7 @@ class FallingSand extends Entity{
|
||||
//FIXME: anvils are supposed to destroy torches
|
||||
$this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1));
|
||||
}else{
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));
|
||||
$this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, BlockFactory::get($this->getBlock(), $this->getDamage())));
|
||||
if(!$ev->isCancelled()){
|
||||
$this->getLevel()->setBlock($pos, $ev->getTo(), true);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\event\player;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\event\Cancellable;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\level\Position;
|
||||
@ -63,7 +64,7 @@ class PlayerInteractEvent extends PlayerEvent implements Cancellable{
|
||||
$this->touchVector = new Vector3(0, 0, 0);
|
||||
}else{
|
||||
$this->touchVector = $block;
|
||||
$this->blockTouched = Block::get(0, 0, new Position(0, 0, 0, $player->level));
|
||||
$this->blockTouched = BlockFactory::get(0, 0, new Position(0, 0, 0, $player->level));
|
||||
}
|
||||
$this->player = $player;
|
||||
$this->item = $item;
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Bed extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::BED_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::BED_BLOCK);
|
||||
parent::__construct(self::BED, $meta, $count, "Bed");
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class BeetrootSeeds extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::BEETROOT_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::BEETROOT_BLOCK);
|
||||
parent::__construct(self::BEETROOT_SEEDS, $meta, $count, "Beetroot Seeds");
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Air;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Liquid;
|
||||
use pocketmine\event\player\PlayerBucketFillEvent;
|
||||
use pocketmine\level\Level;
|
||||
@ -49,7 +50,7 @@ class Bucket extends Item{
|
||||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
||||
$targetBlock = Block::get($this->meta);
|
||||
$targetBlock = BlockFactory::get($this->meta);
|
||||
|
||||
if($targetBlock instanceof Air){
|
||||
if($target instanceof Liquid and $target->getDamage() === 0){
|
||||
@ -57,7 +58,7 @@ class Bucket extends Item{
|
||||
$result->setDamage($target->getId());
|
||||
$player->getServer()->getPluginManager()->callEvent($ev = new PlayerBucketFillEvent($player, $block, $face, $this, $result));
|
||||
if(!$ev->isCancelled()){
|
||||
$player->getLevel()->setBlock($target, Block::get(Block::AIR), true, true);
|
||||
$player->getLevel()->setBlock($target, BlockFactory::get(Block::AIR), true, true);
|
||||
if($player->isSurvival()){
|
||||
$player->getInventory()->setItemInHand($ev->getItem());
|
||||
}
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Cake extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::CAKE_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::CAKE_BLOCK);
|
||||
parent::__construct(self::CAKE, $meta, $count, "Cake");
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Carrot extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::CARROT_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::CARROT_BLOCK);
|
||||
parent::__construct(self::CARROT, $meta, $count, "Carrot");
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Fire;
|
||||
use pocketmine\block\Solid;
|
||||
use pocketmine\level\Level;
|
||||
@ -37,7 +38,7 @@ class FlintSteel extends Tool{
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, int $face, Vector3 $facePos) : bool{
|
||||
if($block->getId() === self::AIR and ($target instanceof Solid)){
|
||||
$level->setBlock($block, Block::get(Block::FIRE), true);
|
||||
$level->setBlock($block, BlockFactory::get(Block::FIRE), true);
|
||||
if(($player->gamemode & 0x01) === 0 and $this->useOn($block)){
|
||||
if($this->getDamage() >= $this->getMaxDurability()){
|
||||
$player->getInventory()->setItemInHand(new Item(Item::AIR, 0, 0));
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class FlowerPot extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::FLOWER_POT_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::FLOWER_POT_BLOCK);
|
||||
parent::__construct(self::FLOWER_POT, $meta, $count, "Flower Pot");
|
||||
}
|
||||
}
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class IronDoor extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::IRON_DOOR_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::IRON_DOOR_BLOCK);
|
||||
parent::__construct(self::IRON_DOOR, $meta, $count, "Iron Door");
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\item\enchantment\Enchantment;
|
||||
use pocketmine\level\Level;
|
||||
@ -328,7 +329,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
public static function get(int $id, int $meta = 0, int $count = 1, $tags = "") : Item{
|
||||
try{
|
||||
if($id < 256){
|
||||
return (new ItemBlock(Block::get($id, $meta), $meta, $count))->setCompoundTag($tags);
|
||||
return (new ItemBlock(BlockFactory::get($id, $meta), $meta, $count))->setCompoundTag($tags);
|
||||
}else{
|
||||
$class = self::$list[$id];
|
||||
if($class === null){
|
||||
@ -388,8 +389,8 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
$this->meta = $meta !== -1 ? $meta & 0xffff : -1;
|
||||
$this->count = $count;
|
||||
$this->name = $name;
|
||||
if(!isset($this->block) and $this->id <= 0xff and isset(Block::$list[$this->id])){
|
||||
$this->block = Block::get($this->id, $this->meta);
|
||||
if(!isset($this->block) and $this->id <= 0xff and isset(BlockFactory::$list[$this->id])){
|
||||
$this->block = BlockFactory::get($this->id, $this->meta);
|
||||
$this->name = $this->block->getName();
|
||||
}
|
||||
}
|
||||
@ -874,7 +875,7 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
if($this->block instanceof Block){
|
||||
return clone $this->block;
|
||||
}else{
|
||||
return Block::get(self::AIR);
|
||||
return BlockFactory::get(self::AIR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class ItemFrame extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::ITEM_FRAME_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::ITEM_FRAME_BLOCK);
|
||||
parent::__construct(self::ITEM_FRAME, $meta, $count, "Item Frame");
|
||||
}
|
||||
}
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class MelonSeeds extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::MELON_STEM);
|
||||
$this->block = BlockFactory::get(Block::MELON_STEM);
|
||||
parent::__construct(self::MELON_SEEDS, $meta, $count, "Melon Seeds");
|
||||
}
|
||||
}
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class NetherWart extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::NETHER_WART_PLANT);
|
||||
$this->block = BlockFactory::get(Block::NETHER_WART_PLANT);
|
||||
parent::__construct(self::NETHER_WART, $meta, $count, "Nether Wart");
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Potato extends Food{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::POTATO_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::POTATO_BLOCK);
|
||||
parent::__construct(self::POTATO, $meta, $count, "Potato");
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class PumpkinSeeds extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::PUMPKIN_STEM);
|
||||
$this->block = BlockFactory::get(Block::PUMPKIN_STEM);
|
||||
parent::__construct(self::PUMPKIN_SEEDS, $meta, $count, "Pumpkin Seeds");
|
||||
}
|
||||
}
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Sign extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::SIGN_POST);
|
||||
$this->block = BlockFactory::get(Block::SIGN_POST);
|
||||
parent::__construct(self::SIGN, $meta, $count, "Sign");
|
||||
}
|
||||
|
||||
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Skull extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::SKULL_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::SKULL_BLOCK);
|
||||
parent::__construct(self::SKULL, $meta, $count, "Mob Head");
|
||||
}
|
||||
}
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class Sugarcane extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::SUGARCANE_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::SUGARCANE_BLOCK);
|
||||
parent::__construct(self::SUGARCANE, $meta, $count, "Sugar Cane");
|
||||
}
|
||||
}
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class WheatSeeds extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::WHEAT_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::WHEAT_BLOCK);
|
||||
parent::__construct(self::WHEAT_SEEDS, $meta, $count, "Wheat Seeds");
|
||||
}
|
||||
}
|
@ -24,10 +24,11 @@ declare(strict_types=1);
|
||||
namespace pocketmine\item;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
class WoodenDoor extends Item{
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
$this->block = Block::get(Block::WOODEN_DOOR_BLOCK);
|
||||
$this->block = BlockFactory::get(Block::WOODEN_DOOR_BLOCK);
|
||||
parent::__construct(self::WOODEN_DOOR, $meta, $count, "Wooden Door");
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\level;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\TNT;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\event\block\BlockUpdateEvent;
|
||||
@ -120,10 +121,10 @@ class Explosion{
|
||||
$blockId = $currentSubChunk->getBlockId($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f);
|
||||
|
||||
if($blockId !== 0){
|
||||
$blastForce -= (Block::$blastResistance[$blockId] / 5 + 0.3) * $this->stepLen;
|
||||
$blastForce -= (BlockFactory::$blastResistance[$blockId] / 5 + 0.3) * $this->stepLen;
|
||||
if($blastForce > 0){
|
||||
if(!isset($this->affectedBlocks[$index = Level::blockHash($vBlock->x, $vBlock->y, $vBlock->z)])){
|
||||
$this->affectedBlocks[$index] = Block::get($blockId, $currentSubChunk->getBlockData($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f), $vBlock);
|
||||
$this->affectedBlocks[$index] = BlockFactory::get($blockId, $currentSubChunk->getBlockData($vBlock->x & 0x0f, $vBlock->y & 0x0f, $vBlock->z & 0x0f), $vBlock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ namespace pocketmine\level;
|
||||
use pocketmine\block\Air;
|
||||
use pocketmine\block\Beetroot;
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\BrownMushroom;
|
||||
use pocketmine\block\Cactus;
|
||||
use pocketmine\block\Carrot;
|
||||
@ -313,7 +314,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(Server $server, string $name, string $path, string $provider){
|
||||
$this->blockStates = Block::$fullList;
|
||||
$this->blockStates = BlockFactory::$fullList;
|
||||
$this->levelId = static::$levelIdCounter++;
|
||||
$this->blockMetadata = new BlockMetadataStore($this);
|
||||
$this->server = $server;
|
||||
@ -915,7 +916,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
}
|
||||
|
||||
public function addRandomTickedBlock(int $id){
|
||||
$this->randomTickBlocks[$id] = get_class(Block::$list[$id]);
|
||||
$this->randomTickBlocks[$id] = get_class(BlockFactory::$list[$id]);
|
||||
}
|
||||
|
||||
public function removeRandomTickedBlock(int $id){
|
||||
@ -1392,7 +1393,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
if($yPlusOne === $oldHeightMap){ //Block changed directly beneath the heightmap. Check if a block was removed or changed to a different light-filter.
|
||||
$newHeightMap = $this->getChunk($x >> 4, $z >> 4)->recalculateHeightMapColumn($x & 0x0f, $z & 0x0f);
|
||||
}elseif($yPlusOne > $oldHeightMap){ //Block changed above the heightmap.
|
||||
if(Block::$lightFilter[$sourceId] > 1 or Block::$diffusesSkyLight[$sourceId]){
|
||||
if(BlockFactory::$lightFilter[$sourceId] > 1 or BlockFactory::$diffusesSkyLight[$sourceId]){
|
||||
$this->setHeightMap($x, $z, $yPlusOne);
|
||||
$newHeightMap = $yPlusOne;
|
||||
}else{ //Block changed which has no effect on direct sky light, for example placing or removing glass.
|
||||
@ -1414,7 +1415,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$update->setAndUpdateLight($x, $i, $z, 15);
|
||||
}
|
||||
}else{ //No heightmap change, block changed "underground"
|
||||
$update->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - Block::$lightFilter[$sourceId]));
|
||||
$update->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - BlockFactory::$lightFilter[$sourceId]));
|
||||
}
|
||||
|
||||
$update->execute();
|
||||
@ -1446,7 +1447,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->timings->doBlockLightUpdates->startTiming();
|
||||
|
||||
$id = $this->getBlockIdAt($x, $y, $z);
|
||||
$newLevel = max(Block::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - Block::$lightFilter[$id]);
|
||||
$newLevel = max(BlockFactory::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - BlockFactory::$lightFilter[$id]);
|
||||
|
||||
$update = new BlockLightUpdate($this);
|
||||
$update->setAndUpdateLight($x, $y, $z, $newLevel);
|
||||
@ -1656,7 +1657,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$above = $this->getBlock(new Vector3($target->x, $target->y + 1, $target->z));
|
||||
if($above !== null){
|
||||
if($above->getId() === Item::FIRE){
|
||||
$this->setBlock($above, Block::get(Block::AIR), true);
|
||||
$this->setBlock($above, BlockFactory::get(Block::AIR), true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2686,7 +2687,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
$wasAir = ($chunk->getBlockId($x, $y - 1, $z) === 0);
|
||||
for(; $y > 0; --$y){
|
||||
$b = $chunk->getFullBlock($x, $y, $z);
|
||||
$block = Block::get($b >> 4, $b & 0x0f);
|
||||
$block = BlockFactory::get($b >> 4, $b & 0x0f);
|
||||
if($this->isFullBlock($block)){
|
||||
if($wasAir){
|
||||
$y++;
|
||||
@ -2699,10 +2700,10 @@ class Level implements ChunkManager, Metadatable{
|
||||
|
||||
for(; $y >= 0 and $y < $max; ++$y){
|
||||
$b = $chunk->getFullBlock($x, $y + 1, $z);
|
||||
$block = Block::get($b >> 4, $b & 0x0f);
|
||||
$block = BlockFactory::get($b >> 4, $b & 0x0f);
|
||||
if(!$this->isFullBlock($block)){
|
||||
$b = $chunk->getFullBlock($x, $y, $z);
|
||||
$block = Block::get($b >> 4, $b & 0x0f);
|
||||
$block = BlockFactory::get($b >> 4, $b & 0x0f);
|
||||
if(!$this->isFullBlock($block)){
|
||||
return new Position($spawn->x, $y === (int) $spawn->y ? $spawn->y : $y, $spawn->z, $this);
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\format;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\nbt\NBT;
|
||||
@ -438,7 +438,7 @@ class Chunk{
|
||||
public function recalculateHeightMapColumn(int $x, int $z) : int{
|
||||
$max = $this->getHighestBlockAt($x, $z);
|
||||
for($y = $max; $y >= 0; --$y){
|
||||
if(Block::$lightFilter[$id = $this->getBlockId($x, $y, $z)] > 1 or Block::$diffusesSkyLight[$id]){
|
||||
if(BlockFactory::$lightFilter[$id = $this->getBlockId($x, $y, $z)] > 1 or BlockFactory::$diffusesSkyLight[$id]){
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -470,7 +470,7 @@ class Chunk{
|
||||
$light = 15;
|
||||
for(; $y >= 0; --$y){
|
||||
if($light > 0){
|
||||
$light -= Block::$lightFilter[$this->getBlockId($x, $y, $z)];
|
||||
$light -= BlockFactory::$lightFilter[$this->getBlockId($x, $y, $z)];
|
||||
if($light <= 0){
|
||||
break;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\generator;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\level\generator\biome\Biome;
|
||||
use pocketmine\level\Level;
|
||||
use pocketmine\level\SimpleChunkManager;
|
||||
@ -47,7 +47,7 @@ class GeneratorRegisterTask extends AsyncTask{
|
||||
}
|
||||
|
||||
public function onRun(){
|
||||
Block::init();
|
||||
BlockFactory::init();
|
||||
Biome::init();
|
||||
$manager = new SimpleChunkManager($this->seed, $this->worldHeight);
|
||||
$this->saveToThreadStore("generation.level{$this->levelId}.manager", $manager);
|
||||
|
@ -24,16 +24,17 @@ declare(strict_types=1);
|
||||
namespace pocketmine\level\generator\normal\biome;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
abstract class GrassyBiome extends NormalBiome{
|
||||
|
||||
public function __construct(){
|
||||
$this->setGroundCover([
|
||||
Block::get(Block::GRASS, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
BlockFactory::get(Block::GRASS, 0),
|
||||
BlockFactory::get(Block::DIRT, 0),
|
||||
BlockFactory::get(Block::DIRT, 0),
|
||||
BlockFactory::get(Block::DIRT, 0),
|
||||
BlockFactory::get(Block::DIRT, 0),
|
||||
]);
|
||||
}
|
||||
}
|
@ -24,16 +24,17 @@ declare(strict_types=1);
|
||||
namespace pocketmine\level\generator\normal\biome;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
abstract class SandyBiome extends NormalBiome{
|
||||
|
||||
public function __construct(){
|
||||
$this->setGroundCover([
|
||||
Block::get(Block::SAND, 0),
|
||||
Block::get(Block::SAND, 0),
|
||||
Block::get(Block::SANDSTONE, 0),
|
||||
Block::get(Block::SANDSTONE, 0),
|
||||
Block::get(Block::SANDSTONE, 0)
|
||||
BlockFactory::get(Block::SAND, 0),
|
||||
BlockFactory::get(Block::SAND, 0),
|
||||
BlockFactory::get(Block::SANDSTONE, 0),
|
||||
BlockFactory::get(Block::SANDSTONE, 0),
|
||||
BlockFactory::get(Block::SANDSTONE, 0)
|
||||
]);
|
||||
}
|
||||
}
|
@ -24,16 +24,17 @@ declare(strict_types=1);
|
||||
namespace pocketmine\level\generator\normal\biome;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
|
||||
abstract class SnowyBiome extends NormalBiome{
|
||||
|
||||
public function __construct(){
|
||||
$this->setGroundCover([
|
||||
Block::get(Block::SNOW_LAYER, 0),
|
||||
Block::get(Block::GRASS, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0),
|
||||
Block::get(Block::DIRT, 0)
|
||||
BlockFactory::get(Block::SNOW_LAYER, 0),
|
||||
BlockFactory::get(Block::GRASS, 0),
|
||||
BlockFactory::get(Block::DIRT, 0),
|
||||
BlockFactory::get(Block::DIRT, 0),
|
||||
BlockFactory::get(Block::DIRT, 0)
|
||||
]);
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Wood;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
@ -60,7 +61,7 @@ class SpruceTree extends Tree{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!Block::$solid[$level->getBlockIdAt($xx, $yyy, $zz)]){
|
||||
if(!BlockFactory::$solid[$level->getBlockIdAt($xx, $yyy, $zz)]){
|
||||
$level->setBlockIdAt($xx, $yyy, $zz, $this->leafBlock);
|
||||
$level->setBlockDataAt($xx, $yyy, $zz, $this->type);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\level\generator\object;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\block\Sapling;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\utils\Random;
|
||||
@ -107,7 +108,7 @@ abstract class Tree{
|
||||
if($xOff === $mid and $zOff === $mid and ($yOff === 0 or $random->nextBoundedInt(2) === 0)){
|
||||
continue;
|
||||
}
|
||||
if(!Block::$solid[$level->getBlockIdAt($xx, $yy, $zz)]){
|
||||
if(!BlockFactory::$solid[$level->getBlockIdAt($xx, $yy, $zz)]){
|
||||
$level->setBlockIdAt($xx, $yy, $zz, $this->leafBlock);
|
||||
$level->setBlockDataAt($xx, $yy, $zz, $this->type);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\generator\populator;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\level\generator\biome\Biome;
|
||||
use pocketmine\utils\Random;
|
||||
@ -44,7 +44,7 @@ class GroundCover extends Populator{
|
||||
|
||||
$column = $chunk->getBlockIdColumn($x, $z);
|
||||
for($y = 127; $y > 0; --$y){
|
||||
if($column{$y} !== "\x00" and !Block::get(ord($column{$y}))->isTransparent()){
|
||||
if($column{$y} !== "\x00" and !BlockFactory::get(ord($column{$y}))->isTransparent()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\level\light;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\level\ChunkManager;
|
||||
use pocketmine\level\Level;
|
||||
|
||||
@ -153,7 +153,7 @@ abstract class LightUpdate{
|
||||
|
||||
protected function computeSpreadLight(int $x, int $y, int $z, int $newAdjacentLevel){
|
||||
$current = $this->getLight($x, $y, $z);
|
||||
$potentialLight = $newAdjacentLevel - Block::$lightFilter[$this->level->getBlockIdAt($x, $y, $z)];
|
||||
$potentialLight = $newAdjacentLevel - BlockFactory::$lightFilter[$this->level->getBlockIdAt($x, $y, $z)];
|
||||
|
||||
if($current < $potentialLight){
|
||||
$this->setLight($x, $y, $z, $potentialLight);
|
||||
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace pocketmine\tile;
|
||||
|
||||
use pocketmine\block\Block;
|
||||
use pocketmine\block\BlockFactory;
|
||||
use pocketmine\event\inventory\FurnaceBurnEvent;
|
||||
use pocketmine\event\inventory\FurnaceSmeltEvent;
|
||||
use pocketmine\inventory\FurnaceInventory;
|
||||
@ -191,7 +192,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
$this->namedtag->BurnTime->setValue($ev->getBurnTime());
|
||||
$this->namedtag->BurnTicks = new ShortTag("BurnTicks", 0);
|
||||
if($this->getBlock()->getId() === Item::FURNACE){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::BURNING_FURNACE, $this->getBlock()->getDamage()), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::BURNING_FURNACE, $this->getBlock()->getDamage()), true);
|
||||
}
|
||||
|
||||
if($this->namedtag->BurnTime->getValue() > 0 and $ev->isBurning()){
|
||||
@ -254,7 +255,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
$ret = true;
|
||||
}else{
|
||||
if($this->getBlock()->getId() === Item::BURNING_FURNACE){
|
||||
$this->getLevel()->setBlock($this, Block::get(Block::FURNACE, $this->getBlock()->getDamage()), true);
|
||||
$this->getLevel()->setBlock($this, BlockFactory::get(Block::FURNACE, $this->getBlock()->getDamage()), true);
|
||||
}
|
||||
$this->namedtag->BurnTime->setValue(0);
|
||||
$this->namedtag->CookTime->setValue(0);
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit e963064839334ce95e297df69bfe8af5fa95ab3a
|
||||
Subproject commit 5867bf4d03af74a2f667ae1c867200487f275f0f
|
Loading…
x
Reference in New Issue
Block a user