cocolabs / cocolib

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

Crash when using SpriteObject #8

Closed Rellit-219 closed 4 years ago

Rellit-219 commented 4 years ago

Implementation:

public static final SpriteObject BAC_HUD_EMPTY = SpriteObject.Builder.create(Defines.MODID, "textures/gui/bac_hud_bar.png").withPos(Alignment.CENTER, 10, 10).withSize(9, 9).build();

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

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

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

        GuiElement.bindAndDrawTexture(BAC_HUD_EMPTY);
    }
}

Crash Report:

java.lang.NoSuchMethodError: net.minecraft.client.Minecraft.func_71410_x()Lnet/minecraft/client/Minecraft;
    at io.yooksi.cocolib.gui.GuiElement.bindAndDrawTexture(GuiElement.java:37) ~[CocoLib-b915c0a15d.jar:1.15.2-0.1.0] {re:classloading}
    at io.vinum.gui.GuiHandler.onPreRenderOverlay(GuiHandler.java:43) ~[main/:?] {re:classloading}
...

Read the full stack trace on PasteBin.

matshou commented 4 years ago

Can you show how you're declaring the library as dependency in build.gradle?

You should also be using the latest version of the CocoLib (1.15.2-0.1.1) .bindAndDrawTexture(GuiElement.java:37) ~[CocoLib-b915c0a15d.jar:1.15.2-0.1.0]

Rellit-219 commented 4 years ago

May have fixed this by refreshing the build thanks.

Rellit-219 commented 4 years ago

image It now no longer crashes, however this black box is the only thing that shows up.

Changed 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.CENTER, 1 + (i * 9) + (i * 3), 10 * i).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.CENTER, 1 + (i * 9) + (i * 3), 10 * i).withUV(9, 0).withSize(9, 9).build());

    }

}

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

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

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

        for (SpriteObject empty_bac_icon : BAC_HUD_EMPTY_ICONS) {

            GuiElement.bindAndDrawTexture(empty_bac_icon);

        }

        for (SpriteObject full_bac_icon : BAC_HUD_FULL_ICONS) {

            GuiElement.bindAndDrawTexture(full_bac_icon);

        }

    }

}
matshou commented 4 years ago

That is a different issue, can you open a separate ticket for this?

Rellit-219 commented 4 years ago

ok