-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a61d834
commit 91e0d49
Showing
11 changed files
with
92 additions
and
45 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/com/takaranoao/mods/autoreconnector/AutoConnectorMod.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,39 @@ | ||
package com.takaranoao.mods.autoreconnector; | ||
|
||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.fabricmc.fabric.api.event.client.ClientTickCallback; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.ConnectScreen; | ||
import net.minecraft.client.gui.screen.DisconnectedScreen; | ||
import net.minecraft.client.gui.screen.TitleScreen; | ||
import net.minecraft.client.options.ServerEntry; | ||
import org.apache.logging.log4j.LogManager; | ||
public class AutoConnectorMod implements ClientModInitializer { | ||
@Environment(EnvType.CLIENT) | ||
public static ServerEntry lastestServerEntry; | ||
|
||
public static int disconnectTick = 0; | ||
public static final int MAX_TICK = 20*15; | ||
@Override | ||
public void onInitializeClient() { | ||
ClientTickCallback.EVENT.register(minecraftClient->clientTick()); | ||
LogManager.getLogger().info("Loading Auto Reconnect"); | ||
} | ||
public static void clientTick(){ | ||
MinecraftClient mc = MinecraftClient.getInstance(); | ||
if(mc.world != null && mc.getCurrentServerEntry() != null){ | ||
lastestServerEntry = mc.getCurrentServerEntry(); | ||
} | ||
if(mc.currentScreen instanceof DisconnectedScreen){ | ||
disconnectTick++; | ||
if(disconnectTick >= MAX_TICK && lastestServerEntry!=null){ | ||
mc.disconnect(); | ||
mc.openScreen(new ConnectScreen(new TitleScreen(), mc, lastestServerEntry)); | ||
} | ||
}else{ | ||
disconnectTick = 0; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/takaranoao/mods/autoreconnector/mixins/MixinDisconnectedScreen.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,34 @@ | ||
package com.takaranoao.mods.autoreconnector.mixins; | ||
|
||
import com.takaranoao.mods.autoreconnector.AutoConnectorMod; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.font.TextRenderer; | ||
import net.minecraft.client.gui.screen.DisconnectedScreen; | ||
import net.minecraft.client.resource.language.I18n; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(DisconnectedScreen.class) | ||
public class MixinDisconnectedScreen { | ||
private static final int FONT_HEIGHT = 9; | ||
@Shadow | ||
private int reasonHeight; | ||
@Inject(method = "render", at = @At("RETURN")) | ||
private void onRender (int p_render_1_, int p_render_2_, float p_render_3_, CallbackInfo ci){ | ||
if(AutoConnectorMod.lastestServerEntry == null)return; | ||
MinecraftClient mc = MinecraftClient.getInstance(); | ||
TextRenderer textRenderer = mc.textRenderer; | ||
if( mc.currentScreen == null) return; | ||
int width = mc.currentScreen.width; | ||
int height = mc.currentScreen.height; | ||
mc.currentScreen.drawCenteredString( | ||
textRenderer, | ||
I18n.translate("autoReconnector.waitingTime", (AutoConnectorMod.MAX_TICK - AutoConnectorMod.disconnectTick)/20), | ||
width/2, | ||
height - this.reasonHeight / 2 - FONT_HEIGHT * 2, | ||
0xffffff); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/main/java/net/fabricmc/example/mixin/ExampleMixin.java
This file was deleted.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,3 @@ | ||
{ | ||
"autoReconnector.waitingTime":"Please wait %d seconds" | ||
} |
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,3 @@ | ||
{ | ||
"autoReconnector.waitingTime":"因为日酱太可爱,所以 %d 秒后自动重新连接" | ||
} |
Binary file not shown.
4 changes: 2 additions & 2 deletions
4
src/main/resources/modid.mixins.json → ...ain/resources/autoreconnector.mixins.json
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
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 |
---|---|---|
@@ -1,36 +1,33 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "modid", | ||
"id": "autoreconnector", | ||
"version": "${version}", | ||
|
||
"name": "Auto reconnector mod", | ||
"description": "Automatically reconnect when you are disconnected from the server.", | ||
"authors": [ | ||
"Takaranoao" | ||
], | ||
"contact": { | ||
"homepage": "https://takaranoao.com/", | ||
"sources": "https://github.com/FabricMC/fabric-example-mod" | ||
"sources": "https://github.com/Takaranoao/AutoReconnector-Fabric" | ||
}, | ||
|
||
"license": "CC0-1.0", | ||
"icon": "assets/modid/icon.png", | ||
|
||
"environment": "*", | ||
"license": "MIT", | ||
"icon": "assets/autoreconnector/icon.png", | ||
"environment": "client", | ||
"entrypoints": { | ||
"main": [ | ||
"net.fabricmc.example.ExampleMod" | ||
"client": [ | ||
"com.takaranoao.mods.autoreconnector.AutoConnectorMod" | ||
] | ||
}, | ||
"mixins": [ | ||
"modid.mixins.json" | ||
], | ||
|
||
"mixins": ["autoreconnector.mixins.json"], | ||
"depends": { | ||
"fabricloader": ">=0.4.0", | ||
"fabric": "*" | ||
}, | ||
"suggests": { | ||
"flamingo": "*" | ||
}, | ||
"custom": { | ||
"modmenu:clientsideOnly": true | ||
} | ||
} |