Jump to content

[1.8]create a gui local only and only when this specific item is in hand ???


Recommended Posts

Posted

good days

 

i wana doo something that sound some how easy but i dont think so.

 

i alredy make a fn p90 gun i have done it complex it can shoot on manual semi and automatic mode has its bullets clip ap to 64 bullets and can work whith diferen types of munition  i been set keybinds to extract clip and change the shoot mode.

but now i wanna give this weapon a little icon in the  down left side of the screen showing munition and shooting mode only visible when the gun is selected

 

and i dont know where to start i been reading the guide for tile entityes but that kind of gui looks like it stop the player from moving while open

 

suggestion??

Posted

Try this out: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-forge-1-6-4-1-8-eventhandler-and

 

Go down to the spoiler that says "GuiManaBar" and see how he puts it on screen. Then, you can kinda go from there.

 

As for when you're holding the item, you could do something like this:

 

if(player.inventory.getCurrentItem().isItemEqual(new ItemStack(YourMod.YourItem))) {
//Add the render stuff
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

hello

ibeen working whith the guides

and get stuck whi this

 

ForgeSubscribe

 

 

error: "The import net.minecraftforge.event.ForgeSubscribe cannot be resolved";

there is not    import net.minecraftforge.event.ForgeSubscribe;  in 1.8 and sems like eclipse could find it

could some one point me where it is the equivalent of  ForgeSubscribe in 1.8

 

thanks

Posted

hello

i been doing more research and find a piece of working code,

adapted it to mi needs and  is working but there is thing i dont get

 

im calculating the position of my items icon  to be at lower left side of the screen using

 

        private int posX=0, posY=0, mulY=-1;

        int displayWidth=mc.displayWidth;  
        int displayHeight=mc.displayHeight;

        int offsetX=16;
        int offsetY=((displayHeight/2)-80); 

 

16 pixel from the left side and 80 pixel from the botom  its works but only when the option "GUI SCALE: NORMAL" if i change it the icon disapears i think it goes out of picture.

 

 

the original code sets the icon to the uper left and uses

        ScaledResolution sr = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
        posX =sr.getScaledWidth() - 160;
        posY =sr.getScaledHeight() - 32;
        mulY = -1;

 

how i solve this  to adapt the icon position to the state of "GUI SCALE:

 

 

 

package mercenarymod.gui;

import mercenarymod.items.MercenaryModItems;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import org.lwjgl.opengl.GL11;

public class NotificationMercenaria extends Gui {

    private Minecraft mc;
    private int posX=0, posY=0, mulY=-1;
    private int conteo=0;
    private String icono="modmercenario:textures/items/comunes/transparencia.png";//transparencia
    
    public NotificationMercenaria(Minecraft mc, Configuration config) {
        super();
        this.mc = mc;

        //Save the top left corner of the fully visible notification to posX, posY and mulY.
        ScaledResolution sr = new ScaledResolution(this.mc, this.mc.displayWidth, this.mc.displayHeight);
        posX = 0;//sr.getScaledWidth() - 160;
        posY = 0;//sr.getScaledHeight() - 32;
        mulY = -1;
        //String[] position = config.get(Configuration.CATEGORY_GENERAL, "position", "top-left").getString().split("-");
        //if (position[0] == "top") { posY = 0; mulY = 1; }
        //if (position[1] == "left") posX = 0;
        //posY = 0; mulY = 1;posX = 0;
    }

    private String text = "";
    
    @SubscribeEvent(priority = EventPriority.NORMAL)
    public void onRender(RenderGameOverlayEvent event) {

    	//Render above the chat
        if(event.isCancelable() || event.type != RenderGameOverlayEvent.ElementType.ALL) return;
        //Render only if there's a new notification
  
        conteo++;
        int displayWidth=mc.displayWidth;
        int displayHeight=mc.displayHeight;
        
        System.out.println("with="+displayWidth+" Height="+displayHeight);
        
        if ( (conteo%20)==0 ){
        int modo=0;
        
        EntityPlayer playerIn=mc.thePlayer;
        
        int         hand = playerIn.inventory.currentItem;
        ItemStack stack0 = playerIn.inventory.getCurrentItem();
        if (stack0 != null){
       	//System.out.println("stack0="+stack0.getUnlocalizedName());	
        
        Item       item0 = stack0.getItem();
        //
                
        boolean transparencia=true;
        
        
        int municion = getInttag(stack0, "municion");
	int municionmaxima =getInttag(stack0, "municionmaxima");
	int municiondisponible=getInttag(stack0, "municiondisponible");
	int tipomunicion=getInttag(stack0, "tipomunicion");
	int tipocargador=getInttag(stack0, "tipocargador");
	int tipocargadormax=getInttag(stack0, "tipocargadormax");

	int tipodisparo=getInttag(stack0, "tipodisparo");
	int tipodisparomax=getInttag(stack0, "tipodisparomax");

	boolean reload= getBooleantag(stack0, "reload");
	boolean shoot= getBooleantag(stack0, "shoot");
	boolean unload= getBooleantag(stack0, "unload");
	float strength=getFloattag(stack0, "strength");
	boolean enable= getBooleantag(stack0, "enable");
        
        if (unload){modo=1;}
        if (tipocargador<=0){modo=2;}
        
        if (item0.equals(MercenaryModItems.subfusil90PNF)){
        	switch(modo){
            case 0: icono="modmercenario:textures/items/armasdefuego/subfusil90pnf/90PNF_icono.png";break;
            case 1: icono="modmercenario:textures/items/armasdefuego/subfusil90pnf/90PNF_descargar.png";break;
            case 2: icono="modmercenario:textures/items/armasdefuego/subfusil90pnf/90PNF_SC.png";break;
                        }
        	switch(tipodisparo){
        	case 0: text=""+municion+"/"+municionmaxima+" Manual";break;
        	case 1: text=""+municion+"/"+municionmaxima+" SemiAutomatico";break;
        	case 2: text=""+municion+"/"+municionmaxima+" Automatico";break;
        	}transparencia=false;}	

        if (item0.equals(MercenaryModItems.vallestaMercenaria)){
        	switch(tipomunicion){
            case 0: icono="modmercenario:textures/items/arcos/flecha00.png";break;
            case 1: icono="modmercenario:textures/items/arcos/flecha01.png";break;
            case 2: icono="modmercenario:textures/items/arcos/flecha02.png";break;
                                }text=""+municiondisponible; transparencia=false;}
        	

        if (item0.equals(MercenaryModItems.arcoMercenario)){
        	switch(tipomunicion){
            case 0: icono="modmercenario:textures/items/arcos/flecha00.png";break;
            case 1: icono="modmercenario:textures/items/arcos/flecha01.png";break;
            case 2: icono="modmercenario:textures/items/arcos/flecha02.png";break;
                                }text=""+municiondisponible; transparencia=false;}	
        	
        	
        if (item0.equals(MercenaryModItems.pistola75NF)){
            switch(modo){
            case 0: icono="modmercenario:textures/items/armasdefuego/pistola75nf/75NF_icono.png";break;
            case 1: icono="modmercenario:textures/items/armasdefuego/pistola75nf/75NF_descargar.png";break;
            case 2: icono="modmercenario:textures/items/armasdefuego/pistola75nf/75NF_icono.png";break;
                        }text=""+municion+" / "+municionmaxima ;transparencia=false;}

        if (item0.equals(MercenaryModItems.pistola1911colt)){
        	switch(modo){
            case 0: icono="modmercenario:textures/items/armasdefuego/pistola1911colt/pistola1911colt_icono.png";break;
            case 1: icono="modmercenario:textures/items/armasdefuego/pistola1911colt/pistola1911colt_descargar.png";break;
            case 2: icono="modmercenario:textures/items/armasdefuego/pistola1911colt/pistola1911colt_icono.png";break;
                        }text=""+municion+" / "+municionmaxima ;transparencia=false;}
        
        if (item0.equals(MercenaryModItems.cargador1911colt)){
        	icono="modmercenario:textures/items/armasdefuego/pistola1911colt/cargador1911colt_icono.png";
        	text=""+municion+" / "+municionmaxima ;transparencia=false;}

        if (item0.equals(MercenaryModItems.cargador75NF)){
        	icono="modmercenario:textures/items/armasdefuego/pistola75nf/cargador_75NF_icono.png";
        	text=""+municion+" / "+municionmaxima ;transparencia=false;}

        if (item0.equals(MercenaryModItems.cargador90PNF)){
        	icono="modmercenario:textures/items/armasdefuego/subfusil90pnf/90PNF_cargador_icono.png";
        	text=""+municion+" / "+municionmaxima ;transparencia=false;}

        if (item0.equals(MercenaryModItems.cargadorBeretta)){
        	icono="modmercenario:textures/items/armasdefuego/pistola1911colt/cargador1911colt_icono.png";
        	text=""+municion+" / "+municionmaxima ;transparencia=false;}


        if (transparencia){icono="modmercenario:textures/items/comunes/transparencia.png";text="";}//
                      
        
        }//(stack0 != null)
        
        }//( (conteo%20)==0 )
        
        //Prepare rendering
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GL11.glDisable(GL11.GL_LIGHTING);


        int offsetX=16;
        int offsetY=((displayHeight/2)-80);

        this.mc.renderEngine.bindTexture(new ResourceLocation(icono));

        
        //drawModalRectWithCustomSizedTexture(int x, int y,float u,float v,int width,int height,float textureWidth,float textureHeight);
        this.drawModalRectWithCustomSizedTexture(posX + offsetX, posY + offsetY, 0.0F, 0.0F, 60, 60, 60.0F, 60.0F); //imagen al 60%
        //this.drawModalRectWithCustomSizedTexture(posX + 8, posY + 8, 0.0F, 0.0F, 200, 200 , 200.0F, 200.0F);
        
        this.mc.fontRendererObj.drawStringWithShadow(text,  posX + offsetX, ((posY + offsetY)+40) , 0xffcccccc);
        //this.mc.fontRendererObj.drawStringWithShadow(text,  posX + 32 + 8, posX + 8, 0xffcccccc);
    }

    

  //#########################################################################3
  public static int[] getIntArraytag(ItemStack item, String tag){	
  	
  	int[] array = new int[5];
  	
  		NBTTagCompound etiquetas = item.getTagCompound();
  		if (etiquetas == null){ 
  			etiquetas = new NBTTagCompound();
  			item.setTagCompound(etiquetas);
  			array[0]=9999;
  			return array;
  		                      }
  			
  		array=etiquetas.getIntArray(tag); 
  		return array;
  	
  }

  //#########################################################################3
  public static void setIntArraytag(ItemStack item, String tag, int[] value){
  	
  	NBTTagCompound etiquetas = item.getTagCompound();
  	if (etiquetas == null){ 
  	etiquetas = new NBTTagCompound();
  	                      }
  	
  	etiquetas.setIntArray(tag, value);
  	item.setTagCompound(etiquetas);
  		
  }
   
  //#########################################################################3
  public static float getFloattag(ItemStack item, String tag){	
  	
  	NBTTagCompound etiquetas = item.getTagCompound();
  	if (etiquetas == null){ 
  		etiquetas = new NBTTagCompound();
  		item.setTagCompound(etiquetas);
  		return 999.9F;
  	                      }
  		
  	float ex=etiquetas.getFloat(tag); 
  	return ex;
  }
  //#########################################################################3
  public static void setFloattag(ItemStack item, String tag, float value){
  	

  	NBTTagCompound etiquetas = item.getTagCompound();
  	if (etiquetas == null){ 
  	etiquetas = new NBTTagCompound();
  	                      }
  	
  	etiquetas.setFloat(tag, value);
  	item.setTagCompound(etiquetas);
  	
  }
  //#########################################################################3
  public static int getInttag(ItemStack item, String tag){	
  	
  		NBTTagCompound etiquetas = item.getTagCompound();
  		if (etiquetas == null){ 
  			etiquetas = new NBTTagCompound();
  			item.setTagCompound(etiquetas);
  			return 9999;
  		                      }
  			
  		int ex=etiquetas.getInteger(tag); 
  		return ex;
  	
  }
  //#########################################################################3
  public static void setInttag(ItemStack item, String tag, int value){
  	
  	NBTTagCompound etiquetas = item.getTagCompound();
  	if (etiquetas == null){ 
  	etiquetas = new NBTTagCompound();
  	                      }
  	
  	etiquetas.setInteger(tag, value);
  	item.setTagCompound(etiquetas);
  		
  }
  //#########################################################################3
  public static Boolean getBooleantag(ItemStack item, String tag){	
  		
  		NBTTagCompound etiquetas = item.getTagCompound();
  		if (etiquetas == null){ 
             etiquetas = new NBTTagCompound();
  			item.setTagCompound(etiquetas);
  			return false;
  		                      }
  		
  		boolean ex=etiquetas.getBoolean(tag); 
  	    
  		return ex;
  }
  //#########################################################################3
  public static void setBooleantag(ItemStack item, String tag, boolean value){

  		
  		NBTTagCompound etiquetas = item.getTagCompound();
  		if (etiquetas == null){ 
  			etiquetas = item.getTagCompound();
  		                      }
  		
  		etiquetas.setBoolean(tag, value);
  		item.setTagCompound(etiquetas);

  }	
  //#########################################################################3

}//fin de la classe


 

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.