Search in sources :

Example 1 with EntityOtherPlayerMP

use of net.minecraft.client.entity.EntityOtherPlayerMP in project Galacticraft by micdoodle8.

the class GameScreenText method render.

@Override
@SideOnly(Side.CLIENT)
public void render(int type, float ticks, float sizeX, float sizeY, IScreenManager scr) {
    DrawGameScreen screen = (DrawGameScreen) scr;
    frameBx = sizeX - frameA;
    frameBy = sizeY - frameA;
    drawBlackBackground(0.0F);
    planeEquation(frameA, frameA, 0, frameA, frameBy, 0, frameA, frameBy, 1);
    GL11.glClipPlane(GL11.GL_CLIP_PLANE0, planes);
    GL11.glEnable(GL11.GL_CLIP_PLANE0);
    planeEquation(frameBx, frameBy, 0, frameBx, frameA, 0, frameBx, frameA, 1);
    GL11.glClipPlane(GL11.GL_CLIP_PLANE1, planes);
    GL11.glEnable(GL11.GL_CLIP_PLANE1);
    planeEquation(frameA, frameBy, 0, frameBx, frameBy, 0, frameBx, frameBy, 1);
    GL11.glClipPlane(GL11.GL_CLIP_PLANE2, planes);
    GL11.glEnable(GL11.GL_CLIP_PLANE2);
    planeEquation(frameBx, frameA, 0, frameA, frameA, 0, frameA, frameA, 1);
    GL11.glClipPlane(GL11.GL_CLIP_PLANE3, planes);
    GL11.glEnable(GL11.GL_CLIP_PLANE3);
    yPos = 0;
    TileEntityTelemetry telemeter = TileEntityTelemetry.getNearest(screen.driver);
    // Make the text to draw.  To look good it's important the width and height
    // of the whole text box are correctly set here.
    String strName = "";
    String[] str = { GCCoreUtil.translate("gui.display.nolink"), "", "", "", "" };
    Render renderEntity = null;
    Entity entity = null;
    float Xmargin = 0;
    if (telemeter != null && telemeter.clientData.length >= 3) {
        if (telemeter.clientClass != null) {
            if (telemeter.clientClass == screen.telemetryLastClass && (telemeter.clientClass != EntityPlayerMP.class || telemeter.clientName.equals(screen.telemetryLastName))) {
                // Used cached data from last time if possible
                entity = screen.telemetryLastEntity;
                renderEntity = screen.telemetryLastRender;
                strName = screen.telemetryLastName;
            } else {
                // Create an entity to render, based on class, and get its name
                entity = null;
                if (telemeter.clientClass == EntityPlayerMP.class) {
                    strName = telemeter.clientName;
                    entity = new EntityOtherPlayerMP(screen.driver.getWorld(), telemeter.clientGameProfile);
                    renderEntity = (Render) FMLClientHandler.instance().getClient().getRenderManager().getEntityRenderObject(entity);
                } else {
                    try {
                        entity = (Entity) telemeter.clientClass.getConstructor(World.class).newInstance(screen.driver.getWorld());
                    } catch (Exception ex) {
                    }
                    if (entity != null) {
                        strName = entity.getName();
                    }
                    renderEntity = (Render) FMLClientHandler.instance().getClient().getRenderManager().entityRenderMap.get(telemeter.clientClass);
                }
            }
            // Setup special visual types from data sent by Telemetry
            if (entity instanceof EntityHorse) {
                ((EntityHorse) entity).setHorseType(telemeter.clientData[3]);
                ((EntityHorse) entity).setHorseVariant(telemeter.clientData[4]);
            }
            if (entity instanceof EntityVillager) {
                ((EntityVillager) entity).setProfession(telemeter.clientData[3]);
                ((EntityVillager) entity).setGrowingAge(telemeter.clientData[4]);
            } else if (entity instanceof EntityWolf) {
                ((EntityWolf) entity).setCollarColor(EnumDyeColor.byDyeDamage(telemeter.clientData[3]));
                ((EntityWolf) entity).setBegging(telemeter.clientData[4] == 1);
            } else if (entity instanceof EntitySheep) {
                ((EntitySheep) entity).setFleeceColor(EnumDyeColor.byDyeDamage(telemeter.clientData[3]));
                ((EntitySheep) entity).setSheared(telemeter.clientData[4] == 1);
            } else if (entity instanceof EntityOcelot) {
                ((EntityOcelot) entity).setTameSkin(telemeter.clientData[3]);
            } else if (entity instanceof EntitySkeleton) {
                ((EntitySkeleton) entity).setSkeletonType(telemeter.clientData[3]);
            } else if (entity instanceof EntityZombie) {
                ((EntityZombie) entity).setVillager(telemeter.clientData[3] == 1);
                ((EntityZombie) entity).setChild(telemeter.clientData[4] == 1);
            }
        }
        if (entity instanceof ITelemetry) {
            ((ITelemetry) entity).receiveData(telemeter.clientData, str);
        } else if (entity instanceof EntityLivingBase) {
            // Living entity:
            // data0 = time to show red damage
            // data1 = health in half-hearts
            // data2 = pulse
            // data3 = hunger (for player); horsetype (for horse)
            // data4 = oxygen (for player); horsevariant (for horse)
            str[0] = telemeter.clientData[0] > 0 ? GCCoreUtil.translate("gui.player.ouch") : "";
            if (telemeter.clientData[1] >= 0) {
                str[1] = GCCoreUtil.translate("gui.player.health") + ": " + telemeter.clientData[1] + "%";
            } else {
                str[1] = "";
            }
            str[2] = "" + telemeter.clientData[2] + " " + GCCoreUtil.translate("gui.player.bpm");
            if (telemeter.clientData[3] > -1) {
                str[3] = GCCoreUtil.translate("gui.player.food") + ": " + telemeter.clientData[3] + "%";
            }
            if (telemeter.clientData[4] > -1) {
                int oxygen = telemeter.clientData[4];
                oxygen = (oxygen % 4096) + (oxygen / 4096);
                if (oxygen == 180 || oxygen == 90) {
                    str[4] = GCCoreUtil.translate("gui.oxygen_storage.desc.1") + ": OK";
                } else {
                    str[4] = GCCoreUtil.translate("gui.oxygen_storage.desc.1") + ": " + this.makeOxygenString(oxygen) + GCCoreUtil.translate("gui.seconds");
                }
            }
        } else // TODO  can add more here, e.g. position data?
        if (telemeter.clientData[2] >= 0) {
            str[2] = makeSpeedString(telemeter.clientData[2]);
        }
    } else {
        // Default - draw a simple time display just to show the Display Screen is working
        World w1 = screen.driver.getWorld();
        int time1 = w1 != null ? (int) ((w1.getWorldTime() + 6000L) % 24000L) : 0;
        str[2] = makeTimeString(time1 * 360);
    }
    int textWidthPixels = 155;
    // 1 lines
    int textHeightPixels = 60;
    if (str[3].isEmpty()) {
        textHeightPixels -= 10;
    }
    if (str[4].isEmpty()) {
        textHeightPixels -= 10;
    }
    // First pass - approximate border size
    float borders = frameA * 2 + 0.05F * Math.min(sizeX, sizeY);
    float scaleXTest = (sizeX - borders) / textWidthPixels;
    float scaleYTest = (sizeY - borders) / textHeightPixels;
    float scale = sizeX;
    if (scaleYTest < scaleXTest) {
        scale = sizeY;
    }
    // Second pass - the border size may be more accurate now
    borders = frameA * 2 + 0.05F * scale;
    scaleXTest = (sizeX - borders) / textWidthPixels;
    scaleYTest = (sizeY - borders) / textHeightPixels;
    scale = sizeX;
    float scaleText = scaleXTest;
    if (scaleYTest < scaleXTest) {
        scale = sizeY;
        scaleText = scaleYTest;
    }
    // Centre the text in the display
    float border = frameA + 0.025F * scale;
    if (entity != null && renderEntity != null) {
        Xmargin = (sizeX - borders) / 2;
    }
    float Xoffset = (sizeX - borders - textWidthPixels * scaleText) / 2 + Xmargin;
    float Yoffset = (sizeY - borders - textHeightPixels * scaleText) / 2 + scaleText;
    GL11.glTranslatef(border + Xoffset, border + Yoffset, 0.0F);
    GL11.glScalef(scaleText, scaleText, 1.0F);
    // Actually draw the text
    int whiteColour = ColorUtil.to32BitColor(255, 240, 216, 255);
    drawText(strName, whiteColour);
    drawText(str[0], whiteColour);
    drawText(str[1], whiteColour);
    drawText(str[2], whiteColour);
    drawText(str[3], whiteColour);
    drawText(str[4], whiteColour);
    // If there is an entity to render, draw it on the left of the text
    if (renderEntity != null && entity != null) {
        GL11.glTranslatef(-Xmargin / 2 / scaleText, textHeightPixels / 2 + (-Yoffset + (sizeY - borders) / 2) / scaleText, -0.0005F);
        float scalefactor = 38F / (float) Math.pow(Math.max(entity.height, entity.width), 0.65);
        GL11.glScalef(scalefactor, scalefactor, 0.0015F);
        GL11.glRotatef(180F, 0, 0, 1);
        GL11.glRotatef(180F, 0, 1, 0);
        if (entity instanceof ITelemetry) {
            ((ITelemetry) entity).adjustDisplay(telemeter.clientData);
        }
        RenderPlayerGC.flagThermalOverride = true;
        if (entity instanceof EntityLivingBase && renderEntity instanceof RendererLivingEntity && renderModelMethod != null) {
            this.renderLiving((EntityLivingBase) entity, (RendererLivingEntity) renderEntity, ticks % 1F);
        } else {
            renderEntity.doRender(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
        }
        RenderPlayerGC.flagThermalOverride = false;
        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
        OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
    }
    // TODO  Cross-dimensional tracking (i.e. old entity setDead, new entity created)
    // TODO  Deal with text off screen (including where localizations longer than English)
    screen.telemetryLastClass = (telemeter == null) ? null : telemeter.clientClass;
    screen.telemetryLastEntity = entity;
    screen.telemetryLastRender = renderEntity;
    screen.telemetryLastName = strName;
    GL11.glDisable(GL11.GL_CLIP_PLANE3);
    GL11.glDisable(GL11.GL_CLIP_PLANE2);
    GL11.glDisable(GL11.GL_CLIP_PLANE1);
    GL11.glDisable(GL11.GL_CLIP_PLANE0);
}
Also used : Entity(net.minecraft.entity.Entity) RendererLivingEntity(net.minecraft.client.renderer.entity.RendererLivingEntity) EntityOtherPlayerMP(net.minecraft.client.entity.EntityOtherPlayerMP) TileEntityTelemetry(micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry) Render(net.minecraft.client.renderer.entity.Render) EntitySkeleton(net.minecraft.entity.monster.EntitySkeleton) World(net.minecraft.world.World) EntityZombie(net.minecraft.entity.monster.EntityZombie) ITelemetry(micdoodle8.mods.galacticraft.api.entity.ITelemetry) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) RendererLivingEntity(net.minecraft.client.renderer.entity.RendererLivingEntity) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

ITelemetry (micdoodle8.mods.galacticraft.api.entity.ITelemetry)1 TileEntityTelemetry (micdoodle8.mods.galacticraft.core.tile.TileEntityTelemetry)1 EntityOtherPlayerMP (net.minecraft.client.entity.EntityOtherPlayerMP)1 Render (net.minecraft.client.renderer.entity.Render)1 RendererLivingEntity (net.minecraft.client.renderer.entity.RendererLivingEntity)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntitySkeleton (net.minecraft.entity.monster.EntitySkeleton)1 EntityZombie (net.minecraft.entity.monster.EntityZombie)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 World (net.minecraft.world.World)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1