fix: Pride Totem doing tasks unsafely off-thread

Fixes #66
This commit is contained in:
Ampflower 🌺 2025-03-14 00:21:29 -07:00
parent 340fb79ab5
commit 47316b94c6
No known key found for this signature in database
GPG Key ID: FC0397C90D508D7F
2 changed files with 29 additions and 15 deletions

View File

@ -31,6 +31,9 @@ modmenu-badges = "2023.6.1"
midnight-fabric = "1.6.9+1.21-fabric"
midnight-neoforge = "1.6.9+1.21-neoforge"
uwrad-fabric = "1.1.0"
uwrad-neoforge = "1.1.1+neoforge"
lib39 = "1.5.0-experimental7+1.20.1"
# Libraries
@ -73,6 +76,9 @@ modmenu-badges = { module = "maven.modrinth:modmenu-badges-lib", version.ref = "
midnight-fabric = { module = "maven.modrinth:midnightlib", version.ref = "midnight-fabric" }
midnight-neoforge = { module = "maven.modrinth:midnightlib", version.ref = "midnight-neoforge" }
uwrad-fabric = { module = "maven.modrinth:uwrad", version.ref = "uwrad-fabric" }
uwrad-neoforge = { module = "maven.modrinth:uwrad", version.ref = "uwrad-neoforge" }
lib39-ripple = { module = "com.unascribed:lib39-ripple", version.ref = "lib39" }
annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" }
@ -86,14 +92,14 @@ testng = { module = "org.testng:testng", version.ref = "testng" }
fabric = ["fabric-loader", "fabric-api", "trinkets", "midnight-fabric"]
fabric-bundle = ["modmenu-badges"]
fabric-compile = ["mavapi"]
fabric-runtime = ["emi-fabric"]
fabric-runtime = ["emi-fabric", "uwrad-fabric"]
fabric-client-runtime = ["modmenu"]
forge = ["curios"]
forge-runtime = []
neoforge = ["midnight-neoforge"]
neoforge-runtime = ["emi-neoforge"]
neoforge-runtime = ["emi-neoforge", "uwrad-neoforge"]
common-compile = ["midnight-fabric"]
common-bundle = ["mixin-squared"]

View File

@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.EntityStatusS2CPacket;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Hand;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
@ -33,21 +34,28 @@ public abstract class ClientPlayNetworkHandlerMixin {
@Inject(at = @At("HEAD"), method = "onEntityStatus")
private void onCustomEntityStatus(EntityStatusS2CPacket packet, CallbackInfo ci) {
if (this.getWorld() == null) return;
Entity entity = packet.getEntity(this.getWorld());
if (entity == null) return;
int status = packet.getStatus();
if (status != 36) return;
MinecraftClient.getInstance().particleManager.addEmitter(entity, JoyParticles.TOTEM_OF_PRIDE_PARTICLE, 30);
if (MinecraftClient.getInstance().world != null) {
MinecraftClient.getInstance().world.playSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.ITEM_TOTEM_USE, entity.getSoundCategory(), 1.0F, 1.0F, false);
if (this.getWorld() == null || packet.getStatus() != 36) {
return;
}
if (entity == MinecraftClient.getInstance().player)
MinecraftClient.getInstance().gameRenderer.showFloatingItem(modifyTotem(MinecraftClient.getInstance().player));
final var client = MinecraftClient.getInstance();
//noinspection ResultOfMethodCallIgnored - unnecessary
client.submit(() -> {
final World world = this.getWorld();
final Entity entity = packet.getEntity(world);
if (entity == null) {
return;
}
client.particleManager.addEmitter(entity, JoyParticles.TOTEM_OF_PRIDE_PARTICLE, 30);
world.playSound(entity.getX(), entity.getY(), entity.getZ(), SoundEvents.ITEM_TOTEM_USE, entity.getSoundCategory(), 1.f, 1.f, false);
if (entity == client.player) {
client.gameRenderer.showFloatingItem(modifyTotem(client.player));
}
});
}
@Unique