All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hendrixshen.magiclib.event.render.impl.RenderEventHandler Maven / Gradle / Ivy

There is a newer version: 0.7.398+fe2125a-beta
Show newest version
package top.hendrixshen.magiclib.event.render.impl;

import com.google.common.collect.Lists;
import com.mojang.blaze3d.vertex.PoseStack;
import lombok.Getter;
import net.minecraft.class_1297;
import net.minecraft.class_1937;
import net.minecraft.class_310;
import top.hendrixshen.magiclib.event.render.api.PostRenderEntityEvent;
import top.hendrixshen.magiclib.event.render.api.PostRenderLevelEvent;

import java.util.List;

public class RenderEventHandler {
    @Getter
    private static final RenderEventHandler instance = new RenderEventHandler();
    private static final class_310 mc = class_310.method_1551();
    private static final List postRenderEntityEvents = Lists.newArrayList();
    private static final List postRenderLevelEvents = Lists.newArrayList();

    public static void registerPostRenderEntityEvent(PostRenderEntityEvent event) {
        RenderEventHandler.postRenderEntityEvents.add(event);
    }

    public static void registerPostRenderLevelEvent(PostRenderLevelEvent event) {
        RenderEventHandler.postRenderLevelEvents.add(event);
    }

    public void dispatchPostRenderEntityEvent(class_1297 entity, PoseStack poseStack, float tickDelta) {
        if (!RenderEventHandler.postRenderEntityEvents.isEmpty()) {
            mc.method_16011().method_15396("MagicRenderEventHandler::dispatchPostRenderEntityEvent");
            RenderContext renderContext = new RenderContext(poseStack);
            RenderEventHandler.postRenderEntityEvents.forEach(event -> {
                mc.method_16011().method_15400(event.getProfilerSectionSupplier());
                event.render(entity, renderContext, tickDelta);
                mc.method_16011().method_15407();
            });
            mc.method_16011().method_15407();
        }
    }

    public void dispatchPostRenderLevelEvent(class_1937 level, PoseStack poseStack, float tickDelta) {
        if (!RenderEventHandler.postRenderLevelEvents.isEmpty()) {
            mc.method_16011().method_15405("MagicRenderEventHandler::dispatchPostRenderLevelEvent");
            RenderContext renderContext = new RenderContext(poseStack);
            RenderEventHandler.postRenderLevelEvents.forEach(event -> {
                mc.method_16011().method_15400(event.getProfilerSectionSupplier());
                event.render(level, renderContext, tickDelta);
                mc.method_16011().method_15407();
            });
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy