Skip to content

Commit 7b46fab

Browse files
committed
feat: support fabric 1.16.5
1 parent 0fecadd commit 7b46fab

27 files changed

Lines changed: 877 additions & 10 deletions

File tree

blueberry-1.20/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ tasks {
2929
relocate("net.kyori", "net.azisaba.interchatmod.lib.net.kyori")
3030
relocate("org.java_websocket", "net.azisaba.interchatmod.lib.org.java_websocket")
3131
}
32+
33+
getByName("build") {
34+
dependsOn("shadowJar")
35+
}
3236
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ allprojects {
1212
}
1313

1414
group = "net.azisaba.interchatmod"
15-
version = "0.1.0"
15+
version = "0.2.0"
1616

1717
repositories {
1818
// mavenLocal()

common/src/main/java/net/azisaba/interchatmod/common/AbstractWebSocketChatClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public void onClose(int code, String reason, boolean remote) {
8282

8383
@Override
8484
public void onError(Exception ex) {
85+
sendMessage("WebSocket接続でエラーが発生しました: " + ex.getMessage());
86+
ex.printStackTrace();
8587
}
8688

8789
public void auth(String key) {

common/src/main/java/net/azisaba/interchatmod/common/util/ByteStreams.java

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,65 @@
66
import java.io.IOException;
77
import java.io.InputStream;
88
import java.nio.charset.Charset;
9+
import java.util.ArrayList;
10+
import java.util.Arrays;
11+
import java.util.List;
912

1013
public class ByteStreams {
1114
public static byte @NotNull [] readFully(@NotNull InputStream is) throws IOException {
12-
byte[] bytes = new byte[is.available()];
13-
if (bytes.length > 0 && is.read(bytes) == -1) {
14-
throw new RuntimeException("read nothing");
15+
List<byte[]> bufs = null;
16+
byte[] result = null;
17+
int total = 0;
18+
int remaining = Integer.MAX_VALUE;
19+
int n;
20+
do {
21+
byte[] buf = new byte[Math.min(remaining, 8192)];
22+
int read = 0;
23+
24+
// read to EOF which may read more or less than buffer size
25+
while ((n = is.read(buf, read, Math.min(buf.length - read, remaining))) > 0) {
26+
read += n;
27+
remaining -= n;
28+
}
29+
30+
if (read > 0) {
31+
if (read < buf.length) {
32+
buf = Arrays.copyOfRange(buf, 0, read);
33+
}
34+
total += read;
35+
if (result == null) {
36+
result = buf;
37+
} else {
38+
if (bufs == null) {
39+
bufs = new ArrayList<>();
40+
bufs.add(result);
41+
}
42+
bufs.add(buf);
43+
}
44+
}
45+
// if the last call to read returned -1 or the number of bytes
46+
// requested have been read then break
47+
} while (n == 0 && remaining > 0);
48+
49+
if (bufs == null) {
50+
if (result == null) {
51+
return new byte[0];
52+
}
53+
return result.length == total ?
54+
result : Arrays.copyOf(result, total);
1555
}
16-
return bytes;
56+
57+
result = new byte[total];
58+
int offset = 0;
59+
remaining = total;
60+
for (byte[] b : bufs) {
61+
int count = Math.min(b.length, remaining);
62+
System.arraycopy(b, 0, result, offset, count);
63+
offset += count;
64+
remaining -= count;
65+
}
66+
67+
return result;
1768
}
1869

1970
@Contract("_, _ -> new")

fabric-1.16/build.gradle.kts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
plugins {
2+
id("fabric-loom") version "1.0-SNAPSHOT"
3+
}
4+
5+
java.toolchain.languageVersion.set(JavaLanguageVersion.of(8))
6+
7+
val minecraftVersion = "1.16.5"
8+
val yarnMappings = "1.16.5+build.10"
9+
val loaderVersion = "0.14.24"
10+
val fabricVersion = "0.42.0+1.16"
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:1.16.23")
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+
include("org.slf4j:slf4j-api:2.0.6")
49+
include("org.slf4j:slf4j-nop:2.0.6")
50+
}
51+
52+
tasks {
53+
processResources {
54+
inputs.property("version", project.version)
55+
56+
filesMatching("fabric.mod.json") {
57+
expand(mapOf("version" to project.version))
58+
}
59+
}
60+
61+
compileJava {
62+
options.encoding = "UTF-8"
63+
}
64+
65+
remapJar {
66+
archiveFileName.set("$archivesBaseName-${project.version}.jar")
67+
from("LICENSE") {
68+
rename { "${it}_${archivesBaseName}"}
69+
}
70+
}
71+
72+
remapSourcesJar {
73+
archiveFileName.set("$archivesBaseName-${project.version}-sources.jar")
74+
from("LICENSE") {
75+
rename { "${it}_${archivesBaseName}"}
76+
}
77+
}
78+
79+
shadowJar {
80+
archiveBaseName.set("$archivesBaseName-DO-NOT-USE")
81+
}
82+
}
83+
84+
java {
85+
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
86+
// if it is present.
87+
// If you remove this line, sources will not be generated.
88+
withSourcesJar()
89+
}
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)