Search in sources :

Example 1 with ITelemetry

use of micdoodle8.mods.galacticraft.api.entity.ITelemetry 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)

Example 2 with ITelemetry

use of micdoodle8.mods.galacticraft.api.entity.ITelemetry in project Galacticraft by micdoodle8.

the class TileEntityTelemetry method update.

@Override
public void update() {
    if (!this.worldObj.isRemote && ++this.ticks % 2 == 0) {
        if (this.toUpdate != null) {
            this.addTrackedEntity(this.toUpdate);
            this.toUpdate = null;
        }
        String name;
        int[] data = { -1, -1, -1, -1, -1 };
        String strUUID = "";
        if (linkedEntity != null) {
            // Help the Garbage Collector
            if (linkedEntity.isDead) {
                linkedEntity = null;
                name = "";
            // TODO: track players after death and respawn? or not?
            } else {
                if (linkedEntity instanceof EntityPlayerMP) {
                    name = "$" + ((EntityPlayerMP) linkedEntity).getName();
                } else {
                    name = (String) EntityList.classToStringMapping.get(linkedEntity.getClass());
                }
                if (name == null) {
                    GCLog.info("Telemetry Unit: Error finding name for " + linkedEntity.getClass().getSimpleName());
                    name = "";
                }
                double xmotion = linkedEntity.motionX;
                double ymotion = linkedEntity instanceof EntityLivingBase ? linkedEntity.motionY + 0.078D : linkedEntity.motionY;
                double zmotion = linkedEntity.motionZ;
                data[2] = (int) (MathHelper.sqrt_double(xmotion * xmotion + ymotion * ymotion + zmotion * zmotion) * 2000D);
                if (linkedEntity instanceof ITelemetry) {
                    ((ITelemetry) linkedEntity).transmitData(data);
                } else if (linkedEntity instanceof EntityLivingBase) {
                    EntityLivingBase eLiving = (EntityLivingBase) linkedEntity;
                    data[0] = eLiving.hurtTime;
                    // Calculate a "pulse rate" based on motion and taking damage
                    this.pulseRate--;
                    if (eLiving.hurtTime > this.lastHurttime) {
                        this.pulseRate += 100;
                    }
                    this.lastHurttime = eLiving.hurtTime;
                    if (eLiving.ridingEntity != null) {
                        // reduced pulse effect if riding a vehicle
                        data[2] /= 4;
                    } else if (data[2] > 1) {
                        this.pulseRate += 2;
                    }
                    this.pulseRate += Math.max(data[2] - pulseRate, 0) / 4;
                    if (this.pulseRate > 2000) {
                        this.pulseRate = 2000;
                    }
                    if (this.pulseRate < 400) {
                        this.pulseRate = 400;
                    }
                    data[2] = this.pulseRate / 10;
                    data[1] = (int) (eLiving.getHealth() * 100 / eLiving.getMaxHealth());
                    if (eLiving instanceof EntityPlayerMP) {
                        data[3] = ((EntityPlayerMP) eLiving).getFoodStats().getFoodLevel() * 5;
                        GCPlayerStats stats = GCPlayerStats.get(eLiving);
                        data[4] = stats.getAirRemaining() * 4096 + stats.getAirRemaining2();
                        UUID uuid = ((EntityPlayerMP) eLiving).getUniqueID();
                        if (uuid != null) {
                            strUUID = uuid.toString();
                        }
                    } else if (eLiving instanceof EntityHorse) {
                        data[3] = ((EntityHorse) eLiving).getHorseType();
                        data[4] = ((EntityHorse) eLiving).getHorseVariant();
                    } else if (eLiving instanceof EntityVillager) {
                        data[3] = ((EntityVillager) eLiving).getProfession();
                        data[4] = ((EntityVillager) eLiving).getGrowingAge();
                    } else if (eLiving instanceof EntityWolf) {
                        data[3] = ((EntityWolf) eLiving).getCollarColor().getDyeDamage();
                        data[4] = ((EntityWolf) eLiving).isBegging() ? 1 : 0;
                    } else if (eLiving instanceof EntitySheep) {
                        data[3] = ((EntitySheep) eLiving).getFleeceColor().getDyeDamage();
                        data[4] = ((EntitySheep) eLiving).getSheared() ? 1 : 0;
                    } else if (eLiving instanceof EntityOcelot) {
                        data[3] = ((EntityOcelot) eLiving).getTameSkin();
                    } else if (eLiving instanceof EntitySkeleton) {
                        data[3] = ((EntitySkeleton) eLiving).getSkeletonType();
                    } else if (eLiving instanceof EntityZombie) {
                        data[3] = ((EntityZombie) eLiving).isVillager() ? 1 : 0;
                        data[4] = ((EntityZombie) eLiving).isChild() ? 1 : 0;
                    }
                }
            }
        } else {
            name = "";
        }
        GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_UPDATE_TELEMETRY, GCCoreUtil.getDimensionID(this.worldObj), new Object[] { this.getPos(), name, data[0], data[1], data[2], data[3], data[4], strUUID }), new TargetPoint(GCCoreUtil.getDimensionID(this.worldObj), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 320D));
    }
}
Also used : EntitySkeleton(net.minecraft.entity.monster.EntitySkeleton) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) EntityZombie(net.minecraft.entity.monster.EntityZombie) ITelemetry(micdoodle8.mods.galacticraft.api.entity.ITelemetry) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) UUID(java.util.UUID)

Aggregations

ITelemetry (micdoodle8.mods.galacticraft.api.entity.ITelemetry)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntitySkeleton (net.minecraft.entity.monster.EntitySkeleton)2 EntityZombie (net.minecraft.entity.monster.EntityZombie)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 UUID (java.util.UUID)1 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)1 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)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 World (net.minecraft.world.World)1 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1