generated from FabricMC/fabric-example-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail auto test server when pack resources fail to load
- Loading branch information
Showing
8 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/io/github/misode/packtest/LoadDiagnostics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.github.misode.packtest; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LoadDiagnostics { | ||
private static final List<Diagnostic> DIAGNOSTICS = new ArrayList<>(); | ||
|
||
public static void error(String resource, String id, String message) { | ||
DIAGNOSTICS.add(new Diagnostic(resource, id, message)); | ||
} | ||
|
||
public static List<Diagnostic> loadErrors() { | ||
return DIAGNOSTICS; | ||
} | ||
|
||
public record Diagnostic(String resource, String id, String message) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/misode/packtest/mixin/LootDataTypeMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import io.github.misode.packtest.LoadDiagnostics; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.storage.loot.LootDataType; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
/** | ||
* Catches loot table, predicate and item modifier errors. | ||
* Improves error message. | ||
*/ | ||
@Mixin(LootDataType.class) | ||
public class LootDataTypeMixin { | ||
@Shadow | ||
@Final | ||
private static Logger LOGGER; | ||
|
||
@WrapOperation(method = "method_53267", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;[Ljava/lang/Object;)V")) | ||
private void deserialize(Logger logger, String message, Object[] args, Operation<Void> original) { | ||
String type = ((String)args[0]).substring(0, ((String)args[0]).length() - 1); | ||
LoadDiagnostics.error(type, ((ResourceLocation)args[1]).toString(), (String)args[2]); | ||
LOGGER.error("Couldn't parse {} {} - {}", type, args[1], args[2]); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/misode/packtest/mixin/RecipeManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import io.github.misode.packtest.LoadDiagnostics; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.crafting.RecipeManager; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
/** | ||
* Catch recipe errors and removes stacktrace. | ||
*/ | ||
@Mixin(RecipeManager.class) | ||
public class RecipeManagerMixin { | ||
@Shadow | ||
@Final | ||
private static Logger LOGGER; | ||
|
||
@WrapOperation(method = "apply(Ljava/util/Map;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V")) | ||
private void apply(Logger logger, String message, Object id, Object e, Operation<Void> original) { | ||
String error = ((Exception)e).getMessage(); | ||
LoadDiagnostics.error("recipe", ((ResourceLocation)id).toString(), error); | ||
LOGGER.error(message + " - {}", id, error); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/io/github/misode/packtest/mixin/ServerAdvancementsManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import io.github.misode.packtest.LoadDiagnostics; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.ServerAdvancementManager; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
/** | ||
* Catch advancement errors. | ||
*/ | ||
@Mixin(ServerAdvancementManager.class) | ||
public class ServerAdvancementsManagerMixin { | ||
@WrapOperation(method = "method_20723", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V")) | ||
private void apply(Logger logger, String message, Object id, Object error, Operation<Void> original) { | ||
LoadDiagnostics.error("advancement", ((ResourceLocation)id).toString(), (String)error); | ||
original.call(logger, message, id, error); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/io/github/misode/packtest/mixin/ServerFunctionLibraryMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import io.github.misode.packtest.LoadDiagnostics; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.ServerFunctionLibrary; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
/** | ||
* Catch function errors and removes stacktrace. | ||
*/ | ||
@Mixin(ServerFunctionLibrary.class) | ||
public class ServerFunctionLibraryMixin { | ||
@Shadow | ||
@Final | ||
private static Logger LOGGER; | ||
|
||
@WrapOperation(method = "method_29457", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V")) | ||
private static void catchFunctionError(Logger logger, String message, Object id, Object e, Operation<Void> original) { | ||
String error = ((Exception)e).getMessage().replaceFirst("^[A-Za-z0-9.]+Exception: ", ""); | ||
LoadDiagnostics.error("function", ((ResourceLocation)id).toString(), error); | ||
LOGGER.error(message + " - {}", id, error); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/io/github/misode/packtest/mixin/TagLoaderMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.mojang.serialization.DataResult; | ||
import io.github.misode.packtest.LoadDiagnostics; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.TagFile; | ||
import net.minecraft.tags.TagLoader; | ||
import org.slf4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Catch tag errors and removes stacktrace. | ||
* Removes the duplicate data result error. | ||
*/ | ||
@Mixin(TagLoader.class) | ||
public class TagLoaderMixin { | ||
@Shadow | ||
@Final | ||
private static Logger LOGGER; | ||
|
||
@WrapOperation(method = "load", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/DataResult;getOrThrow(ZLjava/util/function/Consumer;)Ljava/lang/Object;")) | ||
private static Object removeDuplicateError(DataResult<Object> dataResult, boolean allowPartial, Consumer<String> onError, Operation<TagFile> original) { | ||
return dataResult.getOrThrow(allowPartial, (error) -> {}); | ||
} | ||
|
||
@WrapOperation(method = "load", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;[Ljava/lang/Object;)V")) | ||
private static void catchTagError(Logger logger, String message, Object[] args, Operation<Void> original) { | ||
String error = ((Exception)args[3]).getMessage().replaceFirst("^[A-Za-z0-9.]+Exception: ", ""); | ||
String type = ((ResourceLocation)args[1]).getPath().replaceFirst("tags/", "").replaceFirst("s?/.*", ""); | ||
LoadDiagnostics.error(type + " tag", ((ResourceLocation)args[0]).toString(), error); | ||
LOGGER.error("Couldn't read {} tag {} - {}", type, args[0], error); | ||
} | ||
|
||
@WrapOperation(method = "method_33175", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;error(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V")) | ||
private static void catchTagReferenceError(Logger logger, String message, Object id, Object refs, Operation<Void> original) { | ||
LoadDiagnostics.error("tag", ((ResourceLocation)id).toString(), "Missing references: " + refs); | ||
original.call(logger, message, id, refs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters