MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Ingame overlay

    Planifier Épinglé Verrouillé Déplacé Résolu 1.12.x
    1.12.2
    2 Messages 1 Publieurs 299 Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • KporalK Hors-ligne
      Kporal
      dernière édition par

      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 ?

      Check out my mod : https://www.curseforge.com/minecraft/mc-mods/eygo

      1 réponse Dernière réponse Répondre Citer 0
      • KporalK Hors-ligne
        Kporal
        dernière édition par

        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 );
        	}
        

        Check out my mod : https://www.curseforge.com/minecraft/mc-mods/eygo

        1 réponse Dernière réponse Répondre Citer 0
        • 1 / 1
        • Premier message
          Dernier message
        Design by Woryk
        ContactMentions Légales

        MINECRAFT FORGE FRANCE © 2024

        Powered by NodeBB