Skip to content

Commit

Permalink
V1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Takaranoao committed Nov 16, 2019
1 parent a61d834 commit 91e0d49
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 45 deletions.
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;
}
}
}
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);
}
}
14 changes: 0 additions & 14 deletions src/main/java/net/fabricmc/example/ExampleMod.java

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/net/fabricmc/example/mixin/ExampleMixin.java

This file was deleted.

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.
3 changes: 3 additions & 0 deletions src/main/resources/assets/autoreconnector/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"autoReconnector.waitingTime":"Please wait %d seconds"
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/autoreconnector/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"autoReconnector.waitingTime":"因为日酱太可爱,所以 %d 秒后自动重新连接"
}
Binary file removed src/main/resources/assets/modid/icon.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"required": true,
"package": "net.fabricmc.example.mixin",
"package": "com.takaranoao.mods.autoreconnector.mixins",
"compatibilityLevel": "JAVA_8",
"mixins": [
],
"client": [
"ExampleMixin"
"MixinDisconnectedScreen"
],
"injectors": {
"defaultRequire": 1
Expand Down
25 changes: 11 additions & 14 deletions src/main/resources/fabric.mod.json
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
}
}

0 comments on commit 91e0d49

Please sign in to comment.