Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,7 @@
"paper-newer-world-config-problem": "The Paper config file of the world '{{world-name}}' was created by a newer Paper version (config version {{config-version}}, this server supports up to {{supported-version}}). Settings in it might not work.",
"paper-config-reset-solution": "Back up and delete the file '{{file-path}}'. Paper creates it again with default settings.",
"paper-world-config-reset-solution": "Back up and delete the file 'paper-world.yml' of the world '{{world-name}}'. Paper creates it again with default settings.",
"paper-install-newer-version-solution": "Install the newer Paper version that created this config file."
"paper-install-newer-version-solution": "Install the newer Paper version that created this config file.",
"mod-fabric-loader-version-problem": "The mod '{{mod-name}}' requires Fabric Loader version {{loader-version}} or later, but version {{installed-version}} is installed.",
"fabric-loader-update-solution": "Update Fabric Loader to version {{loader-version}} or later."
}
2 changes: 2 additions & 0 deletions src/Analyser/FabricAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricDuplicateModProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricEntryStageProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricIncompatibleModsProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricLoaderVersionProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricMixinProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricModDependencyProblem;
use Aternos\Codex\Minecraft\Analysis\Problem\Fabric\FabricModIncompatibleMinecraftVersionProblem;
Expand All @@ -26,6 +27,7 @@ public function __construct()
$this->addPossibleInsightClass(FabricModDependencyProblem::class);
$this->addPossibleInsightClass(FabricModIncompatibleMinecraftVersionProblem::class);
$this->addPossibleInsightClass(FabricModJavaVersionProblem::class);
$this->addPossibleInsightClass(FabricLoaderVersionProblem::class);
$this->addPossibleInsightClass(FabricMixinProblem::class);
$this->addPossibleInsightClass(FabricIncompatibleModsProblem::class);
$this->addPossibleInsightClass(FabricDuplicateModProblem::class);
Expand Down
112 changes: 112 additions & 0 deletions src/Analysis/Problem/Fabric/FabricLoaderVersionProblem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Aternos\Codex\Minecraft\Analysis\Problem\Fabric;

use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Solution\Fabric\FabricLoaderUpdateSolution;
use Aternos\Codex\Minecraft\Translator\Translator;

/**
* A mod requires a different version of the Fabric Loader.
* The loader is a built-in mod with the id "fabricloader", so it is reported like any other mod dependency
* but cannot be installed into the mods folder.
*/
class FabricLoaderVersionProblem extends FabricModProblem
{
/**
* The built-in loader mod
* Example: mod 'Fabric Loader' (fabricloader)
*/
public const string LOADER_MOD = "mod '[^']+' \(fabricloader\)";

protected string $loaderVersion;
protected string $installedVersion;

/**
* @return string
*/
public function getLoaderVersion(): string
{
return $this->loaderVersion;
}

/**
* @param string $loaderVersion
* @return $this
*/
protected function setLoaderVersion(string $loaderVersion): static
{
$this->loaderVersion = $loaderVersion;
return $this;
}

/**
* @return string
*/
public function getInstalledVersion(): string
{
return $this->installedVersion;
}

/**
* @param string $installedVersion
* @return $this
*/
protected function setInstalledVersion(string $installedVersion): static
{
$this->installedVersion = $installedVersion;
return $this;
}

/**
* @inheritDoc
*/
public function getMessage(): string
{
return Translator::getInstance()->getTranslation("mod-fabric-loader-version-problem", [
"mod-name" => $this->getModName(),
"loader-version" => $this->getLoaderVersion(),
"installed-version" => $this->getInstalledVersion()
]);
}

/**
* Matches a Fabric Loader version requirement in the dependency list of the loader, e.g.
* - Mod 'Foo' (foo) 1.0.0 requires version 99.0.0 or later of mod 'Fabric Loader' (fabricloader), but only the wrong version is present: 0.20.1!
* - Mod 'Foo' (foo) 1.0.0 requires version 99.0.0 of mod 'Fabric Loader' (fabricloader), but only the wrong version is present: 0.20.1!
*
* @inheritDoc
*/
public static function getPatterns(): array
{
$mod = "/- Mod " . static::getModNamePattern() . "(?: [^ ]+)? ";
$loader = " of " . static::LOADER_MOD . ", but only the wrong version is present: (?<installed>[^ !]+)!/";

return [
'minimum' => $mod . "requires version (?<required>[^ ]+) or later" . $loader,
'specific' => $mod . "requires version (?<required>[^ ]+)" . $loader,
];
}

/**
* @inheritDoc
*/
public function setMatches(array $matches, mixed $patternKey): void
{
$this->setModName($matches["mod"]);
$this->setLoaderVersion($matches["required"]);
$this->setInstalledVersion($matches["installed"]);
$this->addSolution(new FabricLoaderUpdateSolution($this->getLoaderVersion()));
}

/**
* @param InsightInterface $insight
* @return bool
*/
public function isEqual(InsightInterface $insight): bool
{
return $insight instanceof static
&& parent::isEqual($insight)
&& $this->getLoaderVersion() === $insight->getLoaderVersion();
}
}
6 changes: 4 additions & 2 deletions src/Analysis/Problem/Fabric/FabricModDependencyProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public function getMessage(): string
public static function getPatterns(): array
{
$mod = "/- Mod " . static::getModNamePattern() . "(?: [^ ]+)? ";
// Java has its own problem, FabricModJavaVersionProblem
$dependency = " of (?:mod )?(?!" . FabricModJavaVersionProblem::JAVA_MOD . ")" . static::getModNamePattern("dependency") . ",/";
// Java and the Fabric Loader have their own problems, FabricModJavaVersionProblem and FabricLoaderVersionProblem
$dependency = " of (?!" . FabricModJavaVersionProblem::JAVA_MOD
. "|" . FabricLoaderVersionProblem::LOADER_MOD . ")(?:mod )?"
. static::getModNamePattern("dependency") . ",/";

return [
'short-error' => '/net\.fabricmc\.loader\.discovery\.ModResolutionException: Could not find required mod: ' . static::getModNamePattern()
Expand Down
45 changes: 45 additions & 0 deletions src/Analysis/Solution/Fabric/FabricLoaderUpdateSolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Aternos\Codex\Minecraft\Analysis\Solution\Fabric;

use Aternos\Codex\Minecraft\Analysis\Solution\MinecraftSolution;
use Aternos\Codex\Minecraft\Translator\Translator;

/**
* Update the Fabric Loader itself, which is part of the installation and not a file in the mods folder.
*/
class FabricLoaderUpdateSolution extends MinecraftSolution
{
/**
* @param string $version
*/
public function __construct(protected string $version)
{
}

/**
* @inheritDoc
*/
public function getMessage(): string
{
return Translator::getInstance()->getTranslation("fabric-loader-update-solution", ["loader-version" => $this->getVersion()]);
}

/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}

/**
* @param string $version
* @return $this
*/
public function setVersion(string $version): static
{
$this->version = $version;
return $this;
}
}
Loading
Loading