summary refs log tree commit diff stats
path: root/src/main/java/ganarchy/chewstuff/mixin/DesyncFix.java
blob: 7a62a4133cde491355a419521c48ba4aff2d4d36 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package ganarchy.chewstuff.mixin;

import ganarchy.chewstuff.ChewComponents;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
 * The mixin for server player entities.
 */
@Mixin(ServerPlayerEntity.class)
public class DesyncFix {
    /**
     * Checks and corrects for desyncs.
     */
    @Inject(
        at = @At("HEAD"),
        method =
            "onStatusEffectUpgraded(Lnet/minecraft/entity/effect/StatusEffectInstance;ZLnet/minecraft/entity/Entity;)V"
    )
    private void chewstuff_onDesync(CallbackInfo cbinfo) {
        var self = (ServerPlayerEntity) (Object) this;
        var maybeInfo = ChewComponents.CHEW.maybeGet(self);
        maybeInfo.ifPresent(info -> {
            info.sendUpdate = true;
        });
    }
}