Navigation

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    SOLVED Ingame overlay

    1.12.x
    1.12.2
    1
    2
    50
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Kporal
      Kporal last edited by

      Bonsoir 🙂 bon cette fois je suis sur la création d’un overlay pour afficher les pièces d’armure ( image de l’objet ) plus le texte correspondant à la durabilité de l’ItemStack. J’ai commencer par sa :
      OverlayGuiHandler

      package com.kporal.mcplus.overlay;
      
      import net.minecraft.client.Minecraft;
      import net.minecraft.entity.player.EntityPlayer;
      import net.minecraft.world.World;
      import net.minecraftforge.fml.common.network.IGuiHandler;
      
      public class OverlayGuiHandler implements IGuiHandler {
      
      	@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 ) {
      		return new OverlayGui( Minecraft.getMinecraft() );
      	}
      }
      

      OverlayGui

      package com.kporal.mcplus.overlay;
      
      import net.minecraft.client.Minecraft;
      import net.minecraft.client.gui.GuiIngame;
      import net.minecraft.item.ItemStack;
      
      public class OverlayGui extends GuiIngame {
      
      	public OverlayGui( Minecraft mcIn ) {
      		super( mcIn );
      	}
      
      	@Override
      	public void renderGameOverlay( float partialTicks ) {
      		ItemStack itemstack = this.mc.player.inventory.armorItemInSlot( 0 );
      		if( !itemstack.isEmpty() )
      			System.out.println( itemstack.getItem().getRegistryName() );
      	}
      }
      

      et je le déclare dans mon preInit : NetworkRegistry.INSTANCE.registerGuiHandler( Main.instance, new OverlayGuiHandler() );

      Bon je suppose que c’est faux ( forcément puisque j’ai aucun résultat en jeux ) mais le souci c’est que je n’ai même pas d’erreur pour debug … quelqu’un pour m’aiguillier ?

      1 Reply Last reply Reply Quote 0
      • Kporal
        Kporal last edited by

        Encore une fois je m’y prend mal, problème résolu :

        @SideOnly( Side.CLIENT )
        	@SubscribeEvent
        	public void onRender( RenderGameOverlayEvent.Post event ) {
        		Minecraft minecraft = Minecraft.getMinecraft();
        		RenderItem render = minecraft.getRenderItem();
        		EntityPlayer player = minecraft.player;
        		
        		if( event.getType() != ElementType.EXPERIENCE || !Configs.armorOverlay || player.isSpectator() ) return;
        		
        		ItemStack helmet = player.inventory.armorItemInSlot( 3 );
        		ItemStack chest = player.inventory.armorItemInSlot( 2 );
        		ItemStack leggings = player.inventory.armorItemInSlot( 1 );
        		ItemStack boots = player.inventory.armorItemInSlot( 0 );
        		
        		int positionX = Configs.armorOverlayX;
        		int positionY = Configs.armorOverlayY;
        		
        		if( !helmet.isEmpty() ) {
        			drawItemDurability( helmet, minecraft, positionX, positionY );
        			positionY += 16;
        		}
        		if( !chest.isEmpty() ) {
        			drawItemDurability( chest, minecraft, positionX, positionY );
        			positionY += 16;
        		}
        		if( !leggings.isEmpty() ) {
        			drawItemDurability( leggings, minecraft, positionX, positionY );
        			positionY += 16;
        		}
        		if( !boots.isEmpty() ) {
        			drawItemDurability( boots, minecraft, positionX, positionY );
        		}
        	}
        	
        	private void drawItemDurability( ItemStack stack, Minecraft minecraft, int posX, int posY ) {
        		minecraft.getRenderItem().renderItemAndEffectIntoGUI( stack, posX, posY );
        		int damage = stack.getMaxDamage() - stack.getItemDamage();
        		int size = Math.round( damage * 12 / stack.getMaxDamage() );
        		int color = size <= 2 ? Color.RED.getRGB() : size <= 6 ? Color.ORANGE.getRGB() : Color.GREEN.getRGB();
        		minecraft.ingameGUI.drawRect( posX + 2, posY + 15, posX + 14, posY + 16, Color.BLACK.getRGB() );
        		minecraft.ingameGUI.drawRect( posX + 2, posY + 15, posX + 2 + size, posY + 16, color );
        	}
        
        1 Reply Last reply Reply Quote 0
        • Kporal
          Kporal last edited by

          Encore une fois je m’y prend mal, problème résolu :

          @SideOnly( Side.CLIENT )
          	@SubscribeEvent
          	public void onRender( RenderGameOverlayEvent.Post event ) {
          		Minecraft minecraft = Minecraft.getMinecraft();
          		RenderItem render = minecraft.getRenderItem();
          		EntityPlayer player = minecraft.player;
          		
          		if( event.getType() != ElementType.EXPERIENCE || !Configs.armorOverlay || player.isSpectator() ) return;
          		
          		ItemStack helmet = player.inventory.armorItemInSlot( 3 );
          		ItemStack chest = player.inventory.armorItemInSlot( 2 );
          		ItemStack leggings = player.inventory.armorItemInSlot( 1 );
          		ItemStack boots = player.inventory.armorItemInSlot( 0 );
          		
          		int positionX = Configs.armorOverlayX;
          		int positionY = Configs.armorOverlayY;
          		
          		if( !helmet.isEmpty() ) {
          			drawItemDurability( helmet, minecraft, positionX, positionY );
          			positionY += 16;
          		}
          		if( !chest.isEmpty() ) {
          			drawItemDurability( chest, minecraft, positionX, positionY );
          			positionY += 16;
          		}
          		if( !leggings.isEmpty() ) {
          			drawItemDurability( leggings, minecraft, positionX, positionY );
          			positionY += 16;
          		}
          		if( !boots.isEmpty() ) {
          			drawItemDurability( boots, minecraft, positionX, positionY );
          		}
          	}
          	
          	private void drawItemDurability( ItemStack stack, Minecraft minecraft, int posX, int posY ) {
          		minecraft.getRenderItem().renderItemAndEffectIntoGUI( stack, posX, posY );
          		int damage = stack.getMaxDamage() - stack.getItemDamage();
          		int size = Math.round( damage * 12 / stack.getMaxDamage() );
          		int color = size <= 2 ? Color.RED.getRGB() : size <= 6 ? Color.ORANGE.getRGB() : Color.GREEN.getRGB();
          		minecraft.ingameGUI.drawRect( posX + 2, posY + 15, posX + 14, posY + 16, Color.BLACK.getRGB() );
          		minecraft.ingameGUI.drawRect( posX + 2, posY + 15, posX + 2 + size, posY + 16, color );
          	}
          
          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Design by Woryk
          Contact / Mentions Légales / Faire un don

          MINECRAFT FORGE FRANCE © 2018

          Powered by NodeBB