Skip to content

Commit 9db42bd

Browse files
committed
Feat: show welcome when pressing tab in game
Also fixed NPE on join relating to hitlist Some things are probably still broken
1 parent 640cbb3 commit 9db42bd

6 files changed

Lines changed: 88 additions & 28 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package dev.spiritstudios.umbra_express.mixin.client.qol;
2+
3+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
4+
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
5+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
6+
import dev.doctor4t.trainmurdermystery.client.TMMClient;
7+
import dev.doctor4t.trainmurdermystery.client.gui.RoundTextRenderer;
8+
import dev.spiritstudios.umbra_express.UmbraExpress;
9+
import net.minecraft.client.font.TextRenderer;
10+
import net.minecraft.client.gui.DrawContext;
11+
import net.minecraft.client.network.ClientPlayerEntity;
12+
import org.spongepowered.asm.mixin.Mixin;
13+
import org.spongepowered.asm.mixin.Shadow;
14+
import org.spongepowered.asm.mixin.Unique;
15+
import org.spongepowered.asm.mixin.injection.At;
16+
import org.spongepowered.asm.mixin.injection.Inject;
17+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
18+
19+
@Mixin(value = RoundTextRenderer.class, remap = false)
20+
public class RoundTextRendererMixin {
21+
22+
@Shadow
23+
private static int welcomeTime;
24+
@Unique
25+
private static boolean umbra_express$forceShowWelcome = false;
26+
27+
@WrapMethod(method = "renderHud")
28+
private static void showWelcomeWhenPressingPlayerList(TextRenderer renderer, ClientPlayerEntity player, DrawContext context, Operation<Void> original) {
29+
if (umbra_express$forceShowWelcome) {
30+
int realWelcomeTime = welcomeTime;
31+
welcomeTime = 2;
32+
try {
33+
original.call(renderer, player, context);
34+
} catch (Throwable throwable) {
35+
UmbraExpress.LOGGER.error("An error occurred when wrapping RoundTextRenderer.renderHud", throwable);
36+
}
37+
welcomeTime = realWelcomeTime;
38+
}
39+
}
40+
41+
@Inject(method = "tick", at = @At("HEAD"))
42+
private static void assumeFalse(CallbackInfo ci) {
43+
umbra_express$forceShowWelcome = false;
44+
}
45+
46+
@ModifyExpressionValue(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z"))
47+
private static boolean updatePressingPlayerList(boolean original) {
48+
umbra_express$forceShowWelcome = original && TMMClient.gameComponent != null && TMMClient.gameComponent.isRunning();
49+
return original;
50+
}
51+
}
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
{
2-
"required": true,
3-
"package": "dev.spiritstudios.umbra_express.mixin.client",
4-
"compatibilityLevel": "JAVA_21",
5-
"mixinextras": {
6-
"minVersion": "0.5.0"
7-
},
8-
"client": [
9-
"TMMItemTooltipsAccessor",
10-
"haunting.ClientPlayerInteractionManagerMixin",
11-
"qol.PlayerMoodComponentMixin",
12-
"qol.TMMClientMixin",
13-
"roles.assassin.TMMItemTooltipsMixin",
14-
"roles.bartender.BeveragePlateBlockEntityMixinMixin",
15-
"roles.conductor.TimeRendererMixin",
16-
"roles.mystic.TimeRendererMixin",
17-
"roles.shop.LimitedInventoryScreenMixin",
18-
"roles.shop.StoreItemWidgetMixin",
19-
"roles.shop.StoreRendererMixin"
20-
],
21-
"injectors": {
22-
"defaultRequire": 1
23-
},
24-
"overwrites": {
25-
"requireAnnotations": true
26-
}
2+
"required": true,
3+
"package": "dev.spiritstudios.umbra_express.mixin.client",
4+
"compatibilityLevel": "JAVA_21",
5+
"mixinextras": {
6+
"minVersion": "0.5.0"
7+
},
8+
"client": [
9+
"TMMItemTooltipsAccessor",
10+
"haunting.ClientPlayerInteractionManagerMixin",
11+
"qol.PlayerMoodComponentMixin",
12+
"qol.TMMClientMixin",
13+
"roles.assassin.TMMItemTooltipsMixin",
14+
"roles.bartender.BeveragePlateBlockEntityMixinMixin",
15+
"roles.conductor.TimeRendererMixin",
16+
"roles.mystic.TimeRendererMixin",
17+
"roles.shop.LimitedInventoryScreenMixin",
18+
"roles.shop.StoreItemWidgetMixin",
19+
"roles.shop.StoreRendererMixin"
20+
],
21+
"injectors": {
22+
"defaultRequire": 1
23+
},
24+
"overwrites": {
25+
"requireAnnotations": true
26+
},
27+
"mixins": [
28+
"qol.RoundTextRendererMixin"
29+
]
2730
}

‎src/main/java/dev/spiritstudios/umbra_express/init/UmbraExpressEvents.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ static void registerGameLifecycle() {
2828
TMMGameLifecycleEvents.BASE_INITIALIZED.register((serverWorld, game) -> {
2929
HitListWorldComponent hitlist = HitListWorldComponent.cast(game);
3030
resetWorld(serverWorld, hitlist);
31-
hitlist.umbra_express$rerollTarget();
3231
});
3332

33+
TMMGameLifecycleEvents.INITIALIZING.register((serverWorld, game, readyPlayerList) -> {
34+
HitListWorldComponent.cast(game).umbra_express$rerollTarget();
35+
});
36+
3437
// is it necessary to split these??
3538
TMMGameLifecycleEvents.FINALIZING.register((serverWorld, game) -> resetWorld(serverWorld, HitListWorldComponent.cast(game)));
3639
TMMGameLifecycleEvents.FINALIZED.register((serverWorld, game) -> HauntingVoicechatPlugin.reset());

‎src/main/java/dev/spiritstudios/umbra_express/mixin/event/GameFunctionsMixin.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
import net.minecraft.server.world.ServerWorld;
1212
import net.minecraft.util.Identifier;
1313
import org.jetbrains.annotations.Nullable;
14+
import org.spongepowered.asm.mixin.Debug;
1415
import org.spongepowered.asm.mixin.Mixin;
1516
import org.spongepowered.asm.mixin.injection.At;
1617
import org.spongepowered.asm.mixin.injection.Inject;
1718
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1819

1920
import java.util.List;
2021

22+
@Debug(export = true)
2123
@Mixin(value = GameFunctions.class, remap = false)
2224
public class GameFunctionsMixin {
2325

‎src/main/java/dev/spiritstudios/umbra_express/mixin/roles/assassin/GameWorldComponentMixin.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public abstract class GameWorldComponentMixin implements HitListWorldComponent {
5757
if (!GameFunctions.isPlayerAliveAndSurvival(player)) {
5858
return false;
5959
}
60-
return !this.getRole(player).canUseKiller();
60+
Role role = this.getRole(player);
61+
return role != null && !this.getRole(player).canUseKiller();
6162
}).toList();
6263
if (targets.isEmpty()) {
6364
this.umbra_express$assassinationTarget = null;

‎src/main/java/dev/spiritstudios/umbra_express/role/RoleReplacer.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface ReplacementPredicate {
5656
* @param chance the chance that the check will succeed.
5757
* At 1f, this will be equivalent to
5858
* {@linkplain ReplacementPredicate#ALWAYS}
59-
* @return the checker
59+
* @return the predicate
6060
*/
6161
static ReplacementPredicate fromRandom(float chance) {
6262
return (totalPlayers, serverWorld, uuid) -> serverWorld.getRandom().nextFloat() <= chance;

0 commit comments

Comments
 (0)