Search in sources :

Example 1 with ItemOverlay

use of io.xol.chunkstories.api.item.interfaces.ItemOverlay in project chunkstories-core by Hugobros3.

the class EntityPlayer method drawEntityOverlay.

@Override
public void drawEntityOverlay(RenderingInterface renderer) {
    // super.drawEntityOverlay(renderer);
    if (this.equals(((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity())) {
        float scale = 2.0f;
        renderer.textures().getTexture("./textures/gui/hud/hud_survival.png").setLinearFiltering(false);
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 256 * 0.5f * scale, 64 + 64 + 16 - 32 * 0.5f * scale, 256 * scale, 32 * scale, 0, 32f / 256f, 1, 0, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, null);
        // Health bar
        int horizontalBitsToDraw = (int) (8 + 118 * Math2.clamp(getHealth() / getMaxHealth(), 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 - 128 * scale, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0, 64f / 256f, horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // Food bar
        horizontalBitsToDraw = (int) (0 + 126 * Math2.clamp(getFoodLevel() / 100f, 0.0, 1.0));
        renderer.getGuiRenderer().drawBoxWindowsSpaceWithSize(renderer.getWindow().getWidth() / 2 + 0 * 128 * scale + 0, 64 + 64 + 16 - 32 * 0.5f * scale, horizontalBitsToDraw * scale, 32 * scale, 0.5f, 64f / 256f, 0.5f + horizontalBitsToDraw / 256f, 32f / 256f, renderer.textures().getTexture("./textures/gui/hud/hud_survival.png"), false, true, new Vector4f(1.0f, 1.0f, 1.0f, 0.75f));
        // If we're using an item that can render an overlay
        if (this.getSelectedItemComponent().getSelectedItem() != null) {
            ItemPile pile = this.getSelectedItemComponent().getSelectedItem();
            if (pile.getItem() instanceof ItemOverlay)
                ((ItemOverlay) pile.getItem()).drawItemOverlay(renderer, pile);
        }
        // We don't want to render our own tag do we ?
        return;
    }
    // Renders the nametag above the player heads
    Vector3d pos = getLocation();
    // don't render tags too far out
    if (pos.distance(renderer.getCamera().getCameraPosition()) > 32f)
        return;
    // Don't render a dead player tag
    if (this.getHealth() <= 0)
        return;
    Vector3fc posOnScreen = renderer.getCamera().transform3DCoordinate(new Vector3f((float) (double) pos.x(), (float) (double) pos.y() + 2.0f, (float) (double) pos.z()));
    float scale = posOnScreen.z();
    // + rotH;
    String txt = name.getName();
    float dekal = renderer.getFontRenderer().defaultFont().getWidth(txt) * 16 * scale;
    // System.out.println("dekal"+dekal);
    if (scale > 0)
        renderer.getFontRenderer().drawStringWithShadow(renderer.getFontRenderer().defaultFont(), posOnScreen.x() - dekal / 2, posOnScreen.y(), txt, 16 * scale, 16 * scale, new Vector4f(1, 1, 1, 1));
}
Also used : Vector3fc(org.joml.Vector3fc) Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) ItemOverlay(io.xol.chunkstories.api.item.interfaces.ItemOverlay) Vector3f(org.joml.Vector3f) ItemPile(io.xol.chunkstories.api.item.inventory.ItemPile)

Aggregations

ItemOverlay (io.xol.chunkstories.api.item.interfaces.ItemOverlay)1 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)1 Vector3d (org.joml.Vector3d)1 Vector3f (org.joml.Vector3f)1 Vector3fc (org.joml.Vector3fc)1 Vector4f (org.joml.Vector4f)1