Jump to content

Recommended Posts

Posted

I'm trying to make an in-game tutorial-like thing for my mod, and want it to just draw a gui element on screen when you use an item. However, whenever I try, nothing happens. I don't get any error in the console, and I think I have everything set up properly, I'll attach the relevant files. Hell, I'm not even sure if you can use drawTexturedModalRext with a GuiScreen but I really hope you can or there's some other way to draw a gui without needing a whole container setup. What should I be doing that isn't being properly done?

Spoiler

package space.bbkr.aura.client.gui;

import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
import net.minecraft.client.renderer.GlStateManager;
import space.bbkr.aura.Aura;

public class GuiNote extends GuiScreen {
    private static final ResourceLocation BG_TEXTURE = new ResourceLocation(Aura.modId, "textures/gui/note_background.png"); //A/N: the texture is in the right place, and it doesn't seem to be the problem because if it was the issue then it would just show the missing texture file

    @Override
    public void drawScreen(int mouseX, int mouseY, float partialTicks) {
        this.drawDefaultBackground();
        super.drawScreen(mouseX, mouseY, partialTicks);
    }

    @Override
    public boolean doesGuiPauseGame() {
        return false;
    }

    @Override
    public void initGui() {
        GlStateManager.color(1, 1, 1, 1);
        mc.getTextureManager().bindTexture(BG_TEXTURE);
        int x = (width - 248) / 2;
        int y = (height - 166) / 2;
        drawTexturedModalRect(x, y, 0, 0, 248, 166);
    }
}

package space.bbkr.aura;

import net.minecraftforge.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import space.bbkr.aura.client.gui.GuiNote;

public class ModGuiHandler implements IGuiHandler {
    public static final int NOTE_TUTORIAL = 0;

    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        return null;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        switch (ID) {
            case NOTE_TUTORIAL:
                return new GuiNote();
            default:
                return null;
        }
    }
}

package space.bbkr.aura.item;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.item.Item;
import space.bbkr.aura.Aura;

public class ItemNote extends ItemBase {

    protected String name;

    public ItemNote(String name) {
        super(name);
        setMaxStackSize(1);
        setCreativeTab(Aura.creativeTab);
    }

    public EnumActionResult onItemUse(EntityPlayer p, World w, BlockPos pos, EnumHand h, EnumFacing f, float x, float y, float z) {
        if(!w.isRemote) { //A/N: still no idea whether !w.isRemote returns client or server, but having it as just w.isRemote caused a nullPointerException when I tried to open the gui so I think that's server-side
            p.openGui(Aura.instance, 0, w, (int) p.posX, (int) p.posY, (int) p.posZ);
        }
        return EnumActionResult.SUCCESS;
    }
}

 

 

Posted

You're calling Gui#drawTexturedModalRect once when the GUI is first opened, which does nothing. You need to call it every frame (in your override of GuiScreen#drawScreen).

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I'm not really sure what to do otherwise. I'm just going off what tutorials I can find, and I can't really find any for a client-only GUI except for one that's for Forge 1.8 and uses IGuiHandler. I don't know how to use the sided proxy to open a GUI.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.