Search in sources :

Example 1 with RenderGlobal

use of net.minecraft.client.renderer.RenderGlobal in project malmo by Microsoft.

the class TextureHelper method hookIntoRenderPipeline.

public static void hookIntoRenderPipeline() {
    // Subvert the render manager. This MUST be called at the right time (FMLInitializationEvent).
    // 1: Replace the MC entity renderer with our own:
    Minecraft.getMinecraft().entityRenderer = new MalmoEntityRenderer(Minecraft.getMinecraft(), Minecraft.getMinecraft().getResourceManager());
    // 2: Create a new RenderManager:
    RenderManager newRenderManager = new TextureHelper.MalmoRenderManager(Minecraft.getMinecraft().renderEngine, Minecraft.getMinecraft().getRenderItem());
    // 3: Use reflection to:
    // a) replace Minecraft's RenderManager with our new RenderManager
    // b) point Minecraft's RenderGlobal object to the new RenderManager
    // Are we in the dev environment or deployed?
    boolean devEnv = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
    // We need to know, because the names will either be obfuscated or not.
    String mcRenderManagerName = devEnv ? "renderManager" : "field_175616_W";
    String globalRenderManagerName = devEnv ? "renderManager" : "field_175010_j";
    // NOTE: obfuscated name may need updating if Forge changes - search in
    // ~\.gradle\caches\minecraft\de\oceanlabs\mcp\mcp_snapshot\20161220\1.11.2\srgs\mcp-srg.srg
    Field renderMan;
    Field globalRenderMan;
    try {
        renderMan = Minecraft.class.getDeclaredField(mcRenderManagerName);
        renderMan.setAccessible(true);
        renderMan.set(Minecraft.getMinecraft(), newRenderManager);
        globalRenderMan = RenderGlobal.class.getDeclaredField(globalRenderManagerName);
        globalRenderMan.setAccessible(true);
        globalRenderMan.set(Minecraft.getMinecraft().renderGlobal, newRenderManager);
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
}
Also used : Minecraft(net.minecraft.client.Minecraft) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) Field(java.lang.reflect.Field) RenderManager(net.minecraft.client.renderer.entity.RenderManager)

Example 2 with RenderGlobal

use of net.minecraft.client.renderer.RenderGlobal in project GregTech by GregTechCE.

the class DebugRenderer method onRenderWorldLast.

@SubscribeEvent
public static void onRenderWorldLast(RenderWorldLastEvent event) {
    RenderGlobal context = event.getContext();
    float partialTicks = event.getPartialTicks();
    EntityPlayer player = Minecraft.getMinecraft().player;
    WorldClient world = Minecraft.getMinecraft().world;
    if (blockPosSet.size() == 0) {
        return;
    }
    double playerX = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
    double playerY = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
    double playerZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
    GlStateManager.pushMatrix();
    GlStateManager.translate(-playerX, -playerY, -playerZ);
    GlStateManager.enableBlend();
    GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
    GlStateManager.disableTexture2D();
    GlStateManager.disableDepth();
    GlStateManager.glLineWidth(2.5F);
    {
        blockPosSet.forEach(blockPos -> {
            double distance = MathHelper.sqrt(player.getDistanceSqToCenter(blockPos));
            if (distance > 64F) {
                return;
            }
            AxisAlignedBB box = new AxisAlignedBB(blockPos.getX() + 0.25, blockPos.getY() + 0.25, blockPos.getZ() + 0.25, blockPos.getX() + 0.75, blockPos.getY() + 0.75, blockPos.getZ() + 0.75);
            RenderGlobal.drawSelectionBoundingBox(box, 0.0F, 1F, 0.0F, 0.5F);
            TileEntity tileEntity = world.getTileEntity(blockPos);
            if (tileEntity != null) {
                AxisAlignedBB axisAlignedBB = new AxisAlignedBB(blockPos.getX() + 0.25, blockPos.getY() + 0.25, blockPos.getZ() + 0.25, blockPos.getX() + 0.75, blockPos.getY() + 0.75, blockPos.getZ() + 0.75);
                RenderGlobal.drawSelectionBoundingBox(axisAlignedBB, 0.0F, 0.0F, 1F, 0.5F);
            // ((TileEntityCableEmitter) tileEntity).outgoingConnections.forEach(connectionInfo -> {
            // RenderGlobal.drawSelectionBoundingBox(new AxisAlignedBB(connectionInfo.receiverContainer.getPos()), 0.0F, 1F, 1F, 0.5F);
            // 
            // });
            }
        });
    }
    GlStateManager.enableDepth();
    GlStateManager.enableTexture2D();
    GlStateManager.disableBlend();
    GlStateManager.popMatrix();
}
Also used : BlockEvent(net.minecraftforge.event.world.BlockEvent) MetaBlocks(gregtech.common.blocks.MetaBlocks) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) GlStateManager(net.minecraft.client.renderer.GlStateManager) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Set(java.util.Set) WorldClient(net.minecraft.client.multiplayer.WorldClient) BlockPos(net.minecraft.util.math.BlockPos) RenderWorldLastEvent(net.minecraftforge.client.event.RenderWorldLastEvent) HashSet(java.util.HashSet) Minecraft(net.minecraft.client.Minecraft) Side(net.minecraftforge.fml.relauncher.Side) EntityPlayer(net.minecraft.entity.player.EntityPlayer) MathHelper(net.minecraft.util.math.MathHelper) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) TileEntity(net.minecraft.tileentity.TileEntity) Mod(net.minecraftforge.fml.common.Mod) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldClient(net.minecraft.client.multiplayer.WorldClient) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with RenderGlobal

use of net.minecraft.client.renderer.RenderGlobal in project ForestryMC by ForestryMC.

the class TickHandlerCoreClient method onClientTick.

@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
    if (event.phase == Phase.END) {
        Minecraft minecraft = Minecraft.getMinecraft();
        if (minecraft != null) {
            EntityPlayer player = minecraft.player;
            if (player != null) {
                boolean hasNaturalistEye = GeneticsUtil.hasNaturalistEye(player);
                if (this.hasNaturalistEye != hasNaturalistEye) {
                    this.hasNaturalistEye = hasNaturalistEye;
                    RenderGlobal renderGlobal = minecraft.renderGlobal;
                    if (renderGlobal != null) {
                        renderGlobal.markBlockRangeForRenderUpdate((int) player.posX - 32, (int) player.posY - 32, (int) player.posZ - 32, (int) player.posX + 32, (int) player.posY + 32, (int) player.posZ + 32);
                    }
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Minecraft(net.minecraft.client.Minecraft) RenderGlobal(net.minecraft.client.renderer.RenderGlobal) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Minecraft (net.minecraft.client.Minecraft)3 RenderGlobal (net.minecraft.client.renderer.RenderGlobal)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 MetaBlocks (gregtech.common.blocks.MetaBlocks)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 WorldClient (net.minecraft.client.multiplayer.WorldClient)1 GlStateManager (net.minecraft.client.renderer.GlStateManager)1 RenderManager (net.minecraft.client.renderer.entity.RenderManager)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 MathHelper (net.minecraft.util.math.MathHelper)1 RenderWorldLastEvent (net.minecraftforge.client.event.RenderWorldLastEvent)1 BlockEvent (net.minecraftforge.event.world.BlockEvent)1 Mod (net.minecraftforge.fml.common.Mod)1 Side (net.minecraftforge.fml.relauncher.Side)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1