mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 06:25:32 +00:00
Use Block->getVariant() more, get rid of hardcoded bitmasks
This commit is contained in:
parent
91d84aaff4
commit
f148c366f9
@ -51,7 +51,7 @@ class DoublePlant extends Flowable{
|
|||||||
4 => "Rose Bush",
|
4 => "Rose Bush",
|
||||||
5 => "Peony"
|
5 => "Peony"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x07] ?? "";
|
return $names[$this->getVariant()] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
||||||
@ -79,7 +79,7 @@ class DoublePlant extends Flowable{
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
$other->getId() === $this->getId() and
|
$other->getId() === $this->getId() and
|
||||||
($other->getDamage() & 0x07) === ($this->getDamage() & 0x07) and
|
$other->getVariant() === $this->getVariant() and
|
||||||
($other->getDamage() & self::BITFLAG_TOP) !== ($this->getDamage() & self::BITFLAG_TOP)
|
($other->getDamage() & self::BITFLAG_TOP) !== ($this->getDamage() & self::BITFLAG_TOP)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -54,13 +54,13 @@ class DoubleStoneSlab extends Solid{
|
|||||||
6 => "Quartz",
|
6 => "Quartz",
|
||||||
7 => "Nether Brick"
|
7 => "Nether Brick"
|
||||||
];
|
];
|
||||||
return "Double " . $names[$this->meta & 0x07] . " Slab";
|
return "Double " . $names[$this->getVariant()] . " Slab";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item) : array{
|
public function getDrops(Item $item) : array{
|
||||||
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
if($item->isPickaxe() >= Tool::TIER_WOODEN){
|
||||||
return [
|
return [
|
||||||
ItemFactory::get(Item::STONE_SLAB, $this->getDamage() & 0x07, 2)
|
ItemFactory::get(Item::STONE_SLAB, $this->getVariant(), 2)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ class DoubleWoodenSlab extends Solid{
|
|||||||
4 => "Acacia",
|
4 => "Acacia",
|
||||||
5 => "Dark Oak"
|
5 => "Dark Oak"
|
||||||
];
|
];
|
||||||
return "Double " . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab";
|
return "Double " . ($names[$this->getVariant()] ?? "") . " Wooden Slab";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item) : array{
|
public function getDrops(Item $item) : array{
|
||||||
return [
|
return [
|
||||||
ItemFactory::get(Item::WOODEN_SLAB, $this->getDamage() & 0x07, 2)
|
ItemFactory::get(Item::WOODEN_SLAB, $this->getVariant(), 2)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class Leaves extends Transparent{
|
|||||||
self::BIRCH => "Birch Leaves",
|
self::BIRCH => "Birch Leaves",
|
||||||
self::JUNGLE => "Jungle Leaves"
|
self::JUNGLE => "Jungle Leaves"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03];
|
return $names[$this->getVariant()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function diffusesSkyLight() : bool{
|
public function diffusesSkyLight() : bool{
|
||||||
|
@ -36,11 +36,11 @@ class Leaves2 extends Leaves{
|
|||||||
self::ACACIA => "Acacia Leaves",
|
self::ACACIA => "Acacia Leaves",
|
||||||
self::DARK_OAK => "Dark Oak Leaves"
|
self::DARK_OAK => "Dark Oak Leaves"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item) : array{
|
public function getDrops(Item $item) : array{
|
||||||
$variantMeta = $this->getDamage() & 0x03;
|
$variantMeta = $this->getVariant();
|
||||||
|
|
||||||
if($item->isShears()){
|
if($item->isShears()){
|
||||||
return [
|
return [
|
||||||
|
@ -56,7 +56,7 @@ class Planks extends Solid{
|
|||||||
self::ACACIA => "Acacia 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] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFuelTime() : int{
|
public function getFuelTime() : int{
|
||||||
|
@ -48,7 +48,7 @@ class Prismarine extends Solid{
|
|||||||
self::DARK => "Dark Prismarine",
|
self::DARK => "Dark Prismarine",
|
||||||
self::BRICKS => "Prismarine Bricks"
|
self::BRICKS => "Prismarine Bricks"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getToolType() : int{
|
public function getToolType() : int{
|
||||||
|
@ -48,7 +48,7 @@ class Sandstone extends Solid{
|
|||||||
self::CHISELED => "Chiseled Sandstone",
|
self::CHISELED => "Chiseled Sandstone",
|
||||||
self::SMOOTH => "Smooth Sandstone"
|
self::SMOOTH => "Smooth Sandstone"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getToolType() : int{
|
public function getToolType() : int{
|
||||||
|
@ -54,7 +54,7 @@ class Sapling extends Flowable{
|
|||||||
4 => "Acacia Sapling",
|
4 => "Acacia Sapling",
|
||||||
5 => "Dark Oak Sapling"
|
5 => "Dark Oak Sapling"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x07] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ticksRandomly() : bool{
|
public function ticksRandomly() : bool{
|
||||||
@ -75,7 +75,7 @@ class Sapling extends Flowable{
|
|||||||
public function onActivate(Item $item, Player $player = null) : bool{
|
public function onActivate(Item $item, Player $player = null) : bool{
|
||||||
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
|
if($item->getId() === Item::DYE and $item->getDamage() === 0x0F){ //Bonemeal
|
||||||
//TODO: change log type
|
//TODO: change log type
|
||||||
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07);
|
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant());
|
||||||
|
|
||||||
$item->count--;
|
$item->count--;
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ class Sapling extends Flowable{
|
|||||||
}elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth
|
}elseif($type === Level::BLOCK_UPDATE_RANDOM){ //Growth
|
||||||
if(mt_rand(1, 7) === 1){
|
if(mt_rand(1, 7) === 1){
|
||||||
if(($this->meta & 0x08) === 0x08){
|
if(($this->meta & 0x08) === 0x08){
|
||||||
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->meta & 0x07);
|
Tree::growTree($this->getLevel(), $this->x, $this->y, $this->z, new Random(mt_rand()), $this->getVariant());
|
||||||
}else{
|
}else{
|
||||||
$this->meta |= 0x08;
|
$this->meta |= 0x08;
|
||||||
$this->getLevel()->setBlock($this, $this, true);
|
$this->getLevel()->setBlock($this, $this, true);
|
||||||
@ -110,10 +110,8 @@ class Sapling extends Flowable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item) : array{
|
public function getVariantBitmask() : int{
|
||||||
return [
|
return 0x07;
|
||||||
ItemFactory::get($this->getItemId(), $this->getDamage() & 0x07, 1)
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFuelTime() : int{
|
public function getFuelTime() : int{
|
||||||
|
@ -60,7 +60,7 @@ class Stone extends Solid{
|
|||||||
self::ANDESITE => "Andesite",
|
self::ANDESITE => "Andesite",
|
||||||
self::POLISHED_ANDESITE => "Polished Andesite"
|
self::POLISHED_ANDESITE => "Polished Andesite"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x07] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item) : array{
|
public function getDrops(Item $item) : array{
|
||||||
|
@ -53,7 +53,7 @@ class StoneBricks extends Solid{
|
|||||||
self::CRACKED => "Cracked Stone Bricks",
|
self::CRACKED => "Cracked Stone Bricks",
|
||||||
self::CHISELED => "Chiseled Stone Bricks"
|
self::CHISELED => "Chiseled Stone Bricks"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03];
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDrops(Item $item) : array{
|
public function getDrops(Item $item) : array{
|
||||||
|
@ -55,7 +55,7 @@ class StoneSlab extends WoodenSlab{
|
|||||||
self::QUARTZ => "Quartz",
|
self::QUARTZ => "Quartz",
|
||||||
self::NETHER_BRICK => "Nether Brick"
|
self::NETHER_BRICK => "Nether Brick"
|
||||||
];
|
];
|
||||||
return (($this->meta & 0x08) > 0 ? "Upper " : "") . $names[$this->meta & 0x07] . " Slab";
|
return (($this->meta & 0x08) > 0 ? "Upper " : "") . ($names[$this->getVariant()] ?? "") . " Slab";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getToolType() : int{
|
public function getToolType() : int{
|
||||||
|
@ -47,7 +47,7 @@ class TallGrass extends Flowable{
|
|||||||
1 => "Tall Grass",
|
1 => "Tall Grass",
|
||||||
2 => "Fern"
|
2 => "Fern"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
||||||
|
@ -52,7 +52,7 @@ class Wood extends Solid{
|
|||||||
self::BIRCH => "Birch Wood",
|
self::BIRCH => "Birch Wood",
|
||||||
self::JUNGLE => "Jungle Wood"
|
self::JUNGLE => "Jungle Wood"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03];
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
||||||
|
@ -36,6 +36,6 @@ class Wood2 extends Wood{
|
|||||||
0 => "Acacia Wood",
|
0 => "Acacia Wood",
|
||||||
1 => "Dark Oak Wood"
|
1 => "Dark Oak Wood"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x03] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class WoodenFence extends Fence{
|
|||||||
self::FENCE_ACACIA => "Acacia Fence",
|
self::FENCE_ACACIA => "Acacia Fence",
|
||||||
self::FENCE_DARKOAK => "Dark Oak Fence"
|
self::FENCE_DARKOAK => "Dark Oak Fence"
|
||||||
];
|
];
|
||||||
return $names[$this->meta & 0x07] ?? "Unknown";
|
return $names[$this->getVariant()] ?? "Unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFuelTime() : int{
|
public function getFuelTime() : int{
|
||||||
|
@ -52,7 +52,7 @@ class WoodenSlab extends Transparent{
|
|||||||
4 => "Acacia",
|
4 => "Acacia",
|
||||||
5 => "Dark Oak"
|
5 => "Dark Oak"
|
||||||
];
|
];
|
||||||
return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . ($names[$this->meta & 0x07] ?? "") . " Wooden Slab";
|
return (($this->meta & 0x08) === 0x08 ? "Upper " : "") . ($names[$this->getVariant()] ?? "") . " Wooden Slab";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
protected function recalculateBoundingBox() : ?AxisAlignedBB{
|
||||||
@ -93,31 +93,31 @@ class WoodenSlab extends Transparent{
|
|||||||
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
public function place(Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $facePos, Player $player = null) : bool{
|
||||||
$this->meta &= 0x07;
|
$this->meta &= 0x07;
|
||||||
if($face === Vector3::SIDE_DOWN){
|
if($face === Vector3::SIDE_DOWN){
|
||||||
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and ($blockClicked->getDamage() & 0x07) === $this->meta){
|
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0x08 and $blockClicked->getVariant() === $this->getVariant()){
|
||||||
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->meta), true);
|
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->getVariant()), true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($blockReplace->getId() === $this->id and ($blockReplace->getDamage() & 0x07) === $this->meta){
|
}elseif($blockReplace->getId() === $this->id and $blockReplace->getVariant() === $this->getVariant()){
|
||||||
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true);
|
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->getVariant()), true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
$this->meta |= 0x08;
|
$this->meta |= 0x08;
|
||||||
}
|
}
|
||||||
}elseif($face === Vector3::SIDE_UP){
|
}elseif($face === Vector3::SIDE_UP){
|
||||||
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and ($blockClicked->getDamage() & 0x07) === $this->meta){
|
if($blockClicked->getId() === $this->id and ($blockClicked->getDamage() & 0x08) === 0 and $blockClicked->getVariant() === $this->getVariant()){
|
||||||
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->meta), true);
|
$this->getLevel()->setBlock($blockClicked, BlockFactory::get($this->doubleId, $this->getVariant()), true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}elseif($blockReplace->getId() === $this->id and ($blockReplace->getDamage() & 0x07) === $this->meta){
|
}elseif($blockReplace->getId() === $this->id and $blockReplace->getVariant() === $this->getVariant()){
|
||||||
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true);
|
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->getVariant()), true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}else{ //TODO: collision
|
}else{ //TODO: collision
|
||||||
if($blockReplace->getId() === $this->id){
|
if($blockReplace->getId() === $this->id){
|
||||||
if(($blockReplace->getDamage() & 0x07) === $this->meta){
|
if($blockReplace->getVariant() === $this->meta){
|
||||||
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->meta), true);
|
$this->getLevel()->setBlock($blockReplace, BlockFactory::get($this->doubleId, $this->getVariant()), true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ class WoodenSlab extends Transparent{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($blockReplace->getId() === $this->id and ($blockClicked->getDamage() & 0x07) !== ($this->meta & 0x07)){
|
if($blockReplace->getId() === $this->id and $blockClicked->getVariant() !== $this->getVariant()){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->getLevel()->setBlock($blockReplace, $this, true, true);
|
$this->getLevel()->setBlock($blockReplace, $this, true, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user