File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -54,19 +54,25 @@ public function isOpeningObstructed() : bool{
54
54
return false ;
55
55
}
56
56
57
+ abstract protected function getPosition () : Position ;
58
+
59
+ protected function getTile () : ?ContainerTile {
60
+ $ pos = $ this ->getPosition ();
61
+ $ tile = $ pos ->getWorld ()->getTile ($ pos );
62
+ return $ tile instanceof ContainerTile ? $ tile : null ;
63
+ }
64
+
57
65
public function canOpenWith (string $ key ) : bool {
58
66
//TODO: maybe we can bring the key to the block in readStateFromWorld()?
59
- $ tile = $ this ->position ->getWorld ()->getTile ($ this ->position );
60
- return $ tile instanceof ContainerTile && $ tile ->canOpenWith ($ key );
67
+ return $ this ->getTile ()?->canOpenWith($ key ) ?? false ;
61
68
}
62
69
63
70
public function openToUnchecked (Player $ player ) : bool {
64
- $ tile = $ this ->position -> getWorld ()-> getTile ($ this -> position );
65
- return $ tile instanceof ContainerTile && $ player ->setCurrentWindow ($ this ->newMenu ($ player , $ tile ->getInventory (), $ this ->position ));
71
+ $ tile = $ this ->getTile ();
72
+ return $ tile !== null && $ player ->setCurrentWindow ($ this ->newMenu ($ player , $ tile ->getInventory (), $ this ->getPosition () ));
66
73
}
67
74
68
75
public function getInventory () : ?Inventory {
69
- $ tile = $ this ->position ->getWorld ()->getTile ($ this ->position );
70
- return $ tile instanceof ContainerTile ? $ tile ->getInventory () : null ;
76
+ return $ this ->getTile ()?->getInventory();
71
77
}
72
78
}
Original file line number Diff line number Diff line change @@ -50,7 +50,9 @@ public function isOpeningObstructed() : bool{
50
50
return false ;
51
51
}
52
52
53
+ abstract protected function getPosition () : Position ;
54
+
53
55
public function openToUnchecked (Player $ player ) : bool {
54
- return $ player ->setCurrentWindow ($ this ->newMenu ($ player , $ this ->position ));
56
+ return $ player ->setCurrentWindow ($ this ->newMenu ($ player , $ this ->getPosition () ));
55
57
}
56
58
}
You can’t perform that action at this time.
0 commit comments