Résolu Ingame overlay
-
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 :
OverlayGuiHandlerpackage 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 ?
-
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 ); }
-
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 ); }