Modifier l'overlay (HUD) du jeu
-
@Superloup10 je suis en 1.7.10
-
Si tu cherches bien, tu trouveras plein de sujets qui ajoutent des choses côté client sans avoir cette annotation.
-
@Superloup10 j’ai pas trouvé tu peux me donner un exemple de tuto à voir ?
-
Le tutoriel sur les event de la 1.7.10 explique comment enregistrer un event en 1.7.10 : https://www.minecraftforgefrance.fr/topic/636/utiliser-les-événements
-
@robin4002 merci du coup il faut utiliser l’annotation @sideonly
-
bonjour à tous,
mon HUD ne s’affiche pas est je ne comprend pas pourquoi (je suis en 1.7.10) quelqu’un pourrais m’aider?ma classe principale:
/** * */ package ch.gonin.guillaume.zombiecubefree.common; import ch.gonin.guillaume.zombiecubefree.proxy.CommonProxy; import ch.gonin.guillaume.zombiecubefree.proxy.ClientProxy; import ch.gonin.guillaume.zombiecubefree.common.TilesEntity.TileEntityBlockTutorielTiles; import ch.gonin.guillaume.zombiecubefree.common.TilesEntity.TileEntityTele; import ch.gonin.guillaume.zombiecubefree.common.blocks.BlockMetadata; import ch.gonin.guillaume.zombiecubefree.common.blocks.BlockTutoriel; import ch.gonin.guillaume.zombiecubefree.common.blocks.BlockTutorielTiles; import ch.gonin.guillaume.zombiecubefree.common.blocks.Cuisiniere; import ch.gonin.guillaume.zombiecubefree.common.blocks.Tele; import ch.gonin.guillaume.zombiecubefree.common.gui.ZombieCubeFreeCreativeTabs; import ch.gonin.guillaume.zombiecubefree.common.items.CocktailMolotov; import ch.gonin.guillaume.zombiecubefree.common.items.ItemFireStick; import ch.gonin.guillaume.zombiecubefree.common.items.ItemGaz; import ch.gonin.guillaume.zombiecubefree.common.items.ItemShowInfo; import ch.gonin.guillaume.zombiecubefree.common.items.ItemShowMoney; import ch.gonin.guillaume.zombiecubefree.common.items.ItemTutoriel; import ch.gonin.guillaume.zombiecubefree.common.items.ItemblockMetadata; import ch.gonin.guillaume.zombiecubefree.common.packet.Handler; import ch.gonin.guillaume.zombiecubefree.common.packet.PacketMoney; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraftforge.common.MinecraftForge; @Mod(modid = "zombiecubefree", name = "Zombie Cube Free", version = "1.0.0") /** * @author Guillaume * */ public class Main { @Instance("zombiecubefree") public static Main instance; public static final String MODID = "zombiecubefree"; public static SimpleNetworkWrapper network; @EventHandler public void preInit(FMLPreInitializationEvent event) { blockTutoriel = new BlockTutoriel(Material.rock).setBlockName("blockTutoriel") .setBlockTextureName(MODID + ":block_tutoriel").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(blockTutoriel, "block_tutoriel"); blockTutorielTiles = new BlockTutorielTiles(Material.rock).setCreativeTab(CreativeTabs.tabBlock) .setBlockName("tutorielTiles").setBlockTextureName(MODID + ":block_tutoriel_tiles") .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(blockTutorielTiles, "block_tutoriel_tiles"); blockMetadata = new BlockMetadata().setBlockName("blockMetadata").setHardness(1.5F).setResistance(10.0F) .setCreativeTab(CreativeTabs.tabBlock).setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(blockMetadata, ItemblockMetadata.class, "block_metadata"); itemTutoriel = new ItemTutoriel().setUnlocalizedName("itemTutoriel") .setTextureName(Main.MODID + ":item_tutoriel").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(itemTutoriel, "item_tutoriel"); cuisiniere = new Cuisiniere(Material.rock).setBlockName("cuisiniere").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(cuisiniere, "cuisiniere"); tele = new Tele(Material.rock).setBlockName("tele").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(tele, "tele"); itemShowInfo = new ItemShowInfo().setUnlocalizedName("itemShowInfo") .setTextureName(Main.MODID + ":item_show_info").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(itemShowInfo, "item_show_info"); gaz = new ItemGaz().setUnlocalizedName("gaz").setTextureName(Main.MODID + ":gaz") .setCreativeTab(CreativeTabs.tabBlock).setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(gaz, "gaz"); itemShowMoney = new ItemShowMoney().setUnlocalizedName("itemShowMoney") .setTextureName(Main.MODID + ":item_show_money").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(itemShowMoney, "item_show_money"); fireStick = new ItemFireStick().setUnlocalizedName("fireStick") .setTextureName(Main.MODID + ":fire_stick").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(fireStick, "fire_stick"); cocktailMolotov = new CocktailMolotov().setUnlocalizedName("cocktailMolotov") .setTextureName(Main.MODID + ":cocktail_molotov").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(cocktailMolotov, "cocktail_molotov"); network = NetworkRegistry.INSTANCE.newSimpleChannel(MODID); network.registerMessage(Handler.class, PacketMoney.class, 1, Side.CLIENT); } @SidedProxy(clientSide = "ch.gonin.guillaume.zombiecubefree.proxy.ClientProxy", serverSide = "ch.gonin.guillaume.zombiecubefree.proxy.CommonProxy") public static CommonProxy proxy; @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); GameRegistry.registerTileEntity(TileEntityBlockTutorielTiles.class, MODID + ":blockTutorielTiles"); GameRegistry.registerTileEntity(TileEntityTele.class, MODID + ":tele"); FMLCommonHandler.instance().bus().register(new ch.gonin.guillaume.zombiecubefree.even.EventHandler()); MinecraftForge.EVENT_BUS.register(new ch.gonin.guillaume.zombiecubefree.even.EventHandler()); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } public static Block blockTutoriel; public static Block blockTutorielTiles; public static Block blockMetadata; public static Item itemTutoriel; public static Block cuisiniere; public static Block tele; public static Item itemShowInfo; public static Item gaz; public static Item itemShowMoney; public static Item fireStick; public static Item cocktailMolotov; public static CreativeTabs ZombieCubeFreeCreativeTabs = new ZombieCubeFreeCreativeTabs("Zombie Cube Free"); }
celle de mon HUD:
package ch.gonin.guillaume.zombiecubefree.even; import org.lwjgl.util.Color; import ch.gonin.guillaume.zombiecubefree.common.Main; import ch.gonin.guillaume.zombiecubefree.common.autres.ExtendedProperties; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; @SideOnly(Side.CLIENT) public class EventHUD { private static final ResourceLocation emptyLife = new ResourceLocation(Main.MODID, "textures/gui/emptylife.png"); private static final ResourceLocation fullLife = new ResourceLocation(Main.MODID, "textures/gui/fulllife.png"); public static final Minecraft MC = Minecraft.getMinecraft(); @SubscribeEvent public static void renderGameOverlayPre(RenderGameOverlayEvent.Pre event) { } @SubscribeEvent public static void renderGameOverlayPost(RenderGameOverlayEvent.Post event, EntityPlayer player) { if (event.getPhase().equals(ElementType.ALL)) { ExtendedProperties props = ExtendedProperties.get(player); String s = "Argent :" + props.money + "$"; Gui.drawRect(MC.displayWidth - 5 - MC.fontRenderer.getStringWidth(s), 2, MC.displayWidth - 2, 4 + MC.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE); MC.fontRenderer.drawString(s, MC.displayWidth - 3 - MC.fontRenderer.getStringWidth(s), 4, 255); } // drawHealth(event.(), MC.player); /* * String s = MC.getConnection().getPlayerInfoMap().size() + "/" + * MC.getConnection().currentServerMaxPlayers + " joueurs"; * * Gui.drawRect(width - 5 - MC.fontRendererObj.getStringWidth(s), 2, width - 2, * 4 + MC.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE); * * MC.fontRendererObj.drawString(s, width - 3 - * MC.fontRendererObj.getStringWidth(s), 4, Color.WHITE.getRGB()); */ } }
de mon extend propriété (pour la variable a afficher dans l’HUD):
package ch.gonin.guillaume.zombiecubefree.common.autres; import ch.gonin.guillaume.zombiecubefree.proxy.CommonProxy; import ch.gonin.guillaume.zombiecubefree.common.Main; import ch.gonin.guillaume.zombiecubefree.common.packet.PacketMoney; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class ExtendedProperties implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "ExtProp"; public final EntityPlayer player; public long money; public long maxMoney; @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setLong("Money", this.money); properties.setLong("MaxMoney", this.maxMoney); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound .getTag(EXT_PROP_NAME); this.money = properties.getLong("Money"); this.maxMoney = properties.getLong("MaxMoney"); } @Override public void init(Entity entity, World world) { // TODO Auto-generated method stub } public ExtendedProperties(EntityPlayer player) { this.player = player; this.money = 0; this.maxMoney = 2147483645; } public static final void register(EntityPlayer player) { player.registerExtendedProperties(ExtendedProperties.EXT_PROP_NAME, new ExtendedProperties(player)); } public static final ExtendedProperties get(EntityPlayer player) { return (ExtendedProperties) player.getExtendedProperties(EXT_PROP_NAME); } public final void sync() { PacketMoney packetMoney = new PacketMoney(this.maxMoney, this.money); // La ligne suivante dépend de votre manière d'envoyer les packets. Celle-ci // vient de mon mod, je ne la changerais pas car je ne peux l'appliquer à votre // mod, mais elle reste bonne pour un exemple. Main.network.sendToServer(packetMoney); if (!player.worldObj.isRemote) { EntityPlayerMP player1 = (EntityPlayerMP) player; // Ici, même chose que précédemment, sauf que le packet est envoyé au player. Main.network.sendTo(packetMoney, player1); } } private static String getSaveKey(EntityPlayer player) { return player.getDisplayName() + ":" + EXT_PROP_NAME; } public static void saveProxyData(EntityPlayer player) { ExtendedProperties playerData = ExtendedProperties.get(player); NBTTagCompound savedData = new NBTTagCompound(); playerData.saveNBTData(savedData); CommonProxy.storeEntityData(getSaveKey(player), savedData); } public static void loadProxyData(EntityPlayer player) { ExtendedProperties playerData = ExtendedProperties.get(player); NBTTagCompound savedData = CommonProxy .getEntityData(getSaveKey(player)); if (savedData != null) { playerData.loadNBTData(savedData); } playerData.sync(); } public boolean pay(long amount) { if (amount <= this.money) { this.money -= amount; this.sync(); } else { return amount <= this.money; } return true; } public void addMoney(long amount) { this.money += amount; this.sync(); } public long getMoney() { return this.money; } public void setMoney(long newMoney) { this.money = newMoney; this.sync(); } }
les deux de mon packet:
package ch.gonin.guillaume.zombiecubefree.common.packet; import ch.gonin.guillaume.zombiecubefree.common.autres.ExtendedProperties; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import net.minecraft.entity.player.EntityPlayer; public class PacketMoney implements IMessage { public long maxMoney, Money; public PacketMoney() { } public PacketMoney(long maxMoney, long money) { this.maxMoney = maxMoney; this.Money = money; } public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { buffer.writeLong(maxMoney); buffer.writeLong(Money); } public void decodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { this.maxMoney = buffer.readLong(); this.Money = buffer.readLong(); } public void handleClientSide(EntityPlayer player) { ExtendedProperties props = ExtendedProperties .get(player); props.maxMoney = this.maxMoney; props.money = this.Money; } public void handleServerSide(EntityPlayer player) { ExtendedProperties props = ExtendedProperties .get(player); props.maxMoney = this.maxMoney; props.money = this.Money; } @Override public void fromBytes(ByteBuf buf) { // TODO Auto-generated method stub } @Override public void toBytes(ByteBuf buf) { // TODO Auto-generated method stub } }
package ch.gonin.guillaume.zombiecubefree.common.packet; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; public class Handler implements IMessageHandler <PacketMoney, PacketMoney> { @Override public PacketMoney onMessage(PacketMoney message, MessageContext ctx) { // TODO Auto-generated method stub return null; } }
voilà merci si quelqu’un trouve
-
Salut,
Ta classe EventHUD n’est jamais enregistré en tant que classe d’event et ta fonctionrenderGameOverlayPost
ne devrait pas avoirEntityPlayer player
en argument (il faut utiliser le player qui est dans la classeMinecraft
). -
@robin4002 comment on utiliser le player de la classe minecraft ? car j’ai beaucoup cherché mais pas trouvé
-
Tu as déjà une instance de la classe Minecraft dans ta classe EventHUD que tu as nommé
MC
. Donc tu as juste à faireMC.thePlayer
-
@robin4002 il doit y avoir un autre probléme car il s’affiche toujours pas
-
Tu as enregistré la classe
EventHUD
en tant que classe d’event avecMinecraftForge.EVENT_BUS.register(new EventHUD());
dans ta classe principale ou dans ton client proxy ? -
@robin4002 classe principale
ma classe principale:
/** * */ package ch.gonin.guillaume.zombiecubefree.common; import ch.gonin.guillaume.zombiecubefree.proxy.CommonProxy; import ch.gonin.guillaume.zombiecubefree.proxy.ClientProxy; import ch.gonin.guillaume.zombiecubefree.common.TilesEntity.TileEntityBlockTutorielTiles; import ch.gonin.guillaume.zombiecubefree.common.TilesEntity.TileEntityTele; import ch.gonin.guillaume.zombiecubefree.common.blocks.BlockMetadata; import ch.gonin.guillaume.zombiecubefree.common.blocks.BlockTutoriel; import ch.gonin.guillaume.zombiecubefree.common.blocks.BlockTutorielTiles; import ch.gonin.guillaume.zombiecubefree.common.blocks.Cuisiniere; import ch.gonin.guillaume.zombiecubefree.common.blocks.Tele; import ch.gonin.guillaume.zombiecubefree.common.gui.ZombieCubeFreeCreativeTabs; import ch.gonin.guillaume.zombiecubefree.common.items.CocktailMolotov; import ch.gonin.guillaume.zombiecubefree.common.items.ItemFireStick; import ch.gonin.guillaume.zombiecubefree.common.items.ItemGaz; import ch.gonin.guillaume.zombiecubefree.common.items.ItemShowInfo; import ch.gonin.guillaume.zombiecubefree.common.items.ItemShowMoney; import ch.gonin.guillaume.zombiecubefree.common.items.ItemTutoriel; import ch.gonin.guillaume.zombiecubefree.common.items.ItemblockMetadata; import ch.gonin.guillaume.zombiecubefree.common.packet.Handler; import ch.gonin.guillaume.zombiecubefree.common.packet.PacketMoney; import ch.gonin.guillaume.zombiecubefree.even.EventHUD; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraftforge.common.MinecraftForge; @Mod(modid = "zombiecubefree", name = "Zombie Cube Free", version = "1.0.0") /** * @author Guillaume * */ public class Main { @Instance("zombiecubefree") public static Main instance; public static final String MODID = "zombiecubefree"; public static SimpleNetworkWrapper network; @EventHandler public void preInit(FMLPreInitializationEvent event) { blockTutoriel = new BlockTutoriel(Material.rock).setBlockName("blockTutoriel") .setBlockTextureName(MODID + ":block_tutoriel").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(blockTutoriel, "block_tutoriel"); blockTutorielTiles = new BlockTutorielTiles(Material.rock).setCreativeTab(CreativeTabs.tabBlock) .setBlockName("tutorielTiles").setBlockTextureName(MODID + ":block_tutoriel_tiles") .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(blockTutorielTiles, "block_tutoriel_tiles"); blockMetadata = new BlockMetadata().setBlockName("blockMetadata").setHardness(1.5F).setResistance(10.0F) .setCreativeTab(CreativeTabs.tabBlock).setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(blockMetadata, ItemblockMetadata.class, "block_metadata"); itemTutoriel = new ItemTutoriel().setUnlocalizedName("itemTutoriel") .setTextureName(Main.MODID + ":item_tutoriel").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(itemTutoriel, "item_tutoriel"); cuisiniere = new Cuisiniere(Material.rock).setBlockName("cuisiniere").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(cuisiniere, "cuisiniere"); tele = new Tele(Material.rock).setBlockName("tele").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerBlock(tele, "tele"); itemShowInfo = new ItemShowInfo().setUnlocalizedName("itemShowInfo") .setTextureName(Main.MODID + ":item_show_info").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(itemShowInfo, "item_show_info"); gaz = new ItemGaz().setUnlocalizedName("gaz").setTextureName(Main.MODID + ":gaz") .setCreativeTab(CreativeTabs.tabBlock).setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(gaz, "gaz"); itemShowMoney = new ItemShowMoney().setUnlocalizedName("itemShowMoney") .setTextureName(Main.MODID + ":item_show_money").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(itemShowMoney, "item_show_money"); fireStick = new ItemFireStick().setUnlocalizedName("fireStick") .setTextureName(Main.MODID + ":fire_stick").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(fireStick, "fire_stick"); cocktailMolotov = new CocktailMolotov().setUnlocalizedName("cocktailMolotov") .setTextureName(Main.MODID + ":cocktail_molotov").setCreativeTab(CreativeTabs.tabBlock) .setCreativeTab(ZombieCubeFreeCreativeTabs); GameRegistry.registerItem(cocktailMolotov, "cocktail_molotov"); network = NetworkRegistry.INSTANCE.newSimpleChannel(MODID); network.registerMessage(Handler.class, PacketMoney.class, 1, Side.CLIENT); } @SidedProxy(clientSide = "ch.gonin.guillaume.zombiecubefree.proxy.ClientProxy", serverSide = "ch.gonin.guillaume.zombiecubefree.proxy.CommonProxy") public static CommonProxy proxy; @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); GameRegistry.registerTileEntity(TileEntityBlockTutorielTiles.class, MODID + ":blockTutorielTiles"); GameRegistry.registerTileEntity(TileEntityTele.class, MODID + ":tele"); FMLCommonHandler.instance().bus().register(new ch.gonin.guillaume.zombiecubefree.even.EventHandler()); MinecraftForge.EVENT_BUS.register(new ch.gonin.guillaume.zombiecubefree.even.EventHandler()); MinecraftForge.EVENT_BUS.register(new EventHUD()); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } public static Block blockTutoriel; public static Block blockTutorielTiles; public static Block blockMetadata; public static Item itemTutoriel; public static Block cuisiniere; public static Block tele; public static Item itemShowInfo; public static Item gaz; public static Item itemShowMoney; public static Item fireStick; public static Item cocktailMolotov; public static CreativeTabs ZombieCubeFreeCreativeTabs = new ZombieCubeFreeCreativeTabs("Zombie Cube Free"); }
mon HUD:
package ch.gonin.guillaume.zombiecubefree.even; import org.lwjgl.util.Color; import ch.gonin.guillaume.zombiecubefree.common.Main; import ch.gonin.guillaume.zombiecubefree.common.autres.ExtendedProperties; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; @SideOnly(Side.CLIENT) public class EventHUD { public static final Minecraft MC = Minecraft.getMinecraft(); @SubscribeEvent public static void renderGameOverlayPre(RenderGameOverlayEvent.Pre event) { } @SubscribeEvent public static void renderGameOverlayPost(RenderGameOverlayEvent.Post event) { if (event.getPhase().equals(ElementType.ALL)) { ExtendedProperties props = ExtendedProperties.get(MC.thePlayer); String s = "Argent :" + props.money + "$"; int width = event.resolution.getScaledWidth(); Gui.drawRect(width - 5 - MC.fontRenderer.getStringWidth(s), 2, width - 2, 4 + MC.fontRenderer.FONT_HEIGHT, Integer.MIN_VALUE); MC.fontRenderer.drawString(s, 10 - 3 - MC.fontRenderer.getStringWidth(s), 4, 255); } // drawHealth(event.(), MC.player); /* * String s = MC.getConnection().getPlayerInfoMap().size() + "/" + * MC.getConnection().currentServerMaxPlayers + " joueurs"; * * Gui.drawRect(width - 5 - MC.fontRendererObj.getStringWidth(s), 2, width - 2, * 4 + MC.fontRendererObj.FONT_HEIGHT, Integer.MIN_VALUE); * * MC.fontRendererObj.drawString(s, width - 3 - * MC.fontRendererObj.getStringWidth(s), 4, Color.WHITE.getRGB()); */ } }
-
Ah j’ai trouvé le problème, si tu as bien enregistré la classe avec la méthode que je t’ai donné, il faut enlever les
static
aux fonctionsrenderGameOverlayPost
etrenderGameOverlayPre
Ou alors si tu veux garder les static, il faut enregistrer la classe comme ceci :
MinecraftForge.EVENT_BUS.register(EventHUD.class);
-
@robin4002 sa ne s’affiche toujours pas
-
Là je ne vais pas pouvoir t’aider plus, c’est à toi de prendre les choses en main.
Lances le jeu en debug, mets des points d’arrêt aux différents endroits de la fonction pour vérifier que le code est bien appelé. Ou alors met des System.out.println, c’est comme tu veux. -
@robin4002 ok merci
-
@robin4002 j’ai une erreur pour l’inisialisation de la class d’event:
AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102 AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102 AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102 AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102 AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102 AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102 AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102 AL lib: (EE) MMDevApiProc: WaitForSingleObjectEx error: 0x102
-
AL lib est une bibliothèque OpenAL pour le son, je ne crois pas que cela ait un rapport avec ta modification de l’overlay.
-
@robin4002 alors je voit pas pourquoi l’overlay ne s’affiche pas
si qqn à une classe d’overlay déjà faite avec la déclaration dans le main et tous en 1.7.10 est-ce qu’il pourrait me la montre que je compare avec la mienne? -
Tu as vérifié que ta fonction
renderGameOverlayPost
est appelé ? Si oui, elle l’est ou pas ?