From 7b142d4742a5dd22e9c25067d235616ef0d5bc38 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 13:25:36 +0100 Subject: [PATCH 01/23] Generated some TODO comments for blocks --- src/pocketmine/block/Block.php | 75 ++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 8d8b7ccb38..561fbf8379 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -99,17 +99,18 @@ class Block extends Position implements BlockIds, Metadatable{ 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()); @@ -130,7 +131,7 @@ class Block extends Position implements BlockIds, Metadatable{ 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()); @@ -165,14 +166,17 @@ class Block extends Position implements BlockIds, Metadatable{ 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()); @@ -190,25 +194,27 @@ class Block extends Position implements BlockIds, Metadatable{ 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()); @@ -219,20 +225,23 @@ class Block extends Position implements BlockIds, Metadatable{ 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()); - + //TODO: NETHER_QUARTZ_ORE + //TODO: HOPPER_BLOCK self::registerBlock(new Quartz()); self::registerBlock(new QuartzStairs()); self::registerBlock(new DoubleWoodenSlab()); self::registerBlock(new WoodenSlab()); self::registerBlock(new StainedClay()); - + //TODO: STAINED_GLASS_PANE 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()); @@ -244,11 +253,18 @@ class Block extends Position implements BlockIds, Metadatable{ 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)); @@ -257,7 +273,22 @@ class Block extends Position implements BlockIds, Metadatable{ 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 + //TODO: END_ROD + //TODO: END_GATEWAY + + //TODO: MAGMA + //TODO: NETHER_WART_BLOCK + //TODO: RED_NETHER_BRICK + //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")); @@ -275,11 +306,23 @@ class Block extends Position implements BlockIds, Metadatable{ 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 + //TODO: STAINED_GLASS self::registerBlock(new Podzol()); self::registerBlock(new Beetroot()); self::registerBlock(new Stonecutter()); self::registerBlock(new GlowingObsidian()); + //TODO: NETHERREACTOR + //TODO: INFO_UPDATE + //TODO: INFO_UPDATE2 + //TODO: MOVINGBLOCK + //TODO: OBSERVER + + //TODO: RESERVED6 foreach(self::$list as $id => $block){ if($block === null){ From 8510be062c65a8d4ff002c45370298e251b2bf85 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 14:17:14 +0100 Subject: [PATCH 02/23] Nether Reactor block is back This should never have been removed, it exists as an unobtainable block in vanilla which drops iron and diamond. --- src/pocketmine/block/Block.php | 2 +- src/pocketmine/block/NetherReactor.php | 64 ++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/pocketmine/block/NetherReactor.php diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 561fbf8379..20cadfd75a 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -316,7 +316,7 @@ class Block extends Position implements BlockIds, Metadatable{ self::registerBlock(new Beetroot()); self::registerBlock(new Stonecutter()); self::registerBlock(new GlowingObsidian()); - //TODO: NETHERREACTOR + self::registerBlock(new NetherReactor()); //TODO: INFO_UPDATE //TODO: INFO_UPDATE2 //TODO: MOVINGBLOCK diff --git a/src/pocketmine/block/NetherReactor.php b/src/pocketmine/block/NetherReactor.php new file mode 100644 index 0000000000..1303a856df --- /dev/null +++ b/src/pocketmine/block/NetherReactor.php @@ -0,0 +1,64 @@ +meta = $meta; + } + + public function getName(){ + static $prefixes = [ + "", + "Active ", + "Used " + ]; + return ($prefixes[$this->meta] ?? "") . "Nether Reactor Core"; + } + + public function getToolType(){ + return Tool::TYPE_PICKAXE; + } + + public function getHardness(){ + return 3; + } + + public function getDrops(Item $item){ + if($item->isPickaxe() >= Tool::TIER_WOODEN){ + return [ + [Item::IRON_INGOT, 0, 6], + [Item::DIAMOND, 0, 3] + ]; + } + + return []; + } + +} \ No newline at end of file From 021dbd65d77a455e2508f834cfcfa6bbf927cfe7 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 14:38:41 +0100 Subject: [PATCH 03/23] Cleaned up some copy-pasted code for coloured blocks names --- src/pocketmine/block/Carpet.php | 21 +------- src/pocketmine/block/DoubleWoodenSlab.php | 6 +-- src/pocketmine/block/Flower.php | 12 +---- src/pocketmine/block/Sandstone.php | 5 +- src/pocketmine/block/Sapling.php | 6 +-- src/pocketmine/block/StainedClay.php | 21 +------- src/pocketmine/block/Stone.php | 5 +- src/pocketmine/block/TallGrass.php | 5 +- src/pocketmine/block/Wood2.php | 6 +-- src/pocketmine/block/WoodenSlab.php | 6 +-- src/pocketmine/block/Wool.php | 21 +------- .../block/utils/ColorBlockMetaHelper.php | 50 +++++++++++++++++++ 12 files changed, 72 insertions(+), 92 deletions(-) create mode 100644 src/pocketmine/block/utils/ColorBlockMetaHelper.php diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 80b956450e..08ada6a6a7 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\ColorBlockMetaHelper; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\math\AxisAlignedBB; @@ -46,25 +47,7 @@ class Carpet extends Flowable{ } public function getName(){ - static $names = [ - 0 => "White Carpet", - 1 => "Orange Carpet", - 2 => "Magenta Carpet", - 3 => "Light Blue Carpet", - 4 => "Yellow Carpet", - 5 => "Lime Carpet", - 6 => "Pink Carpet", - 7 => "Gray Carpet", - 8 => "Light Gray Carpet", - 9 => "Cyan Carpet", - 10 => "Purple Carpet", - 11 => "Blue Carpet", - 12 => "Brown Carpet", - 13 => "Green Carpet", - 14 => "Red Carpet", - 15 => "Black Carpet", - ]; - return $names[$this->meta & 0x0f]; + return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Carpet"; } protected function recalculateBoundingBox(){ diff --git a/src/pocketmine/block/DoubleWoodenSlab.php b/src/pocketmine/block/DoubleWoodenSlab.php index 9bce0a192a..a0603abc36 100644 --- a/src/pocketmine/block/DoubleWoodenSlab.php +++ b/src/pocketmine/block/DoubleWoodenSlab.php @@ -49,11 +49,9 @@ class DoubleWoodenSlab extends Solid{ 2 => "Birch", 3 => "Jungle", 4 => "Acacia", - 5 => "Dark Oak", - 6 => "", - 7 => "" + 5 => "Dark Oak" ]; - return "Double " . $names[$this->meta & 0x07] . " Wooden Slab"; + return "Double " . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab"; } public function getDrops(Item $item){ diff --git a/src/pocketmine/block/Flower.php b/src/pocketmine/block/Flower.php index 4fb79bc1ca..abcc6aed1d 100644 --- a/src/pocketmine/block/Flower.php +++ b/src/pocketmine/block/Flower.php @@ -55,19 +55,11 @@ class Flower extends Flowable{ self::TYPE_ORANGE_TULIP => "Orange Tulip", self::TYPE_WHITE_TULIP => "White Tulip", self::TYPE_PINK_TULIP => "Pink Tulip", - self::TYPE_OXEYE_DAISY => "Oxeye Daisy", - 9 => "Unknown", - 10 => "Unknown", - 11 => "Unknown", - 12 => "Unknown", - 13 => "Unknown", - 14 => "Unknown", - 15 => "Unknown" + self::TYPE_OXEYE_DAISY => "Oxeye Daisy" ]; - return $names[$this->meta]; + return $names[$this->meta] ?? "Unknown"; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ diff --git a/src/pocketmine/block/Sandstone.php b/src/pocketmine/block/Sandstone.php index 89b3c61114..92c8a72312 100644 --- a/src/pocketmine/block/Sandstone.php +++ b/src/pocketmine/block/Sandstone.php @@ -46,10 +46,9 @@ class Sandstone extends Solid{ static $names = [ self::NORMAL => "Sandstone", self::CHISELED => "Chiseled Sandstone", - self::SMOOTH => "Smooth Sandstone", - 3 => "", + self::SMOOTH => "Smooth Sandstone" ]; - return $names[$this->meta & 0x03]; + return $names[$this->meta & 0x03] ?? "Unknown"; } public function getToolType(){ diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index f3dc414945..8eedaacb6d 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -51,11 +51,9 @@ class Sapling extends Flowable{ 2 => "Birch Sapling", 3 => "Jungle Sapling", 4 => "Acacia Sapling", - 5 => "Dark Oak Sapling", - 6 => "", - 7 => "", + 5 => "Dark Oak Sapling" ]; - return $names[$this->meta & 0x07]; + return $names[$this->meta & 0x07] ?? "Unknown"; } diff --git a/src/pocketmine/block/StainedClay.php b/src/pocketmine/block/StainedClay.php index d3bf674d57..f4fe4ca634 100644 --- a/src/pocketmine/block/StainedClay.php +++ b/src/pocketmine/block/StainedClay.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\ColorBlockMetaHelper; use pocketmine\item\Tool; class StainedClay extends Solid{ @@ -42,25 +43,7 @@ class StainedClay extends Solid{ } public function getName(){ - static $names = [ - 0 => "White Stained Clay", - 1 => "Orange Stained Clay", - 2 => "Magenta Stained Clay", - 3 => "Light Blue Stained Clay", - 4 => "Yellow Stained Clay", - 5 => "Lime Stained Clay", - 6 => "Pink Stained Clay", - 7 => "Gray Stained Clay", - 8 => "Light Gray Stained Clay", - 9 => "Cyan Stained Clay", - 10 => "Purple Stained Clay", - 11 => "Blue Stained Clay", - 12 => "Brown Stained Clay", - 13 => "Green Stained Clay", - 14 => "Red Stained Clay", - 15 => "Black Stained Clay", - ]; - return $names[$this->meta & 0x0f]; + return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Clay"; } } \ No newline at end of file diff --git a/src/pocketmine/block/Stone.php b/src/pocketmine/block/Stone.php index e6c798fdda..ced1540f6b 100644 --- a/src/pocketmine/block/Stone.php +++ b/src/pocketmine/block/Stone.php @@ -57,10 +57,9 @@ class Stone extends Solid{ self::DIORITE => "Diorite", self::POLISHED_DIORITE => "Polished Diorite", self::ANDESITE => "Andesite", - self::POLISHED_ANDESITE => "Polished Andesite", - 7 => "Unknown Stone", + self::POLISHED_ANDESITE => "Polished Andesite" ]; - return $names[$this->meta & 0x07]; + return $names[$this->meta & 0x07] ?? "Unknown"; } public function getDrops(Item $item){ diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index e836bc9022..2ba679456d 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -44,10 +44,9 @@ class TallGrass extends Flowable{ static $names = [ 0 => "Dead Shrub", 1 => "Tall Grass", - 2 => "Fern", - 3 => "" + 2 => "Fern" ]; - return $names[$this->meta & 0x03]; + return $names[$this->meta & 0x03] ?? "Unknown"; } public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ diff --git a/src/pocketmine/block/Wood2.php b/src/pocketmine/block/Wood2.php index 2b2a45d6f4..7094787d2e 100644 --- a/src/pocketmine/block/Wood2.php +++ b/src/pocketmine/block/Wood2.php @@ -34,10 +34,8 @@ class Wood2 extends Wood{ public function getName(){ static $names = [ 0 => "Acacia Wood", - 1 => "Dark Oak Wood", - 2 => "Unknown", - 3 => "Unknown" + 1 => "Dark Oak Wood" ]; - return $names[$this->meta & 0x03]; + return $names[$this->meta & 0x03] ?? "Unknown"; } } diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index cd7227a597..1e8ec8a2bf 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -49,11 +49,9 @@ class WoodenSlab extends Transparent{ 2 => "Birch", 3 => "Jungle", 4 => "Acacia", - 5 => "Dark Oak", - 6 => "", - 7 => "" + 5 => "Dark Oak" ]; - return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . $names[$this->meta & 0x07] . " Wooden Slab"; + return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab"; } protected function recalculateBoundingBox(){ diff --git a/src/pocketmine/block/Wool.php b/src/pocketmine/block/Wool.php index b55bcfe901..a34ba8622f 100644 --- a/src/pocketmine/block/Wool.php +++ b/src/pocketmine/block/Wool.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\block\utils\ColorBlockMetaHelper; use pocketmine\item\Tool; class Wool extends Solid{ @@ -42,25 +43,7 @@ class Wool extends Solid{ } public function getName(){ - static $names = [ - 0 => "White Wool", - 1 => "Orange Wool", - 2 => "Magenta Wool", - 3 => "Light Blue Wool", - 4 => "Yellow Wool", - 5 => "Lime Wool", - 6 => "Pink Wool", - 7 => "Gray Wool", - 8 => "Light Gray Wool", - 9 => "Cyan Wool", - 10 => "Purple Wool", - 11 => "Blue Wool", - 12 => "Brown Wool", - 13 => "Green Wool", - 14 => "Red Wool", - 15 => "Black Wool", - ]; - return $names[$this->meta & 0x0f]; + return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Wool"; } } \ No newline at end of file diff --git a/src/pocketmine/block/utils/ColorBlockMetaHelper.php b/src/pocketmine/block/utils/ColorBlockMetaHelper.php new file mode 100644 index 0000000000..01a6ab77f9 --- /dev/null +++ b/src/pocketmine/block/utils/ColorBlockMetaHelper.php @@ -0,0 +1,50 @@ + "White", + 1 => "Orange", + 2 => "Magenta", + 3 => "Light Blue", + 4 => "Yellow", + 5 => "Lime", + 6 => "Pink", + 7 => "Gray", + 8 => "Light Gray", + 9 => "Cyan", + 10 => "Purple", + 11 => "Blue", + 12 => "Brown", + 13 => "Green", + 14 => "Red", + 15 => "Black", + ]; + + return $names[$meta] ?? "Unknown"; + } +} \ No newline at end of file From 696c67f5419c762ccfc69127d2e35a0f084074f5 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 14:43:18 +0100 Subject: [PATCH 04/23] Missed a couple --- src/pocketmine/block/Fence.php | 6 ++---- src/pocketmine/block/Planks.php | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index d0480cf70c..a706ea7960 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -57,11 +57,9 @@ class Fence extends Transparent{ self::FENCE_BIRCH => "Birch Fence", self::FENCE_JUNGLE => "Jungle Fence", self::FENCE_ACACIA => "Acacia Fence", - self::FENCE_DARKOAK => "Dark Oak Fence", - "", - "" + self::FENCE_DARKOAK => "Dark Oak Fence" ]; - return $names[$this->meta & 0x07]; + return $names[$this->meta & 0x07] ?? "Unknown"; } protected function recalculateBoundingBox(){ diff --git a/src/pocketmine/block/Planks.php b/src/pocketmine/block/Planks.php index 850b56bb79..96237aec74 100644 --- a/src/pocketmine/block/Planks.php +++ b/src/pocketmine/block/Planks.php @@ -54,11 +54,9 @@ class Planks extends Solid{ self::BIRCH => "Birch Wood Planks", self::JUNGLE => "Jungle Wood Planks", self::ACACIA => "Acacia Wood Planks", - self::DARK_OAK => "Dark Oak Wood Planks", - "", - "" + self::DARK_OAK => "Dark Oak Wood Planks" ]; - return $names[$this->meta & 0x07]; + return $names[$this->meta & 0x07] ?? "Unknown"; } } From ea414ea72d3ddfa0376c9ec6b967072b6324dfb8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 17:09:03 +0100 Subject: [PATCH 05/23] Fixed MetadataStore --- .../metadata/BlockMetadataStore.php | 32 ++++++++-------- src/pocketmine/metadata/MetadataStore.php | 38 ++++++++----------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/src/pocketmine/metadata/BlockMetadataStore.php b/src/pocketmine/metadata/BlockMetadataStore.php index e86141cd6d..202ef3dd6d 100644 --- a/src/pocketmine/metadata/BlockMetadataStore.php +++ b/src/pocketmine/metadata/BlockMetadataStore.php @@ -43,45 +43,45 @@ class BlockMetadataStore extends MetadataStore{ return $block->x . ":" . $block->y . ":" . $block->z . ":" . $metadataKey; } - public function getMetadata($block, $metadataKey){ - if(!($block instanceof Block)){ + public function getMetadata(Metadatable $subject, string $metadataKey){ + if(!($subject instanceof Block)){ throw new \InvalidArgumentException("Object must be a Block"); } - if($block->getLevel() === $this->owningLevel){ - return parent::getMetadata($block, $metadataKey); + if($subject->getLevel() === $this->owningLevel){ + return parent::getMetadata($subject, $metadataKey); }else{ throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } - public function hasMetadata($block, $metadataKey){ - if(!($block instanceof Block)){ + public function hasMetadata(Metadatable $subject, string $metadataKey) : bool{ + if(!($subject instanceof Block)){ throw new \InvalidArgumentException("Object must be a Block"); } - if($block->getLevel() === $this->owningLevel){ - return parent::hasMetadata($block, $metadataKey); + if($subject->getLevel() === $this->owningLevel){ + return parent::hasMetadata($subject, $metadataKey); }else{ throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } - public function removeMetadata($block, $metadataKey, Plugin $owningPlugin){ - if(!($block instanceof Block)){ + public function removeMetadata(Metadatable $subject, string $metadataKey, Plugin $owningPlugin){ + if(!($subject instanceof Block)){ throw new \InvalidArgumentException("Object must be a Block"); } - if($block->getLevel() === $this->owningLevel){ - parent::removeMetadata($block, $metadataKey, $owningPlugin); + if($subject->getLevel() === $this->owningLevel){ + parent::removeMetadata($subject, $metadataKey, $owningPlugin); }else{ throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } } - public function setMetadata($block, $metadataKey, MetadataValue $newMetadatavalue){ - if(!($block instanceof Block)){ + public function setMetadata(Metadatable $subject, string $metadataKey, MetadataValue $newMetadataValue){ + if(!($subject instanceof Block)){ throw new \InvalidArgumentException("Object must be a Block"); } - if($block->getLevel() === $this->owningLevel){ - parent::setMetadata($block, $metadataKey, $newMetadatavalue); + if($subject->getLevel() === $this->owningLevel){ + parent::setMetadata($subject, $metadataKey, $newMetadataValue); }else{ throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName()); } diff --git a/src/pocketmine/metadata/MetadataStore.php b/src/pocketmine/metadata/MetadataStore.php index 3b594deefa..52f9925f2f 100644 --- a/src/pocketmine/metadata/MetadataStore.php +++ b/src/pocketmine/metadata/MetadataStore.php @@ -30,19 +30,17 @@ use pocketmine\plugin\Plugin; use pocketmine\plugin\PluginException; abstract class MetadataStore{ - /** @var \WeakMap[] */ + /** @var \SplObjectStorage[] */ private $metadataMap; /** * Adds a metadata value to an object. * - * @param mixed $subject + * @param Metadatable $subject * @param string $metadataKey * @param MetadataValue $newMetadataValue - * - * @throws \Exception */ - public function setMetadata($subject, $metadataKey, MetadataValue $newMetadataValue){ + public function setMetadata(Metadatable $subject, string $metadataKey, MetadataValue $newMetadataValue){ $owningPlugin = $newMetadataValue->getOwningPlugin(); if($owningPlugin === null){ throw new PluginException("Plugin cannot be null"); @@ -50,8 +48,8 @@ abstract class MetadataStore{ $key = $this->disambiguate($subject, $metadataKey); if(!isset($this->metadataMap[$key])){ - //$entry = new \WeakMap(); - $this->metadataMap[$key] = new \SplObjectStorage();//$entry; + $entry = new \SplObjectStorage(); + $this->metadataMap[$key] = $entry; }else{ $entry = $this->metadataMap[$key]; } @@ -62,14 +60,12 @@ abstract class MetadataStore{ * Returns all metadata values attached to an object. If multiple * have attached metadata, each will value will be included. * - * @param mixed $subject - * @param string $metadataKey + * @param Metadatable $subject + * @param string $metadataKey * * @return MetadataValue[] - * - * @throws \Exception */ - public function getMetadata($subject, $metadataKey){ + public function getMetadata(Metadatable $subject, string $metadataKey){ $key = $this->disambiguate($subject, $metadataKey); if(isset($this->metadataMap[$key])){ return $this->metadataMap[$key]; @@ -81,27 +77,23 @@ abstract class MetadataStore{ /** * Tests to see if a metadata attribute has been set on an object. * - * @param mixed $subject - * @param string $metadataKey + * @param Metadatable $subject + * @param string $metadataKey * * @return bool - * - * @throws \Exception */ - public function hasMetadata($subject, $metadataKey){ + public function hasMetadata(Metadatable $subject, string $metadataKey) : bool{ return isset($this->metadataMap[$this->disambiguate($subject, $metadataKey)]); } /** * Removes a metadata item owned by a plugin from a subject. * - * @param mixed $subject - * @param string $metadataKey - * @param Plugin $owningPlugin - * - * @throws \Exception + * @param Metadatable $subject + * @param string $metadataKey + * @param Plugin $owningPlugin */ - public function removeMetadata($subject, $metadataKey, Plugin $owningPlugin){ + public function removeMetadata(Metadatable $subject, string $metadataKey, Plugin $owningPlugin){ $key = $this->disambiguate($subject, $metadataKey); if(isset($this->metadataMap[$key])){ unset($this->metadataMap[$key][$owningPlugin]); From 741394dab1da97c1c182c30dde1c92e2eb2bb599 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 19:03:39 +0100 Subject: [PATCH 06/23] Typehinted up entity API Did you guys think ALPHA7 changes were done?! Sone stuff still needs some work, most notably data-properties can't be typed yet because they are just mushed into a couple of methods. --- src/pocketmine/IPlayer.php | 2 +- src/pocketmine/OfflinePlayer.php | 2 +- src/pocketmine/Player.php | 11 +- src/pocketmine/command/CommandSender.php | 2 +- .../command/ConsoleCommandSender.php | 2 +- .../command/RemoteConsoleCommandSender.php | 2 +- src/pocketmine/entity/Ageable.php | 2 +- src/pocketmine/entity/Animal.php | 2 +- src/pocketmine/entity/Arrow.php | 2 +- src/pocketmine/entity/Effect.php | 73 ++++---- src/pocketmine/entity/Entity.php | 174 +++++++++++------- src/pocketmine/entity/FallingSand.php | 4 +- src/pocketmine/entity/Human.php | 4 +- src/pocketmine/entity/Item.php | 18 +- src/pocketmine/entity/Living.php | 12 +- src/pocketmine/entity/PrimedTNT.php | 4 +- src/pocketmine/entity/Projectile.php | 4 +- src/pocketmine/entity/Snowball.php | 2 +- src/pocketmine/entity/Squid.php | 6 +- src/pocketmine/entity/Villager.php | 12 +- src/pocketmine/entity/WaterAnimal.php | 2 +- src/pocketmine/entity/Zombie.php | 2 +- src/pocketmine/level/Location.php | 2 + 23 files changed, 197 insertions(+), 149 deletions(-) diff --git a/src/pocketmine/IPlayer.php b/src/pocketmine/IPlayer.php index f2612a6461..65e6cd2001 100644 --- a/src/pocketmine/IPlayer.php +++ b/src/pocketmine/IPlayer.php @@ -35,7 +35,7 @@ interface IPlayer extends ServerOperator{ /** * @return string */ - public function getName(); + public function getName() : string; /** * @return bool diff --git a/src/pocketmine/OfflinePlayer.php b/src/pocketmine/OfflinePlayer.php index 09d76dd405..0b7af091a0 100644 --- a/src/pocketmine/OfflinePlayer.php +++ b/src/pocketmine/OfflinePlayer.php @@ -55,7 +55,7 @@ class OfflinePlayer implements IPlayer, Metadatable{ return $this->getPlayer() !== null; } - public function getName(){ + public function getName() : string{ return $this->name; } diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 94d85aaa17..93de2a5b7e 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -487,7 +487,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function canCollideWith(Entity $entity){ + public function canCollideWith(Entity $entity) : bool{ return false; } @@ -756,7 +756,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $this->inAirTicks; } - protected function switchLevel(Level $targetLevel){ + protected function switchLevel(Level $targetLevel) : bool{ $oldLevel = $this->level; if(parent::switchLevel($targetLevel)){ foreach($this->usedChunks as $index => $d){ @@ -1398,7 +1398,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return []; } - protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){ + protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){ if(!$this->onGround or $movY != 0){ $bb = clone $this->boundingBox; $bb->minY = $this->y - 0.01; @@ -1643,7 +1643,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if(!$this->loggedIn){ return false; } @@ -3549,10 +3549,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** * Gets the username - * * @return string */ - public function getName(){ + public function getName() : string{ return $this->username; } diff --git a/src/pocketmine/command/CommandSender.php b/src/pocketmine/command/CommandSender.php index 2a522fd27c..e14ba3f6c3 100644 --- a/src/pocketmine/command/CommandSender.php +++ b/src/pocketmine/command/CommandSender.php @@ -42,7 +42,7 @@ interface CommandSender extends Permissible{ /** * @return string */ - public function getName(); + public function getName() : string; /** * Returns the line height of the command-sender's screen. Used for determining sizes for command output pagination diff --git a/src/pocketmine/command/ConsoleCommandSender.php b/src/pocketmine/command/ConsoleCommandSender.php index ac78a69f39..db369403b4 100644 --- a/src/pocketmine/command/ConsoleCommandSender.php +++ b/src/pocketmine/command/ConsoleCommandSender.php @@ -124,7 +124,7 @@ class ConsoleCommandSender implements CommandSender{ /** * @return string */ - public function getName(){ + public function getName() : string{ return "CONSOLE"; } diff --git a/src/pocketmine/command/RemoteConsoleCommandSender.php b/src/pocketmine/command/RemoteConsoleCommandSender.php index 57bf2b546a..faf5c6999f 100644 --- a/src/pocketmine/command/RemoteConsoleCommandSender.php +++ b/src/pocketmine/command/RemoteConsoleCommandSender.php @@ -44,7 +44,7 @@ class RemoteConsoleCommandSender extends ConsoleCommandSender{ return $this->messages; } - public function getName(){ + public function getName() : string{ return "Rcon"; } diff --git a/src/pocketmine/entity/Ageable.php b/src/pocketmine/entity/Ageable.php index f6aa95090a..a05ead400d 100644 --- a/src/pocketmine/entity/Ageable.php +++ b/src/pocketmine/entity/Ageable.php @@ -25,5 +25,5 @@ namespace pocketmine\entity; interface Ageable{ - public function isBaby(); + public function isBaby() : bool; } \ No newline at end of file diff --git a/src/pocketmine/entity/Animal.php b/src/pocketmine/entity/Animal.php index 6ef2da7ebb..d8c502a41b 100644 --- a/src/pocketmine/entity/Animal.php +++ b/src/pocketmine/entity/Animal.php @@ -26,7 +26,7 @@ namespace pocketmine\entity; abstract class Animal extends Creature implements Ageable{ - public function isBaby(){ + public function isBaby() : bool{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); } } \ No newline at end of file diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index eebbe5131c..d79963a76f 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -62,7 +62,7 @@ class Arrow extends Projectile{ } } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed){ return false; } diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 17ccb97f6f..a7a1c41c31 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -82,6 +82,10 @@ class Effect{ } } + /** + * @param string $internalName + * @param Effect $effect + */ public static function registerEffect(string $internalName, Effect $effect){ self::$effects[$effect->getId()] = $effect; self::$effects[$internalName] = $effect; @@ -92,9 +96,9 @@ class Effect{ * * @return Effect|null */ - public static function getEffect($id){ + public static function getEffect(int $id){ if(isset(self::$effects[$id])){ - return clone self::$effects[(int) $id]; + return clone self::$effects[$id]; } return null; } @@ -104,7 +108,7 @@ class Effect{ * * @return Effect|null */ - public static function getEffectByName($name){ + public static function getEffectByName(string $name){ if(isset(self::$effects[$name])){ return clone self::$effects[$name]; } @@ -113,23 +117,23 @@ class Effect{ /** @var int */ protected $id; - + /** @var string */ protected $name; - + /** @var int */ protected $duration; - + /** @var int */ protected $amplifier = 0; - + /** @var int[] */ protected $color; - - protected $show = true; - + /** @var bool */ + protected $visible = true; + /** @var bool */ protected $ambient = false; - + /** @var bool */ protected $bad; - + /** @var int */ protected $defaultDuration = 300 * 20; - + /** @var bool */ protected $hasBubbles = true; /** @@ -142,10 +146,10 @@ class Effect{ * @param int $defaultDuration Duration in ticks the effect will last for by default if applied without a duration. * @param bool $hasBubbles Whether the effect has potion bubbles. Some do not (e.g. Instant Damage has its own particles instead of bubbles) */ - public function __construct($id, $name, $r, $g, $b, $isBad = false, int $defaultDuration = 300 * 20, bool $hasBubbles = true){ + public function __construct(int $id, string $name, int $r, int $g, int $b, bool $isBad = false, int $defaultDuration = 300 * 20, bool $hasBubbles = true){ $this->id = $id; $this->name = $name; - $this->bad = (bool) $isBad; + $this->bad = $isBad; $this->setColor($r, $g, $b); $this->defaultDuration = $defaultDuration; $this->duration = $defaultDuration; @@ -156,7 +160,7 @@ class Effect{ * Returns the translation key used to translate this effect's name. * @return string */ - public function getName(){ + public function getName() : string{ return $this->name; } @@ -164,7 +168,7 @@ class Effect{ * Returns the effect ID as per Minecraft PE * @return int */ - public function getId(){ + public function getId() : int{ return $this->id; } @@ -186,7 +190,7 @@ class Effect{ * Returns the duration remaining of the effect in ticks. * @return int */ - public function getDuration(){ + public function getDuration() : int{ return $this->duration; } @@ -212,18 +216,19 @@ class Effect{ * * @return bool */ - public function isVisible(){ - return $this->show; + public function isVisible() : bool{ + return $this->visible; } /** * Changes the visibility of the effect. + * * @param bool $bool * * @return $this */ - public function setVisible($bool){ - $this->show = (bool) $bool; + public function setVisible(bool $bool){ + $this->visible = $bool; return $this; } @@ -238,10 +243,9 @@ class Effect{ /** * Returns the amplifier of this effect. - * * @return int */ - public function getAmplifier(){ + public function getAmplifier() : int{ return $this->amplifier; } @@ -259,18 +263,19 @@ class Effect{ * Returns whether the effect is ambient. * @return bool */ - public function isAmbient(){ + public function isAmbient() : bool{ return $this->ambient; } /** * Sets the ambiency of this effect. + * * @param bool $ambient * * @return $this */ - public function setAmbient($ambient = true){ - $this->ambient = (bool) $ambient; + public function setAmbient(bool $ambient = true){ + $this->ambient = $ambient; return $this; } @@ -280,7 +285,7 @@ class Effect{ * * @return bool */ - public function isBad(){ + public function isBad() : bool{ return $this->bad; } @@ -289,7 +294,7 @@ class Effect{ * * @return bool */ - public function canTick(){ + public function canTick() : bool{ switch($this->id){ case Effect::POISON: if(($interval = (25 >> $this->amplifier)) > 0){ @@ -370,9 +375,9 @@ class Effect{ /** * Returns an RGB color array of this effect's color. - * @return array + * @return int[] */ - public function getColor(){ + public function getColor() : array{ return [$this->color >> 16, ($this->color >> 8) & 0xff, $this->color & 0xff]; } @@ -382,8 +387,10 @@ class Effect{ * @param int $r * @param int $g * @param int $b + * + * @return int */ - public function setColor($r, $g, $b){ + public function setColor(int $r, int $g, int $b) { $this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff); } @@ -394,7 +401,7 @@ class Effect{ * @param bool $modify * @param Effect|null $oldEffect */ - public function add(Entity $entity, $modify = false, Effect $oldEffect = null){ + public function add(Entity $entity, bool $modify = false, Effect $oldEffect = null){ $entity->getLevel()->getServer()->getPluginManager()->callEvent($ev = new EntityEffectAddEvent($entity, $this, $modify, $oldEffect)); if($ev->isCancelled()){ return; diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 43e069674e..e37bbfdaf1 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -222,6 +222,7 @@ abstract class Entity extends Location implements Metadatable{ */ protected $hasSpawned = []; + /** @var int */ protected $id; protected $dataProperties = [ @@ -241,85 +242,121 @@ abstract class Entity extends Location implements Metadatable{ /** @var Chunk */ public $chunk; + /** @var EntityDamageEvent|null */ protected $lastDamageCause = null; /** @var Block[] */ private $blocksAround = []; + /** @var float|null */ public $lastX = null; + /** @var float|null */ public $lastY = null; + /** @var float|null */ public $lastZ = null; + /** @var float */ public $motionX; + /** @var float */ public $motionY; + /** @var float */ public $motionZ; /** @var Vector3 */ public $temporalVector; + /** @var float */ public $lastMotionX; + /** @var float */ public $lastMotionY; + /** @var float */ public $lastMotionZ; + /** @var float */ public $lastYaw; + /** @var float */ public $lastPitch; /** @var AxisAlignedBB */ public $boundingBox; + /** @var bool */ public $onGround; - public $inBlock = false; - public $positionChanged; - public $motionChanged; + /** @var int */ public $deadTicks = 0; + /** @var int */ protected $age = 0; - public $height; - + /** @var float */ public $eyeHeight = null; + /** @var float */ + public $height; + /** @var float */ public $width; + /** @var float */ public $length; + /** @var float */ protected $baseOffset = 0.0; /** @var int */ private $health = 20; private $maxHealth = 20; - protected $ySize = 0; - protected $stepHeight = 0; + /** @var float */ + protected $ySize = 0.0; + /** @var float */ + protected $stepHeight = 0.0; + /** @var bool */ public $keepMovement = false; /** @var float */ public $fallDistance = 0.0; + /** @var int */ public $ticksLived = 0; + /** @var int */ public $lastUpdate; + /** @var int */ public $maxFireTicks; + /** @var int */ public $fireTicks = 0; + /** @var CompoundTag */ public $namedtag; + /** @var bool */ public $canCollide = true; + /** @var bool */ protected $isStatic = false; + /** @var bool */ public $isCollided = false; + /** @var bool */ public $isCollidedHorizontally = false; + /** @var bool */ public $isCollidedVertically = false; + /** @var int */ public $noDamageTicks; - protected $justCreated; + /** @var bool */ + protected $justCreated = true; + /** @var bool */ private $invulnerable; /** @var AttributeMap */ protected $attributeMap; + /** @var float */ protected $gravity; + /** @var float */ protected $drag; /** @var Server */ protected $server; + /** @var bool */ public $closed = false; /** @var TimingsHandler */ protected $timings; + /** @var bool */ protected $isPlayer = false; @@ -335,7 +372,6 @@ abstract class Entity extends Location implements Metadatable{ } $this->id = Entity::$entityCount++; - $this->justCreated = true; $this->namedtag = $nbt; $this->chunk = $level->getChunk($this->namedtag["Pos"][0] >> 4, $this->namedtag["Pos"][2] >> 4, true); @@ -372,7 +408,7 @@ abstract class Entity extends Location implements Metadatable{ if(!isset($this->namedtag->Fire)){ $this->namedtag->Fire = new ShortTag("Fire", 0); } - $this->fireTicks = $this->namedtag["Fire"]; + $this->fireTicks = (int) $this->namedtag["Fire"]; if(!isset($this->namedtag->Air)){ $this->namedtag->Air = new ShortTag("Air", 300); @@ -412,14 +448,14 @@ abstract class Entity extends Location implements Metadatable{ /** * @return bool */ - public function isNameTagVisible(){ + public function isNameTagVisible() : bool{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG); } /** * @return bool */ - public function isNameTagAlwaysVisible(){ + public function isNameTagAlwaysVisible() : bool{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG); } @@ -434,14 +470,14 @@ abstract class Entity extends Location implements Metadatable{ /** * @param bool $value */ - public function setNameTagVisible($value = true){ + public function setNameTagVisible(bool $value = true){ $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG, $value); } /** * @param bool $value */ - public function setNameTagAlwaysVisible($value = true){ + public function setNameTagAlwaysVisible(bool $value = true){ $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value); } @@ -480,21 +516,21 @@ abstract class Entity extends Location implements Metadatable{ } - public function isSneaking(){ + public function isSneaking() : bool{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING); } - public function setSneaking($value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, (bool) $value); + public function setSneaking(bool $value = true){ + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, $value); } - public function isSprinting(){ + public function isSprinting() : bool{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING); } - public function setSprinting($value = true){ + public function setSprinting(bool $value = true){ if($value !== $this->isSprinting()){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, (bool) $value); + $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, $value); $attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED); $attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true); } @@ -504,7 +540,7 @@ abstract class Entity extends Location implements Metadatable{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE); } - public function setImmobile($value = true){ + public function setImmobile(bool $value = true){ $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE, $value); } @@ -544,7 +580,7 @@ abstract class Entity extends Location implements Metadatable{ /** * Returns the entity ID of the owning entity, or null if the entity doesn't have an owner. - * @return int|string|null + * @return int|null */ public function getOwningEntityId(){ return $this->getDataProperty(self::DATA_OWNER_EID); @@ -580,7 +616,7 @@ abstract class Entity extends Location implements Metadatable{ /** * Returns the entity ID of the entity's target, or null if it doesn't have a target. - * @return int|string|null + * @return int|null */ public function getTargetEntityId(){ return $this->getDataProperty(self::DATA_TARGET_EID); @@ -689,7 +725,7 @@ abstract class Entity extends Location implements Metadatable{ return null; } - public static function registerEntity($className, $force = false){ + public static function registerEntity($className, bool $force = false) : bool{ $class = new \ReflectionClass($className); if(is_a($className, Entity::class, true) and !$class->isAbstract()){ if($className::NETWORK_ID !== -1){ @@ -771,7 +807,7 @@ abstract class Entity extends Location implements Metadatable{ /** * @return Player[] */ - public function getViewers(){ + public function getViewers() : array{ return $this->hasSpawned; } @@ -884,7 +920,7 @@ abstract class Entity extends Location implements Metadatable{ return $this->health; } - public function isAlive(){ + public function isAlive() : bool{ return $this->health > 0; } @@ -950,11 +986,11 @@ abstract class Entity extends Location implements Metadatable{ $this->maxHealth = (int) $amount; } - public function canCollideWith(Entity $entity){ + public function canCollideWith(Entity $entity) : bool{ return !$this->justCreated and $entity !== $this; } - protected function checkObstruction($x, $y, $z){ + protected function checkObstruction(float $x, float $y, float $z) : bool{ if(count($this->level->getCollisionCubes($this, $this->getBoundingBox(), false)) === 0){ return false; } @@ -1049,7 +1085,7 @@ abstract class Entity extends Location implements Metadatable{ return false; } - public function entityBaseTick($tickDiff = 1){ + public function entityBaseTick(int $tickDiff = 1) : bool{ //TODO: check vehicles $this->blocksAround = null; @@ -1156,7 +1192,7 @@ abstract class Entity extends Location implements Metadatable{ /** * @return Vector3 */ - public function getDirectionVector(){ + public function getDirectionVector() : Vector3{ $y = -sin(deg2rad($this->pitch)); $xz = cos(deg2rad($this->pitch)); $x = -$xz * sin(deg2rad($this->yaw)); @@ -1165,11 +1201,11 @@ abstract class Entity extends Location implements Metadatable{ return $this->temporalVector->setComponents($x, $y, $z)->normalize(); } - public function getDirectionPlane(){ + public function getDirectionPlane() : Vector2{ return (new Vector2(-cos(deg2rad($this->yaw) - M_PI_2), -sin(deg2rad($this->yaw) - M_PI_2)))->normalize(); } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed){ return false; } @@ -1212,11 +1248,11 @@ abstract class Entity extends Location implements Metadatable{ $this->level->updateEntities[$this->id] = $this; } - public function isOnFire(){ + public function isOnFire() : bool{ return $this->fireTicks > 0; } - public function setOnFire($seconds){ + public function setOnFire(int $seconds){ $ticks = $seconds * 20; if($ticks > $this->fireTicks){ $this->fireTicks = $ticks; @@ -1234,6 +1270,9 @@ abstract class Entity extends Location implements Metadatable{ return false; } + /** + * @return int|null + */ public function getDirection(){ $rotation = ($this->yaw - 90) % 360; if($rotation < 0){ @@ -1252,9 +1291,7 @@ abstract class Entity extends Location implements Metadatable{ } } - - - public function canTriggerWalking(){ + public function canTriggerWalking() : bool{ return true; } @@ -1267,7 +1304,7 @@ abstract class Entity extends Location implements Metadatable{ * @param bool $onGround */ protected function updateFallState(float $distanceThisTick, bool $onGround){ - if($onGround === true){ + if($onGround){ if($this->fallDistance > 0){ $this->fall($this->fallDistance); $this->resetFallDistance(); @@ -1290,7 +1327,7 @@ abstract class Entity extends Location implements Metadatable{ } - public function getEyeHeight(){ + public function getEyeHeight() : float{ return $this->eyeHeight; } @@ -1302,7 +1339,7 @@ abstract class Entity extends Location implements Metadatable{ } - protected function switchLevel(Level $targetLevel){ + protected function switchLevel(Level $targetLevel) : bool{ if($this->closed){ return false; } @@ -1327,15 +1364,15 @@ abstract class Entity extends Location implements Metadatable{ return true; } - public function getPosition(){ - return new Position($this->x, $this->y, $this->z, $this->level); + public function getPosition() : Position{ + return $this->asPosition(); } - public function getLocation(){ - return new Location($this->x, $this->y, $this->z, $this->yaw, $this->pitch, $this->level); + public function getLocation() : Location{ + return $this->asLocation(); } - public function isInsideOfWater(){ + public function isInsideOfWater() : bool{ $block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); if($block instanceof Water){ @@ -1346,7 +1383,7 @@ abstract class Entity extends Location implements Metadatable{ return false; } - public function isInsideOfSolid(){ + public function isInsideOfSolid() : bool{ $block = $this->level->getBlock($this->temporalVector->setComponents(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z))); $bb = $block->getBoundingBox(); @@ -1357,7 +1394,7 @@ abstract class Entity extends Location implements Metadatable{ return false; } - public function fastMove($dx, $dy, $dz){ + public function fastMove(float $dx, float $dy, float $dz) : bool{ if($dx == 0 and $dz == 0 and $dy == 0){ return true; } @@ -1396,7 +1433,7 @@ abstract class Entity extends Location implements Metadatable{ return true; } - public function move($dx, $dy, $dz){ + public function move(float $dx, float $dy, float $dz) : bool{ if($dx == 0 and $dz == 0 and $dy == 0){ return true; @@ -1557,14 +1594,17 @@ abstract class Entity extends Location implements Metadatable{ } } - protected function checkGroundState($movX, $movY, $movZ, $dx, $dy, $dz){ + protected function checkGroundState(float $movX, float $movY, float $movZ, float $dx, float $dy, float $dz){ $this->isCollidedVertically = $movY != $dy; $this->isCollidedHorizontally = ($movX != $dx or $movZ != $dz); $this->isCollided = ($this->isCollidedHorizontally or $this->isCollidedVertically); $this->onGround = ($movY != $dy and $movY < 0); } - public function getBlocksAround(){ + /** + * @return Block[] + */ + public function getBlocksAround() : array{ if($this->blocksAround === null){ $minX = Math::floorFloat($this->boundingBox->minX); $minY = Math::floorFloat($this->boundingBox->minY); @@ -1607,7 +1647,7 @@ abstract class Entity extends Location implements Metadatable{ } } - public function setPositionAndRotation(Vector3 $pos, $yaw, $pitch){ + public function setPositionAndRotation(Vector3 $pos, float $yaw, float $pitch) : bool{ if($this->setPosition($pos) === true){ $this->setRotation($yaw, $pitch); @@ -1617,7 +1657,7 @@ abstract class Entity extends Location implements Metadatable{ return false; } - public function setRotation($yaw, $pitch){ + public function setRotation(float $yaw, float $pitch){ $this->yaw = $yaw; $this->pitch = $pitch; $this->scheduleUpdate(); @@ -1681,7 +1721,7 @@ abstract class Entity extends Location implements Metadatable{ list($this->lastMotionX, $this->lastMotionY, $this->lastMotionZ) = [$this->motionX, $this->motionY, $this->motionZ]; } - public function getMotion(){ + public function getMotion() : Vector3{ return new Vector3($this->motionX, $this->motionY, $this->motionZ); } @@ -1704,7 +1744,7 @@ abstract class Entity extends Location implements Metadatable{ return true; } - public function isOnGround(){ + public function isOnGround() : bool{ return $this->onGround === true; } @@ -1754,7 +1794,7 @@ abstract class Entity extends Location implements Metadatable{ return false; } - public function getId(){ + public function getId() : int{ return $this->id; } @@ -1813,7 +1853,7 @@ abstract class Entity extends Location implements Metadatable{ * * @return bool */ - public function setDataProperty($id, $type, $value, bool $send = true){ + public function setDataProperty(int $id, int $type, $value, bool $send = true) : bool{ if($this->getDataProperty($id) !== $value){ $this->dataProperties[$id] = [$type, $value]; if($send){ @@ -1831,7 +1871,7 @@ abstract class Entity extends Location implements Metadatable{ * * @return mixed */ - public function getDataProperty($id){ + public function getDataProperty(int $id){ return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null; } @@ -1840,32 +1880,32 @@ abstract class Entity extends Location implements Metadatable{ * * @return int|null */ - public function getDataPropertyType($id){ + public function getDataPropertyType(int $id){ return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][0] : null; } /** * @param int $propertyId - * @param int $id + * @param int $flagId * @param bool $value - * @param int $type + * @param int $propertyType */ - public function setDataFlag($propertyId, $id, $value = true, $type = self::DATA_TYPE_LONG){ - if($this->getDataFlag($propertyId, $id) !== $value){ + public function setDataFlag(int $propertyId, int $flagId, bool $value = true, int $propertyType = self::DATA_TYPE_LONG){ + if($this->getDataFlag($propertyId, $flagId) !== $value){ $flags = (int) $this->getDataProperty($propertyId); - $flags ^= 1 << $id; - $this->setDataProperty($propertyId, $type, $flags); + $flags ^= 1 << $flagId; + $this->setDataProperty($propertyId, $propertyType, $flags); } } /** * @param int $propertyId - * @param int $id + * @param int $flagId * * @return bool */ - public function getDataFlag($propertyId, $id){ - return (((int) $this->getDataProperty($propertyId)) & (1 << $id)) > 0; + public function getDataFlag(int $propertyId, int $flagId) : bool{ + return (((int) $this->getDataProperty($propertyId)) & (1 << $flagId)) > 0; } public function __destruct(){ diff --git a/src/pocketmine/entity/FallingSand.php b/src/pocketmine/entity/FallingSand.php index 87f6be8a7a..eaa9c3f00d 100644 --- a/src/pocketmine/entity/FallingSand.php +++ b/src/pocketmine/entity/FallingSand.php @@ -70,7 +70,7 @@ class FallingSand extends Entity{ $this->setDataProperty(self::DATA_VARIANT, self::DATA_TYPE_INT, $this->getBlock() | ($this->getDamage() << 8)); } - public function canCollideWith(Entity $entity){ + public function canCollideWith(Entity $entity) : bool{ return false; } @@ -80,7 +80,7 @@ class FallingSand extends Entity{ } } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed){ return false; diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 231dff00e1..0dee4e7de8 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -378,7 +378,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ $this->attributeMap->addAttribute(Attribute::getAttribute(Attribute::EXPERIENCE)); } - public function entityBaseTick($tickDiff = 1){ + public function entityBaseTick(int $tickDiff = 1) : bool{ $hasUpdate = parent::entityBaseTick($tickDiff); $this->doFoodTick($tickDiff); @@ -427,7 +427,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ } } - public function getName(){ + public function getName() : string{ return $this->getNameTag(); } diff --git a/src/pocketmine/entity/Item.php b/src/pocketmine/entity/Item.php index 335d43feba..973a0d0a5e 100644 --- a/src/pocketmine/entity/Item.php +++ b/src/pocketmine/entity/Item.php @@ -98,7 +98,7 @@ class Item extends Entity{ } } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed){ return false; } @@ -181,53 +181,53 @@ class Item extends Entity{ /** * @return ItemItem */ - public function getItem(){ + public function getItem() : ItemItem{ return $this->item; } - public function canCollideWith(Entity $entity){ + public function canCollideWith(Entity $entity) : bool{ return false; } /** * @return int */ - public function getPickupDelay(){ + public function getPickupDelay() : int{ return $this->pickupDelay; } /** * @param int $delay */ - public function setPickupDelay($delay){ + public function setPickupDelay(int $delay){ $this->pickupDelay = $delay; } /** * @return string */ - public function getOwner(){ + public function getOwner() : string{ return $this->owner; } /** * @param string $owner */ - public function setOwner($owner){ + public function setOwner(string $owner){ $this->owner = $owner; } /** * @return string */ - public function getThrower(){ + public function getThrower() : string{ return $this->thrower; } /** * @param string $thrower */ - public function setThrower($thrower){ + public function setThrower(string $thrower){ $this->thrower = $thrower; } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 2d13a09181..6447f463e2 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -57,7 +57,7 @@ abstract class Living extends Entity implements Damageable{ /** @var Effect[] */ protected $effects = []; - abstract public function getName(); + abstract public function getName() : string; protected function initEntity(){ parent::initEntity(); @@ -151,7 +151,7 @@ abstract class Living extends Entity implements Damageable{ } - public function hasLineOfSight(Entity $entity){ + public function hasLineOfSight(Entity $entity) : bool{ //TODO: head height return true; //return $this->getLevel()->rayTraceBlocks(Vector3::createVector($this->x, $this->y + $this->height, $this->z), Vector3::createVector($entity->x, $entity->y + $entity->height, $entity->z)) === null; @@ -377,7 +377,7 @@ abstract class Living extends Entity implements Damageable{ $this->attackTime = 10; //0.5 seconds cooldown } - public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4){ + public function knockBack(Entity $attacker, float $damage, float $x, float $z, float $base = 0.4){ $f = sqrt($x * $x + $z * $z); if($f <= 0){ return; @@ -416,7 +416,7 @@ abstract class Living extends Entity implements Damageable{ } } - public function entityBaseTick($tickDiff = 1){ + public function entityBaseTick(int $tickDiff = 1) : bool{ Timings::$timerLivingEntityBaseTick->startTiming(); $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BREATHING, !$this->isInsideOfWater()); @@ -505,7 +505,7 @@ abstract class Living extends Entity implements Damageable{ * * @return Block[] */ - public function getLineOfSight($maxDistance, $maxLength = 0, array $transparent = []){ + public function getLineOfSight(int $maxDistance, int $maxLength = 0, array $transparent = []) : array{ if($maxDistance > 120){ $maxDistance = 120; } @@ -551,7 +551,7 @@ abstract class Living extends Entity implements Damageable{ * * @return Block|null */ - public function getTargetBlock($maxDistance, array $transparent = []){ + public function getTargetBlock(int $maxDistance, array $transparent = []){ try{ $block = $this->getLineOfSight($maxDistance, 1, $transparent)[0]; if($block instanceof Block){ diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index c9d96b3e86..4cc7e233d1 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -70,7 +70,7 @@ class PrimedTNT extends Entity implements Explosive{ } - public function canCollideWith(Entity $entity){ + public function canCollideWith(Entity $entity) : bool{ return false; } @@ -79,7 +79,7 @@ class PrimedTNT extends Entity implements Explosive{ $this->namedtag->Fuse = new ByteTag("Fuse", $this->fuse); } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed){ return false; diff --git a/src/pocketmine/entity/Projectile.php b/src/pocketmine/entity/Projectile.php index 8a4b90bf38..c48d9ccdaa 100644 --- a/src/pocketmine/entity/Projectile.php +++ b/src/pocketmine/entity/Projectile.php @@ -65,7 +65,7 @@ abstract class Projectile extends Entity{ } } - public function canCollideWith(Entity $entity){ + public function canCollideWith(Entity $entity) : bool{ return $entity instanceof Living and !$this->onGround; } @@ -108,7 +108,7 @@ abstract class Projectile extends Entity{ $this->namedtag->Age = new ShortTag("Age", $this->age); } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed){ return false; } diff --git a/src/pocketmine/entity/Snowball.php b/src/pocketmine/entity/Snowball.php index 52a439d66f..680353ff05 100644 --- a/src/pocketmine/entity/Snowball.php +++ b/src/pocketmine/entity/Snowball.php @@ -42,7 +42,7 @@ class Snowball extends Projectile{ parent::__construct($level, $nbt, $shootingEntity); } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed){ return false; } diff --git a/src/pocketmine/entity/Squid.php b/src/pocketmine/entity/Squid.php index fbb7c41abb..f6e3b77482 100644 --- a/src/pocketmine/entity/Squid.php +++ b/src/pocketmine/entity/Squid.php @@ -49,7 +49,7 @@ class Squid extends WaterAnimal{ parent::initEntity(); } - public function getName(){ + public function getName() : string{ return "Squid"; } @@ -73,12 +73,12 @@ class Squid extends WaterAnimal{ } } - private function generateRandomDirection(){ + private function generateRandomDirection() : Vector3{ return new Vector3(mt_rand(-1000, 1000) / 1000, mt_rand(-500, 500) / 1000, mt_rand(-1000, 1000) / 1000); } - public function onUpdate($currentTick){ + public function onUpdate(int $currentTick) : bool{ if($this->closed !== false){ return false; } diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index fd757f4b61..910922195c 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -41,7 +41,7 @@ class Villager extends Creature implements NPC, Ageable{ public $length = 0.6; public $height = 1.8; - public function getName(){ + public function getName() : string{ return "Villager"; } @@ -73,17 +73,17 @@ class Villager extends Creature implements NPC, Ageable{ /** * Sets the villager profession * - * @param $profession + * @param int $profession */ - public function setProfession($profession){ + public function setProfession(int $profession){ $this->namedtag->Profession = new IntTag("Profession", $profession); } - public function getProfession(){ - return $this->namedtag["Profession"]; + public function getProfession() : int{ + return (int) $this->namedtag["Profession"]; } - public function isBaby(){ + public function isBaby() : bool{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); } } diff --git a/src/pocketmine/entity/WaterAnimal.php b/src/pocketmine/entity/WaterAnimal.php index d47597a4b8..6f4e3f4a8a 100644 --- a/src/pocketmine/entity/WaterAnimal.php +++ b/src/pocketmine/entity/WaterAnimal.php @@ -25,7 +25,7 @@ namespace pocketmine\entity; abstract class WaterAnimal extends Creature implements Ageable{ - public function isBaby(){ + public function isBaby() : bool{ return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); } } diff --git a/src/pocketmine/entity/Zombie.php b/src/pocketmine/entity/Zombie.php index e926ed282e..4d578a67be 100644 --- a/src/pocketmine/entity/Zombie.php +++ b/src/pocketmine/entity/Zombie.php @@ -35,7 +35,7 @@ class Zombie extends Monster{ public $length = 0.6; public $height = 1.8; - public function getName(){ + public function getName() : string{ return "Zombie"; } diff --git a/src/pocketmine/level/Location.php b/src/pocketmine/level/Location.php index 3ce6660f56..25de1f346b 100644 --- a/src/pocketmine/level/Location.php +++ b/src/pocketmine/level/Location.php @@ -27,7 +27,9 @@ use pocketmine\math\Vector3; class Location extends Position{ + /** @var float */ public $yaw; + /** @var float */ public $pitch; /** From 20aa519f3a4ce05826f4ba026ff9a83e9dbbd605 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 19:14:15 +0100 Subject: [PATCH 07/23] Added capability to remove owners/target entities --- src/pocketmine/entity/Entity.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index e37bbfdaf1..3742336730 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -600,18 +600,20 @@ abstract class Entity extends Location implements Metadatable{ } /** - * Sets the owner of the entity. + * Sets the owner of the entity. Passing null will remove the current owner. * - * @param Entity $owner + * @param Entity|null $owner * * @throws \InvalidArgumentException if the supplied entity is not valid */ - public function setOwningEntity(Entity $owner){ - if($owner->closed){ + public function setOwningEntity(Entity $owner = null){ + if($owner === null){ + $this->removeDataProperty(self::DATA_OWNER_EID); + }elseif($owner->closed){ throw new \InvalidArgumentException("Supplied owning entity is garbage and cannot be used"); + }else{ + $this->setDataProperty(self::DATA_OWNER_EID, self::DATA_TYPE_LONG, $owner->getId()); } - - $this->setDataProperty(self::DATA_OWNER_EID, self::DATA_TYPE_LONG, $owner->getId()); } /** @@ -638,18 +640,20 @@ abstract class Entity extends Location implements Metadatable{ } /** - * Sets the entity's target entity. + * Sets the entity's target entity. Passing null will remove the current target. * - * @param Entity $target + * @param Entity|null $target * * @throws \InvalidArgumentException if the target entity is not valid */ - public function setTargetEntity(Entity $target){ - if($target->closed){ + public function setTargetEntity(Entity $target = null){ + if($target === null){ + $this->removeDataProperty(self::DATA_TARGET_EID); + }elseif($target->closed){ throw new \InvalidArgumentException("Supplied target entity is garbage and cannot be used"); + }else{ + $this->setDataProperty(self::DATA_TARGET_EID, self::DATA_TYPE_LONG, $target->getId()); } - - $this->setDataProperty(self::DATA_TARGET_EID, self::DATA_TYPE_LONG, $target->getId()); } /** @@ -1875,6 +1879,10 @@ abstract class Entity extends Location implements Metadatable{ return isset($this->dataProperties[$id]) ? $this->dataProperties[$id][1] : null; } + public function removeDataProperty(int $id){ + unset($this->dataProperties[$id]); + } + /** * @param int $id * From eebc52e00ba6ad38bf1c249a6f0e9415c81d5072 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 19:30:23 +0100 Subject: [PATCH 08/23] Added API method Entity->isClosed() and made Entity->closed protected --- src/pocketmine/Player.php | 4 ++-- src/pocketmine/entity/Entity.php | 15 ++++++++++++++- src/pocketmine/level/Level.php | 2 +- src/pocketmine/level/format/Chunk.php | 2 +- src/pocketmine/level/format/io/region/Anvil.php | 2 +- .../level/format/io/region/McRegion.php | 2 +- src/pocketmine/level/format/io/region/PMAnvil.php | 2 +- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 93de2a5b7e..b610f4b491 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -817,7 +817,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->spawned){ foreach($this->level->getChunkEntities($x, $z) as $entity){ - if($entity !== $this and !$entity->closed and $entity->isAlive()){ + if($entity !== $this and !$entity->isClosed() and $entity->isAlive()){ $entity->spawnTo($this); } } @@ -896,7 +896,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ foreach($this->usedChunks as $index => $c){ Level::getXZ($index, $chunkX, $chunkZ); foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ - if($entity !== $this and !$entity->closed and $entity->isAlive()){ + if($entity !== $this and !$entity->isClosed() and $entity->isAlive()){ $entity->spawnTo($this); } } diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 3742336730..4e48778df5 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -352,7 +352,7 @@ abstract class Entity extends Location implements Metadatable{ protected $server; /** @var bool */ - public $closed = false; + protected $closed = false; /** @var TimingsHandler */ protected $timings; @@ -1826,6 +1826,19 @@ abstract class Entity extends Location implements Metadatable{ } } + /** + * Returns whether the entity has been "closed". + * @return bool + */ + public function isClosed() : bool{ + return $this->closed; + } + + /** + * Closes the entity and frees attached references. + * + * WARNING: Entities are unusable after this has been executed! + */ public function close(){ if(!$this->closed){ $this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this)); diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 136b78bcb0..b775b08a8c 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -722,7 +722,7 @@ class Level implements ChunkManager, Metadatable{ //Update entities that need update Timings::$tickEntityTimer->startTiming(); foreach($this->updateEntities as $id => $entity){ - if($entity->closed or !$entity->onUpdate($currentTick)){ + if($entity->isClosed() or !$entity->onUpdate($currentTick)){ unset($this->updateEntities[$id]); } } diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index 68a0c44507..f5611e308c 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -611,7 +611,7 @@ class Chunk{ * @param Entity $entity */ public function addEntity(Entity $entity){ - if($entity->closed){ + if($entity->isClosed()){ throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to a chunk"); } $this->entities[$entity->getId()] = $entity; diff --git a/src/pocketmine/level/format/io/region/Anvil.php b/src/pocketmine/level/format/io/region/Anvil.php index 9a87d40f67..243f70fcb4 100644 --- a/src/pocketmine/level/format/io/region/Anvil.php +++ b/src/pocketmine/level/format/io/region/Anvil.php @@ -71,7 +71,7 @@ class Anvil extends McRegion{ $entities = []; foreach($chunk->getEntities() as $entity){ - if(!($entity instanceof Player) and !$entity->closed){ + if(!($entity instanceof Player) and !$entity->isClosed()){ $entity->saveNBT(); $entities[] = $entity->namedtag; } diff --git a/src/pocketmine/level/format/io/region/McRegion.php b/src/pocketmine/level/format/io/region/McRegion.php index e1bfcb6ac0..a0ee729804 100644 --- a/src/pocketmine/level/format/io/region/McRegion.php +++ b/src/pocketmine/level/format/io/region/McRegion.php @@ -89,7 +89,7 @@ class McRegion extends BaseLevelProvider{ $entities = []; foreach($chunk->getEntities() as $entity){ - if(!($entity instanceof Player) and !$entity->closed){ + if(!($entity instanceof Player) and !$entity->isClosed()){ $entity->saveNBT(); $entities[] = $entity->namedtag; } diff --git a/src/pocketmine/level/format/io/region/PMAnvil.php b/src/pocketmine/level/format/io/region/PMAnvil.php index 7e14404846..db65e40734 100644 --- a/src/pocketmine/level/format/io/region/PMAnvil.php +++ b/src/pocketmine/level/format/io/region/PMAnvil.php @@ -74,7 +74,7 @@ class PMAnvil extends Anvil{ $entities = []; foreach($chunk->getEntities() as $entity){ - if(!($entity instanceof Player) and !$entity->closed){ + if(!($entity instanceof Player) and !$entity->isClosed()){ $entity->saveNBT(); $entities[] = $entity->namedtag; } From b4c40050092b76fc5d871556bf0a3fa224a9b8bd Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 16 Aug 2017 20:06:48 +0100 Subject: [PATCH 09/23] Some condition simplifications suggested by static analysis --- src/pocketmine/entity/Entity.php | 5 +---- src/pocketmine/item/Item.php | 5 +---- src/pocketmine/level/format/io/leveldb/LevelDB.php | 6 +----- src/pocketmine/tile/Chest.php | 6 +----- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 4e48778df5..f061728cdb 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -1392,10 +1392,7 @@ abstract class Entity extends Location implements Metadatable{ $bb = $block->getBoundingBox(); - if($bb !== null and $block->isSolid() and !$block->isTransparent() and $bb->intersectsWith($this->getBoundingBox())){ - return true; - } - return false; + return $bb !== null and $block->isSolid() and !$block->isTransparent() and $bb->intersectsWith($this->getBoundingBox()); } public function fastMove(float $dx, float $dy, float $dz) : bool{ diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index c073a6e2e4..29902a02c1 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -437,11 +437,8 @@ class Item implements ItemIds, \JsonSerializable{ } $tag = $this->getNamedTag(); - if(isset($tag->BlockEntityTag) and $tag->BlockEntityTag instanceof CompoundTag){ - return true; - } - return false; + return isset($tag->BlockEntityTag) and $tag->BlockEntityTag instanceof CompoundTag; } public function clearCustomBlockData(){ diff --git a/src/pocketmine/level/format/io/leveldb/LevelDB.php b/src/pocketmine/level/format/io/leveldb/LevelDB.php index 3d155b0a2d..37a4b9af69 100644 --- a/src/pocketmine/level/format/io/leveldb/LevelDB.php +++ b/src/pocketmine/level/format/io/leveldb/LevelDB.php @@ -599,11 +599,7 @@ class LevelDB extends BaseLevelProvider{ } public function isChunkGenerated(int $chunkX, int $chunkZ) : bool{ - if($this->chunkExists($chunkX, $chunkZ) and ($chunk = $this->getChunk($chunkX, $chunkZ, false)) !== null){ - return true; - } - - return false; + return $this->chunkExists($chunkX, $chunkZ) and ($chunk = $this->getChunk($chunkX, $chunkZ, false)) !== null; } public function isChunkPopulated(int $chunkX, int $chunkZ) : bool{ diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index 5e3a882853..be13449336 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -213,11 +213,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ } public function isPaired(){ - if(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)){ - return false; - } - - return true; + return !(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)); } /** From dc3f13cd304026bc734a73334770c9e250013171 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 09:42:00 +0100 Subject: [PATCH 10/23] Cleanup from previous commit --- src/pocketmine/tile/Chest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pocketmine/tile/Chest.php b/src/pocketmine/tile/Chest.php index be13449336..fb66179a42 100644 --- a/src/pocketmine/tile/Chest.php +++ b/src/pocketmine/tile/Chest.php @@ -213,7 +213,7 @@ class Chest extends Spawnable implements InventoryHolder, Container, Nameable{ } public function isPaired(){ - return !(!isset($this->namedtag->pairx) or !isset($this->namedtag->pairz)); + return isset($this->namedtag->pairx) and isset($this->namedtag->pairz); } /** From 6efa4343b1ea950fe6915d7df6a2119f3d91bcbb Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 10:22:47 +0100 Subject: [PATCH 11/23] Cleaned up fuel duration handling, fixed some fuel items not working in furnaces --- src/pocketmine/block/Block.php | 8 +++ src/pocketmine/block/Bookshelf.php | 4 ++ src/pocketmine/block/Chest.php | 4 ++ src/pocketmine/block/Coal.php | 4 ++ src/pocketmine/block/CraftingTable.php | 4 ++ src/pocketmine/block/DaylightSensor.php | 4 ++ src/pocketmine/block/Fence.php | 4 ++ src/pocketmine/block/FenceGate.php | 4 ++ src/pocketmine/block/NoteBlock.php | 4 ++ src/pocketmine/block/Planks.php | 4 ++ src/pocketmine/block/Sapling.php | 4 ++ src/pocketmine/block/StoneSlab.php | 4 ++ src/pocketmine/block/Trapdoor.php | 4 ++ src/pocketmine/block/Wood.php | 4 ++ src/pocketmine/block/WoodenPressurePlate.php | 4 ++ src/pocketmine/block/WoodenSlab.php | 4 ++ src/pocketmine/inventory/Fuel.php | 60 -------------------- src/pocketmine/item/Boat.php | 4 ++ src/pocketmine/item/Bow.php | 4 ++ src/pocketmine/item/Bucket.php | 8 +++ src/pocketmine/item/Coal.php | 4 ++ src/pocketmine/item/Item.php | 16 ++---- src/pocketmine/item/ItemBlock.php | 4 ++ src/pocketmine/item/Stick.php | 4 ++ src/pocketmine/item/WoodenAxe.php | 4 ++ src/pocketmine/item/WoodenHoe.php | 4 ++ src/pocketmine/item/WoodenPickaxe.php | 4 ++ src/pocketmine/item/WoodenShovel.php | 4 ++ src/pocketmine/item/WoodenSword.php | 4 ++ src/pocketmine/tile/Furnace.php | 2 +- 30 files changed, 123 insertions(+), 71 deletions(-) delete mode 100644 src/pocketmine/inventory/Fuel.php diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 20cadfd75a..1342eaf081 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -718,6 +718,14 @@ class Block extends Position implements BlockIds, Metadatable{ return $this->getHardness() !== -1; } + /** + * Returns the time in ticks which the block will fuel a furnace for. + * @return int + */ + public function getFuelTime() : int{ + return 0; + } + /** * Returns the Block on the side $side, works like Vector3::side() * diff --git a/src/pocketmine/block/Bookshelf.php b/src/pocketmine/block/Bookshelf.php index 39b47dd574..c110baf214 100644 --- a/src/pocketmine/block/Bookshelf.php +++ b/src/pocketmine/block/Bookshelf.php @@ -52,4 +52,8 @@ class Bookshelf extends Solid{ ]; } + public function getFuelTime() : int{ + return 300; + } + } \ No newline at end of file diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index 9abedb9567..e2b7688f67 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -174,4 +174,8 @@ class Chest extends Transparent{ [$this->id, 0, 1], ]; } + + public function getFuelTime() : int{ + return 300; + } } \ No newline at end of file diff --git a/src/pocketmine/block/Coal.php b/src/pocketmine/block/Coal.php index 3ea29656f8..c0262577a3 100644 --- a/src/pocketmine/block/Coal.php +++ b/src/pocketmine/block/Coal.php @@ -55,4 +55,8 @@ class Coal extends Solid{ return []; } } + + public function getFuelTime() : int{ + return 16000; + } } \ No newline at end of file diff --git a/src/pocketmine/block/CraftingTable.php b/src/pocketmine/block/CraftingTable.php index fea3307e00..658659050a 100644 --- a/src/pocketmine/block/CraftingTable.php +++ b/src/pocketmine/block/CraftingTable.php @@ -60,4 +60,8 @@ class CraftingTable extends Solid{ [$this->id, 0, 1], ]; } + + public function getFuelTime() : int{ + return 300; + } } \ No newline at end of file diff --git a/src/pocketmine/block/DaylightSensor.php b/src/pocketmine/block/DaylightSensor.php index 423b65a985..29a2093fd0 100644 --- a/src/pocketmine/block/DaylightSensor.php +++ b/src/pocketmine/block/DaylightSensor.php @@ -38,4 +38,8 @@ class DaylightSensor extends Transparent{ public function getHardness(){ return 0.2; } + + public function getFuelTime() : int{ + return 300; + } } diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index a706ea7960..34c50949de 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -88,4 +88,8 @@ class Fence extends Transparent{ return ($block instanceof Fence or $block instanceof FenceGate) ? true : $block->isSolid() and !$block->isTransparent(); } + public function getFuelTime() : int{ + return 300; + } + } diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index ed484d5ed8..270c1636d9 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -92,4 +92,8 @@ class FenceGate extends Transparent{ $this->level->addSound(new DoorSound($this)); return true; } + + public function getFuelTime() : int{ + return 300; + } } diff --git a/src/pocketmine/block/NoteBlock.php b/src/pocketmine/block/NoteBlock.php index d03c656699..177f9c7125 100644 --- a/src/pocketmine/block/NoteBlock.php +++ b/src/pocketmine/block/NoteBlock.php @@ -34,4 +34,8 @@ class NoteBlock extends Solid{ public function getName(){ return "Note Block"; } + + public function getFuelTime() : int{ + return 300; + } } diff --git a/src/pocketmine/block/Planks.php b/src/pocketmine/block/Planks.php index 96237aec74..d54627c350 100644 --- a/src/pocketmine/block/Planks.php +++ b/src/pocketmine/block/Planks.php @@ -59,4 +59,8 @@ class Planks extends Solid{ return $names[$this->meta & 0x07] ?? "Unknown"; } + public function getFuelTime() : int{ + return 300; + } + } diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 8eedaacb6d..7c89d49953 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -112,4 +112,8 @@ class Sapling extends Flowable{ [$this->id, $this->meta & 0x07, 1], ]; } + + public function getFuelTime() : int{ + return 100; + } } \ No newline at end of file diff --git a/src/pocketmine/block/StoneSlab.php b/src/pocketmine/block/StoneSlab.php index 6470b238d1..788e013f35 100644 --- a/src/pocketmine/block/StoneSlab.php +++ b/src/pocketmine/block/StoneSlab.php @@ -75,4 +75,8 @@ class StoneSlab extends WoodenSlab{ return []; } } + + public function getFuelTime() : int{ + return 0; + } } \ No newline at end of file diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 93aa586eb0..b65b872609 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -156,4 +156,8 @@ class Trapdoor extends Transparent{ public function getToolType(){ return Tool::TYPE_AXE; } + + public function getFuelTime() : int{ + return 300; + } } diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index 5d9e1b6052..46c8dac062 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -78,4 +78,8 @@ class Wood extends Solid{ public function getToolType(){ return Tool::TYPE_AXE; } + + public function getFuelTime() : int{ + return 300; + } } \ No newline at end of file diff --git a/src/pocketmine/block/WoodenPressurePlate.php b/src/pocketmine/block/WoodenPressurePlate.php index 09be38f716..47e420e109 100644 --- a/src/pocketmine/block/WoodenPressurePlate.php +++ b/src/pocketmine/block/WoodenPressurePlate.php @@ -34,4 +34,8 @@ class WoodenPressurePlate extends StonePressurePlate{ public function getName(){ return "Wooden Pressure Plate"; } + + public function getFuelTime() : int{ + return 300; + } } diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index 1e8ec8a2bf..067655c8ef 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -134,4 +134,8 @@ class WoodenSlab extends Transparent{ [$this->id, $this->meta & 0x07, 1], ]; } + + public function getFuelTime() : int{ + return 300; + } } \ No newline at end of file diff --git a/src/pocketmine/inventory/Fuel.php b/src/pocketmine/inventory/Fuel.php deleted file mode 100644 index d7862b4c9a..0000000000 --- a/src/pocketmine/inventory/Fuel.php +++ /dev/null @@ -1,60 +0,0 @@ - 1600, - Item::COAL_BLOCK => 16000, - Item::WOOD => 300, - Item::WOODEN_PLANKS => 300, - Item::SAPLING => 100, - Item::WOODEN_AXE => 200, - Item::WOODEN_PICKAXE => 200, - Item::WOODEN_SWORD => 200, - Item::WOODEN_SHOVEL => 200, - Item::WOODEN_HOE => 200, - Item::STICK => 100, - Item::FENCE => 300, - Item::FENCE_GATE => 300, - Item::SPRUCE_FENCE_GATE => 300, - Item::BIRCH_FENCE_GATE => 300, - Item::JUNGLE_FENCE_GATE => 300, - Item::ACACIA_FENCE_GATE => 300, - Item::DARK_OAK_FENCE_GATE => 300, - Item::WOODEN_STAIRS => 300, - Item::SPRUCE_STAIRS => 300, - Item::BIRCH_STAIRS => 300, - Item::JUNGLE_STAIRS => 300, - Item::TRAPDOOR => 300, - Item::WORKBENCH => 300, - Item::BOOKSHELF => 300, - Item::CHEST => 300, - Item::BUCKET => 20000, - ]; - -} \ No newline at end of file diff --git a/src/pocketmine/item/Boat.php b/src/pocketmine/item/Boat.php index 222a202f12..b2bab71f7c 100644 --- a/src/pocketmine/item/Boat.php +++ b/src/pocketmine/item/Boat.php @@ -27,4 +27,8 @@ class Boat extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(self::BOAT, $meta, $count, "Boat"); } + + public function getFuelTime() : int{ + return 1200; //400 in PC + } } diff --git a/src/pocketmine/item/Bow.php b/src/pocketmine/item/Bow.php index a407dc715f..20051c3b96 100644 --- a/src/pocketmine/item/Bow.php +++ b/src/pocketmine/item/Bow.php @@ -29,4 +29,8 @@ class Bow extends Tool{ parent::__construct(self::BOW, $meta, $count, "Bow"); } + public function getFuelTime() : int{ + return 200; + } + } \ No newline at end of file diff --git a/src/pocketmine/item/Bucket.php b/src/pocketmine/item/Bucket.php index d276d04d1e..44b2c53827 100644 --- a/src/pocketmine/item/Bucket.php +++ b/src/pocketmine/item/Bucket.php @@ -39,6 +39,14 @@ class Bucket extends Item{ return 1; } + public function getFuelTime() : int{ + if($this->meta === Block::LAVA or $this->meta === Block::FLOWING_LAVA){ + return 20000; + } + + return 0; + } + public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $targetBlock = Block::get($this->meta); diff --git a/src/pocketmine/item/Coal.php b/src/pocketmine/item/Coal.php index c75f2b708f..1dd48ab47b 100644 --- a/src/pocketmine/item/Coal.php +++ b/src/pocketmine/item/Coal.php @@ -32,4 +32,8 @@ class Coal extends Item{ } } + public function getFuelTime() : int{ + return 1600; + } + } \ No newline at end of file diff --git a/src/pocketmine/item/Item.php b/src/pocketmine/item/Item.php index 29902a02c1..d79bccfc44 100644 --- a/src/pocketmine/item/Item.php +++ b/src/pocketmine/item/Item.php @@ -28,7 +28,6 @@ namespace pocketmine\item; use pocketmine\block\Block; use pocketmine\entity\Entity; -use pocketmine\inventory\Fuel; use pocketmine\item\enchantment\Enchantment; use pocketmine\level\Level; use pocketmine\nbt\NBT; @@ -917,15 +916,12 @@ class Item implements ItemIds, \JsonSerializable{ return 64; } - final public function getFuelTime(){ - if(!isset(Fuel::$duration[$this->id])){ - return null; - } - if($this->id !== self::BUCKET or $this->meta === 10){ - return Fuel::$duration[$this->id]; - } - - return null; + /** + * Returns the time in ticks which the item will fuel a furnace for. + * @return int + */ + public function getFuelTime() : int{ + return 0; } /** diff --git a/src/pocketmine/item/ItemBlock.php b/src/pocketmine/item/ItemBlock.php index 192c055dda..c7ea320808 100644 --- a/src/pocketmine/item/ItemBlock.php +++ b/src/pocketmine/item/ItemBlock.php @@ -43,4 +43,8 @@ class ItemBlock extends Item{ return $this->block; } + public function getFuelTime() : int{ + return $this->block->getFuelTime(); + } + } \ No newline at end of file diff --git a/src/pocketmine/item/Stick.php b/src/pocketmine/item/Stick.php index 435c2a6e74..fd02c60239 100644 --- a/src/pocketmine/item/Stick.php +++ b/src/pocketmine/item/Stick.php @@ -29,4 +29,8 @@ class Stick extends Item{ parent::__construct(self::STICK, $meta, $count, "Stick"); } + public function getFuelTime() : int{ + return 5; + } + } \ No newline at end of file diff --git a/src/pocketmine/item/WoodenAxe.php b/src/pocketmine/item/WoodenAxe.php index 3321a05cf5..5def14b7d1 100644 --- a/src/pocketmine/item/WoodenAxe.php +++ b/src/pocketmine/item/WoodenAxe.php @@ -32,4 +32,8 @@ class WoodenAxe extends Tool{ public function isAxe(){ return Tool::TIER_WOODEN; } + + public function getFuelTime() : int{ + return 200; + } } diff --git a/src/pocketmine/item/WoodenHoe.php b/src/pocketmine/item/WoodenHoe.php index d19823164a..b9926cc0e2 100644 --- a/src/pocketmine/item/WoodenHoe.php +++ b/src/pocketmine/item/WoodenHoe.php @@ -32,4 +32,8 @@ class WoodenHoe extends Tool{ public function isHoe(){ return Tool::TIER_WOODEN; } + + public function getFuelTime() : int{ + return 200; + } } \ No newline at end of file diff --git a/src/pocketmine/item/WoodenPickaxe.php b/src/pocketmine/item/WoodenPickaxe.php index e0f59b3f91..66d28b5374 100644 --- a/src/pocketmine/item/WoodenPickaxe.php +++ b/src/pocketmine/item/WoodenPickaxe.php @@ -32,4 +32,8 @@ class WoodenPickaxe extends Tool{ public function isPickaxe(){ return Tool::TIER_WOODEN; } + + public function getFuelTime() : int{ + return 200; + } } diff --git a/src/pocketmine/item/WoodenShovel.php b/src/pocketmine/item/WoodenShovel.php index df85b017b0..e12907a473 100644 --- a/src/pocketmine/item/WoodenShovel.php +++ b/src/pocketmine/item/WoodenShovel.php @@ -32,4 +32,8 @@ class WoodenShovel extends Tool{ public function isShovel(){ return Tool::TIER_WOODEN; } + + public function getFuelTime() : int{ + return 200; + } } diff --git a/src/pocketmine/item/WoodenSword.php b/src/pocketmine/item/WoodenSword.php index 4a85a40b56..5a1d526433 100644 --- a/src/pocketmine/item/WoodenSword.php +++ b/src/pocketmine/item/WoodenSword.php @@ -32,4 +32,8 @@ class WoodenSword extends Tool{ public function isSword(){ return Tool::TIER_WOODEN; } + + public function getFuelTime() : int{ + return 200; + } } diff --git a/src/pocketmine/tile/Furnace.php b/src/pocketmine/tile/Furnace.php index 966701a745..57431d39b6 100644 --- a/src/pocketmine/tile/Furnace.php +++ b/src/pocketmine/tile/Furnace.php @@ -218,7 +218,7 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{ $smelt = $this->server->getCraftingManager()->matchFurnaceRecipe($raw); $canSmelt = ($smelt instanceof FurnaceRecipe and $raw->getCount() > 0 and (($smelt->getResult()->equals($product) and $product->getCount() < $product->getMaxStackSize()) or $product->getId() === Item::AIR)); - if($this->namedtag->BurnTime->getValue() <= 0 and $canSmelt and $fuel->getFuelTime() !== null and $fuel->getCount() > 0){ + if($this->namedtag->BurnTime->getValue() <= 0 and $canSmelt and $fuel->getFuelTime() > 0 and $fuel->getCount() > 0){ $this->checkFuel($fuel); } From 670a9fe44ff16e6f890d69d1560416d8dfdc72e0 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 10:29:12 +0100 Subject: [PATCH 12/23] Fix some crashy issues when incompatible players get disconnected --- src/pocketmine/Player.php | 10 ++++++---- src/pocketmine/entity/Entity.php | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index b610f4b491..ec20eb369c 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -247,9 +247,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ protected $ip; protected $removeFormat = true; protected $port; - protected $username; - protected $iusername; - protected $displayName; + protected $username = ""; + protected $iusername = ""; + protected $displayName = ""; protected $startAction = -1; /** @var Vector3|null */ protected $sleeping = null; @@ -3472,7 +3472,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->windows = null; $this->windowIndex = []; - parent::close(); + if($this->constructed){ + parent::close(); + } $this->spawned = false; if($this->loggedIn){ diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index f061728cdb..9220e4ad2d 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -359,8 +359,12 @@ abstract class Entity extends Location implements Metadatable{ /** @var bool */ protected $isPlayer = false; + /** @var bool */ + protected $constructed = false; + public function __construct(Level $level, CompoundTag $nbt){ + $this->constructed = true; $this->timings = Timings::getEntityTimings($this); $this->isPlayer = $this instanceof Player; From 21a1e0eb6bc0002ff310e8d9b46893443a05c0c8 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 11:08:54 +0100 Subject: [PATCH 13/23] Player API typehints --- src/pocketmine/IPlayer.php | 4 +- src/pocketmine/Player.php | 76 ++++++++++++++++++++------------- src/pocketmine/entity/Human.php | 2 +- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/src/pocketmine/IPlayer.php b/src/pocketmine/IPlayer.php index 65e6cd2001..bc0e8bc9dc 100644 --- a/src/pocketmine/IPlayer.php +++ b/src/pocketmine/IPlayer.php @@ -63,12 +63,12 @@ interface IPlayer extends ServerOperator{ public function getPlayer(); /** - * @return int|double + * @return int|null */ public function getFirstPlayed(); /** - * @return int|double + * @return int|null */ public function getLastPlayed(); diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index ec20eb369c..7fdd96f12f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -267,7 +267,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var Player[] */ protected $hiddenPlayers = []; - /** @var Vector3 */ + /** @var Vector3|null */ protected $newPosition; /** @var bool */ @@ -388,12 +388,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $this->flying; } - public function setAutoJump($value){ + public function setAutoJump(bool $value){ $this->autoJump = $value; $this->sendSettings(); } - public function hasAutoJump(){ + public function hasAutoJump() : bool{ return $this->autoJump; } @@ -439,7 +439,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** * @param bool $remove */ - public function setRemoveFormat($remove = true){ + public function setRemoveFormat(bool $remove = true){ $this->removeFormat = (bool) $remove; } @@ -636,7 +636,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @param string $ip * @param int $port */ - public function __construct(SourceInterface $interface, $clientID, $ip, $port){ + public function __construct(SourceInterface $interface, $clientID, string $ip, int $port){ $this->interface = $interface; $this->windows = new \SplObjectStorage(); $this->perm = new PermissibleBase($this); @@ -668,7 +668,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** * @param string $achievementId */ - public function removeAchievement($achievementId){ + public function removeAchievement(string $achievementId){ if($this->hasAchievement($achievementId)){ $this->achievements[$achievementId] = false; } @@ -706,14 +706,14 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** * @param string $name */ - public function setDisplayName($name){ + public function setDisplayName(string $name){ $this->displayName = $name; if($this->spawned){ $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $this->getSkinId(), $this->getSkinData()); } } - public function setSkin($str, $skinId){ + public function setSkin(string $str, string $skinId){ parent::setSkin($str, $skinId); if($this->spawned){ $this->server->updatePlayerListData($this->getUniqueId(), $this->getId(), $this->getDisplayName(), $skinId, $str); @@ -741,8 +741,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $this->port; } - public function getNextPosition(){ - return $this->newPosition !== null ? new Position($this->newPosition->x, $this->newPosition->y, $this->newPosition->z, $this->level) : $this->getPosition(); + /** + * @return Position + */ + public function getNextPosition() : Position{ + return $this->newPosition !== null ? Position::fromObject($this->newPosition, $this->level) : $this->getPosition(); } /** @@ -752,7 +755,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ return $this->sleeping !== null; } - public function getInAirTicks(){ + public function getInAirTicks() : int{ return $this->inAirTicks; } @@ -769,7 +772,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - private function unloadChunk($x, $z, Level $level = null){ + private function unloadChunk(int $x, int $z, Level $level = null){ $level = $level ?? $this->level; $index = Level::chunkHash($x, $z); if(isset($this->usedChunks[$index])){ @@ -1045,9 +1048,9 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @param DataPacket $packet * @param bool $needACK * - * @return int|bool + * @return bool|int */ - public function dataPacket(DataPacket $packet, $needACK = false){ + public function dataPacket(DataPacket $packet, bool $needACK = false){ if(!$this->connected){ return false; } @@ -1085,7 +1088,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * * @return bool|int */ - public function directDataPacket(DataPacket $packet, $needACK = false){ + public function directDataPacket(DataPacket $packet, bool $needACK = false){ if($this->connected === false){ return false; } @@ -1419,7 +1422,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - protected function checkNearEntities($tickDiff){ + protected function checkNearEntities(int $tickDiff){ foreach($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity){ $entity->scheduleUpdate(); @@ -1481,7 +1484,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - protected function processMovement($tickDiff){ + protected function processMovement(int $tickDiff){ if(!$this->isAlive() or !$this->spawned or $this->newPosition === null or $this->isSleeping()){ return; } @@ -1743,7 +1746,16 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - public function canInteract(Vector3 $pos, $maxDistance, $maxDiff = 0.5){ + /** + * Returns whether the player can interact with the specified position. This checks distance and direction. + * + * @param Vector3 $pos + * @param $maxDistance + * @param float $maxDiff + * + * @return bool + */ + public function canInteract(Vector3 $pos, $maxDistance, float $maxDiff = 0.5) : bool{ $eyePos = $this->getPosition()->add(0, $this->getEyeHeight(), 0); if($eyePos->distanceSquared($pos) > $maxDistance ** 2){ return false; @@ -3228,11 +3240,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * Kicks a player from the server * * @param string $reason - * @param bool $isAdmin + * @param bool $isAdmin * * @return bool */ - public function kick($reason = "", bool $isAdmin = true) : bool{ + public function kick(string $reason = "", bool $isAdmin = true) : bool{ $this->server->getPluginManager()->callEvent($ev = new PlayerKickEvent($this, $reason, $this->getLeaveMessage())); if(!$ev->isCancelled()){ if($isAdmin){ @@ -3360,7 +3372,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->dataPacket($pk); } - public function sendTranslation($message, array $parameters = []){ + /** + * @param string $message + * @param string[] $parameters + */ + public function sendTranslation(string $message, array $parameters = []){ $pk = new TextPacket(); if(!$this->server->isLanguageForced()){ $pk->type = TextPacket::TYPE_TRANSLATION; @@ -3376,7 +3392,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->dataPacket($pk); } - public function sendPopup($message, $subtitle = ""){ + public function sendPopup(string $message, string $subtitle = ""){ $pk = new TextPacket(); $pk->type = TextPacket::TYPE_POPUP; $pk->source = $message; @@ -3384,7 +3400,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->dataPacket($pk); } - public function sendTip($message){ + public function sendTip(string $message){ $pk = new TextPacket(); $pk->type = TextPacket::TYPE_TIP; $pk->message = $message; @@ -3395,7 +3411,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @param string $sender * @param string $message */ - public function sendWhisper($sender, $message){ + public function sendWhisper(string $sender, string $message){ $pk = new TextPacket(); $pk->type = TextPacket::TYPE_WHISPER; $pk->source = $sender; @@ -3407,11 +3423,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * Note for plugin developers: use kick() with the isAdmin * flag set to kick without the "Kicked by admin" part instead of this method. * - * @param string $message Message to be broadcasted - * @param string $reason Reason showed in console - * @param bool $notify + * @param TextContainer|string $message Message to be broadcasted + * @param string $reason Reason showed in console + * @param bool $notify */ - final public function close($message = "", $reason = "generic reason", $notify = true){ + final public function close($message = "", string $reason = "generic reason", bool $notify = true){ if($this->connected and !$this->closed){ try{ @@ -3518,8 +3534,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * Handles player data saving * * @param bool $async + * + * @throws \InvalidStateException if the player is closed */ - public function save($async = false){ + public function save(bool $async = false){ if($this->closed){ throw new \InvalidStateException("Tried to save closed player"); } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 0dee4e7de8..b4b87d5f85 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -107,7 +107,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ * @param string $str * @param string $skinId */ - public function setSkin($str, $skinId){ + public function setSkin(string $str, string $skinId){ if(!Player::isValidSkin($str)){ throw new \InvalidStateException("Specified skin is not valid, must be 8KiB or 16KiB"); } From 56e45a031b3e5f82b8fea31b4f0c9127d367064a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 11:15:22 +0100 Subject: [PATCH 14/23] Fixed missing returns for Player->switchLevel() --- src/pocketmine/Player.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 7fdd96f12f..a1108f0f72 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -769,7 +769,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->usedChunks = []; $this->level->sendTime($this); + + return true; } + + return false; } private function unloadChunk(int $x, int $z, Level $level = null){ From 77376d3e33a877f30ca12a78f6b1c733de8c562a Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 11:15:42 +0100 Subject: [PATCH 15/23] No idea how this happened --- src/pocketmine/entity/Effect.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index a7a1c41c31..43afd93202 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -387,10 +387,8 @@ class Effect{ * @param int $r * @param int $g * @param int $b - * - * @return int */ - public function setColor(int $r, int $g, int $b) { + public function setColor(int $r, int $g, int $b){ $this->color = (($r & 0xff) << 16) + (($g & 0xff) << 8) + ($b & 0xff); } From 5b4035253bed6be6ad4d84391db690fa393fd557 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 11:24:49 +0100 Subject: [PATCH 16/23] Casting cleanup and removed some 32-bit string-int leftovers --- src/pocketmine/Player.php | 4 ++-- src/pocketmine/Server.php | 6 +++--- src/pocketmine/level/Level.php | 11 ++++++----- .../level/format/io/BaseLevelProvider.php | 8 ++++---- src/pocketmine/level/format/io/LevelProvider.php | 16 ++++++++-------- src/pocketmine/plugin/PluginManager.php | 4 ++-- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index a1108f0f72..310bbe17a3 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -440,7 +440,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ * @param bool $remove */ public function setRemoveFormat(bool $remove = true){ - $this->removeFormat = (bool) $remove; + $this->removeFormat = $remove; } public function getScreenLineHeight() : int{ @@ -3435,7 +3435,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if($this->connected and !$this->closed){ try{ - if($notify and strlen((string) $reason) > 0){ + if($notify and strlen($reason) > 0){ $pk = new DisconnectPacket(); $pk->message = $reason; $this->directDataPacket($pk); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index c951901303..3b120c3885 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -428,7 +428,7 @@ class Server{ * @return string */ public static function getGamemodeString(int $mode) : string{ - switch((int) $mode){ + switch($mode){ case Player::SURVIVAL: return "%gameMode.survival"; case Player::CREATIVE: @@ -1209,7 +1209,7 @@ class Server{ return (int) $v[$variable]; } - return $this->properties->exists($variable) ? (int) $this->properties->get($variable) : (int) $defaultValue; + return $this->properties->exists($variable) ? (int) $this->properties->get($variable) : $defaultValue; } /** @@ -1217,7 +1217,7 @@ class Server{ * @param int $value */ public function setConfigInt(string $variable, int $value){ - $this->properties->set($variable, (int) $value); + $this->properties->set($variable, $value); } /** diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index b775b08a8c..555350af78 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -180,6 +180,7 @@ class Level implements ChunkManager, Metadatable{ /** @var float[] */ private $unloadQueue = []; + /** @var int */ private $time; public $stopTime; @@ -334,7 +335,7 @@ class Level implements ChunkManager, Metadatable{ $this->neighbourBlockUpdateQueue = new \SplQueue(); - $this->time = (int) $this->provider->getTime(); + $this->time = $this->provider->getTime(); $this->chunkTickRadius = min($this->server->getViewDistance(), max(1, (int) $this->server->getProperty("chunk-ticking.tick-radius", 4))); $this->chunksPerTick = (int) $this->server->getProperty("chunk-ticking.per-tick", 40); @@ -668,7 +669,7 @@ class Level implements ChunkManager, Metadatable{ */ public function sendTime(Player ...$targets){ $pk = new SetTimePacket(); - $pk->time = (int) $this->time; + $pk->time = $this->time; $this->server->broadcastPacket(count($targets) > 0 ? $targets : $this->players, $pk); } @@ -1010,7 +1011,7 @@ class Level implements ChunkManager, Metadatable{ $this->server->getPluginManager()->callEvent(new LevelSaveEvent($this)); - $this->provider->setTime((int) $this->time); + $this->provider->setTime($this->time); $this->saveChunks(); if($this->provider instanceof BaseLevelProvider){ $this->provider->saveLevelData(); @@ -1090,7 +1091,7 @@ class Level implements ChunkManager, Metadatable{ return; } $this->scheduledBlockUpdateQueueIndex[$index] = $delay; - $this->scheduledBlockUpdateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), (int) $delay + $this->server->getTick()); + $this->scheduledBlockUpdateQueue->insert(new Vector3((int) $pos->x, (int) $pos->y, (int) $pos->z), $delay + $this->server->getTick()); } /** @@ -2729,7 +2730,7 @@ class Level implements ChunkManager, Metadatable{ * @return int */ public function getTime() : int{ - return (int) $this->time; + return $this->time; } /** diff --git a/src/pocketmine/level/format/io/BaseLevelProvider.php b/src/pocketmine/level/format/io/BaseLevelProvider.php index 9d3689cbd5..eefe7ea981 100644 --- a/src/pocketmine/level/format/io/BaseLevelProvider.php +++ b/src/pocketmine/level/format/io/BaseLevelProvider.php @@ -84,19 +84,19 @@ abstract class BaseLevelProvider implements LevelProvider{ return (string) $this->levelData["LevelName"]; } - public function getTime(){ + public function getTime() : int{ return $this->levelData["Time"]; } - public function setTime($value){ + public function setTime(int $value){ $this->levelData->Time = new LongTag("Time", $value); } - public function getSeed(){ + public function getSeed() : int{ return $this->levelData["RandomSeed"]; } - public function setSeed($value){ + public function setSeed(int $value){ $this->levelData->RandomSeed = new LongTag("RandomSeed", $value); } diff --git a/src/pocketmine/level/format/io/LevelProvider.php b/src/pocketmine/level/format/io/LevelProvider.php index e033052810..e3634c3b69 100644 --- a/src/pocketmine/level/format/io/LevelProvider.php +++ b/src/pocketmine/level/format/io/LevelProvider.php @@ -177,24 +177,24 @@ interface LevelProvider{ public function getName() : string; /** - * @return int|string int, or the string numeric representation of a long in 32-bit systems + * @return int */ - public function getTime(); + public function getTime() : int; /** - * @param int|string $value int, or the string numeric representation of a long in 32-bit systems + * @param int */ - public function setTime($value); + public function setTime(int $value); /** - * @return int|string int, or the string numeric representation of a long in 32-bit systems + * @return int */ - public function getSeed(); + public function getSeed() : int; /** - * @param int|string $value int, or the string numeric representation of a long in 32-bit systems + * @param int */ - public function setSeed($value); + public function setSeed(int $value); /** * @return Vector3 diff --git a/src/pocketmine/plugin/PluginManager.php b/src/pocketmine/plugin/PluginManager.php index c53dab85c1..17511cec01 100644 --- a/src/pocketmine/plugin/PluginManager.php +++ b/src/pocketmine/plugin/PluginManager.php @@ -260,8 +260,8 @@ class PluginManager{ $plugins[$name] = $file; - $softDependencies[$name] = (array) $description->getSoftDepend(); - $dependencies[$name] = (array) $description->getDepend(); + $softDependencies[$name] = $description->getSoftDepend(); + $dependencies[$name] = $description->getDepend(); foreach($description->getLoadBefore() as $before){ if(isset($softDependencies[$before])){ From 2cd05bf5b554620f8fefe585145c05afe22f4136 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 11:42:26 +0100 Subject: [PATCH 17/23] Removed redundant Block constructor overrides --- src/pocketmine/block/ActivatorRail.php | 4 ---- src/pocketmine/block/DetectorRail.php | 4 ---- src/pocketmine/block/LitRedstoneLamp.php | 4 ---- src/pocketmine/block/PoweredRail.php | 4 ---- src/pocketmine/block/StoneSlab.php | 4 ---- src/pocketmine/block/WeightedPressurePlateHeavy.php | 4 ---- src/pocketmine/block/WoodenButton.php | 4 ---- src/pocketmine/block/WoodenPressurePlate.php | 4 ---- 8 files changed, 32 deletions(-) diff --git a/src/pocketmine/block/ActivatorRail.php b/src/pocketmine/block/ActivatorRail.php index 39e2048431..65bdddeb1a 100644 --- a/src/pocketmine/block/ActivatorRail.php +++ b/src/pocketmine/block/ActivatorRail.php @@ -27,10 +27,6 @@ class ActivatorRail extends Rail{ protected $id = self::ACTIVATOR_RAIL; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getName(){ return "Activator Rail"; } diff --git a/src/pocketmine/block/DetectorRail.php b/src/pocketmine/block/DetectorRail.php index 9c7a321dcb..9685a02efd 100644 --- a/src/pocketmine/block/DetectorRail.php +++ b/src/pocketmine/block/DetectorRail.php @@ -27,10 +27,6 @@ class DetectorRail extends Rail{ protected $id = self::DETECTOR_RAIL; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getName(){ return "Detector Rail"; } diff --git a/src/pocketmine/block/LitRedstoneLamp.php b/src/pocketmine/block/LitRedstoneLamp.php index b57db747c4..d6a67ad813 100644 --- a/src/pocketmine/block/LitRedstoneLamp.php +++ b/src/pocketmine/block/LitRedstoneLamp.php @@ -27,10 +27,6 @@ class LitRedstoneLamp extends RedstoneLamp{ protected $id = self::LIT_REDSTONE_LAMP; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getName(){ return "Lit Redstone Lamp"; } diff --git a/src/pocketmine/block/PoweredRail.php b/src/pocketmine/block/PoweredRail.php index de9dff4b12..c1eca33a68 100644 --- a/src/pocketmine/block/PoweredRail.php +++ b/src/pocketmine/block/PoweredRail.php @@ -26,10 +26,6 @@ namespace pocketmine\block; class PoweredRail extends Rail{ protected $id = self::POWERED_RAIL; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getName(){ return "Powered Rail"; } diff --git a/src/pocketmine/block/StoneSlab.php b/src/pocketmine/block/StoneSlab.php index 788e013f35..cab8656c9b 100644 --- a/src/pocketmine/block/StoneSlab.php +++ b/src/pocketmine/block/StoneSlab.php @@ -40,10 +40,6 @@ class StoneSlab extends WoodenSlab{ protected $doubleId = self::DOUBLE_STONE_SLAB; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getHardness(){ return 2; } diff --git a/src/pocketmine/block/WeightedPressurePlateHeavy.php b/src/pocketmine/block/WeightedPressurePlateHeavy.php index caeb76af06..9b341ca3f6 100644 --- a/src/pocketmine/block/WeightedPressurePlateHeavy.php +++ b/src/pocketmine/block/WeightedPressurePlateHeavy.php @@ -27,10 +27,6 @@ class WeightedPressurePlateHeavy extends WeightedPressurePlateLight{ protected $id = self::HEAVY_WEIGHTED_PRESSURE_PLATE; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getName(){ return "Weighted Pressure Plate Heavy"; } diff --git a/src/pocketmine/block/WoodenButton.php b/src/pocketmine/block/WoodenButton.php index 3e9d667c72..63a60d7d08 100644 --- a/src/pocketmine/block/WoodenButton.php +++ b/src/pocketmine/block/WoodenButton.php @@ -27,10 +27,6 @@ class WoodenButton extends StoneButton{ protected $id = self::WOODEN_BUTTON; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getName(){ return "Wooden Button"; } diff --git a/src/pocketmine/block/WoodenPressurePlate.php b/src/pocketmine/block/WoodenPressurePlate.php index 47e420e109..d42605df3f 100644 --- a/src/pocketmine/block/WoodenPressurePlate.php +++ b/src/pocketmine/block/WoodenPressurePlate.php @@ -27,10 +27,6 @@ class WoodenPressurePlate extends StonePressurePlate{ protected $id = self::WOODEN_PRESSURE_PLATE; - public function __construct($meta = 0){ - $this->meta = $meta; - } - public function getName(){ return "Wooden Pressure Plate"; } From 9e02f3c4e3fb5a20b1cb9489bd517ecb681f2d2f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 11:47:10 +0100 Subject: [PATCH 18/23] Fixed redstone lamp light levels and hardness --- src/pocketmine/block/LitRedstoneLamp.php | 4 ++++ src/pocketmine/block/RedstoneLamp.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/pocketmine/block/LitRedstoneLamp.php b/src/pocketmine/block/LitRedstoneLamp.php index d6a67ad813..296caca865 100644 --- a/src/pocketmine/block/LitRedstoneLamp.php +++ b/src/pocketmine/block/LitRedstoneLamp.php @@ -30,4 +30,8 @@ class LitRedstoneLamp extends RedstoneLamp{ public function getName(){ return "Lit Redstone Lamp"; } + + public function getLightLevel(){ + return 15; + } } diff --git a/src/pocketmine/block/RedstoneLamp.php b/src/pocketmine/block/RedstoneLamp.php index 92b0cf09a9..954181beae 100644 --- a/src/pocketmine/block/RedstoneLamp.php +++ b/src/pocketmine/block/RedstoneLamp.php @@ -34,4 +34,8 @@ class RedstoneLamp extends Solid{ public function getName(){ return "Redstone Lamp"; } + + public function getHardness(){ + return 0.3; + } } From 6320a63ca5476377974a8b9ca6542c6f81f58c91 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sat, 22 Apr 2017 12:21:50 +0100 Subject: [PATCH 19/23] Use standard format for color hex, some minor name alteration --- src/pocketmine/entity/Effect.php | 4 +- src/pocketmine/resources/effects.json | 96 +++++++++++++-------------- 2 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 43afd93202..36675effc6 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -65,13 +65,13 @@ class Effect{ $config = new Config(\pocketmine\PATH . "src/pocketmine/resources/effects.json", Config::JSON, []); foreach($config->getAll() as $name => $data){ - $color = hexdec($data["color"]); + $color = hexdec(substr($data["color"], 3)); $r = ($color >> 16) & 0xff; $g = ($color >> 8) & 0xff; $b = $color & 0xff; self::registerEffect($name, new Effect( $data["id"], - "%" . $data["name"], + "%potion." . $data["name"], $r, $g, $b, diff --git a/src/pocketmine/resources/effects.json b/src/pocketmine/resources/effects.json index 0ae688c514..54a0203f1d 100644 --- a/src/pocketmine/resources/effects.json +++ b/src/pocketmine/resources/effects.json @@ -1,135 +1,135 @@ { "speed": { "id": 1, - "color": "7cafc6", - "name": "potion.moveSpeed" + "color": "#FF7CAFC6", + "name": "moveSpeed" }, "slowness": { "id": 2, - "color": "5a6c81", - "name": "potion.moveSlowdown", + "color": "#FF5A6C81", + "name": "moveSlowdown", "isBad": true }, "haste": { "id": 3, - "color": "d9c043", - "name": "potion.digSpeed" + "color": "#FFD9C043", + "name": "digSpeed" }, "mining_fatigue": { "id": 4, - "color": "4a4217", - "name": "potion.digSlowDown", + "color": "#FF4A4217", + "name": "digSlowDown", "isBad": true }, "strength": { "id": 5, - "color": "932423", - "name": "potion.damageBoost" + "color": "#FF932423", + "name": "damageBoost" }, "instant_health": { "id": 6, - "color": "f82423", - "name": "potion.heal", + "color": "#FFF82423", + "name": "heal", "default_duration": 1, "has_bubbles": false }, "instant_damage": { "id": 7, - "color": "430a09", - "name": "potion.harm", + "color": "#FF430A09", + "name": "harm", "isBad": true, "default_duration": 1, "has_bubbles": false }, "jump_boost": { "id": 8, - "color": "22ff4c", - "name": "potion.jump" + "color": "#FF22FF4C", + "name": "jump" }, "nausea": { "id": 9, - "color": "551d4a", - "name": "potion.confusion", + "color": "#FF551D4A", + "name": "confusion", "isBad": true }, "regeneration": { "id": 10, - "color": "cd5cab", - "name": "potion.regeneration" + "color": "#FFCD5CAB", + "name": "regeneration" }, "resistance": { "id": 11, - "color": "99453a", - "name": "potion.resistance" + "color": "#FF99453A", + "name": "resistance" }, "fire_resistance": { "id": 12, - "color": "e49a3a", - "name": "potion.fireResistance" + "color": "#FFE49A3A", + "name": "fireResistance" }, "water_breathing": { "id": 13, - "color": "2e5299", - "name": "potion.waterBreathing" + "color": "#FF2E5299", + "name": "waterBreathing" }, "invisibility": { "id": 14, - "color": "7f8392", - "name": "potion.invisibility" + "color": "#FF7F8392", + "name": "invisibility" }, "blindness": { "id": 15, - "color": "1f1f23", - "name": "potion.blindness", + "color": "#FF1F1F23", + "name": "blindness", "isBad": true }, "night_vision": { "id": 16, - "color": "1f1fa1", - "name": "potion.nightVision" + "color": "#FF1F1FA1", + "name": "nightVision" }, "hunger": { "id": 17, - "color": "587653", - "name": "potion.hunger", + "color": "#FF587653", + "name": "hunger", "isBad": true }, "weakness": { "id": 18, - "color": "484d48", - "name": "potion.weakness", + "color": "#FF484D48", + "name": "weakness", "isBad": true }, "poison": { "id": 19, - "color": "4e9331", - "name": "potion.poison", + "color": "#FF4E9331", + "name": "poison", "isBad": true }, "wither": { "id": 20, - "color": "352a27", - "name": "potion.wither", + "color": "#FF352A27", + "name": "wither", "isBad": true }, "health_boost": { "id": 21, - "color": "f87d23", - "name": "potion.healthBoost" + "color": "#FFF87D23", + "name": "healthBoost" }, "absorption": { "id": 22, - "color": "2552a5", - "name": "potion.absorption" + "color": "#FF2552A5", + "name": "absorption" }, "saturation": { "id": 23, - "color": "f82423", - "name": "potion.saturation" + "color": "#FFF82423", + "name": "saturation" }, "levitation": { "id": 24, - "color": "ceffff", - "name": "potion.levitation" + "color": "#FFCEFFFF", + "name": "levitation" } } \ No newline at end of file From f6c31680f651f4f27e75adde4df6ea424452478d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 13:25:11 +0100 Subject: [PATCH 20/23] Fixed unknown blocks dropping themselves --- src/pocketmine/block/Block.php | 10 +++------- src/pocketmine/block/UnknownBlock.php | 6 ++++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 1342eaf081..7663737cd6 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -659,13 +659,9 @@ class Block extends Position implements BlockIds, Metadatable{ * @return array */ public function getDrops(Item $item){ - if(!isset(self::$list[$this->getId()])){ //Unknown blocks - return []; - }else{ - return [ - [$this->getItemId(), $this->getDamage(), 1], - ]; - } + return [ + [$this->getItemId(), $this->getDamage(), 1], + ]; } /** diff --git a/src/pocketmine/block/UnknownBlock.php b/src/pocketmine/block/UnknownBlock.php index d8e2d58b81..16088afdda 100644 --- a/src/pocketmine/block/UnknownBlock.php +++ b/src/pocketmine/block/UnknownBlock.php @@ -23,9 +23,15 @@ declare(strict_types=1); namespace pocketmine\block; +use pocketmine\item\Item; + class UnknownBlock extends Transparent{ public function getHardness(){ return 0; } + + public function getDrops(Item $item){ + return []; + } } \ No newline at end of file From 83af4dcd5955db5249867b41b40b44dbccc5bcb3 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 13:50:19 +0100 Subject: [PATCH 21/23] Block API typehints --- src/pocketmine/block/ActivatorRail.php | 2 +- src/pocketmine/block/Air.php | 20 ++--- src/pocketmine/block/Anvil.php | 18 ++--- src/pocketmine/block/Bed.php | 12 +-- src/pocketmine/block/Bedrock.php | 10 +-- src/pocketmine/block/Beetroot.php | 4 +- src/pocketmine/block/Block.php | 76 +++++++++---------- src/pocketmine/block/Bookshelf.php | 8 +- src/pocketmine/block/BrewingStand.php | 8 +- src/pocketmine/block/BrickStairs.php | 10 +-- src/pocketmine/block/Bricks.php | 10 +-- src/pocketmine/block/BrownMushroom.php | 10 +-- src/pocketmine/block/BurningFurnace.php | 14 ++-- src/pocketmine/block/Cactus.php | 12 +-- src/pocketmine/block/Cake.php | 12 +-- src/pocketmine/block/Carpet.php | 12 +-- src/pocketmine/block/Carrot.php | 4 +- src/pocketmine/block/Chest.php | 14 ++-- src/pocketmine/block/Clay.php | 8 +- src/pocketmine/block/Coal.php | 8 +- src/pocketmine/block/CoalOre.php | 8 +- src/pocketmine/block/Cobblestone.php | 8 +- src/pocketmine/block/CobblestoneStairs.php | 8 +- src/pocketmine/block/CobblestoneWall.php | 10 +-- src/pocketmine/block/Cobweb.php | 10 +-- src/pocketmine/block/CocoaBlock.php | 4 +- src/pocketmine/block/CraftingTable.php | 10 +-- src/pocketmine/block/Crops.php | 6 +- src/pocketmine/block/Dandelion.php | 8 +- src/pocketmine/block/DaylightSensor.php | 6 +- src/pocketmine/block/DeadBush.php | 6 +- src/pocketmine/block/DetectorRail.php | 2 +- src/pocketmine/block/Diamond.php | 8 +- src/pocketmine/block/DiamondOre.php | 8 +- src/pocketmine/block/Dirt.php | 10 +-- src/pocketmine/block/Door.php | 10 +-- src/pocketmine/block/DoublePlant.php | 12 +-- src/pocketmine/block/DoubleStoneSlab.php | 8 +- src/pocketmine/block/DoubleWoodenSlab.php | 8 +- src/pocketmine/block/Emerald.php | 8 +- src/pocketmine/block/EmeraldOre.php | 8 +- src/pocketmine/block/EnchantingTable.php | 14 ++-- src/pocketmine/block/EndPortalFrame.php | 12 +-- src/pocketmine/block/EndStone.php | 8 +- src/pocketmine/block/Fallable.php | 2 +- src/pocketmine/block/Farmland.php | 8 +- src/pocketmine/block/Fence.php | 8 +- src/pocketmine/block/FenceGate.php | 8 +- src/pocketmine/block/Fire.php | 14 ++-- src/pocketmine/block/Flowable.php | 8 +- src/pocketmine/block/Flower.php | 8 +- src/pocketmine/block/FlowerPot.php | 10 +-- src/pocketmine/block/Furnace.php | 4 +- src/pocketmine/block/Glass.php | 6 +- src/pocketmine/block/GlassPane.php | 6 +- src/pocketmine/block/GlazedTerracotta.php | 6 +- src/pocketmine/block/GlowingObsidian.php | 6 +- src/pocketmine/block/GlowingRedstoneOre.php | 6 +- src/pocketmine/block/Glowstone.php | 10 +-- src/pocketmine/block/Gold.php | 8 +- src/pocketmine/block/GoldOre.php | 8 +- src/pocketmine/block/Grass.php | 12 +-- src/pocketmine/block/GrassPath.php | 8 +- src/pocketmine/block/Gravel.php | 8 +- src/pocketmine/block/HardenedClay.php | 8 +- src/pocketmine/block/HayBale.php | 8 +- src/pocketmine/block/Ice.php | 12 +-- src/pocketmine/block/Iron.php | 8 +- src/pocketmine/block/IronBars.php | 8 +- src/pocketmine/block/IronDoor.php | 8 +- src/pocketmine/block/IronOre.php | 8 +- src/pocketmine/block/IronTrapdoor.php | 6 +- src/pocketmine/block/ItemFrame.php | 12 +-- src/pocketmine/block/Ladder.php | 16 ++-- src/pocketmine/block/Lapis.php | 8 +- src/pocketmine/block/LapisOre.php | 8 +- src/pocketmine/block/Lava.php | 8 +- src/pocketmine/block/Leaves.php | 14 ++-- src/pocketmine/block/Leaves2.php | 2 +- src/pocketmine/block/Lever.php | 4 +- src/pocketmine/block/Liquid.php | 12 +-- src/pocketmine/block/LitPumpkin.php | 4 +- src/pocketmine/block/LitRedstoneLamp.php | 4 +- src/pocketmine/block/Melon.php | 8 +- src/pocketmine/block/MelonStem.php | 6 +- src/pocketmine/block/MonsterSpawner.php | 8 +- src/pocketmine/block/MossyCobblestone.php | 8 +- src/pocketmine/block/Mycelium.php | 10 +-- src/pocketmine/block/NetherBrick.php | 8 +- src/pocketmine/block/NetherBrickFence.php | 8 +- src/pocketmine/block/NetherBrickStairs.php | 8 +- src/pocketmine/block/NetherReactor.php | 8 +- src/pocketmine/block/NetherWartPlant.php | 6 +- src/pocketmine/block/Netherrack.php | 8 +- src/pocketmine/block/NoteBlock.php | 4 +- src/pocketmine/block/Obsidian.php | 8 +- src/pocketmine/block/PackedIce.php | 8 +- src/pocketmine/block/Planks.php | 8 +- src/pocketmine/block/Podzol.php | 8 +- src/pocketmine/block/Potato.php | 4 +- src/pocketmine/block/PoweredRail.php | 2 +- src/pocketmine/block/Prismarine.php | 8 +- src/pocketmine/block/Pumpkin.php | 10 +-- src/pocketmine/block/PumpkinStem.php | 6 +- src/pocketmine/block/Quartz.php | 8 +- src/pocketmine/block/QuartzStairs.php | 8 +- src/pocketmine/block/Rail.php | 10 +-- src/pocketmine/block/RedMushroom.php | 8 +- src/pocketmine/block/Redstone.php | 8 +- src/pocketmine/block/RedstoneLamp.php | 6 +- src/pocketmine/block/RedstoneOre.php | 12 +-- src/pocketmine/block/RedstoneTorch.php | 4 +- src/pocketmine/block/RedstoneTorchUnlit.php | 4 +- src/pocketmine/block/Sand.php | 8 +- src/pocketmine/block/Sandstone.php | 8 +- src/pocketmine/block/SandstoneStairs.php | 8 +- src/pocketmine/block/Sapling.php | 10 +-- src/pocketmine/block/SeaLantern.php | 8 +- src/pocketmine/block/SignPost.php | 14 ++-- src/pocketmine/block/Skull.php | 8 +- src/pocketmine/block/Snow.php | 8 +- src/pocketmine/block/SnowLayer.php | 14 ++-- src/pocketmine/block/Solid.php | 2 +- src/pocketmine/block/SoulSand.php | 8 +- src/pocketmine/block/Sponge.php | 6 +- src/pocketmine/block/StainedClay.php | 8 +- src/pocketmine/block/Stair.php | 2 +- src/pocketmine/block/StillLava.php | 2 +- src/pocketmine/block/StillWater.php | 2 +- src/pocketmine/block/Stone.php | 8 +- src/pocketmine/block/StoneBrickStairs.php | 8 +- src/pocketmine/block/StoneBricks.php | 8 +- src/pocketmine/block/StoneButton.php | 6 +- src/pocketmine/block/StonePressurePlate.php | 8 +- src/pocketmine/block/StoneSlab.php | 6 +- src/pocketmine/block/Stonecutter.php | 6 +- src/pocketmine/block/Sugarcane.php | 10 +-- src/pocketmine/block/TNT.php | 8 +- src/pocketmine/block/TallGrass.php | 10 +-- src/pocketmine/block/Thin.php | 2 +- src/pocketmine/block/Torch.php | 10 +-- src/pocketmine/block/Transparent.php | 2 +- src/pocketmine/block/Trapdoor.php | 12 +-- src/pocketmine/block/TrappedChest.php | 2 +- src/pocketmine/block/Tripwire.php | 4 +- src/pocketmine/block/TripwireHook.php | 4 +- src/pocketmine/block/UnknownBlock.php | 2 +- src/pocketmine/block/Vine.php | 18 ++--- src/pocketmine/block/WallSign.php | 4 +- src/pocketmine/block/Water.php | 6 +- src/pocketmine/block/WaterLily.php | 10 +-- .../block/WeightedPressurePlateHeavy.php | 2 +- .../block/WeightedPressurePlateLight.php | 8 +- src/pocketmine/block/Wheat.php | 4 +- src/pocketmine/block/Wood.php | 10 +-- src/pocketmine/block/Wood2.php | 2 +- src/pocketmine/block/WoodenButton.php | 2 +- src/pocketmine/block/WoodenDoor.php | 4 +- src/pocketmine/block/WoodenPressurePlate.php | 2 +- src/pocketmine/block/WoodenSlab.php | 10 +-- src/pocketmine/block/WoodenStairs.php | 6 +- src/pocketmine/block/Wool.php | 8 +- 162 files changed, 665 insertions(+), 667 deletions(-) diff --git a/src/pocketmine/block/ActivatorRail.php b/src/pocketmine/block/ActivatorRail.php index 65bdddeb1a..56e8a99792 100644 --- a/src/pocketmine/block/ActivatorRail.php +++ b/src/pocketmine/block/ActivatorRail.php @@ -27,7 +27,7 @@ class ActivatorRail extends Rail{ protected $id = self::ACTIVATOR_RAIL; - public function getName(){ + public function getName() : string{ return "Activator Rail"; } } diff --git a/src/pocketmine/block/Air.php b/src/pocketmine/block/Air.php index 21ec6ed846..e8f519a966 100644 --- a/src/pocketmine/block/Air.php +++ b/src/pocketmine/block/Air.php @@ -34,35 +34,35 @@ class Air extends Transparent{ protected $id = self::AIR; protected $meta = 0; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Air"; } - public function canPassThrough(){ + public function canPassThrough() : bool{ return true; } - public function isBreakable(Item $item){ + public function isBreakable(Item $item) : bool{ return false; } - public function canBeFlowedInto(){ + public function canBeFlowedInto() : bool{ return true; } - public function canBeReplaced(){ + public function canBeReplaced() : bool{ return true; } - public function canBePlaced(){ + public function canBePlaced() : bool{ return false; } - public function isSolid(){ + public function isSolid() : bool{ return false; } @@ -70,11 +70,11 @@ class Air extends Transparent{ return null; } - public function getHardness(){ + public function getHardness() : float{ return -1; } - public function getResistance(){ + public function getResistance() : float{ return 0; } diff --git a/src/pocketmine/block/Anvil.php b/src/pocketmine/block/Anvil.php index 28e3497697..e89c679164 100644 --- a/src/pocketmine/block/Anvil.php +++ b/src/pocketmine/block/Anvil.php @@ -36,23 +36,23 @@ class Anvil extends Fallable{ protected $id = self::ANVIL; - public function isSolid(){ + public function isSolid() : bool{ return false; } - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getResistance(){ + public function getResistance() : float{ return 6000; } - public function getName(){ + public function getName() : string{ static $names = [ self::TYPE_NORMAL => "Anvil", self::TYPE_SLIGHTLY_DAMAGED => "Slightly Damaged Anvil", @@ -61,11 +61,11 @@ class Anvil extends Fallable{ return $names[$this->meta & 0x0c] ?? "Anvil"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ $player->addWindow(new AnvilInventory($this)); } @@ -73,10 +73,10 @@ class Anvil extends Fallable{ return true; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $direction = ($player !== null ? $player->getDirection() : 0) & 0x03; $this->meta = ($this->meta & 0x0c) | $direction; - $this->getLevel()->setBlock($block, $this, true, true); + return $this->getLevel()->setBlock($block, $this, true, true); } public function getDrops(Item $item){ diff --git a/src/pocketmine/block/Bed.php b/src/pocketmine/block/Bed.php index 11e202b1aa..0bec31d3d4 100644 --- a/src/pocketmine/block/Bed.php +++ b/src/pocketmine/block/Bed.php @@ -43,15 +43,15 @@ class Bed extends Transparent{ protected $id = self::BED_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.2; } - public function getName(){ + public function getName() : string{ return "Bed Block"; } @@ -135,7 +135,7 @@ class Bed extends Transparent{ return null; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($player !== null){ $other = $this->getOtherHalf(); if($other === null){ @@ -172,7 +172,7 @@ class Bed extends Transparent{ } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if(!$down->isTransparent()){ $meta = (($player instanceof Player ? $player->getDirection() : 0) - 1) & 0x03; @@ -203,7 +203,7 @@ class Bed extends Transparent{ return false; } - public function onBreak(Item $item){ + public function onBreak(Item $item) : bool{ $this->getLevel()->setBlock($this, Block::get(Block::AIR), true, true); if(($other = $this->getOtherHalf()) !== null){ $this->getLevel()->useBreakOn($other); //make sure tiles get removed diff --git a/src/pocketmine/block/Bedrock.php b/src/pocketmine/block/Bedrock.php index 1196f99ecd..aa3d21ef17 100644 --- a/src/pocketmine/block/Bedrock.php +++ b/src/pocketmine/block/Bedrock.php @@ -29,23 +29,23 @@ class Bedrock extends Solid{ protected $id = self::BEDROCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Bedrock"; } - public function getHardness(){ + public function getHardness() : float{ return -1; } - public function getResistance(){ + public function getResistance() : float{ return 18000000; } - public function isBreakable(Item $item){ + public function isBreakable(Item $item) : bool{ return false; } diff --git a/src/pocketmine/block/Beetroot.php b/src/pocketmine/block/Beetroot.php index 0cecf9e003..b1de667e36 100644 --- a/src/pocketmine/block/Beetroot.php +++ b/src/pocketmine/block/Beetroot.php @@ -29,11 +29,11 @@ class Beetroot extends Crops{ protected $id = self::BEETROOT_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Beetroot Block"; } diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 7663737cd6..027955ffc1 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -375,7 +375,7 @@ class Block extends Position implements BlockIds, Metadatable{ * * @return Block */ - public static function get($id, $meta = 0, Position $pos = null){ + public static function get(int $id, int $meta = 0, Position $pos = null) : Block{ try{ $block = self::$fullList[($id << 4) | $meta]; if($block !== null){ @@ -425,14 +425,14 @@ class Block extends Position implements BlockIds, Metadatable{ /** * @return string */ - public function getName(){ + public function getName() : string{ return $this->fallbackName; } /** * @return int */ - final public function getId(){ + final public function getId() : int{ return $this->id; } @@ -449,32 +449,32 @@ class Block extends Position implements BlockIds, Metadatable{ /** * @return int */ - final public function getDamage(){ + final public function getDamage() : int{ return $this->meta; } /** * @param int $meta */ - final public function setDamage($meta){ + final public function setDamage(int $meta){ $this->meta = $meta & 0x0f; } /** * Places the Block, using block space and block target, and side. Returns if the block has been placed. * - * @param Item $item - * @param Block $block - * @param Block $target - * @param int $face - * @param float $fx - * @param float $fy - * @param float $fz - * @param Player $player = null + * @param Item $item + * @param Block $block + * @param Block $target + * @param int $face + * @param float $fx + * @param float $fy + * @param float $fz + * @param Player|null $player * * @return bool */ - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ return $this->getLevel()->setBlock($this, $this, true, true); } @@ -485,7 +485,7 @@ class Block extends Position implements BlockIds, Metadatable{ * * @return bool */ - public function isBreakable(Item $item){ + public function isBreakable(Item $item) : bool{ return true; } @@ -494,9 +494,9 @@ class Block extends Position implements BlockIds, Metadatable{ * * @param Item $item * - * @return mixed + * @return bool */ - public function onBreak(Item $item){ + public function onBreak(Item $item) : bool{ return $this->getLevel()->setBlock($this, new Air(), true, true); } @@ -505,56 +505,56 @@ class Block extends Position implements BlockIds, Metadatable{ * * @param int $type * - * @return int|bool + * @return bool|int */ - public function onUpdate($type){ + public function onUpdate(int $type){ return false; } /** * Do actions when activated by Item. Returns if it has done anything * - * @param Item $item - * @param Player $player + * @param Item $item + * @param Player|null $player * * @return bool */ - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ return false; } /** * @return float */ - public function getHardness(){ + public function getHardness() : float{ return 10; } /** * @return float */ - public function getResistance(){ + public function getResistance() : float{ return $this->getHardness() * 5; } /** * @return int */ - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_NONE; } /** * @return float */ - public function getFrictionFactor(){ + public function getFrictionFactor() : float{ return 0.6; } /** * @return int 0-15 */ - public function getLightLevel(){ + public function getLightLevel() : int{ return 0; } @@ -583,45 +583,43 @@ class Block extends Position implements BlockIds, Metadatable{ /** * AKA: Block->isPlaceable - * * @return bool */ - public function canBePlaced(){ + public function canBePlaced() : bool{ return true; } /** * @return bool */ - public function canBeReplaced(){ + public function canBeReplaced() : bool{ return false; } /** * @return bool */ - public function isTransparent(){ + public function isTransparent() : bool{ return false; } - public function isSolid(){ + public function isSolid() : bool{ return true; } /** * AKA: Block->isFlowable - * * @return bool */ - public function canBeFlowedInto(){ + public function canBeFlowedInto() : bool{ return false; } - public function hasEntityCollision(){ + public function hasEntityCollision() : bool{ return false; } - public function canPassThrough(){ + public function canPassThrough() : bool{ return false; } @@ -671,7 +669,7 @@ class Block extends Position implements BlockIds, Metadatable{ * * @return float */ - public function getBreakTime(Item $item){ + public function getBreakTime(Item $item) : float{ $base = $this->getHardness() * 1.5; if($this->canBeBrokenWith($item)){ if($this->getToolType() === Tool::TYPE_SHEARS and $item->isShears()){ @@ -710,7 +708,7 @@ class Block extends Position implements BlockIds, Metadatable{ return $base; } - public function canBeBrokenWith(Item $item){ + public function canBeBrokenWith(Item $item) : bool{ return $this->getHardness() !== -1; } @@ -752,7 +750,7 @@ class Block extends Position implements BlockIds, Metadatable{ * * @return bool */ - public function collidesWithBB(AxisAlignedBB $bb){ + public function collidesWithBB(AxisAlignedBB $bb) : bool{ $bb2 = $this->getBoundingBox(); return $bb2 !== null and $bb->intersectsWith($bb2); diff --git a/src/pocketmine/block/Bookshelf.php b/src/pocketmine/block/Bookshelf.php index c110baf214..9a12f77970 100644 --- a/src/pocketmine/block/Bookshelf.php +++ b/src/pocketmine/block/Bookshelf.php @@ -30,19 +30,19 @@ class Bookshelf extends Solid{ protected $id = self::BOOKSHELF; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Bookshelf"; } - public function getHardness(){ + public function getHardness() : float{ return 1.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/BrewingStand.php b/src/pocketmine/block/BrewingStand.php index 36d688f018..329f71d616 100644 --- a/src/pocketmine/block/BrewingStand.php +++ b/src/pocketmine/block/BrewingStand.php @@ -29,19 +29,19 @@ class BrewingStand extends Transparent{ protected $id = self::BREWING_STAND_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Brewing Stand"; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } } \ No newline at end of file diff --git a/src/pocketmine/block/BrickStairs.php b/src/pocketmine/block/BrickStairs.php index 87e94afcaa..b5669e381b 100644 --- a/src/pocketmine/block/BrickStairs.php +++ b/src/pocketmine/block/BrickStairs.php @@ -29,23 +29,23 @@ class BrickStairs extends Stair{ protected $id = self::BRICK_STAIRS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getResistance(){ + public function getResistance() : float{ return 30; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Brick Stairs"; } diff --git a/src/pocketmine/block/Bricks.php b/src/pocketmine/block/Bricks.php index 4eb22d9282..ff90619eb7 100644 --- a/src/pocketmine/block/Bricks.php +++ b/src/pocketmine/block/Bricks.php @@ -30,23 +30,23 @@ class Bricks extends Solid{ protected $id = self::BRICK_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getResistance(){ + public function getResistance() : float{ return 30; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Bricks"; } diff --git a/src/pocketmine/block/BrownMushroom.php b/src/pocketmine/block/BrownMushroom.php index f82ba59135..ff03f18fd6 100644 --- a/src/pocketmine/block/BrownMushroom.php +++ b/src/pocketmine/block/BrownMushroom.php @@ -32,19 +32,19 @@ class BrownMushroom extends Flowable{ protected $id = self::BROWN_MUSHROOM; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Brown Mushroom"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 1; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ $this->getLevel()->useBreakOn($this); @@ -56,7 +56,7 @@ class BrownMushroom extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->isTransparent() === false){ $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/BurningFurnace.php b/src/pocketmine/block/BurningFurnace.php index e3075b0498..ddc2b91f52 100644 --- a/src/pocketmine/block/BurningFurnace.php +++ b/src/pocketmine/block/BurningFurnace.php @@ -38,27 +38,27 @@ class BurningFurnace extends Solid{ protected $id = self::BURNING_FURNACE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Burning Furnace"; } - public function getHardness(){ + public function getHardness() : float{ return 3.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 13; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $faces = [ 0 => 4, 1 => 2, @@ -91,7 +91,7 @@ class BurningFurnace extends Solid{ return true; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ $furnace = $this->getLevel()->getTile($this); if(!($furnace instanceof TileFurnace)){ diff --git a/src/pocketmine/block/Cactus.php b/src/pocketmine/block/Cactus.php index 1402dc9844..4903302379 100644 --- a/src/pocketmine/block/Cactus.php +++ b/src/pocketmine/block/Cactus.php @@ -38,19 +38,19 @@ class Cactus extends Transparent{ protected $id = self::CACTUS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.4; } - public function hasEntityCollision(){ + public function hasEntityCollision() : bool{ return true; } - public function getName(){ + public function getName() : string{ return "Cactus"; } @@ -71,7 +71,7 @@ class Cactus extends Transparent{ $entity->attack($ev->getFinalDamage(), $ev); } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() !== self::SAND and $down->getId() !== self::CACTUS){ @@ -108,7 +108,7 @@ class Cactus extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::SAND or $down->getId() === self::CACTUS){ $block0 = $this->getSide(Vector3::SIDE_NORTH); diff --git a/src/pocketmine/block/Cake.php b/src/pocketmine/block/Cake.php index 3903739131..40f254e2b4 100644 --- a/src/pocketmine/block/Cake.php +++ b/src/pocketmine/block/Cake.php @@ -36,15 +36,15 @@ class Cake extends Transparent implements FoodSource{ protected $id = self::CAKE_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } - public function getName(){ + public function getName() : string{ return "Cake Block"; } @@ -62,7 +62,7 @@ class Cake extends Transparent implements FoodSource{ ); } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() !== self::AIR){ $this->getLevel()->setBlock($block, $this, true, true); @@ -73,7 +73,7 @@ class Cake extends Transparent implements FoodSource{ return false; } - public function onUpdate($type){ + 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, new Air(), true); @@ -89,7 +89,7 @@ class Cake extends Transparent implements FoodSource{ return []; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player and $player->getHealth() < $player->getMaxHealth()){ $ev = new EntityEatBlockEvent($player, $this); diff --git a/src/pocketmine/block/Carpet.php b/src/pocketmine/block/Carpet.php index 08ada6a6a7..edd54ae793 100644 --- a/src/pocketmine/block/Carpet.php +++ b/src/pocketmine/block/Carpet.php @@ -34,19 +34,19 @@ class Carpet extends Flowable{ protected $id = self::CARPET; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.1; } - public function isSolid(){ + public function isSolid() : bool{ return true; } - public function getName(){ + public function getName() : string{ return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Carpet"; } @@ -62,7 +62,7 @@ class Carpet extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() !== self::AIR){ $this->getLevel()->setBlock($block, $this, true, true); @@ -73,7 +73,7 @@ class Carpet extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/Carrot.php b/src/pocketmine/block/Carrot.php index 2e13d5bb29..a9acbc11c4 100644 --- a/src/pocketmine/block/Carrot.php +++ b/src/pocketmine/block/Carrot.php @@ -29,11 +29,11 @@ class Carrot extends Crops{ protected $id = self::CARROT_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Carrot Block"; } diff --git a/src/pocketmine/block/Chest.php b/src/pocketmine/block/Chest.php index e2b7688f67..b688647177 100644 --- a/src/pocketmine/block/Chest.php +++ b/src/pocketmine/block/Chest.php @@ -40,19 +40,19 @@ class Chest extends Transparent{ protected $id = self::CHEST; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2.5; } - public function getName(){ + public function getName() : string{ return "Chest"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } @@ -67,7 +67,7 @@ class Chest extends Transparent{ ); } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $faces = [ 0 => 4, 1 => 2, @@ -124,7 +124,7 @@ class Chest extends Transparent{ return true; } - public function onBreak(Item $item){ + public function onBreak(Item $item) : bool{ $t = $this->getLevel()->getTile($this); if($t instanceof TileChest){ $t->unpair(); @@ -134,7 +134,7 @@ class Chest extends Transparent{ return true; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ $top = $this->getSide(Vector3::SIDE_UP); if($top->isTransparent() !== true){ diff --git a/src/pocketmine/block/Clay.php b/src/pocketmine/block/Clay.php index 989b20d525..3afb17a5fb 100644 --- a/src/pocketmine/block/Clay.php +++ b/src/pocketmine/block/Clay.php @@ -30,19 +30,19 @@ class Clay extends Solid{ protected $id = self::CLAY_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } - public function getName(){ + public function getName() : string{ return "Clay Block"; } diff --git a/src/pocketmine/block/Coal.php b/src/pocketmine/block/Coal.php index c0262577a3..46b50dc178 100644 --- a/src/pocketmine/block/Coal.php +++ b/src/pocketmine/block/Coal.php @@ -30,19 +30,19 @@ class Coal extends Solid{ protected $id = self::COAL_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Coal Block"; } diff --git a/src/pocketmine/block/CoalOre.php b/src/pocketmine/block/CoalOre.php index d6342c6710..2ba2b6209a 100644 --- a/src/pocketmine/block/CoalOre.php +++ b/src/pocketmine/block/CoalOre.php @@ -30,19 +30,19 @@ class CoalOre extends Solid{ protected $id = self::COAL_ORE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 3; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Coal Ore"; } diff --git a/src/pocketmine/block/Cobblestone.php b/src/pocketmine/block/Cobblestone.php index c5376b5c0b..df6d0ae647 100644 --- a/src/pocketmine/block/Cobblestone.php +++ b/src/pocketmine/block/Cobblestone.php @@ -30,19 +30,19 @@ class Cobblestone extends Solid{ protected $id = self::COBBLESTONE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Cobblestone"; } - public function getHardness(){ + public function getHardness() : float{ return 2; } diff --git a/src/pocketmine/block/CobblestoneStairs.php b/src/pocketmine/block/CobblestoneStairs.php index c13783a7e6..2e6b429ef1 100644 --- a/src/pocketmine/block/CobblestoneStairs.php +++ b/src/pocketmine/block/CobblestoneStairs.php @@ -29,19 +29,19 @@ class CobblestoneStairs extends Stair{ protected $id = self::COBBLESTONE_STAIRS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Cobblestone Stairs"; } diff --git a/src/pocketmine/block/CobblestoneWall.php b/src/pocketmine/block/CobblestoneWall.php index ff918482dc..589b8a691d 100644 --- a/src/pocketmine/block/CobblestoneWall.php +++ b/src/pocketmine/block/CobblestoneWall.php @@ -33,23 +33,23 @@ class CobblestoneWall extends Transparent{ protected $id = self::COBBLESTONE_WALL; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function isSolid(){ + public function isSolid() : bool{ return false; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getName(){ + public function getName() : string{ if($this->meta === 0x01){ return "Mossy Cobblestone Wall"; } diff --git a/src/pocketmine/block/Cobweb.php b/src/pocketmine/block/Cobweb.php index 3d2fc189c8..70c2163fb0 100644 --- a/src/pocketmine/block/Cobweb.php +++ b/src/pocketmine/block/Cobweb.php @@ -31,23 +31,23 @@ class Cobweb extends Flowable{ protected $id = self::COBWEB; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function hasEntityCollision(){ + public function hasEntityCollision() : bool{ return true; } - public function getName(){ + public function getName() : string{ return "Cobweb"; } - public function getHardness(){ + public function getHardness() : float{ return 4; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SWORD; } diff --git a/src/pocketmine/block/CocoaBlock.php b/src/pocketmine/block/CocoaBlock.php index f3b8cafb33..74c349dd98 100644 --- a/src/pocketmine/block/CocoaBlock.php +++ b/src/pocketmine/block/CocoaBlock.php @@ -27,11 +27,11 @@ class CocoaBlock extends Solid{ protected $id = self::COCOA_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Cocoa Block"; } } diff --git a/src/pocketmine/block/CraftingTable.php b/src/pocketmine/block/CraftingTable.php index 658659050a..797ef4ee45 100644 --- a/src/pocketmine/block/CraftingTable.php +++ b/src/pocketmine/block/CraftingTable.php @@ -31,23 +31,23 @@ class CraftingTable extends Solid{ protected $id = self::CRAFTING_TABLE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2.5; } - public function getName(){ + public function getName() : string{ return "Crafting Table"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ $player->craftingType = 1; } diff --git a/src/pocketmine/block/Crops.php b/src/pocketmine/block/Crops.php index e6bfd30683..da387e9e73 100644 --- a/src/pocketmine/block/Crops.php +++ b/src/pocketmine/block/Crops.php @@ -32,7 +32,7 @@ use pocketmine\Server; abstract class Crops extends Flowable{ - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($block->getSide(Vector3::SIDE_DOWN)->getId() === Block::FARMLAND){ $this->getLevel()->setBlock($block, $this, true, true); @@ -43,7 +43,7 @@ abstract class Crops extends Flowable{ } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal $block = clone $this; $block->meta += mt_rand(2, 5); @@ -65,7 +65,7 @@ abstract class Crops extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/Dandelion.php b/src/pocketmine/block/Dandelion.php index c086784ae0..ba8e43e119 100644 --- a/src/pocketmine/block/Dandelion.php +++ b/src/pocketmine/block/Dandelion.php @@ -32,16 +32,16 @@ class Dandelion extends Flowable{ protected $id = self::DANDELION; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Dandelion"; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === 2 or $down->getId() === 3 or $down->getId() === 60){ $this->getLevel()->setBlock($block, $this, true, true); @@ -52,7 +52,7 @@ class Dandelion extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/DaylightSensor.php b/src/pocketmine/block/DaylightSensor.php index 29a2093fd0..14c41b1878 100644 --- a/src/pocketmine/block/DaylightSensor.php +++ b/src/pocketmine/block/DaylightSensor.php @@ -27,15 +27,15 @@ class DaylightSensor extends Transparent{ protected $id = self::DAYLIGHT_SENSOR; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Daylight Sensor"; } - public function getHardness(){ + public function getHardness() : float{ return 0.2; } diff --git a/src/pocketmine/block/DeadBush.php b/src/pocketmine/block/DeadBush.php index 40c5f9ebd6..380ed8b65f 100644 --- a/src/pocketmine/block/DeadBush.php +++ b/src/pocketmine/block/DeadBush.php @@ -30,16 +30,16 @@ class DeadBush extends Flowable{ protected $id = self::DEAD_BUSH; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Dead Bush"; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/DetectorRail.php b/src/pocketmine/block/DetectorRail.php index 9685a02efd..d221b7c947 100644 --- a/src/pocketmine/block/DetectorRail.php +++ b/src/pocketmine/block/DetectorRail.php @@ -27,7 +27,7 @@ class DetectorRail extends Rail{ protected $id = self::DETECTOR_RAIL; - public function getName(){ + public function getName() : string{ return "Detector Rail"; } } diff --git a/src/pocketmine/block/Diamond.php b/src/pocketmine/block/Diamond.php index 1c3fb8cb0f..baedad53f1 100644 --- a/src/pocketmine/block/Diamond.php +++ b/src/pocketmine/block/Diamond.php @@ -30,19 +30,19 @@ class Diamond extends Solid{ protected $id = self::DIAMOND_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getName(){ + public function getName() : string{ return "Diamond Block"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/DiamondOre.php b/src/pocketmine/block/DiamondOre.php index 188dd5d12f..f9e2992b43 100644 --- a/src/pocketmine/block/DiamondOre.php +++ b/src/pocketmine/block/DiamondOre.php @@ -30,19 +30,19 @@ class DiamondOre extends Solid{ protected $id = self::DIAMOND_ORE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 3; } - public function getName(){ + public function getName() : string{ return "Diamond Ore"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/Dirt.php b/src/pocketmine/block/Dirt.php index 3ee68eeabe..004f5f7f76 100644 --- a/src/pocketmine/block/Dirt.php +++ b/src/pocketmine/block/Dirt.php @@ -31,23 +31,23 @@ class Dirt extends Solid{ protected $id = self::DIRT; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } - public function getName(){ + public function getName() : string{ return "Dirt"; } - public function onActivate(Item $item, Player $player = null){ + 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); diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index 44799bc413..fc02d773e4 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -33,7 +33,7 @@ use pocketmine\Player; abstract class Door extends Transparent{ - public function isSolid(){ + public function isSolid() : bool{ return false; } @@ -201,7 +201,7 @@ abstract class Door extends Transparent{ return $bb; } - public function onUpdate($type){ + 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, new Air(), false); @@ -216,7 +216,7 @@ abstract class Door extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($face === 1){ $blockUp = $this->getSide(Vector3::SIDE_UP); $blockDown = $this->getSide(Vector3::SIDE_DOWN); @@ -246,7 +246,7 @@ abstract class Door extends Transparent{ return false; } - public function onBreak(Item $item){ + public function onBreak(Item $item) : bool{ if(($this->getDamage() & 0x08) === 0x08){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === $this->getId()){ @@ -263,7 +263,7 @@ abstract class Door extends Transparent{ return true; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if(($this->getDamage() & 0x08) === 0x08){ //Top $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === $this->getId()){ diff --git a/src/pocketmine/block/DoublePlant.php b/src/pocketmine/block/DoublePlant.php index 7de4912a71..2287da7968 100644 --- a/src/pocketmine/block/DoublePlant.php +++ b/src/pocketmine/block/DoublePlant.php @@ -33,15 +33,15 @@ class DoublePlant extends Flowable{ protected $id = self::DOUBLE_PLANT; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function canBeReplaced(){ + public function canBeReplaced() : bool{ return $this->meta === 2 or $this->meta === 3; //grass or fern } - public function getName(){ + public function getName() : string{ static $names = [ 0 => "Sunflower", 1 => "Lilac", @@ -53,7 +53,7 @@ class DoublePlant extends Flowable{ return $names[$this->meta & 0x07] ?? ""; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $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); @@ -83,7 +83,7 @@ class DoublePlant extends Flowable{ ); } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $down = $this->getSide(Vector3::SIDE_DOWN); if(!$this->isValidHalfPlant() or (($this->meta & self::BITFLAG_TOP) === 0 and $down->isTransparent())){ @@ -96,7 +96,7 @@ class DoublePlant extends Flowable{ return false; } - public function onBreak(Item $item){ + 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)); } diff --git a/src/pocketmine/block/DoubleStoneSlab.php b/src/pocketmine/block/DoubleStoneSlab.php index 84fb76b049..b2c4e456db 100644 --- a/src/pocketmine/block/DoubleStoneSlab.php +++ b/src/pocketmine/block/DoubleStoneSlab.php @@ -30,19 +30,19 @@ class DoubleStoneSlab extends Solid{ protected $id = self::DOUBLE_STONE_SLAB; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ static $names = [ 0 => "Stone", 1 => "Sandstone", diff --git a/src/pocketmine/block/DoubleWoodenSlab.php b/src/pocketmine/block/DoubleWoodenSlab.php index a0603abc36..a4f431b482 100644 --- a/src/pocketmine/block/DoubleWoodenSlab.php +++ b/src/pocketmine/block/DoubleWoodenSlab.php @@ -30,19 +30,19 @@ class DoubleWoodenSlab extends Solid{ protected $id = self::DOUBLE_WOODEN_SLAB; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } - public function getName(){ + public function getName() : string{ static $names = [ 0 => "Oak", 1 => "Spruce", diff --git a/src/pocketmine/block/Emerald.php b/src/pocketmine/block/Emerald.php index ec516b1548..6cb9bd53e8 100644 --- a/src/pocketmine/block/Emerald.php +++ b/src/pocketmine/block/Emerald.php @@ -30,19 +30,19 @@ class Emerald extends Solid{ protected $id = self::EMERALD_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Emerald Block"; } diff --git a/src/pocketmine/block/EmeraldOre.php b/src/pocketmine/block/EmeraldOre.php index b10cf1743e..3ace4ec7fd 100644 --- a/src/pocketmine/block/EmeraldOre.php +++ b/src/pocketmine/block/EmeraldOre.php @@ -30,19 +30,19 @@ class EmeraldOre extends Solid{ protected $id = self::EMERALD_ORE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Emerald Ore"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 3; } diff --git a/src/pocketmine/block/EnchantingTable.php b/src/pocketmine/block/EnchantingTable.php index df2d6aa602..d3f3c263c4 100644 --- a/src/pocketmine/block/EnchantingTable.php +++ b/src/pocketmine/block/EnchantingTable.php @@ -36,11 +36,11 @@ class EnchantingTable extends Transparent{ protected $id = self::ENCHANTING_TABLE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $this->getLevel()->setBlock($block, $this, true, true); $nbt = new CompoundTag("", [ new StringTag("id", Tile::ENCHANT_TABLE), @@ -64,23 +64,23 @@ class EnchantingTable extends Transparent{ return true; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getResistance(){ + public function getResistance() : float{ return 6000; } - public function getName(){ + public function getName() : string{ return "Enchanting Table"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($player instanceof Player){ //TODO lock diff --git a/src/pocketmine/block/EndPortalFrame.php b/src/pocketmine/block/EndPortalFrame.php index 858ca375e3..3141929ef9 100644 --- a/src/pocketmine/block/EndPortalFrame.php +++ b/src/pocketmine/block/EndPortalFrame.php @@ -30,27 +30,27 @@ class EndPortalFrame extends Solid{ protected $id = self::END_PORTAL_FRAME; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 1; } - public function getName(){ + public function getName() : string{ return "End Portal Frame"; } - public function getHardness(){ + public function getHardness() : float{ return -1; } - public function getResistance(){ + public function getResistance() : float{ return 18000000; } - public function isBreakable(Item $item){ + public function isBreakable(Item $item) : bool{ return false; } diff --git a/src/pocketmine/block/EndStone.php b/src/pocketmine/block/EndStone.php index 5487b68f23..3b4910dccc 100644 --- a/src/pocketmine/block/EndStone.php +++ b/src/pocketmine/block/EndStone.php @@ -29,19 +29,19 @@ class EndStone extends Solid{ protected $id = self::END_STONE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "End Stone"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 3; } } \ No newline at end of file diff --git a/src/pocketmine/block/Fallable.php b/src/pocketmine/block/Fallable.php index 2ae79796ac..19ee9f7378 100644 --- a/src/pocketmine/block/Fallable.php +++ b/src/pocketmine/block/Fallable.php @@ -35,7 +35,7 @@ use pocketmine\nbt\tag\ListTag; abstract class Fallable extends Solid{ - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::AIR or ($down instanceof Liquid)){ diff --git a/src/pocketmine/block/Farmland.php b/src/pocketmine/block/Farmland.php index 32a4389222..426fa8ae76 100644 --- a/src/pocketmine/block/Farmland.php +++ b/src/pocketmine/block/Farmland.php @@ -31,19 +31,19 @@ class Farmland extends Transparent{ protected $id = self::FARMLAND; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Farmland"; } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } diff --git a/src/pocketmine/block/Fence.php b/src/pocketmine/block/Fence.php index 34c50949de..771ce24e5b 100644 --- a/src/pocketmine/block/Fence.php +++ b/src/pocketmine/block/Fence.php @@ -37,20 +37,20 @@ class Fence extends Transparent{ protected $id = self::FENCE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } - public function getName(){ + public function getName() : string{ static $names = [ self::FENCE_OAK => "Oak Fence", self::FENCE_SPRUCE => "Spruce Fence", diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index 270c1636d9..3153d19296 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -31,11 +31,11 @@ use pocketmine\Player; class FenceGate extends Transparent{ - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } @@ -68,7 +68,7 @@ class FenceGate extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $this->meta = ($player instanceof Player ? ($player->getDirection() - 1) & 0x03 : 0); $this->getLevel()->setBlock($block, $this, true, true); @@ -81,7 +81,7 @@ class FenceGate extends Transparent{ ]; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ $this->meta = (($this->meta ^ 0x04) & ~0x02); if($player !== null){ diff --git a/src/pocketmine/block/Fire.php b/src/pocketmine/block/Fire.php index fb3919e669..f7ceda0343 100644 --- a/src/pocketmine/block/Fire.php +++ b/src/pocketmine/block/Fire.php @@ -37,27 +37,27 @@ class Fire extends Flowable{ protected $id = self::FIRE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function hasEntityCollision(){ + public function hasEntityCollision() : bool{ return true; } - public function getName(){ + public function getName() : string{ return "Fire Block"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 15; } - public function isBreakable(Item $item){ + public function isBreakable(Item $item) : bool{ return false; } - public function canBeReplaced(){ + public function canBeReplaced() : bool{ return true; } @@ -79,7 +79,7 @@ class Fire extends Flowable{ return []; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ for($s = 0; $s <= 5; ++$s){ $side = $this->getSide($s); diff --git a/src/pocketmine/block/Flowable.php b/src/pocketmine/block/Flowable.php index e7cb0de466..73d5e54885 100644 --- a/src/pocketmine/block/Flowable.php +++ b/src/pocketmine/block/Flowable.php @@ -25,19 +25,19 @@ namespace pocketmine\block; abstract class Flowable extends Transparent{ - public function canBeFlowedInto(){ + public function canBeFlowedInto() : bool{ return true; } - public function getHardness(){ + public function getHardness() : float{ return 0; } - public function getResistance(){ + public function getResistance() : float{ return 0; } - public function isSolid(){ + public function isSolid() : bool{ return false; } diff --git a/src/pocketmine/block/Flower.php b/src/pocketmine/block/Flower.php index abcc6aed1d..c227e8a8fa 100644 --- a/src/pocketmine/block/Flower.php +++ b/src/pocketmine/block/Flower.php @@ -41,11 +41,11 @@ class Flower extends Flowable{ protected $id = self::RED_FLOWER; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ static $names = [ self::TYPE_POPPY => "Poppy", self::TYPE_BLUE_ORCHID => "Blue Orchid", @@ -60,7 +60,7 @@ class Flower extends Flowable{ return $names[$this->meta] ?? "Unknown"; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === Block::GRASS or $down->getId() === Block::DIRT or $down->getId() === Block::FARMLAND){ $this->getLevel()->setBlock($block, $this, true); @@ -71,7 +71,7 @@ class Flower extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/FlowerPot.php b/src/pocketmine/block/FlowerPot.php index 45f0650607..44dd69fd94 100644 --- a/src/pocketmine/block/FlowerPot.php +++ b/src/pocketmine/block/FlowerPot.php @@ -42,11 +42,11 @@ class FlowerPot extends Flowable{ protected $id = self::FLOWER_POT_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Flower Pot Block"; } @@ -61,7 +61,7 @@ class FlowerPot extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ return false; } @@ -87,7 +87,7 @@ class FlowerPot extends Flowable{ return true; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ $this->getLevel()->useBreakOn($this); @@ -99,7 +99,7 @@ class FlowerPot extends Flowable{ return false; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ $pot = $this->getLevel()->getTile($this); if(!($pot instanceof TileFlowerPot)){ return false; diff --git a/src/pocketmine/block/Furnace.php b/src/pocketmine/block/Furnace.php index 3c1fdeae06..c554500252 100644 --- a/src/pocketmine/block/Furnace.php +++ b/src/pocketmine/block/Furnace.php @@ -28,11 +28,11 @@ class Furnace extends BurningFurnace{ protected $id = self::FURNACE; - public function getName(){ + public function getName() : string{ return "Furnace"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 0; } } \ No newline at end of file diff --git a/src/pocketmine/block/Glass.php b/src/pocketmine/block/Glass.php index ce0884c4e7..fe460f1d3f 100644 --- a/src/pocketmine/block/Glass.php +++ b/src/pocketmine/block/Glass.php @@ -29,15 +29,15 @@ class Glass extends Transparent{ protected $id = self::GLASS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Glass"; } - public function getHardness(){ + public function getHardness() : float{ return 0.3; } diff --git a/src/pocketmine/block/GlassPane.php b/src/pocketmine/block/GlassPane.php index 2d9d3f8c6e..f67faca64b 100644 --- a/src/pocketmine/block/GlassPane.php +++ b/src/pocketmine/block/GlassPane.php @@ -29,15 +29,15 @@ class GlassPane extends Thin{ protected $id = self::GLASS_PANE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Glass Pane"; } - public function getHardness(){ + public function getHardness() : float{ return 0.3; } diff --git a/src/pocketmine/block/GlazedTerracotta.php b/src/pocketmine/block/GlazedTerracotta.php index 2525a2f7c2..b2df2c0c86 100644 --- a/src/pocketmine/block/GlazedTerracotta.php +++ b/src/pocketmine/block/GlazedTerracotta.php @@ -30,15 +30,15 @@ use pocketmine\Player; class GlazedTerracotta extends Solid{ - public function getHardness(){ + public function getHardness() : float{ return 1.4; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($player !== null){ $faces = [ 0 => 4, diff --git a/src/pocketmine/block/GlowingObsidian.php b/src/pocketmine/block/GlowingObsidian.php index f2f04c25b7..c851563c18 100644 --- a/src/pocketmine/block/GlowingObsidian.php +++ b/src/pocketmine/block/GlowingObsidian.php @@ -28,15 +28,15 @@ class GlowingObsidian extends Solid{ protected $id = self::GLOWING_OBSIDIAN; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Glowing Obsidian"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 12; } diff --git a/src/pocketmine/block/GlowingRedstoneOre.php b/src/pocketmine/block/GlowingRedstoneOre.php index 90bb683ae6..161b65c282 100644 --- a/src/pocketmine/block/GlowingRedstoneOre.php +++ b/src/pocketmine/block/GlowingRedstoneOre.php @@ -29,15 +29,15 @@ class GlowingRedstoneOre extends RedstoneOre{ protected $id = self::GLOWING_REDSTONE_ORE; - public function getName(){ + public function getName() : string{ return "Glowing Redstone Ore"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 9; } - public function onUpdate($type){ + 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); diff --git a/src/pocketmine/block/Glowstone.php b/src/pocketmine/block/Glowstone.php index 592acbeb30..8d850b6313 100644 --- a/src/pocketmine/block/Glowstone.php +++ b/src/pocketmine/block/Glowstone.php @@ -30,23 +30,23 @@ class Glowstone extends Transparent{ protected $id = self::GLOWSTONE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Glowstone"; } - public function getHardness(){ + public function getHardness() : float{ return 0.3; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 15; } diff --git a/src/pocketmine/block/Gold.php b/src/pocketmine/block/Gold.php index 6fe7128ec6..e000d0526c 100644 --- a/src/pocketmine/block/Gold.php +++ b/src/pocketmine/block/Gold.php @@ -30,19 +30,19 @@ class Gold extends Solid{ protected $id = self::GOLD_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Gold Block"; } - public function getHardness(){ + public function getHardness() : float{ return 3; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/GoldOre.php b/src/pocketmine/block/GoldOre.php index a56ecf5b65..59841d708e 100644 --- a/src/pocketmine/block/GoldOre.php +++ b/src/pocketmine/block/GoldOre.php @@ -30,19 +30,19 @@ class GoldOre extends Solid{ protected $id = self::GOLD_ORE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Gold Ore"; } - public function getHardness(){ + public function getHardness() : float{ return 3; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/Grass.php b/src/pocketmine/block/Grass.php index 7c9b77f512..97c80a7db8 100644 --- a/src/pocketmine/block/Grass.php +++ b/src/pocketmine/block/Grass.php @@ -36,19 +36,19 @@ class Grass extends Solid{ protected $id = self::GRASS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Grass"; } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } @@ -58,7 +58,7 @@ class Grass extends Solid{ ]; } - public function onUpdate($type){ + 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 @@ -97,7 +97,7 @@ class Grass extends Solid{ return false; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ $item->count--; TallGrassObject::growGrass($this->getLevel(), $this, new Random(mt_rand()), 8, 2); diff --git a/src/pocketmine/block/GrassPath.php b/src/pocketmine/block/GrassPath.php index 489b6a2932..3d688c12a3 100644 --- a/src/pocketmine/block/GrassPath.php +++ b/src/pocketmine/block/GrassPath.php @@ -31,15 +31,15 @@ class GrassPath extends Transparent{ protected $id = self::GRASS_PATH; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Grass Path"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } @@ -54,7 +54,7 @@ class GrassPath extends Transparent{ ); } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } diff --git a/src/pocketmine/block/Gravel.php b/src/pocketmine/block/Gravel.php index 4c5f4abfd5..80b786738e 100644 --- a/src/pocketmine/block/Gravel.php +++ b/src/pocketmine/block/Gravel.php @@ -30,19 +30,19 @@ class Gravel extends Fallable{ protected $id = self::GRAVEL; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Gravel"; } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } diff --git a/src/pocketmine/block/HardenedClay.php b/src/pocketmine/block/HardenedClay.php index 9e1f2aaaa2..1e7a1b0bb1 100644 --- a/src/pocketmine/block/HardenedClay.php +++ b/src/pocketmine/block/HardenedClay.php @@ -29,19 +29,19 @@ class HardenedClay extends Solid{ protected $id = self::HARDENED_CLAY; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Hardened Clay"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 1.25; } } \ No newline at end of file diff --git a/src/pocketmine/block/HayBale.php b/src/pocketmine/block/HayBale.php index 8192dc443f..652700c52c 100644 --- a/src/pocketmine/block/HayBale.php +++ b/src/pocketmine/block/HayBale.php @@ -30,19 +30,19 @@ class HayBale extends Solid{ protected $id = self::HAY_BALE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Hay Bale"; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 0, diff --git a/src/pocketmine/block/Ice.php b/src/pocketmine/block/Ice.php index 7467a869d8..da1941d4db 100644 --- a/src/pocketmine/block/Ice.php +++ b/src/pocketmine/block/Ice.php @@ -31,15 +31,15 @@ class Ice extends Transparent{ protected $id = self::ICE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Ice"; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } @@ -47,17 +47,17 @@ class Ice extends Transparent{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function onBreak(Item $item){ + public function onBreak(Item $item) : bool{ $this->getLevel()->setBlock($this, new Water(), true); return true; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_RANDOM){ if($this->level->getHighestAdjacentBlockLight($this->x, $this->y, $this->z) >= 12){ $this->level->useBreakOn($this); diff --git a/src/pocketmine/block/Iron.php b/src/pocketmine/block/Iron.php index bf4bc4c161..83a7c1b548 100644 --- a/src/pocketmine/block/Iron.php +++ b/src/pocketmine/block/Iron.php @@ -30,19 +30,19 @@ class Iron extends Solid{ protected $id = self::IRON_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Iron Block"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 5; } diff --git a/src/pocketmine/block/IronBars.php b/src/pocketmine/block/IronBars.php index 47ee0f644c..d37aa545d5 100644 --- a/src/pocketmine/block/IronBars.php +++ b/src/pocketmine/block/IronBars.php @@ -30,19 +30,19 @@ class IronBars extends Thin{ protected $id = self::IRON_BARS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Iron Bars"; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/IronDoor.php b/src/pocketmine/block/IronDoor.php index 381b45ce4b..f2b38cb6a4 100644 --- a/src/pocketmine/block/IronDoor.php +++ b/src/pocketmine/block/IronDoor.php @@ -30,19 +30,19 @@ class IronDoor extends Door{ protected $id = self::IRON_DOOR_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Iron Door Block"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 5; } diff --git a/src/pocketmine/block/IronOre.php b/src/pocketmine/block/IronOre.php index 7d5a6880fa..7d2a433053 100644 --- a/src/pocketmine/block/IronOre.php +++ b/src/pocketmine/block/IronOre.php @@ -30,19 +30,19 @@ class IronOre extends Solid{ protected $id = self::IRON_ORE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Iron Ore"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 3; } diff --git a/src/pocketmine/block/IronTrapdoor.php b/src/pocketmine/block/IronTrapdoor.php index 110102d72b..3fd776ea40 100644 --- a/src/pocketmine/block/IronTrapdoor.php +++ b/src/pocketmine/block/IronTrapdoor.php @@ -29,15 +29,15 @@ class IronTrapdoor extends Trapdoor{ protected $id = self::IRON_TRAPDOOR; - public function getName(){ + public function getName() : string{ return "Iron Trapdoor"; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } } diff --git a/src/pocketmine/block/ItemFrame.php b/src/pocketmine/block/ItemFrame.php index 940bf897f3..97050a14eb 100644 --- a/src/pocketmine/block/ItemFrame.php +++ b/src/pocketmine/block/ItemFrame.php @@ -35,15 +35,15 @@ use pocketmine\tile\Tile; class ItemFrame extends Flowable{ protected $id = Block::ITEM_FRAME_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Item Frame"; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ $tile = $this->level->getTile($this); if(!($tile instanceof TileItemFrame)){ $nbt = new CompoundTag("", [ @@ -74,7 +74,7 @@ class ItemFrame extends Flowable{ return true; } - public function onBreak(Item $item){ + public function onBreak(Item $item) : bool{ $tile = $this->level->getTile($this); if($tile instanceof TileItemFrame){ //TODO: add events @@ -85,7 +85,7 @@ class ItemFrame extends Flowable{ return parent::onBreak($item); } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $sides = [ 0 => 4, @@ -101,7 +101,7 @@ class ItemFrame extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($face === 0 or $face === 1){ return false; } diff --git a/src/pocketmine/block/Ladder.php b/src/pocketmine/block/Ladder.php index 0ced0e6556..2b948bc65d 100644 --- a/src/pocketmine/block/Ladder.php +++ b/src/pocketmine/block/Ladder.php @@ -34,23 +34,23 @@ class Ladder extends Transparent{ protected $id = self::LADDER; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Ladder"; } - public function hasEntityCollision(){ + public function hasEntityCollision() : bool{ return true; } - public function isSolid(){ + public function isSolid() : bool{ return false; } - public function getHardness(){ + public function getHardness() : float{ return 0.4; } @@ -109,7 +109,7 @@ class Ladder extends Transparent{ } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($target->isTransparent() === false){ $faces = [ 2 => 2, @@ -128,7 +128,7 @@ class Ladder extends Transparent{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $sides = [ 2 => 3, @@ -145,7 +145,7 @@ class Ladder extends Transparent{ return false; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/Lapis.php b/src/pocketmine/block/Lapis.php index b0f4cf52ea..2924afe437 100644 --- a/src/pocketmine/block/Lapis.php +++ b/src/pocketmine/block/Lapis.php @@ -30,19 +30,19 @@ class Lapis extends Solid{ protected $id = self::LAPIS_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Lapis Lazuli Block"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 3; } diff --git a/src/pocketmine/block/LapisOre.php b/src/pocketmine/block/LapisOre.php index 5d850e5356..a8243ebffc 100644 --- a/src/pocketmine/block/LapisOre.php +++ b/src/pocketmine/block/LapisOre.php @@ -30,19 +30,19 @@ class LapisOre extends Solid{ protected $id = self::LAPIS_ORE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 3; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Lapis Lazuli Ore"; } diff --git a/src/pocketmine/block/Lava.php b/src/pocketmine/block/Lava.php index 7d67f4cb6e..67601274e5 100644 --- a/src/pocketmine/block/Lava.php +++ b/src/pocketmine/block/Lava.php @@ -35,15 +35,15 @@ class Lava extends Liquid{ protected $id = self::FLOWING_LAVA; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 15; } - public function getName(){ + public function getName() : string{ return "Lava"; } @@ -62,7 +62,7 @@ class Lava extends Liquid{ $entity->resetFallDistance(); } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $ret = $this->getLevel()->setBlock($this, $this, true, false); $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index d9fc154797..8fb0deb831 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -41,19 +41,19 @@ class Leaves extends Transparent{ protected $id = self::LEAVES; protected $woodType = self::WOOD; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHEARS; } - public function getName(){ + public function getName() : string{ static $names = [ self::OAK => "Oak Leaves", self::SPRUCE => "Spruce Leaves", @@ -132,7 +132,7 @@ class Leaves extends Transparent{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if(($this->meta & 0b00001100) === 0){ $this->meta |= 0x08; @@ -159,9 +159,9 @@ class Leaves extends Transparent{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $this->meta |= 0x04; - $this->getLevel()->setBlock($this, $this, true); + return $this->getLevel()->setBlock($this, $this, true); } public function getDrops(Item $item){ diff --git a/src/pocketmine/block/Leaves2.php b/src/pocketmine/block/Leaves2.php index 421870c13d..b25668f873 100644 --- a/src/pocketmine/block/Leaves2.php +++ b/src/pocketmine/block/Leaves2.php @@ -30,7 +30,7 @@ class Leaves2 extends Leaves{ protected $id = self::LEAVES2; protected $woodType = self::WOOD2; - public function getName(){ + public function getName() : string{ static $names = [ self::ACACIA => "Acacia Leaves", self::DARK_OAK => "Dark Oak Leaves", diff --git a/src/pocketmine/block/Lever.php b/src/pocketmine/block/Lever.php index 493cd404f8..add57cf413 100644 --- a/src/pocketmine/block/Lever.php +++ b/src/pocketmine/block/Lever.php @@ -27,11 +27,11 @@ class Lever extends Flowable{ protected $id = self::LEVER; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Lever"; } } diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index a08c6b28b5..100e29bee0 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -33,19 +33,19 @@ abstract class Liquid extends Transparent{ /** @var Vector3 */ private $temporalVector = null; - public function hasEntityCollision(){ + public function hasEntityCollision() : bool{ return true; } - public function isBreakable(Item $item){ + public function isBreakable(Item $item) : bool{ return false; } - public function canBeReplaced(){ + public function canBeReplaced() : bool{ return true; } - public function isSolid(){ + public function isSolid() : bool{ return false; } @@ -188,7 +188,7 @@ abstract class Liquid extends Transparent{ return 0; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $this->checkForHarden(); $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); @@ -358,7 +358,7 @@ abstract class Liquid extends Transparent{ return $cost; } - public function getHardness(){ + public function getHardness() : float{ return 100; } diff --git a/src/pocketmine/block/LitPumpkin.php b/src/pocketmine/block/LitPumpkin.php index 249f05aa7a..2ecfa33e84 100644 --- a/src/pocketmine/block/LitPumpkin.php +++ b/src/pocketmine/block/LitPumpkin.php @@ -27,11 +27,11 @@ class LitPumpkin extends Pumpkin{ protected $id = self::LIT_PUMPKIN; - public function getLightLevel(){ + public function getLightLevel() : int{ return 15; } - public function getName(){ + public function getName() : string{ return "Jack o'Lantern"; } } \ No newline at end of file diff --git a/src/pocketmine/block/LitRedstoneLamp.php b/src/pocketmine/block/LitRedstoneLamp.php index 296caca865..ecc8128f0c 100644 --- a/src/pocketmine/block/LitRedstoneLamp.php +++ b/src/pocketmine/block/LitRedstoneLamp.php @@ -27,11 +27,11 @@ class LitRedstoneLamp extends RedstoneLamp{ protected $id = self::LIT_REDSTONE_LAMP; - public function getName(){ + public function getName() : string{ return "Lit Redstone Lamp"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 15; } } diff --git a/src/pocketmine/block/Melon.php b/src/pocketmine/block/Melon.php index fdbfdec240..02e02cc31e 100644 --- a/src/pocketmine/block/Melon.php +++ b/src/pocketmine/block/Melon.php @@ -30,19 +30,19 @@ class Melon extends Transparent{ protected $id = self::MELON_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Melon Block"; } - public function getHardness(){ + public function getHardness() : float{ return 1; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/MelonStem.php b/src/pocketmine/block/MelonStem.php index f8d53f0286..4829e71d59 100644 --- a/src/pocketmine/block/MelonStem.php +++ b/src/pocketmine/block/MelonStem.php @@ -33,15 +33,15 @@ class MelonStem extends Crops{ protected $id = self::MELON_STEM; - public function getName(){ + public function getName() : string{ return "Melon Stem"; } - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/MonsterSpawner.php b/src/pocketmine/block/MonsterSpawner.php index e06e19f4b2..e22fec7a6f 100644 --- a/src/pocketmine/block/MonsterSpawner.php +++ b/src/pocketmine/block/MonsterSpawner.php @@ -30,19 +30,19 @@ class MonsterSpawner extends Solid{ protected $id = self::MONSTER_SPAWNER; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Monster Spawner"; } diff --git a/src/pocketmine/block/MossyCobblestone.php b/src/pocketmine/block/MossyCobblestone.php index 3eec116642..569a4b6fbb 100644 --- a/src/pocketmine/block/MossyCobblestone.php +++ b/src/pocketmine/block/MossyCobblestone.php @@ -30,19 +30,19 @@ class MossyCobblestone extends Solid{ protected $id = self::MOSSY_COBBLESTONE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Moss Stone"; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/Mycelium.php b/src/pocketmine/block/Mycelium.php index 4e6b4ba10f..539eae09a3 100644 --- a/src/pocketmine/block/Mycelium.php +++ b/src/pocketmine/block/Mycelium.php @@ -34,19 +34,19 @@ class Mycelium extends Solid{ protected $id = self::MYCELIUM; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Mycelium"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } @@ -56,7 +56,7 @@ class Mycelium extends Solid{ ]; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_RANDOM){ //TODO: light levels $x = mt_rand($this->x - 1, $this->x + 1); diff --git a/src/pocketmine/block/NetherBrick.php b/src/pocketmine/block/NetherBrick.php index 17d35c5f4e..9d15cd7c4c 100644 --- a/src/pocketmine/block/NetherBrick.php +++ b/src/pocketmine/block/NetherBrick.php @@ -30,19 +30,19 @@ class NetherBrick extends Solid{ protected $id = self::NETHER_BRICK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Nether Bricks"; } - public function getHardness(){ + public function getHardness() : float{ return 2; } diff --git a/src/pocketmine/block/NetherBrickFence.php b/src/pocketmine/block/NetherBrickFence.php index 8b58a3de61..ddcb1b21fa 100644 --- a/src/pocketmine/block/NetherBrickFence.php +++ b/src/pocketmine/block/NetherBrickFence.php @@ -29,19 +29,19 @@ class NetherBrickFence extends Transparent{ protected $id = self::NETHER_BRICK_FENCE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Nether Brick Fence"; } diff --git a/src/pocketmine/block/NetherBrickStairs.php b/src/pocketmine/block/NetherBrickStairs.php index 6c56002994..a912d95a50 100644 --- a/src/pocketmine/block/NetherBrickStairs.php +++ b/src/pocketmine/block/NetherBrickStairs.php @@ -29,19 +29,19 @@ class NetherBrickStairs extends Stair{ protected $id = self::NETHER_BRICK_STAIRS; - public function getName(){ + public function getName() : string{ return "Nether Brick Stairs"; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } diff --git a/src/pocketmine/block/NetherReactor.php b/src/pocketmine/block/NetherReactor.php index 1303a856df..6ca1fb6eaf 100644 --- a/src/pocketmine/block/NetherReactor.php +++ b/src/pocketmine/block/NetherReactor.php @@ -29,11 +29,11 @@ use pocketmine\item\Tool; class NetherReactor extends Solid{ protected $id = Block::NETHER_REACTOR; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ static $prefixes = [ "", "Active ", @@ -42,11 +42,11 @@ class NetherReactor extends Solid{ return ($prefixes[$this->meta] ?? "") . "Nether Reactor Core"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 3; } diff --git a/src/pocketmine/block/NetherWartPlant.php b/src/pocketmine/block/NetherWartPlant.php index 16e4e187bd..a5f0e601f5 100644 --- a/src/pocketmine/block/NetherWartPlant.php +++ b/src/pocketmine/block/NetherWartPlant.php @@ -33,11 +33,11 @@ use pocketmine\Player; class NetherWartPlant extends Flowable{ protected $id = Block::NETHER_WART_PLANT; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === Block::SOUL_SAND){ $this->getLevel()->setBlock($block, $this, false, true); @@ -48,7 +48,7 @@ class NetherWartPlant extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ switch($type){ case Level::BLOCK_UPDATE_RANDOM: if($this->meta < 3 and mt_rand(0, 10) === 0){ //Still growing diff --git a/src/pocketmine/block/Netherrack.php b/src/pocketmine/block/Netherrack.php index 905addf5cf..2303d77262 100644 --- a/src/pocketmine/block/Netherrack.php +++ b/src/pocketmine/block/Netherrack.php @@ -30,19 +30,19 @@ class Netherrack extends Solid{ protected $id = self::NETHERRACK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Netherrack"; } - public function getHardness(){ + public function getHardness() : float{ return 0.4; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/NoteBlock.php b/src/pocketmine/block/NoteBlock.php index 177f9c7125..5b40fa42bc 100644 --- a/src/pocketmine/block/NoteBlock.php +++ b/src/pocketmine/block/NoteBlock.php @@ -27,11 +27,11 @@ class NoteBlock extends Solid{ protected $id = self::NOTE_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Note Block"; } diff --git a/src/pocketmine/block/Obsidian.php b/src/pocketmine/block/Obsidian.php index 439325892b..3284b44204 100644 --- a/src/pocketmine/block/Obsidian.php +++ b/src/pocketmine/block/Obsidian.php @@ -30,19 +30,19 @@ class Obsidian extends Solid{ protected $id = self::OBSIDIAN; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Obsidian"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 35; } diff --git a/src/pocketmine/block/PackedIce.php b/src/pocketmine/block/PackedIce.php index fe36a1644e..b1a77bc57c 100644 --- a/src/pocketmine/block/PackedIce.php +++ b/src/pocketmine/block/PackedIce.php @@ -29,19 +29,19 @@ class PackedIce extends Solid{ protected $id = self::PACKED_ICE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Packed Ice"; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/Planks.php b/src/pocketmine/block/Planks.php index d54627c350..5ae7a9dbf9 100644 --- a/src/pocketmine/block/Planks.php +++ b/src/pocketmine/block/Planks.php @@ -35,19 +35,19 @@ class Planks extends Solid{ protected $id = self::WOODEN_PLANKS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } - public function getName(){ + public function getName() : string{ static $names = [ self::OAK => "Oak Wood Planks", self::SPRUCE => "Spruce Wood Planks", diff --git a/src/pocketmine/block/Podzol.php b/src/pocketmine/block/Podzol.php index 0219614ee0..77b937203d 100644 --- a/src/pocketmine/block/Podzol.php +++ b/src/pocketmine/block/Podzol.php @@ -29,19 +29,19 @@ class Podzol extends Solid{ protected $id = self::PODZOL; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } - public function getName(){ + public function getName() : string{ return "Podzol"; } - public function getHardness(){ + public function getHardness() : float{ return 2.5; } } \ No newline at end of file diff --git a/src/pocketmine/block/Potato.php b/src/pocketmine/block/Potato.php index cf1cbfa2fc..99a98c12d1 100644 --- a/src/pocketmine/block/Potato.php +++ b/src/pocketmine/block/Potato.php @@ -29,11 +29,11 @@ class Potato extends Crops{ protected $id = self::POTATO_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Potato Block"; } diff --git a/src/pocketmine/block/PoweredRail.php b/src/pocketmine/block/PoweredRail.php index c1eca33a68..fe559a80a9 100644 --- a/src/pocketmine/block/PoweredRail.php +++ b/src/pocketmine/block/PoweredRail.php @@ -26,7 +26,7 @@ namespace pocketmine\block; class PoweredRail extends Rail{ protected $id = self::POWERED_RAIL; - public function getName(){ + public function getName() : string{ return "Powered Rail"; } } diff --git a/src/pocketmine/block/Prismarine.php b/src/pocketmine/block/Prismarine.php index 340fa41f28..c78e2e7ebb 100644 --- a/src/pocketmine/block/Prismarine.php +++ b/src/pocketmine/block/Prismarine.php @@ -34,15 +34,15 @@ class Prismarine extends Solid{ protected $id = self::PRISMARINE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 1.5; } - public function getName(){ + public function getName() : string{ static $names = [ self::NORMAL => "Prismarine", self::DARK => "Dark Prismarine", @@ -51,7 +51,7 @@ class Prismarine extends Solid{ return $names[$this->meta & 0x03] ?? "Unknown"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/Pumpkin.php b/src/pocketmine/block/Pumpkin.php index 2357544836..882089ae70 100644 --- a/src/pocketmine/block/Pumpkin.php +++ b/src/pocketmine/block/Pumpkin.php @@ -31,23 +31,23 @@ class Pumpkin extends Solid{ protected $id = self::PUMPKIN; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 1; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } - public function getName(){ + public function getName() : string{ return "Pumpkin"; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($player instanceof Player){ $this->meta = ((int) $player->getDirection() + 1) % 4; } diff --git a/src/pocketmine/block/PumpkinStem.php b/src/pocketmine/block/PumpkinStem.php index 8d5207b204..8735dfeb00 100644 --- a/src/pocketmine/block/PumpkinStem.php +++ b/src/pocketmine/block/PumpkinStem.php @@ -33,15 +33,15 @@ class PumpkinStem extends Crops{ protected $id = self::PUMPKIN_STEM; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Pumpkin Stem"; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() !== Block::FARMLAND){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/Quartz.php b/src/pocketmine/block/Quartz.php index a6d8c7233d..f98c70fb8c 100644 --- a/src/pocketmine/block/Quartz.php +++ b/src/pocketmine/block/Quartz.php @@ -35,15 +35,15 @@ class Quartz extends Solid{ protected $id = self::QUARTZ_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.8; } - public function getName(){ + public function getName() : string{ static $names = [ self::QUARTZ_NORMAL => "Quartz Block", self::QUARTZ_CHISELED => "Chiseled Quartz Block", @@ -53,7 +53,7 @@ class Quartz extends Solid{ return $names[$this->meta & 0x03]; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/QuartzStairs.php b/src/pocketmine/block/QuartzStairs.php index f8f6d62b28..b5905f6474 100644 --- a/src/pocketmine/block/QuartzStairs.php +++ b/src/pocketmine/block/QuartzStairs.php @@ -29,19 +29,19 @@ class QuartzStairs extends Stair{ protected $id = self::QUARTZ_STAIRS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.8; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Quartz Stairs"; } diff --git a/src/pocketmine/block/Rail.php b/src/pocketmine/block/Rail.php index dd20823a0e..041be4a595 100644 --- a/src/pocketmine/block/Rail.php +++ b/src/pocketmine/block/Rail.php @@ -43,19 +43,19 @@ class Rail extends Flowable{ protected $id = self::RAIL; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Rail"; } - public function getHardness(){ + public function getHardness() : float{ return 0.7; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if(!$block->getSide(Vector3::SIDE_DOWN)->isTransparent()){ return $this->getLevel()->setBlock($block, $this, true, true); } @@ -63,7 +63,7 @@ class Rail extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent()){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/RedMushroom.php b/src/pocketmine/block/RedMushroom.php index 79b1a0e623..7b49bb5a79 100644 --- a/src/pocketmine/block/RedMushroom.php +++ b/src/pocketmine/block/RedMushroom.php @@ -32,16 +32,16 @@ class RedMushroom extends Flowable{ protected $id = self::RED_MUSHROOM; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Red Mushroom"; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ $this->getLevel()->useBreakOn($this); @@ -53,7 +53,7 @@ class RedMushroom extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->isTransparent() === false){ $this->getLevel()->setBlock($block, $this, true, true); diff --git a/src/pocketmine/block/Redstone.php b/src/pocketmine/block/Redstone.php index 97ff3fc96f..edc6bae76d 100644 --- a/src/pocketmine/block/Redstone.php +++ b/src/pocketmine/block/Redstone.php @@ -30,19 +30,19 @@ class Redstone extends Solid{ protected $id = self::REDSTONE_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Redstone Block"; } diff --git a/src/pocketmine/block/RedstoneLamp.php b/src/pocketmine/block/RedstoneLamp.php index 954181beae..a90e944f9a 100644 --- a/src/pocketmine/block/RedstoneLamp.php +++ b/src/pocketmine/block/RedstoneLamp.php @@ -27,15 +27,15 @@ class RedstoneLamp extends Solid{ protected $id = self::REDSTONE_LAMP; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Redstone Lamp"; } - public function getHardness(){ + public function getHardness() : float{ return 0.3; } } diff --git a/src/pocketmine/block/RedstoneOre.php b/src/pocketmine/block/RedstoneOre.php index 5a978bf651..326418da57 100644 --- a/src/pocketmine/block/RedstoneOre.php +++ b/src/pocketmine/block/RedstoneOre.php @@ -32,23 +32,23 @@ class RedstoneOre extends Solid{ protected $id = self::REDSTONE_ORE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Redstone Ore"; } - public function getHardness(){ + public function getHardness() : float{ return 3; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ return $this->getLevel()->setBlock($this, $this, true, false); } - public function onUpdate($type){ + 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)); @@ -58,7 +58,7 @@ class RedstoneOre extends Solid{ return false; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/RedstoneTorch.php b/src/pocketmine/block/RedstoneTorch.php index a401e896ef..4d0770d1dd 100644 --- a/src/pocketmine/block/RedstoneTorch.php +++ b/src/pocketmine/block/RedstoneTorch.php @@ -27,11 +27,11 @@ class RedstoneTorch extends Torch{ protected $id = self::LIT_REDSTONE_TORCH; - public function getName(){ + public function getName() : string{ return "Redstone Torch"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 7; } } diff --git a/src/pocketmine/block/RedstoneTorchUnlit.php b/src/pocketmine/block/RedstoneTorchUnlit.php index 254187f306..f074d0f666 100644 --- a/src/pocketmine/block/RedstoneTorchUnlit.php +++ b/src/pocketmine/block/RedstoneTorchUnlit.php @@ -27,11 +27,11 @@ class RedstoneTorchUnlit extends Torch{ protected $id = self::UNLIT_REDSTONE_TORCH; - public function getName(){ + public function getName() : string{ return "Unlit Redstone Torch"; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 0; } } diff --git a/src/pocketmine/block/Sand.php b/src/pocketmine/block/Sand.php index f594d82765..196b303ae3 100644 --- a/src/pocketmine/block/Sand.php +++ b/src/pocketmine/block/Sand.php @@ -29,19 +29,19 @@ class Sand extends Fallable{ protected $id = self::SAND; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } - public function getName(){ + public function getName() : string{ if($this->meta === 0x01){ return "Red Sand"; } diff --git a/src/pocketmine/block/Sandstone.php b/src/pocketmine/block/Sandstone.php index 92c8a72312..88e5dc1e0d 100644 --- a/src/pocketmine/block/Sandstone.php +++ b/src/pocketmine/block/Sandstone.php @@ -34,15 +34,15 @@ class Sandstone extends Solid{ protected $id = self::SANDSTONE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.8; } - public function getName(){ + public function getName() : string{ static $names = [ self::NORMAL => "Sandstone", self::CHISELED => "Chiseled Sandstone", @@ -51,7 +51,7 @@ class Sandstone extends Solid{ return $names[$this->meta & 0x03] ?? "Unknown"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/SandstoneStairs.php b/src/pocketmine/block/SandstoneStairs.php index b22daf1d6d..8204253f07 100644 --- a/src/pocketmine/block/SandstoneStairs.php +++ b/src/pocketmine/block/SandstoneStairs.php @@ -29,19 +29,19 @@ class SandstoneStairs extends Stair{ protected $id = self::SANDSTONE_STAIRS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.8; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return "Sandstone Stairs"; } diff --git a/src/pocketmine/block/Sapling.php b/src/pocketmine/block/Sapling.php index 7c89d49953..36b72bcc6b 100644 --- a/src/pocketmine/block/Sapling.php +++ b/src/pocketmine/block/Sapling.php @@ -40,11 +40,11 @@ class Sapling extends Flowable{ protected $id = self::SAPLING; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ static $names = [ 0 => "Oak Sapling", 1 => "Spruce Sapling", @@ -57,7 +57,7 @@ class Sapling extends Flowable{ } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::GRASS or $down->getId() === self::DIRT or $down->getId() === self::FARMLAND){ $this->getLevel()->setBlock($block, $this, true, true); @@ -68,7 +68,7 @@ class Sapling extends Flowable{ return false; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal //TODO: change log type Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07); @@ -82,7 +82,7 @@ class Sapling extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->isTransparent() === true){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/SeaLantern.php b/src/pocketmine/block/SeaLantern.php index 4d3ac8c083..b571cb6e73 100644 --- a/src/pocketmine/block/SeaLantern.php +++ b/src/pocketmine/block/SeaLantern.php @@ -29,19 +29,19 @@ class SeaLantern extends Transparent{ protected $id = self::SEA_LANTERN; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Sea Lantern"; } - public function getHardness(){ + public function getHardness() : float{ return 0.3; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 15; } diff --git a/src/pocketmine/block/SignPost.php b/src/pocketmine/block/SignPost.php index b93c2598fe..e6ea4579f7 100644 --- a/src/pocketmine/block/SignPost.php +++ b/src/pocketmine/block/SignPost.php @@ -37,19 +37,19 @@ class SignPost extends Transparent{ protected $id = self::SIGN_POST; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 1; } - public function isSolid(){ + public function isSolid() : bool{ return false; } - public function getName(){ + public function getName() : string{ return "Sign Post"; } @@ -58,7 +58,7 @@ class SignPost extends Transparent{ } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($face !== 0){ $nbt = new CompoundTag("", [ new StringTag("id", Tile::SIGN), @@ -97,7 +97,7 @@ class SignPost extends Transparent{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if($this->getSide(Vector3::SIDE_DOWN)->getId() === self::AIR){ $this->getLevel()->useBreakOn($this); @@ -115,7 +115,7 @@ class SignPost extends Transparent{ ]; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } } \ No newline at end of file diff --git a/src/pocketmine/block/Skull.php b/src/pocketmine/block/Skull.php index 8478756044..e40254c619 100644 --- a/src/pocketmine/block/Skull.php +++ b/src/pocketmine/block/Skull.php @@ -38,15 +38,15 @@ class Skull extends Flowable{ protected $id = self::SKULL_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 1; } - public function getName(){ + public function getName() : string{ return "Mob Head Block"; } @@ -62,7 +62,7 @@ class Skull extends Flowable{ ); } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($face !== 0){ $this->meta = $face; if($face === 1){ diff --git a/src/pocketmine/block/Snow.php b/src/pocketmine/block/Snow.php index a7499e82a0..d9c0ceabfe 100644 --- a/src/pocketmine/block/Snow.php +++ b/src/pocketmine/block/Snow.php @@ -29,19 +29,19 @@ class Snow extends Solid{ protected $id = self::SNOW_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.2; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } - public function getName(){ + public function getName() : string{ return "Snow Block"; } diff --git a/src/pocketmine/block/SnowLayer.php b/src/pocketmine/block/SnowLayer.php index 88702dcd56..b3f46f3751 100644 --- a/src/pocketmine/block/SnowLayer.php +++ b/src/pocketmine/block/SnowLayer.php @@ -33,28 +33,28 @@ class SnowLayer extends Flowable{ protected $id = self::SNOW_LAYER; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Snow Layer"; } - public function canBeReplaced(){ + public function canBeReplaced() : bool{ return true; } - public function getHardness(){ + public function getHardness() : float{ return 0.1; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($block->getSide(Vector3::SIDE_DOWN)->isSolid()){ //TODO: fix placement $this->getLevel()->setBlock($block, $this, true); @@ -65,7 +65,7 @@ class SnowLayer extends Flowable{ return false; } - public function onUpdate($type){ + 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); diff --git a/src/pocketmine/block/Solid.php b/src/pocketmine/block/Solid.php index 720b734bed..9625104ca0 100644 --- a/src/pocketmine/block/Solid.php +++ b/src/pocketmine/block/Solid.php @@ -25,7 +25,7 @@ namespace pocketmine\block; abstract class Solid extends Block{ - public function isSolid(){ + public function isSolid() : bool{ return true; } } \ No newline at end of file diff --git a/src/pocketmine/block/SoulSand.php b/src/pocketmine/block/SoulSand.php index af761a2753..fa586dd010 100644 --- a/src/pocketmine/block/SoulSand.php +++ b/src/pocketmine/block/SoulSand.php @@ -30,19 +30,19 @@ class SoulSand extends Solid{ protected $id = self::SOUL_SAND; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Soul Sand"; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHOVEL; } diff --git a/src/pocketmine/block/Sponge.php b/src/pocketmine/block/Sponge.php index c819437cb7..6a12cddc96 100644 --- a/src/pocketmine/block/Sponge.php +++ b/src/pocketmine/block/Sponge.php @@ -28,15 +28,15 @@ class Sponge extends Solid{ protected $id = self::SPONGE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } - public function getName(){ + public function getName() : string{ return "Sponge"; } diff --git a/src/pocketmine/block/StainedClay.php b/src/pocketmine/block/StainedClay.php index f4fe4ca634..c44e1ccc27 100644 --- a/src/pocketmine/block/StainedClay.php +++ b/src/pocketmine/block/StainedClay.php @@ -30,19 +30,19 @@ class StainedClay extends Solid{ protected $id = self::STAINED_CLAY; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 1.25; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Stained Clay"; } diff --git a/src/pocketmine/block/Stair.php b/src/pocketmine/block/Stair.php index 85489f2141..3e30107a4c 100644 --- a/src/pocketmine/block/Stair.php +++ b/src/pocketmine/block/Stair.php @@ -129,7 +129,7 @@ abstract class Stair extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 2, diff --git a/src/pocketmine/block/StillLava.php b/src/pocketmine/block/StillLava.php index 84f21c4a5c..16166e14c1 100644 --- a/src/pocketmine/block/StillLava.php +++ b/src/pocketmine/block/StillLava.php @@ -27,7 +27,7 @@ class StillLava extends Lava{ protected $id = self::STILL_LAVA; - public function getName(){ + public function getName() : string{ return "Still Lava"; } diff --git a/src/pocketmine/block/StillWater.php b/src/pocketmine/block/StillWater.php index 7d7824f623..7e352c4bdd 100644 --- a/src/pocketmine/block/StillWater.php +++ b/src/pocketmine/block/StillWater.php @@ -27,7 +27,7 @@ class StillWater extends Water{ protected $id = self::STILL_WATER; - public function getName(){ + public function getName() : string{ return "Still Water"; } } \ No newline at end of file diff --git a/src/pocketmine/block/Stone.php b/src/pocketmine/block/Stone.php index ced1540f6b..6139a3421c 100644 --- a/src/pocketmine/block/Stone.php +++ b/src/pocketmine/block/Stone.php @@ -37,19 +37,19 @@ class Stone extends Solid{ protected $id = self::STONE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 1.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ static $names = [ self::NORMAL => "Stone", self::GRANITE => "Granite", diff --git a/src/pocketmine/block/StoneBrickStairs.php b/src/pocketmine/block/StoneBrickStairs.php index 495e4f67cd..cb7397065e 100644 --- a/src/pocketmine/block/StoneBrickStairs.php +++ b/src/pocketmine/block/StoneBrickStairs.php @@ -29,19 +29,19 @@ class StoneBrickStairs extends Stair{ protected $id = self::STONE_BRICK_STAIRS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getHardness(){ + public function getHardness() : float{ return 1.5; } - public function getName(){ + public function getName() : string{ return "Stone Brick Stairs"; } diff --git a/src/pocketmine/block/StoneBricks.php b/src/pocketmine/block/StoneBricks.php index f03b40fe62..094b7dfd71 100644 --- a/src/pocketmine/block/StoneBricks.php +++ b/src/pocketmine/block/StoneBricks.php @@ -34,19 +34,19 @@ class StoneBricks extends Solid{ protected $id = self::STONE_BRICKS; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 1.5; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } - public function getName(){ + public function getName() : string{ static $names = [ self::NORMAL => "Stone Bricks", self::MOSSY => "Mossy Stone Bricks", diff --git a/src/pocketmine/block/StoneButton.php b/src/pocketmine/block/StoneButton.php index a6365f0dbc..616d416bda 100644 --- a/src/pocketmine/block/StoneButton.php +++ b/src/pocketmine/block/StoneButton.php @@ -27,15 +27,15 @@ class StoneButton extends Flowable{ protected $id = self::STONE_BUTTON; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Stone Button"; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } } diff --git a/src/pocketmine/block/StonePressurePlate.php b/src/pocketmine/block/StonePressurePlate.php index bd014ebec0..b6f1e672b7 100644 --- a/src/pocketmine/block/StonePressurePlate.php +++ b/src/pocketmine/block/StonePressurePlate.php @@ -27,19 +27,19 @@ class StonePressurePlate extends Transparent{ protected $id = self::STONE_PRESSURE_PLATE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Stone Pressure Plate"; } - public function isSolid(){ + public function isSolid() : bool{ return false; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } } diff --git a/src/pocketmine/block/StoneSlab.php b/src/pocketmine/block/StoneSlab.php index cab8656c9b..80717b2c5d 100644 --- a/src/pocketmine/block/StoneSlab.php +++ b/src/pocketmine/block/StoneSlab.php @@ -40,11 +40,11 @@ class StoneSlab extends WoodenSlab{ protected $doubleId = self::DOUBLE_STONE_SLAB; - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getName(){ + public function getName() : string{ static $names = [ self::STONE => "Stone", self::SANDSTONE => "Sandstone", @@ -58,7 +58,7 @@ class StoneSlab extends WoodenSlab{ return (($this->meta & 0x08) > 0 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/Stonecutter.php b/src/pocketmine/block/Stonecutter.php index ecccb23127..21c108d133 100644 --- a/src/pocketmine/block/Stonecutter.php +++ b/src/pocketmine/block/Stonecutter.php @@ -31,15 +31,15 @@ class Stonecutter extends Solid{ protected $id = self::STONECUTTER; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Stonecutter"; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_PICKAXE; } diff --git a/src/pocketmine/block/Sugarcane.php b/src/pocketmine/block/Sugarcane.php index 2680b4efeb..0d6ba05b89 100644 --- a/src/pocketmine/block/Sugarcane.php +++ b/src/pocketmine/block/Sugarcane.php @@ -34,11 +34,11 @@ class Sugarcane extends Flowable{ protected $id = self::SUGARCANE_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Sugarcane"; } @@ -49,7 +49,7 @@ class Sugarcane extends Flowable{ ]; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal if($this->getSide(Vector3::SIDE_DOWN)->getId() !== self::SUGARCANE_BLOCK){ for($y = 1; $y < 3; ++$y){ @@ -75,7 +75,7 @@ class Sugarcane extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->isTransparent() === true and $down->getId() !== self::SUGARCANE_BLOCK){ @@ -107,7 +107,7 @@ class Sugarcane extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::SUGARCANE_BLOCK){ $this->getLevel()->setBlock($block, new Sugarcane(), true); diff --git a/src/pocketmine/block/TNT.php b/src/pocketmine/block/TNT.php index 2d964505d4..ac7b849b29 100644 --- a/src/pocketmine/block/TNT.php +++ b/src/pocketmine/block/TNT.php @@ -37,19 +37,19 @@ class TNT extends Solid{ protected $id = self::TNT; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "TNT"; } - public function getHardness(){ + public function getHardness() : float{ return 0; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ if($item->getId() === Item::FLINT_STEEL){ $item->useOn($this); $this->ignite(); diff --git a/src/pocketmine/block/TallGrass.php b/src/pocketmine/block/TallGrass.php index 2ba679456d..aeac09f0d7 100644 --- a/src/pocketmine/block/TallGrass.php +++ b/src/pocketmine/block/TallGrass.php @@ -32,15 +32,15 @@ class TallGrass extends Flowable{ protected $id = self::TALL_GRASS; - public function __construct($meta = 1){ + public function __construct(int $meta = 1){ $this->meta = $meta; } - public function canBeReplaced(){ + public function canBeReplaced() : bool{ return true; } - public function getName(){ + public function getName() : string{ static $names = [ 0 => "Dead Shrub", 1 => "Tall Grass", @@ -49,7 +49,7 @@ class TallGrass extends Flowable{ return $names[$this->meta & 0x03] ?? "Unknown"; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $down = $this->getSide(Vector3::SIDE_DOWN); if($down->getId() === self::GRASS){ $this->getLevel()->setBlock($block, $this, true); @@ -61,7 +61,7 @@ class TallGrass extends Flowable{ } - public function onUpdate($type){ + 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, new Air(), true, true); diff --git a/src/pocketmine/block/Thin.php b/src/pocketmine/block/Thin.php index ef121b8471..c28d0b78f7 100644 --- a/src/pocketmine/block/Thin.php +++ b/src/pocketmine/block/Thin.php @@ -28,7 +28,7 @@ use pocketmine\math\Vector3; abstract class Thin extends Transparent{ - public function isSolid(){ + public function isSolid() : bool{ return false; } diff --git a/src/pocketmine/block/Torch.php b/src/pocketmine/block/Torch.php index 5f15588f5b..10edd3d846 100644 --- a/src/pocketmine/block/Torch.php +++ b/src/pocketmine/block/Torch.php @@ -32,20 +32,20 @@ class Torch extends Flowable{ protected $id = self::TORCH; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getLightLevel(){ + public function getLightLevel() : int{ return 14; } - public function getName(){ + public function getName() : string{ return "Torch"; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $below = $this->getSide(Vector3::SIDE_DOWN); $side = $this->getDamage(); @@ -68,7 +68,7 @@ class Torch extends Flowable{ return false; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $below = $this->getSide(Vector3::SIDE_DOWN); if($target->isTransparent() === false and $face !== 0){ diff --git a/src/pocketmine/block/Transparent.php b/src/pocketmine/block/Transparent.php index 00cf6d5544..3e99d4e68e 100644 --- a/src/pocketmine/block/Transparent.php +++ b/src/pocketmine/block/Transparent.php @@ -26,7 +26,7 @@ namespace pocketmine\block; abstract class Transparent extends Block{ - public function isTransparent(){ + public function isTransparent() : bool{ return true; } diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index b65b872609..608a886fa0 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -40,15 +40,15 @@ class Trapdoor extends Transparent{ protected $id = self::TRAPDOOR; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Wooden Trapdoor"; } - public function getHardness(){ + public function getHardness() : float{ return 3; } @@ -123,7 +123,7 @@ class Trapdoor extends Transparent{ return $bb; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $directions = [ 0 => 1, 1 => 3, @@ -146,14 +146,14 @@ class Trapdoor extends Transparent{ ]; } - public function onActivate(Item $item, Player $player = null){ + public function onActivate(Item $item, Player $player = null) : bool{ $this->meta ^= self::MASK_OPENED; $this->getLevel()->setBlock($this, $this, true); $this->level->addSound(new DoorSound($this)); return true; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/TrappedChest.php b/src/pocketmine/block/TrappedChest.php index 98473ddd73..a559c69426 100644 --- a/src/pocketmine/block/TrappedChest.php +++ b/src/pocketmine/block/TrappedChest.php @@ -29,7 +29,7 @@ class TrappedChest extends Chest{ protected $id = self::TRAPPED_CHEST; - public function getName(){ + public function getName() : string{ return "Trapped Chest"; } } diff --git a/src/pocketmine/block/Tripwire.php b/src/pocketmine/block/Tripwire.php index 6d21c9dcc4..1b0416bd6e 100644 --- a/src/pocketmine/block/Tripwire.php +++ b/src/pocketmine/block/Tripwire.php @@ -27,11 +27,11 @@ class Tripwire extends Flowable{ protected $id = self::TRIPWIRE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Tripwire"; } } diff --git a/src/pocketmine/block/TripwireHook.php b/src/pocketmine/block/TripwireHook.php index fdeec43ed3..9a0017ae09 100644 --- a/src/pocketmine/block/TripwireHook.php +++ b/src/pocketmine/block/TripwireHook.php @@ -27,11 +27,11 @@ class TripwireHook extends Flowable{ protected $id = self::TRIPWIRE_HOOK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Tripwire Hook"; } } diff --git a/src/pocketmine/block/UnknownBlock.php b/src/pocketmine/block/UnknownBlock.php index 16088afdda..1c1f2af032 100644 --- a/src/pocketmine/block/UnknownBlock.php +++ b/src/pocketmine/block/UnknownBlock.php @@ -27,7 +27,7 @@ use pocketmine\item\Item; class UnknownBlock extends Transparent{ - public function getHardness(){ + public function getHardness() : float{ return 0; } diff --git a/src/pocketmine/block/Vine.php b/src/pocketmine/block/Vine.php index be0dbdb523..82fc25b79a 100644 --- a/src/pocketmine/block/Vine.php +++ b/src/pocketmine/block/Vine.php @@ -39,27 +39,27 @@ class Vine extends Transparent{ protected $id = self::VINE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function isSolid(){ + public function isSolid() : bool{ return false; } - public function getName(){ + public function getName() : string{ return "Vines"; } - public function getHardness(){ + public function getHardness() : float{ return 0.2; } - public function canPassThrough(){ + public function canPassThrough() : bool{ return true; } - public function hasEntityCollision(){ + public function hasEntityCollision() : bool{ return true; } @@ -132,7 +132,7 @@ class Vine extends Transparent{ } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ //TODO: multiple sides if($target->isSolid()){ $faces = [ @@ -152,7 +152,7 @@ class Vine extends Transparent{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ $sides = [ 1 => 3, @@ -184,7 +184,7 @@ class Vine extends Transparent{ } } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } } \ No newline at end of file diff --git a/src/pocketmine/block/WallSign.php b/src/pocketmine/block/WallSign.php index 0d105f58a8..50863d8248 100644 --- a/src/pocketmine/block/WallSign.php +++ b/src/pocketmine/block/WallSign.php @@ -29,11 +29,11 @@ class WallSign extends SignPost{ protected $id = self::WALL_SIGN; - public function getName(){ + public function getName() : string{ return "Wall Sign"; } - public function onUpdate($type){ + public function onUpdate(int $type){ $faces = [ 2 => 3, 3 => 2, diff --git a/src/pocketmine/block/Water.php b/src/pocketmine/block/Water.php index e12cb62f12..7027b4d858 100644 --- a/src/pocketmine/block/Water.php +++ b/src/pocketmine/block/Water.php @@ -31,11 +31,11 @@ class Water extends Liquid{ protected $id = self::FLOWING_WATER; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Water"; } @@ -52,7 +52,7 @@ class Water extends Liquid{ $entity->resetFallDistance(); } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $ret = $this->getLevel()->setBlock($this, $this, true, false); $this->getLevel()->scheduleDelayedBlockUpdate($this, $this->tickRate()); diff --git a/src/pocketmine/block/WaterLily.php b/src/pocketmine/block/WaterLily.php index 869c8121f7..8d7144152d 100644 --- a/src/pocketmine/block/WaterLily.php +++ b/src/pocketmine/block/WaterLily.php @@ -33,15 +33,15 @@ class WaterLily extends Flowable{ protected $id = self::WATER_LILY; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Lily Pad"; } - public function getHardness(){ + public function getHardness() : float{ return 0.6; } @@ -57,7 +57,7 @@ class WaterLily extends Flowable{ } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ if($target instanceof Water){ $up = $target->getSide(Vector3::SIDE_UP); if($up->getId() === Block::AIR){ @@ -69,7 +69,7 @@ class WaterLily extends Flowable{ return false; } - public function onUpdate($type){ + public function onUpdate(int $type){ if($type === Level::BLOCK_UPDATE_NORMAL){ if(!($this->getSide(Vector3::SIDE_DOWN) instanceof Water)){ $this->getLevel()->useBreakOn($this); diff --git a/src/pocketmine/block/WeightedPressurePlateHeavy.php b/src/pocketmine/block/WeightedPressurePlateHeavy.php index 9b341ca3f6..bcfe010d49 100644 --- a/src/pocketmine/block/WeightedPressurePlateHeavy.php +++ b/src/pocketmine/block/WeightedPressurePlateHeavy.php @@ -27,7 +27,7 @@ class WeightedPressurePlateHeavy extends WeightedPressurePlateLight{ protected $id = self::HEAVY_WEIGHTED_PRESSURE_PLATE; - public function getName(){ + public function getName() : string{ return "Weighted Pressure Plate Heavy"; } } diff --git a/src/pocketmine/block/WeightedPressurePlateLight.php b/src/pocketmine/block/WeightedPressurePlateLight.php index 4e7dcbbac1..ac4e793ad6 100644 --- a/src/pocketmine/block/WeightedPressurePlateLight.php +++ b/src/pocketmine/block/WeightedPressurePlateLight.php @@ -27,19 +27,19 @@ class WeightedPressurePlateLight extends Transparent{ protected $id = self::LIGHT_WEIGHTED_PRESSURE_PLATE; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Weighted Pressure Plate Light"; } - public function isSolid(){ + public function isSolid() : bool{ return false; } - public function getHardness(){ + public function getHardness() : float{ return 0.5; } } diff --git a/src/pocketmine/block/Wheat.php b/src/pocketmine/block/Wheat.php index 28a64bddab..5d69a5049d 100644 --- a/src/pocketmine/block/Wheat.php +++ b/src/pocketmine/block/Wheat.php @@ -29,11 +29,11 @@ class Wheat extends Crops{ protected $id = self::WHEAT_BLOCK; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getName(){ + public function getName() : string{ return "Wheat Block"; } diff --git a/src/pocketmine/block/Wood.php b/src/pocketmine/block/Wood.php index 46c8dac062..7bd249a7fc 100644 --- a/src/pocketmine/block/Wood.php +++ b/src/pocketmine/block/Wood.php @@ -35,15 +35,15 @@ class Wood extends Solid{ protected $id = self::WOOD; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getName(){ + public function getName() : string{ static $names = [ self::OAK => "Oak Wood", self::SPRUCE => "Spruce Wood", @@ -53,7 +53,7 @@ class Wood extends Solid{ return $names[$this->meta & 0x03]; } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $faces = [ 0 => 0, 1 => 0, @@ -75,7 +75,7 @@ class Wood extends Solid{ ]; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/Wood2.php b/src/pocketmine/block/Wood2.php index 7094787d2e..2db985f0ce 100644 --- a/src/pocketmine/block/Wood2.php +++ b/src/pocketmine/block/Wood2.php @@ -31,7 +31,7 @@ class Wood2 extends Wood{ protected $id = self::WOOD2; - public function getName(){ + public function getName() : string{ static $names = [ 0 => "Acacia Wood", 1 => "Dark Oak Wood" diff --git a/src/pocketmine/block/WoodenButton.php b/src/pocketmine/block/WoodenButton.php index 63a60d7d08..91a531c1c1 100644 --- a/src/pocketmine/block/WoodenButton.php +++ b/src/pocketmine/block/WoodenButton.php @@ -27,7 +27,7 @@ class WoodenButton extends StoneButton{ protected $id = self::WOODEN_BUTTON; - public function getName(){ + public function getName() : string{ return "Wooden Button"; } } diff --git a/src/pocketmine/block/WoodenDoor.php b/src/pocketmine/block/WoodenDoor.php index 502e0fa7cd..70618183b8 100644 --- a/src/pocketmine/block/WoodenDoor.php +++ b/src/pocketmine/block/WoodenDoor.php @@ -28,11 +28,11 @@ use pocketmine\item\Tool; class WoodenDoor extends Door{ - public function getHardness(){ + public function getHardness() : float{ return 3; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/WoodenPressurePlate.php b/src/pocketmine/block/WoodenPressurePlate.php index d42605df3f..0994b52ea4 100644 --- a/src/pocketmine/block/WoodenPressurePlate.php +++ b/src/pocketmine/block/WoodenPressurePlate.php @@ -27,7 +27,7 @@ class WoodenPressurePlate extends StonePressurePlate{ protected $id = self::WOODEN_PRESSURE_PLATE; - public function getName(){ + public function getName() : string{ return "Wooden Pressure Plate"; } diff --git a/src/pocketmine/block/WoodenSlab.php b/src/pocketmine/block/WoodenSlab.php index 067655c8ef..a4ade5ea75 100644 --- a/src/pocketmine/block/WoodenSlab.php +++ b/src/pocketmine/block/WoodenSlab.php @@ -34,15 +34,15 @@ class WoodenSlab extends Transparent{ protected $doubleId = self::DOUBLE_WOODEN_SLAB; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getName(){ + public function getName() : string{ static $names = [ 0 => "Oak", 1 => "Spruce", @@ -77,7 +77,7 @@ class WoodenSlab extends Transparent{ } } - public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ + public function place(Item $item, Block $block, Block $target, int $face, float $fx, float $fy, float $fz, Player $player = null) : bool{ $this->meta &= 0x07; if($face === 0){ if($target->getId() === $this->id and ($target->getDamage() & 0x08) === 0x08 and ($target->getDamage() & 0x07) === ($this->meta)){ @@ -125,7 +125,7 @@ class WoodenSlab extends Transparent{ return true; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/WoodenStairs.php b/src/pocketmine/block/WoodenStairs.php index 1b8034aec0..ae91ae9e5d 100644 --- a/src/pocketmine/block/WoodenStairs.php +++ b/src/pocketmine/block/WoodenStairs.php @@ -28,15 +28,15 @@ use pocketmine\item\Tool; class WoodenStairs extends Stair{ - public function getHardness(){ + public function getHardness() : float{ return 2; } - public function getResistance(){ + public function getResistance() : float{ return 15; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_AXE; } diff --git a/src/pocketmine/block/Wool.php b/src/pocketmine/block/Wool.php index a34ba8622f..4a41732c73 100644 --- a/src/pocketmine/block/Wool.php +++ b/src/pocketmine/block/Wool.php @@ -30,19 +30,19 @@ class Wool extends Solid{ protected $id = self::WOOL; - public function __construct($meta = 0){ + public function __construct(int $meta = 0){ $this->meta = $meta; } - public function getHardness(){ + public function getHardness() : float{ return 0.8; } - public function getToolType(){ + public function getToolType() : int{ return Tool::TYPE_SHEARS; } - public function getName(){ + public function getName() : string{ return ColorBlockMetaHelper::getColorFromMeta($this->meta) . " Wool"; } From e825ebd8fa1ab09833fbdcb93f5e574064a64926 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 16:52:17 +0100 Subject: [PATCH 22/23] Added some wrapper methods to make data flags less of a pain in the ass to work with --- src/pocketmine/Player.php | 18 +++++----- src/pocketmine/entity/Animal.php | 2 +- src/pocketmine/entity/Arrow.php | 4 +-- src/pocketmine/entity/Effect.php | 4 +-- src/pocketmine/entity/Entity.php | 52 ++++++++++++++++++--------- src/pocketmine/entity/Human.php | 22 +++++++++++- src/pocketmine/entity/Living.php | 2 +- src/pocketmine/entity/PrimedTNT.php | 2 +- src/pocketmine/entity/Villager.php | 2 +- src/pocketmine/entity/WaterAnimal.php | 2 +- 10 files changed, 75 insertions(+), 35 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 310bbe17a3..c66b980b4f 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1147,7 +1147,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->sleeping = clone $pos; $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [$pos->x, $pos->y, $pos->z]); - $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, true, self::DATA_TYPE_BYTE); + $this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, true); $this->setSpawn($pos); @@ -1188,7 +1188,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->sleeping = null; $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0]); - $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE); + $this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false); $this->level->sleepTicks = 0; @@ -2166,7 +2166,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->craftingType = 0; - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); //TODO: check if this should be true + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); //TODO: check if this should be true switch($packet->event){ case EntityEventPacket::USE_ITEM: //Eating @@ -2218,7 +2218,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->inventory->equipItem($packet->hotbarSlot, $packet->inventorySlot); - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); return true; } @@ -2387,7 +2387,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->craftingType = 0; if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); if(!$this->canInteract($blockVector->add(0.5, 0.5, 0.5), 13) or $this->isSpectator()){ }elseif($this->isCreative()){ @@ -2482,7 +2482,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } } - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, true); + $this->setGenericFlag(self::DATA_FLAG_ACTION, true); $this->startAction = $this->server->getTick(); } @@ -2532,7 +2532,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->level->broadcastLevelEvent($pos, LevelEventPacket::EVENT_BLOCK_STOP_BREAK); break; case PlayerActionPacket::ACTION_RELEASE_ITEM: - if($this->startAction > -1 and $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION)){ + if($this->startAction > -1 and $this->getGenericFlag(self::DATA_FLAG_ACTION)){ if($this->inventory->getItemInHand()->getId() === Item::BOW){ $bow = $this->inventory->getItemInHand(); if($this->isSurvival() and !$this->inventory->contains(Item::get(Item::ARROW, 0, 1))){ @@ -2728,7 +2728,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } $this->startAction = -1; - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); return true; } @@ -2774,7 +2774,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->level->dropItem($this->add(0, 1.3, 0), $item, $motion, 40); - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false); + $this->setGenericFlag(self::DATA_FLAG_ACTION, false); return true; } diff --git a/src/pocketmine/entity/Animal.php b/src/pocketmine/entity/Animal.php index d8c502a41b..9cd4e86f74 100644 --- a/src/pocketmine/entity/Animal.php +++ b/src/pocketmine/entity/Animal.php @@ -27,6 +27,6 @@ namespace pocketmine\entity; abstract class Animal extends Creature implements Ageable{ public function isBaby() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); + return $this->getGenericFlag(self::DATA_FLAG_BABY); } } \ No newline at end of file diff --git a/src/pocketmine/entity/Arrow.php b/src/pocketmine/entity/Arrow.php index d79963a76f..2580c1c877 100644 --- a/src/pocketmine/entity/Arrow.php +++ b/src/pocketmine/entity/Arrow.php @@ -46,11 +46,11 @@ class Arrow extends Projectile{ } public function isCritical() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CRITICAL); + return $this->getGenericFlag(self::DATA_FLAG_CRITICAL); } public function setCritical(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CRITICAL, $value); + $this->setGenericFlag(self::DATA_FLAG_CRITICAL, $value); } public function getResultDamage() : int{ diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index 36675effc6..1241c5b340 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -422,7 +422,7 @@ class Effect{ switch($this->id){ case Effect::INVISIBILITY: - $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, true); + $entity->setGenericFlag(Entity::DATA_FLAG_INVISIBLE, true); $entity->setNameTagVisible(false); break; case Effect::SPEED: @@ -487,7 +487,7 @@ class Effect{ switch($this->id){ case Effect::INVISIBILITY: - $entity->setDataFlag(Entity::DATA_FLAGS, Entity::DATA_FLAG_INVISIBLE, false); + $entity->setGenericFlag(Entity::DATA_FLAG_INVISIBLE, false); $entity->setNameTagVisible(true); break; case Effect::SPEED: diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 9220e4ad2d..1648539ce9 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -453,14 +453,14 @@ abstract class Entity extends Location implements Metadatable{ * @return bool */ public function isNameTagVisible() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG); + return $this->getGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG); } /** * @return bool */ public function isNameTagAlwaysVisible() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG); + return $this->getGenericFlag(self::DATA_FLAG_ALWAYS_SHOW_NAMETAG); } @@ -475,14 +475,14 @@ abstract class Entity extends Location implements Metadatable{ * @param bool $value */ public function setNameTagVisible(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_SHOW_NAMETAG, $value); + $this->setGenericFlag(self::DATA_FLAG_CAN_SHOW_NAMETAG, $value); } /** * @param bool $value */ public function setNameTagAlwaysVisible(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value); + $this->setGenericFlag(self::DATA_FLAG_ALWAYS_SHOW_NAMETAG, $value); } /** @@ -521,31 +521,31 @@ abstract class Entity extends Location implements Metadatable{ public function isSneaking() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING); + return $this->getGenericFlag(self::DATA_FLAG_SNEAKING); } public function setSneaking(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SNEAKING, $value); + $this->setGenericFlag(self::DATA_FLAG_SNEAKING, $value); } public function isSprinting() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING); + return $this->getGenericFlag(self::DATA_FLAG_SPRINTING); } public function setSprinting(bool $value = true){ if($value !== $this->isSprinting()){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_SPRINTING, $value); + $this->setGenericFlag(self::DATA_FLAG_SPRINTING, $value); $attr = $this->attributeMap->getAttribute(Attribute::MOVEMENT_SPEED); $attr->setValue($value ? ($attr->getValue() * 1.3) : ($attr->getValue() / 1.3), false, true); } } public function isImmobile() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE); + return $this->getGenericFlag(self::DATA_FLAG_IMMOBILE); } public function setImmobile(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IMMOBILE, $value); + $this->setGenericFlag(self::DATA_FLAG_IMMOBILE, $value); } /** @@ -553,7 +553,7 @@ abstract class Entity extends Location implements Metadatable{ * @return bool */ public function canClimb() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_CLIMB); + return $this->getGenericFlag(self::DATA_FLAG_CAN_CLIMB); } /** @@ -561,7 +561,7 @@ abstract class Entity extends Location implements Metadatable{ * @param bool $value */ public function setCanClimb(bool $value){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_CAN_CLIMB, $value); + $this->setGenericFlag(self::DATA_FLAG_CAN_CLIMB, $value); } /** @@ -570,7 +570,7 @@ abstract class Entity extends Location implements Metadatable{ * @return bool */ public function canClimbWalls() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING); + return $this->getGenericFlag(self::DATA_FLAG_WALLCLIMBING); } /** @@ -579,7 +579,7 @@ abstract class Entity extends Location implements Metadatable{ * @param bool $value */ public function setCanClimbWalls(bool $value = true){ - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_WALLCLIMBING, $value); + $this->setGenericFlag(self::DATA_FLAG_WALLCLIMBING, $value); } /** @@ -1266,12 +1266,12 @@ abstract class Entity extends Location implements Metadatable{ $this->fireTicks = $ticks; } - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, true); + $this->setGenericFlag(self::DATA_FLAG_ONFIRE, true); } public function extinguish(){ $this->fireTicks = 0; - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ONFIRE, false); + $this->setGenericFlag(self::DATA_FLAG_ONFIRE, false); } public function isFireProof() : bool{ @@ -1930,6 +1930,26 @@ abstract class Entity extends Location implements Metadatable{ return (((int) $this->getDataProperty($propertyId)) & (1 << $flagId)) > 0; } + /** + * Wrapper around {@link Entity#getDataFlag} for generic data flag reading. + * + * @param int $flagId + * @return bool + */ + public function getGenericFlag(int $flagId) : bool{ + return $this->getDataFlag(self::DATA_FLAGS, $flagId); + } + + /** + * Wrapper around {@link Entity#setDataFlag} for generic data flag setting. + * + * @param int $flagId + * @param bool $value + */ + public function setGenericFlag(int $flagId, bool $value = true){ + $this->setDataFlag(self::DATA_FLAGS, $flagId, $value, self::DATA_TYPE_LONG); + } + public function __destruct(){ $this->close(); } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index b4b87d5f85..db36c093c6 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -283,7 +283,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ protected function initEntity(){ - $this->setDataFlag(self::DATA_PLAYER_FLAGS, self::DATA_PLAYER_FLAG_SLEEP, false, self::DATA_TYPE_BYTE); + $this->setPlayerFlag(self::DATA_PLAYER_FLAG_SLEEP, false); $this->setDataProperty(self::DATA_PLAYER_BED_POSITION, self::DATA_TYPE_POS, [0, 0, 0], false); $this->inventory = new PlayerInventory($this); @@ -542,4 +542,24 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ parent::close(); } } + + /** + * Wrapper around {@link Entity#getDataFlag} for player-specific data flag reading. + * + * @param int $flagId + * @return bool + */ + public function getPlayerFlag(int $flagId){ + return $this->getDataFlag(self::DATA_PLAYER_FLAGS, $flagId); + } + + /** + * Wrapper around {@link Entity#setDataFlag} for player-specific data flag setting. + * + * @param int $flagId + * @param bool $value + */ + public function setPlayerFlag(int $flagId, bool $value = true){ + $this->setDataFlag(self::DATA_PLAYER_FLAGS, $flagId, $value, self::DATA_TYPE_BYTE); + } } diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index 6447f463e2..11b9b4cb73 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -418,7 +418,7 @@ abstract class Living extends Entity implements Damageable{ public function entityBaseTick(int $tickDiff = 1) : bool{ Timings::$timerLivingEntityBaseTick->startTiming(); - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BREATHING, !$this->isInsideOfWater()); + $this->setGenericFlag(self::DATA_FLAG_BREATHING, !$this->isInsideOfWater()); $hasUpdate = parent::entityBaseTick($tickDiff); diff --git a/src/pocketmine/entity/PrimedTNT.php b/src/pocketmine/entity/PrimedTNT.php index 4cc7e233d1..b88f622340 100644 --- a/src/pocketmine/entity/PrimedTNT.php +++ b/src/pocketmine/entity/PrimedTNT.php @@ -63,7 +63,7 @@ class PrimedTNT extends Entity implements Explosive{ $this->fuse = 80; } - $this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_IGNITED, true); + $this->setGenericFlag(self::DATA_FLAG_IGNITED, true); $this->setDataProperty(self::DATA_FUSE_LENGTH, self::DATA_TYPE_INT, $this->fuse); $this->level->broadcastLevelEvent($this, LevelEventPacket::EVENT_SOUND_IGNITE); diff --git a/src/pocketmine/entity/Villager.php b/src/pocketmine/entity/Villager.php index 910922195c..3bd32d0c02 100644 --- a/src/pocketmine/entity/Villager.php +++ b/src/pocketmine/entity/Villager.php @@ -84,6 +84,6 @@ class Villager extends Creature implements NPC, Ageable{ } public function isBaby() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); + return $this->getGenericFlag(self::DATA_FLAG_BABY); } } diff --git a/src/pocketmine/entity/WaterAnimal.php b/src/pocketmine/entity/WaterAnimal.php index 6f4e3f4a8a..eb1452c5a7 100644 --- a/src/pocketmine/entity/WaterAnimal.php +++ b/src/pocketmine/entity/WaterAnimal.php @@ -26,6 +26,6 @@ namespace pocketmine\entity; abstract class WaterAnimal extends Creature implements Ageable{ public function isBaby() : bool{ - return $this->getDataFlag(self::DATA_FLAGS, self::DATA_FLAG_BABY); + return $this->getGenericFlag(self::DATA_FLAG_BABY); } } From 83f29e56398a06a192c16976a4b8947dc9d0ed7f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 17 Aug 2017 17:02:13 +0100 Subject: [PATCH 23/23] Fixed tests failing since 83af4dcd --- tests/plugins/PocketMine-TesterPlugin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plugins/PocketMine-TesterPlugin b/tests/plugins/PocketMine-TesterPlugin index c51e4bbd3a..26a03d6d46 160000 --- a/tests/plugins/PocketMine-TesterPlugin +++ b/tests/plugins/PocketMine-TesterPlugin @@ -1 +1 @@ -Subproject commit c51e4bbd3a7c66fd00e2255d49e46df85b037d55 +Subproject commit 26a03d6d467f7e505a292610078b65c0205e4ed8