2828
2929class Anvil extends Fallable{
3030
31+ const TYPE_NORMAL = 0 ;
32+ const TYPE_SLIGHTLY_DAMAGED = 4 ;
33+ const TYPE_VERY_DAMAGED = 8 ;
34+
3135 protected $ id = self ::ANVIL ;
3236
3337 public function isSolid (){
@@ -51,7 +55,12 @@ public function getResistance(){
5155 }
5256
5357 public function getName (){
54- return "Anvil " ;
58+ static $ names = [
59+ self ::TYPE_NORMAL => "Anvil " ,
60+ self ::TYPE_SLIGHTLY_DAMAGED => "Slightly Damaged Anvil " ,
61+ self ::TYPE_VERY_DAMAGED => "Very Damaged Anvil "
62+ ];
63+ return $ names [$ this ->meta & 0x0c ] ?? "Anvil " ;
5564 }
5665
5766 public function getToolType (){
@@ -66,10 +75,16 @@ public function onActivate(Item $item, Player $player = null){
6675 return true ;
6776 }
6877
78+ public function place (Item $ item , Block $ block , Block $ target , $ face , $ fx , $ fy , $ fz , Player $ player = null ){
79+ $ direction = ($ player !== null ? $ player ->getDirection () : 0 ) & 0x03 ;
80+ $ this ->meta = ($ this ->meta & 0x0c ) | $ direction ;
81+ $ this ->getLevel ()->setBlock ($ block , $ this , true , true );
82+ }
83+
6984 public function getDrops (Item $ item ){
7085 if ($ item ->isPickaxe () >= Tool::TIER_WOODEN ){
7186 return [
72- [$ this ->id , 0 , 1 ], //TODO break level
87+ [$ this ->id , $ this -> meta & 0x0c , 1 ],
7388 ];
7489 }else {
7590 return [];
0 commit comments