cocolabs / cocolib

Simple Minecraft modding library.
GNU General Public License v3.0
0 stars 1 forks source link

Not able to offset sprites. #11

Closed Rellit-219 closed 4 years ago

Rellit-219 commented 4 years ago

image

When trying to draw sprites over the hunger bar with BOTTOM_CENTER alignment, it forces the sprite to remain in the middle.

Implementation:

public static final ArrayList<SpriteObject> BAC_HUD_EMPTY_ICONS = new ArrayList<SpriteObject>();
    public static final ArrayList<SpriteObject> BAC_HUD_FULL_ICONS = new ArrayList<SpriteObject>();

    public static final void initIcons() {

        BAC_HUD_EMPTY_ICONS.clear();
        BAC_HUD_FULL_ICONS.clear();

        for (int i = 0; i < 9; i++) {

            BAC_HUD_EMPTY_ICONS.add(SpriteObject.Builder.create(Defines.MODID, "textures/gui/bac_hud_bar.png").withPos(Alignment.BOTTOM_RIGHT, 221 - (i * 9), 40).withUV(0, 0).withSize(9, 9).build());
            BAC_HUD_FULL_ICONS.add(SpriteObject.Builder.create(Defines.MODID, "textures/gui/bac_hud_bar.png").withPos(Alignment.BOTTOM_RIGHT, 221 - (i * 9), 40).withUV(9, 0).withSize(9, 9).build());

        }

    }

    @SubscribeEvent
    public void onPreRenderOverlay(RenderGameOverlayEvent.Pre event) {

        @Nullable PlayerController controller = Minecraft.getInstance().playerController;

        @Nullable ClientPlayerEntity player = Minecraft.getInstance().player;

        if (controller != null && player != null && controller.gameIsSurvivalOrAdventure()) {

            for (SpriteObject empty_bac_icon : BAC_HUD_EMPTY_ICONS) {

                GuiElement.bindAndDrawTexture(empty_bac_icon);

            }

            player.getCapability(BACCapability.BAC_CAPABILITY).ifPresent(new NonNullConsumer<IBAC>() {

                @Override
                public void accept(@Nonnull IBAC iBAC) {

                    for (int i = 0; i < BAC_HUD_FULL_ICONS.size(); i++) {

                        if (i <= iBAC.getBACLevel()) {

                            GuiElement.bindAndDrawTexture(BAC_HUD_FULL_ICONS.get(i));

                        }

                    }

                }

            });

        }

    }