Skip to content

Commit 465208d

Browse files
committed
support fabric 1.18.2/1.19.4
changes in all platforms: - reconnect if disconnected
1 parent c480b9f commit 465208d

36 files changed

Lines changed: 1313 additions & 5 deletions

File tree

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ N/A
2121

2222
## Fabric
2323

24-
### 前提Mod
24+
### 1.19.4以上
25+
26+
#### 前提Mod
27+
28+
- [fabric-api](https://modrinth.com/mod/fabric-api)
29+
- [owo-lib](https://modrinth.com/mod/owo-lib/version/0.11.3+1.20.2)
30+
31+
#### あったほうがいいMod
32+
33+
- [Mod Menu](https://modrinth.com/mod/modmenu)
2534

26-
- [fabric-api](https://modrinth.com/mod/fabric-api/version/0.90.0+1.20.2) (0.90.0以上)
27-
- [owo-lib](https://modrinth.com/mod/owo-lib/version/0.11.3+1.20.2) (0.11.3以上)
35+
### 1.18.2以下
2836

29-
### あったほうがいいMod
37+
#### 前提Mod
3038

39+
- [fabric-api](https://modrinth.com/mod/fabric-api)
3140
- [Mod Menu](https://modrinth.com/mod/modmenu)
3241

3342
### 手順

blueberry-1.20/src/main/java/net/azisaba/interchatmod/blueberry/Mod.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import net.minecraft.client.Minecraft;
1919
import net.minecraft.client.multiplayer.ServerData;
2020
import net.minecraft.client.server.IntegratedServer;
21+
import net.minecraft.network.chat.Component;
22+
import org.java_websocket.exceptions.WebsocketNotConnectedException;
2123
import org.jetbrains.annotations.NotNull;
2224

2325
import javax.net.ssl.SSLContext;
@@ -176,6 +178,12 @@ public void onChat(ClientLocalPlayerChatEvent e) {
176178
return;
177179
}
178180
e.setCancelled(true);
179-
client.sendMessageToGuild(null, e.getMessage());
181+
try {
182+
client.sendMessageToGuild(null, e.getMessage());
183+
} catch (WebsocketNotConnectedException ex) {
184+
assert Minecraft.getInstance().player != null;
185+
Minecraft.getInstance().player.sendSystemMessage(Component.literal("ギルドチャットに接続されていません。"));
186+
reconnect();
187+
}
180188
}
181189
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package net.azisaba.interchatmod.common.util;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.concurrent.atomic.AtomicReference;
6+
import java.util.function.Supplier;
7+
8+
public class LazyValue<T> {
9+
private final AtomicReference<T> value = new AtomicReference<>();
10+
private final Mode mode;
11+
private final Supplier<T> supplier;
12+
13+
public LazyValue(@NotNull Mode mode, @NotNull Supplier<T> supplier) {
14+
this.mode = mode;
15+
this.supplier = supplier;
16+
}
17+
18+
public T get() {
19+
if (mode == Mode.SYNCHRONIZED) {
20+
synchronized (this) {
21+
T t = supplier.get();
22+
value.set(t);
23+
return t;
24+
}
25+
} else {
26+
T t = supplier.get();
27+
value.set(t);
28+
return t;
29+
}
30+
}
31+
32+
public enum Mode {
33+
SYNCHRONIZED,
34+
NON_BLOCKING,
35+
}
36+
}

fabric-1.18/build.gradle.kts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
plugins {
2+
id("fabric-loom") version "1.0-SNAPSHOT"
3+
}
4+
5+
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
6+
7+
val minecraftVersion = "1.18.2"
8+
val yarnMappings = "1.18.2+build.4"
9+
val loaderVersion = "0.14.24"
10+
val fabricVersion = "0.76.0+1.18.2"
11+
val archivesBaseName = "InterChatMod-${project.name}"
12+
val adventureVersion by project.properties
13+
14+
repositories {
15+
// Add repositories to retrieve artifacts from in here.
16+
// You should only use this when depending on other mods because
17+
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
18+
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
19+
// for more information about repositories.
20+
maven { url = uri("https://maven.terraformersmc.com/releases/") }
21+
}
22+
23+
dependencies {
24+
// To change the versions see the gradle.properties file
25+
minecraft("com.mojang:minecraft:$minecraftVersion")
26+
mappings("net.fabricmc:yarn:$yarnMappings:v2")
27+
modImplementation("net.fabricmc:fabric-loader:$loaderVersion")
28+
29+
// Fabric API. This is technically optional, but you probably want it anyway.
30+
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricVersion")
31+
32+
modImplementation("com.terraformersmc:modmenu:3.2.5")
33+
34+
// Uncomment the following line to enable the deprecated Fabric API modules.
35+
// These are included in the Fabric API production distribution and allow you to update your mod to the latest modules at a later more convenient time.
36+
37+
// modImplementation "net.fabricmc.fabric-api:fabric-api-deprecated:${project.fabric_version}"
38+
implementation(project(":common"))
39+
include(project(":common"))
40+
include("net.kyori:adventure-api:$adventureVersion")
41+
include("net.kyori:adventure-key:$adventureVersion")
42+
include("net.kyori:examination-api:1.3.0")
43+
include("net.kyori:examination-string:1.3.0")
44+
include("net.kyori:adventure-text-serializer-legacy:$adventureVersion")
45+
include("net.kyori:adventure-text-serializer-json:$adventureVersion")
46+
include("net.kyori:adventure-text-serializer-gson:$adventureVersion")
47+
include("org.java-websocket:Java-WebSocket:1.5.4")
48+
}
49+
50+
tasks {
51+
processResources {
52+
inputs.property("version", project.version)
53+
54+
filesMatching("fabric.mod.json") {
55+
expand(mapOf("version" to project.version))
56+
}
57+
}
58+
59+
compileJava {
60+
options.encoding = "UTF-8"
61+
}
62+
63+
remapJar {
64+
archiveFileName.set("$archivesBaseName-${project.version}.jar")
65+
from("LICENSE") {
66+
rename { "${it}_${archivesBaseName}"}
67+
}
68+
}
69+
70+
remapSourcesJar {
71+
archiveFileName.set("$archivesBaseName-${project.version}-sources.jar")
72+
from("LICENSE") {
73+
rename { "${it}_${archivesBaseName}"}
74+
}
75+
}
76+
77+
shadowJar {
78+
archiveBaseName.set("$archivesBaseName-DO-NOT-USE")
79+
}
80+
}
81+
82+
java {
83+
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
84+
// if it is present.
85+
// If you remove this line, sources will not be generated.
86+
withSourcesJar()
87+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package net.azisaba.interchatmod.fabric;
2+
3+
import com.mojang.brigadier.arguments.StringArgumentType;
4+
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
5+
import net.azisaba.interchatmod.fabric.model.Guild;
6+
import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager;
7+
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
8+
import net.minecraft.command.CommandSource;
9+
import net.minecraft.text.Text;
10+
11+
public class Commands {
12+
public static LiteralArgumentBuilder<FabricClientCommandSource> builderGS() {
13+
return ClientCommandManager.literal("cgs")
14+
.then(ClientCommandManager.argument("guild", StringArgumentType.word())
15+
.suggests((ctx, builder) -> CommandSource.suggestMatching(Mod.GUILDS.stream().map(Guild::name), builder))
16+
.executes(ctx -> executeFocus(ctx.getSource(), StringArgumentType.getString(ctx, "guild")))
17+
.then(ClientCommandManager.argument("message", StringArgumentType.greedyString())
18+
.executes(ctx -> executeChat(ctx.getSource(), StringArgumentType.getString(ctx, "guild"), StringArgumentType.getString(ctx, "message")))
19+
)
20+
);
21+
}
22+
23+
public static LiteralArgumentBuilder<FabricClientCommandSource> builderG() {
24+
return ClientCommandManager.literal("cg")
25+
.then(ClientCommandManager.argument("message", StringArgumentType.greedyString())
26+
.executes(ctx -> executeChat(ctx.getSource(), null, StringArgumentType.getString(ctx, "message")))
27+
);
28+
}
29+
30+
public static LiteralArgumentBuilder<FabricClientCommandSource> builderReconnectInterChat() {
31+
return ClientCommandManager.literal("reconnectinterchat")
32+
.executes(ctx -> {
33+
Mod.reconnect();
34+
return 0;
35+
})
36+
.then(ClientCommandManager.argument("apikey", StringArgumentType.greedyString())
37+
.executes(ctx -> {
38+
ModConfig.apiKey = StringArgumentType.getString(ctx, "apikey");
39+
Mod.reconnect();
40+
return 0;
41+
})
42+
);
43+
}
44+
45+
public static LiteralArgumentBuilder<FabricClientCommandSource> builderGuild() {
46+
return ClientCommandManager.literal("cguild")
47+
.then(ClientCommandManager.literal("invite")
48+
.then(ClientCommandManager.argument("player", StringArgumentType.word())
49+
.executes(ctx -> {
50+
Mod.client.invite(StringArgumentType.getString(ctx, "player"));
51+
return 0;
52+
})
53+
)
54+
)
55+
.then(ClientCommandManager.literal("accept")
56+
.then(ClientCommandManager.argument("guild", StringArgumentType.word())
57+
.executes(ctx -> {
58+
Mod.client.respondInvite(StringArgumentType.getString(ctx, "guild"), true);
59+
return 0;
60+
})
61+
)
62+
)
63+
.then(ClientCommandManager.literal("reject")
64+
.then(ClientCommandManager.argument("guild", StringArgumentType.word())
65+
.executes(ctx -> {
66+
Mod.client.respondInvite(StringArgumentType.getString(ctx, "guild"), false);
67+
return 0;
68+
})
69+
)
70+
)
71+
.then(ClientCommandManager.literal("nick")
72+
.executes(ctx -> {
73+
Mod.client.nick(null);
74+
return 0;
75+
})
76+
.then(ClientCommandManager.argument("nickname", StringArgumentType.greedyString())
77+
.executes(ctx -> {
78+
Mod.client.nick(StringArgumentType.getString(ctx, "nickname"));
79+
return 0;
80+
})
81+
)
82+
);
83+
}
84+
85+
private static int executeFocus(FabricClientCommandSource source, String guildName) {
86+
Guild guild = Mod.GUILDS.stream().filter(g -> g.name().equalsIgnoreCase(guildName)).findAny().orElse(null);
87+
if (guild == null) {
88+
source.sendError(Text.of("そんなぎるどないよ " + guildName));
89+
return 0;
90+
}
91+
Mod.client.selectGuild(guild.id());
92+
source.sendFeedback(Text.of(guild.name() + " にちゃっとするようにしたよ(/cg <めっせーじ>でできるよ)"));
93+
return 1;
94+
}
95+
96+
private static int executeChat(FabricClientCommandSource source, String guildName, String message) {
97+
if (guildName != null) {
98+
Guild guild = Mod.GUILDS.stream().filter(g -> g.name().equalsIgnoreCase(guildName)).findAny().orElse(null);
99+
if (guild == null) {
100+
source.sendError(Text.of("そんなぎるどないよ " + guildName));
101+
return 0;
102+
}
103+
Mod.client.sendMessageToGuild(guild.id(), message);
104+
} else {
105+
Mod.client.sendMessageToGuild(null, message);
106+
}
107+
return 1;
108+
}
109+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package net.azisaba.interchatmod.fabric;
2+
3+
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
4+
import com.terraformersmc.modmenu.api.ModMenuApi;
5+
6+
public class InterChatModMenuApiImpl implements ModMenuApi {
7+
@Override
8+
public ConfigScreenFactory<?> getModConfigScreenFactory() {
9+
return ModConfigScreen::new;
10+
}
11+
}

0 commit comments

Comments
 (0)