Skip to content

Commit e52d84d

Browse files
Implement mod + README.md
1 parent 9b7ebdb commit e52d84d

File tree

9 files changed

+84
-103
lines changed

9 files changed

+84
-103
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# "Cannot remove from team" workaround
2+
3+
On some buggy servers you may have noticeable lag spikes caused by `Error executing task on client`:
4+
```text
5+
net.minecraft.class_148: Main thread packet handler
6+
at net.minecraft.class_2600.method_11072(class_2600.java:33) ~[client-intermediary.jar:?]
7+
at net.minecraft.class_1255.method_18859(class_1255.java:156) ~[client-intermediary.jar:?]
8+
at net.minecraft.class_4093.method_18859(class_4093.java:23) ~[client-intermediary.jar:?]
9+
at net.minecraft.class_1255.method_16075(class_1255.java:130) ~[client-intermediary.jar:?]
10+
at net.minecraft.class_1255.method_5383(class_1255.java:115) ~[client-intermediary.jar:?]
11+
at net.minecraft.class_310.method_1523(class_310.java:1283) ~[client-intermediary.jar:?]
12+
at net.minecraft.class_310.method_1514(class_310.java:888) ~[client-intermediary.jar:?]
13+
at net.minecraft.client.main.Main.main(Main.java:265) ~[Fabric%201.20.4.jar:?]
14+
at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:470) ~[fabric-loader-0.15.7.jar:?]
15+
at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) ~[fabric-loader-0.15.7.jar:?]
16+
at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) ~[fabric-loader-0.15.7.jar:?]
17+
Caused by: java.lang.IllegalStateException: Player is either on another team or not on any team. Cannot remove from team 'Z/Sta/517631'.
18+
at net.minecraft.class_269.method_1157(class_269.java:307) ~[client-intermediary.jar:?]
19+
at net.minecraft.class_634.method_11099(class_634.java:2029) ~[client-intermediary.jar:?]
20+
at net.minecraft.class_5900.method_34173(class_5900.java:129) ~[client-intermediary.jar:?]
21+
at net.minecraft.class_5900.method_11054(class_5900.java:14) ~[client-intermediary.jar:?]
22+
at net.minecraft.class_2600.method_11072(class_2600.java:24) ~[client-intermediary.jar:?]
23+
... 10 more
24+
```
25+
26+
One thing this mod does is it replaces `IllegalStateException` throwing with `LOGGER.warn()`.
27+
28+
Default `net.minecraft.scoreboard.Scoreboard.removeScoreHolderFromTeam()` (`class_269.method_1157()`) implementation:
29+
```java
30+
public void removeScoreHolderFromTeam(String scoreHolderName, Team team) {
31+
if (this.getScoreHolderTeam(scoreHolderName) != team) {
32+
throw new IllegalStateException("Player is either on another team or not on any team. Cannot remove from team '" + team.getName() + "'.");
33+
} else {
34+
this.teamsByScoreHolder.remove(scoreHolderName);
35+
team.getPlayerList().remove(scoreHolderName);
36+
}
37+
}
38+
```
39+
40+
Though I'm not a Java coding guru, I don't understand why the exception is thrown on render thread.

src/client/java/com/bluegradienthorizon/cannotremovefromteamworkaround/CannotRemoveFromTeamWorkaroundClient.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/client/java/com/bluegradienthorizon/cannotremovefromteamworkaround/mixin/client/ExampleClientMixin.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/client/resources/cannot-remove-from-team-workaround.client.mixins.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/main/java/com/bluegradienthorizon/cannotremovefromteamworkaround/CannotRemoveFromTeamWorkaround.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/main/java/com/bluegradienthorizon/cannotremovefromteamworkaround/mixin/ExampleMixin.java

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.bluegradienthorizon.cannotremovefromteamworkaround.mixin;
2+
3+
import net.minecraft.scoreboard.Scoreboard;
4+
import net.minecraft.scoreboard.Team;
5+
import org.slf4j.Logger;
6+
import org.spongepowered.asm.mixin.Final;
7+
import org.spongepowered.asm.mixin.Mixin;
8+
import org.spongepowered.asm.mixin.Shadow;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Inject;
11+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
12+
13+
@Mixin(Scoreboard.class)
14+
public class ScoreboardMixin {
15+
@Final
16+
@Shadow
17+
private static Logger LOGGER;
18+
19+
@Inject(method = "removeScoreHolderFromTeam", at = @At(
20+
value = "INVOKE",
21+
target = "java/lang/IllegalStateException.<init> (Ljava/lang/String;)V"
22+
), cancellable = true)
23+
private void removeScoreHolderFromTeam(String scoreHolderName, Team team, CallbackInfo ci) {
24+
LOGGER.warn("Player is either on another team or not on any team. Cannot remove from team '{}'. "+
25+
"IllegalStateException was not threw due to currently applied \"Cannot remove from team\" workaround.", team.getName());
26+
ci.cancel();
27+
}
28+
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
2-
"required": true,
3-
"package": "com.bluegradienthorizon.cannotremovefromteamworkaround.mixin",
4-
"compatibilityLevel": "JAVA_17",
5-
"mixins": [
6-
"ExampleMixin"
7-
],
8-
"injectors": {
9-
"defaultRequire": 1
2+
"required": true,
3+
"package": "com.bluegradienthorizon.cannotremovefromteamworkaround.mixin",
4+
"compatibilityLevel": "JAVA_17",
5+
"mixins": [
6+
"ScoreboardMixin"
7+
],
8+
"injectors": {
9+
"defaultRequire": 1
1010
}
1111
}

src/main/resources/fabric.mod.json

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,25 @@
33
"id": "cannot-remove-from-team-workaround",
44
"version": "${version}",
55
"name": "\"Cannot remove from team\" workaround",
6-
"description": "This is an example description! Tell everyone what your mod is about!",
6+
"description": "Don't throw IllegalStateException \"Player is either on another team or not on any team. Cannot remove from team\"",
77
"authors": [
8-
"Me!"
8+
"BlueGradientHorizon"
99
],
1010
"contact": {
11-
"homepage": "https://fabricmc.net/",
12-
"sources": "https://github.com/FabricMC/fabric-example-mod"
11+
"homepage": "https://github.com/BlueGradientHorizon/cannot-remove-from-team-workaround",
12+
"sources": "https://github.com/BlueGradientHorizon/cannot-remove-from-team-workaround",
13+
"issues": "https://github.com/BlueGradientHorizon/cannot-remove-from-team-workaround/issues"
1314
},
1415
"license": "CC0-1.0",
1516
"icon": "assets/cannot-remove-from-team-workaround/icon.png",
16-
"environment": "*",
17-
"entrypoints": {
18-
"main": [
19-
"com.bluegradienthorizon.cannotremovefromteamworkaround.CannotRemoveFromTeamWorkaround"
20-
],
21-
"client": [
22-
"com.bluegradienthorizon.cannotremovefromteamworkaround.CannotRemoveFromTeamWorkaroundClient"
23-
]
24-
},
17+
"environment": "client",
2518
"mixins": [
26-
"cannot-remove-from-team-workaround.mixins.json",
27-
{
28-
"config": "cannot-remove-from-team-workaround.client.mixins.json",
29-
"environment": "client"
30-
}
19+
"cannot-remove-from-team-workaround.mixins.json"
3120
],
3221
"depends": {
33-
"fabricloader": ">=0.15.9",
22+
"fabricloader": ">=0.15.7",
3423
"minecraft": "~1.20.4",
3524
"java": ">=17",
3625
"fabric-api": "*"
37-
},
38-
"suggests": {
39-
"another-mod": "*"
4026
}
4127
}

0 commit comments

Comments
 (0)