Skip to content

Commit

Permalink
Fixed bug where logging didn't work on servers at the cost of the ser…
Browse files Browse the repository at this point in the history
…ver gui not being accessible for now.
  • Loading branch information
MartinSVK12 committed Jun 12, 2024
1 parent 9e5ad71 commit 5b3b01e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ loader_version=0.15.6-babric.6-bta
mod_menu_version=2.0.6

# Mod
mod_version=4.0.6-beta.1
mod_version=4.0.7
mod_group=turniplabs
mod_name=halplibe

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.Global;
import net.minecraft.core.achievement.stat.StatList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.net.thread.ThreadServerApplication;
import org.apache.log4j.Logger;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -17,6 +21,8 @@
public class MinecraftServerMixin {
@Shadow private static MinecraftServer instance;

@Shadow public static Logger logger;

@Inject(method = "startServer", at = @At(value = "INVOKE",target = "Lnet/minecraft/core/data/DataLoader;loadRecipesFromFile(Ljava/lang/String;)V", ordinal = 3, shift = At.Shift.AFTER))
public void recipeEntrypoint(CallbackInfoReturnable<Boolean> cir){
FabricLoader.getInstance().getEntrypoints("recipesReady", RecipeEntrypoint.class).forEach(RecipeEntrypoint::initNamespaces);
Expand All @@ -36,4 +42,21 @@ public void afterGameStartEntrypoint(CallbackInfoReturnable<Boolean> cir){
RecipeBuilder.exportRecipes();
}
}

/**
* @author sunsetsatellite
* @reason begone log4j (this fixes logging not existing on a modded server at the cost of no gui)
*/
@Overwrite
public static void main(String[] args) {
StatList.init();

try {
MinecraftServer minecraftserver = new MinecraftServer();
(new ThreadServerApplication("Server thread", minecraftserver)).start();
} catch (Exception e) {
logger.error("Failed to start the minecraft server", e);
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package turniplabs.halplibe.mixin.mixins.registry;

import net.minecraft.core.achievement.stat.StatList;
import net.minecraft.core.lang.I18n;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -19,9 +20,7 @@ public void postInit(CallbackInfo ci) {
m.setAccessible(true);
m.invoke(null);
m.setAccessible(false);
StatList.init();
StatList.onBlockInit();
StatList.onItemInit();
I18n.initialize("en_US");
} catch (Throwable err) {
throw new RuntimeException(err);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/halplibe.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"mixins.commands.CommandsCoreMixin",
"mixins.network.PacketMixin",
"mixins.registry.BlockMixin",
"mixins.registry.ItemMixin"
"mixins.registry.ItemMixin",
"mixins.registry.MinecraftMixin",
"mixins.registry.MinecraftServerMixin"
],
"client": [
"accessors.RenderManagerAccessor",
Expand All @@ -28,20 +30,18 @@
"mixins.MinecraftMixin",
"mixins.NetClientHandlerMixin",
"mixins.commands.CommandsClientMixin",
"mixins.models.EntityRenderDispatcherMixin",
"mixins.models.TileEntityRendererDispatcherMixin",
"mixins.models.BlockColorDispatcherMixin",
"mixins.models.BlockModelDispatcherMixin",
"mixins.models.EntityRenderDispatcherMixin",
"mixins.models.ItemModelDispatcherMixin",
"mixins.models.TileEntityRendererDispatcherMixin",
"mixins.network.MinecraftMixin",
"mixins.registry.MinecraftMixin",
"mixins.version.NetClientHandlerMixin"
],
"server": [
"mixins.MinecraftServerMixin",
"mixins.commands.CommandsServerMixin",
"mixins.network.MinecraftServerMixin",
"mixins.registry.MinecraftServerMixin",
"mixins.version.NetLoginHandlerMixin"
],
"injectors": {
Expand Down

0 comments on commit 5b3b01e

Please sign in to comment.