mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 09:10:00 +00:00
CraftingTransaction: Fixed ingredient map trimming
I really don't know why I made this so complicated to start with. This works much better and is much easier to read. Fixes #2083.
This commit is contained in:
parent
5059a92b91
commit
2e125168c3
@ -105,24 +105,27 @@ class CraftingTransaction extends InventoryTransaction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function reindexInputs() : array{
|
private function reindexInputs() : array{
|
||||||
$xOffset = $this->gridSize;
|
$minX = 0;
|
||||||
$yOffset = $this->gridSize;
|
$maxX = 0;
|
||||||
|
|
||||||
$height = 0;
|
$minY = 0;
|
||||||
$width = 0;
|
$maxY = 0;
|
||||||
|
|
||||||
foreach($this->inputs as $y => $row){
|
foreach($this->inputs as $y => $row){
|
||||||
foreach($row as $x => $item){
|
foreach($row as $x => $item){
|
||||||
if(!$item->isNull()){
|
if(!$item->isNull()){
|
||||||
$xOffset = min($x, $xOffset);
|
$minX = min($minX, $x);
|
||||||
$yOffset = min($y, $yOffset);
|
$maxX = max($maxX, $x);
|
||||||
|
|
||||||
$height = max($y + 1 - $yOffset, $height);
|
$minY = min($minY, $y);
|
||||||
$width = max($x + 1 - $xOffset, $width);
|
$maxY = max($maxY, $y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$height = $maxY - $minY + 1;
|
||||||
|
$width = $maxX - $minX + 1;
|
||||||
|
|
||||||
if($height === 0 or $width === 0){
|
if($height === 0 or $width === 0){
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -131,7 +134,7 @@ class CraftingTransaction extends InventoryTransaction{
|
|||||||
$reindexed = array_fill(0, $height, array_fill(0, $width, $air));
|
$reindexed = array_fill(0, $height, array_fill(0, $width, $air));
|
||||||
foreach($reindexed as $y => $row){
|
foreach($reindexed as $y => $row){
|
||||||
foreach($row as $x => $item){
|
foreach($row as $x => $item){
|
||||||
$reindexed[$y][$x] = $this->inputs[$y + $yOffset][$x + $xOffset];
|
$reindexed[$y][$x] = $this->inputs[$y + $minY][$x + $minX];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user