Use callback-style events for crosshair and hotbar render events

This commit is contained in:
Jonas Herzig
2021-02-27 15:49:40 +01:00
parent da16b0fb78
commit 06a46e6f38
5 changed files with 56 additions and 17 deletions

View File

@@ -1,11 +1,13 @@
//#if MC>=11400
package com.replaymod.replay.mixin;
import com.replaymod.replay.events.RenderHotbarCallback;
import com.replaymod.replay.events.RenderSpectatorCrosshairCallback;
import net.minecraft.client.gui.hud.InGameHud;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(InGameHud.class)
@@ -17,5 +19,13 @@ public class MixinInGameHud {
ci.setReturnValue(state);
}
}
@Inject(method = "renderHotbar", at = @At("HEAD"), cancellable = true)
private void shouldRenderHotbar(CallbackInfo ci) {
Boolean state = RenderHotbarCallback.EVENT.invoker().shouldRenderHotbar();
if (state == Boolean.FALSE) {
ci.cancel();
}
}
}
//#endif