mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2024-12-26 06:57:02 +01:00
Move events to platforms
This commit is contained in:
parent
6e0702aa0b
commit
58278dd8b4
9 changed files with 76 additions and 7 deletions
|
@ -0,0 +1,15 @@
|
|||
package com.jozufozu.flywheel.api.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface BeginFrameCallback {
|
||||
Event<BeginFrameCallback> EVENT = EventFactory.createArrayBacked(BeginFrameCallback.class, callbacks -> context -> {
|
||||
for (BeginFrameCallback callback : callbacks) {
|
||||
callback.onBeginFrame(context);
|
||||
}
|
||||
});
|
||||
|
||||
void onBeginFrame(RenderContext context);
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.jozufozu.flywheel.api.event;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EndClientResourceReloadCallback {
|
||||
Event<EndClientResourceReloadCallback> EVENT = EventFactory.createArrayBacked(EndClientResourceReloadCallback.class,
|
||||
callbacks -> (minecraft, resourceManager, initialReload, error) -> {
|
||||
for (EndClientResourceReloadCallback callback : callbacks) {
|
||||
callback.onEndClientResourceReload(minecraft, resourceManager, initialReload, error);
|
||||
}
|
||||
});
|
||||
|
||||
void onEndClientResourceReload(Minecraft minecraft, ResourceManager resourceManager, boolean initialReload,
|
||||
Optional<Throwable> error);
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.jozufozu.flywheel.api.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ReloadLevelRendererCallback {
|
||||
Event<ReloadLevelRendererCallback> EVENT =
|
||||
EventFactory.createArrayBacked(ReloadLevelRendererCallback.class, callbacks -> level -> {
|
||||
for (ReloadLevelRendererCallback callback : callbacks) {
|
||||
callback.onReloadLevelRenderer(level);
|
||||
}
|
||||
});
|
||||
|
||||
void onReloadLevelRenderer(ClientLevel level);
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.jozufozu.flywheel.api.event;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
|
||||
public interface RenderStageCallback {
|
||||
Event<RenderStageCallback> EVENT =
|
||||
EventFactory.createArrayBacked(RenderStageCallback.class, callbacks -> (context, stage) -> {
|
||||
for (RenderStageCallback callback : callbacks) {
|
||||
callback.onRenderStage(context, stage);
|
||||
}
|
||||
});
|
||||
|
||||
void onRenderStage(RenderContext context, RenderStage stage);
|
||||
}
|
|
@ -3,10 +3,6 @@ package com.jozufozu.flywheel.impl.mixin;
|
|||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.EndClientResourceReloadEvent;
|
||||
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
@ -14,6 +10,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.jozufozu.flywheel.api.event.EndClientResourceReloadCallback;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
|
||||
|
@ -25,11 +23,14 @@ abstract class MinecraftMixin {
|
|||
|
||||
@Inject(method = "method_24040", at = @At("HEAD"))
|
||||
private void flywheel$onEndInitialResourceReload(Optional<Throwable> error, CallbackInfo ci) {
|
||||
ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, true, error));
|
||||
EndClientResourceReloadCallback.EVENT.invoker()
|
||||
.onEndClientResourceReload((Minecraft) (Object) this, resourceManager, true, error);
|
||||
}
|
||||
|
||||
@Inject(method = "method_24228", at = @At("HEAD"))
|
||||
private void flywheel$onEndManualResourceReload(boolean recovery, CompletableFuture<Void> future, Optional<Throwable> error, CallbackInfo ci) {
|
||||
ModLoader.get().postEvent(new EndClientResourceReloadEvent((Minecraft) (Object) this, resourceManager, false, error));
|
||||
private void flywheel$onEndManualResourceReload(boolean recovery, CompletableFuture<Void> future,
|
||||
Optional<Throwable> error, CallbackInfo ci) {
|
||||
EndClientResourceReloadCallback.EVENT.invoker()
|
||||
.onEndClientResourceReload((Minecraft) (Object) this, resourceManager, false, error);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue