/** * Finds the plot at a certain position or null if there is no plot at that position * * @api * @param Position $position * @return Plot|null */ public function getPlotByPosition(Position $position) { $x = $position->x; $z = $position->z; $levelName = $position->level->getName(); $plotLevel = $this->getLevelSettings($levelName); if ($plotLevel === null) { return null; } $plotSize = $plotLevel->plotSize; $roadWidth = $plotLevel->roadWidth; $totalSize = $plotSize + $roadWidth; if ($x >= 0) { $X = floor($x / $totalSize); $difX = $x % $totalSize; } else { $X = ceil(($x - $plotSize + 1) / $totalSize); $difX = abs(($x - $plotSize + 1) % $totalSize); } if ($z >= 0) { $Z = floor($z / $totalSize); $difZ = $z % $totalSize; } else { $Z = ceil(($z - $plotSize + 1) / $totalSize); $difZ = abs(($z - $plotSize + 1) % $totalSize); } if ($difX > $plotSize - 1 or $difZ > $plotSize - 1) { return null; } return $this->dataProvider->getPlot($levelName, $X, $Z); }
/** * Finds the plot at a certain position or null if there is no plot at that position * * @api * @param Position $position * @return Plot|null */ public function getPlotByPosition(Position $position) { $x = $position->x; $z = $position->z; $levelName = $position->level->getName(); $plotLevel = $this->getLevelSettings($levelName); if ($plotLevel === null) { return null; } $plotSize = $plotLevel->plotSize; $roadWidth = $plotLevel->roadWidth; $totalSize = $plotSize + $roadWidth; $halfRoadWidth = round($roadWidth / 2); // the road width that concerns this plot // mwvent - added offset of half a road width $x -= $halfRoadWidth; $z -= $halfRoadWidth; // dont forget the +1 is the offset in clearplottask too $X = ceil(($x - $plotSize + 1) / $totalSize); $Z = ceil(($z - $plotSize + 1) / $totalSize); // sometimes ciel returns a string "-0" - cast to int to be sure $X = (int) $X; $Z = (int) $Z; /* if ($x >= 0) { $X = floor($x / $totalSize); $difX = $x % $totalSize; } else { $X = ceil(($x - $plotSize + 1) / $totalSize); $difX = abs(($x - $plotSize + 1) % $totalSize); } if ($z >= 0) { $Z = floor($z / $totalSize); $difZ = $z % $totalSize; } else { $Z = ceil(($z - $plotSize + 1) / $totalSize); $difZ = abs(($z - $plotSize + 1) % $totalSize); } */ /* Removed to allow road building if (($difX > $plotSize - 1) or ($difZ > $plotSize - 1)) { return null; } */ return $this->dataProvider->getPlot($levelName, $X, $Z); }