Jump to content

[1.7.10] Checking if inventory is full and rendering it into the screen


Recommended Posts

Posted

Hello..

I'm trying to code this mod which tells you if you're inventory is full, and if it is, it render the stats (GUI) into the screen, For example I have a simple GUI on the left corner of my screen that says Inventory stats: Full <-- that's if its full, If its not full and can still contain items it says Inventory stats: Empty

So here's my code..

Main class

package me.q8minecraft.fullinv;

 

import com.q8minecraft.event.ScreenRender;

 

import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.event.FMLInitializationEvent;

 

 

@Mod(modid = FullInv.MODID, version = FullInv.VERSION, name = FullInv.NAME)

public class FullInv {

 

public final static String MODID = "FullInv";

public final static String NAME = "FullInv";

public final static String VERSION = "1.0.0";

 

@EventHandler

public void init(FMLInitializationEvent e) {

MinecraftForge.EVENT_BUS.register(new ScreenRender());

}

}

 

 

 

ScreenRender class:

 

package com.q8minecraft.event;

 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import net.minecraft.client.Minecraft;

import net.minecraftforge.client.event.RenderGameOverlayEvent;

import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

 

public class ScreenRender {

 

@SubscribeEvent

public void renderOverlay(RenderGameOverlayEvent e) {

if(e.type == ElementType.JUMPBAR || e.type == ElementType.EXPERIENCE) {

Minecraft.getMinecraft().fontRenderer.drawString("Inventory Stats: ", 2, 2, 0xFFFFFF);

 

 

}

}

 

}

 

Posted

I have a tutorial examples showing you how to modify the overlay:

 

https://github.com/Nephroid1/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/overlay_simple

https://github.com/Nephroid1/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/overlay_advanced

 

The second one renders an HP bar, so it shows you how to access player information while rendering the overlay. The same concepts apply if you want to render other things, like the inventory status of a player.

 

In general, you only want to handle the RenderGameOverlay.Post and RenderGameOverlay.Pre events, not the RenderGameOverlayEvent itself. For rendering a bit of text, it's only necessary to render it once per screen update. The code you have right now would render your text at least four times (twice in the pre event and twice in the post event; once for the jump bar, once for the exp bar), which is extra, unnecessary work.

 

 

Also, when asking for help, it's a good idea to actually say what you're having problems with. That way, people can actually help you with your problem.

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.