Résolu Uncmlaim finder en 1.12.2
-
Il faut que tu vérifie que
event.getType() != null
et si ça marche pas envoie ton code avec les imports car sinon les lignes ne sont pas juste avec le crash report -
@DailyCraft merci de ta réponse.
Ca ne marche toujours pas…
Le crash report me donne un NullPointerExceptionCode :
package com.avonia.mod.util.handlers; import org.jline.utils.PumpReader; import com.avonia.mod.init.ItemInit; import com.avonia.mod.init.objects.ItemRadar; import com.avonia.mod.util.Reference; import net.minecraft.block.BlockDoublePlant.EnumPlantType; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class RadarHandler extends Gui { private Minecraft mc; public static int amountTiles; FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() != null) { mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); amountTiles = mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 0).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ - 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX - 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); drawCenteredString(fontRender, this.amountTiles + "%", 0,100, 11); event.setCanceled(true); } } }
Crash-report:
---- Minecraft Crash Report ---- // This doesn't make any sense! Time: 4/14/20 4:28 PM Description: Unexpected error java.lang.NullPointerException: Unexpected error at net.minecraft.client.gui.Gui.drawCenteredString(Gui.java:127) at com.avonia.mod.util.handlers.RadarHandler.onRenderPre(RadarHandler.java:64) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_16_RadarHandler_onRenderPre_Pre.invoke(.dynamic) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) at net.minecraftforge.client.GuiIngameForge.pre(GuiIngameForge.java:910) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:119) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1151) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1209) at net.minecraft.client.Minecraft.run(Minecraft.java:442) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:25) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Client thread Stacktrace: at net.minecraft.client.gui.Gui.drawCenteredString(Gui.java:127) at com.avonia.mod.util.handlers.RadarHandler.onRenderPre(RadarHandler.java:64) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_16_RadarHandler_onRenderPre_Pre.invoke(.dynamic) at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) at net.minecraftforge.client.GuiIngameForge.pre(GuiIngameForge.java:910) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:119) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityPlayerSP['Player997'/494, l='MpServer', x=8.50, y=65.00, z=8.50]] Chunk stats: MultiplayerChunkCache: 0, 0 Level seed: 0 Level generator: ID 00 - default, ver 1. Features enabled: false Level generator options: Level spawn location: World: (8,64,8), Chunk: (at 8,4,8 in 0,0; contains blocks 0,0,0 to 15,255,15), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 0 game time, 0 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 1 total; [EntityPlayerSP['Player997'/494, l='MpServer', x=8.50, y=65.00, z=8.50]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:461) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2889) at net.minecraft.client.Minecraft.run(Minecraft.java:471) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:25) -- System Details -- Details: Minecraft Version: 1.12.2 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_181, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 701521864 bytes (669 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP 9.42 Powered by Forge 14.23.5.2847 5 mods loaded, 5 mods active States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored | State | ID | Version | Source | Signature | |:------ |:--------- |:------------ |:-------------------------------- |:--------- | | LCHIJA | minecraft | 1.12.2 | minecraft.jar | None | | LCHIJA | mcp | 9.42 | minecraft.jar | None | | LCHIJA | FML | 8.0.99.99 | forgeSrc-1.12.2-14.23.5.2847.jar | None | | LCHIJA | forge | 14.23.5.2847 | forgeSrc-1.12.2-14.23.5.2847.jar | None | | LCHIJA | avonia | 1.0.0 | bin | None | Loaded coremods (and transformers): GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 445.75' Renderer: 'GeForce GTX 1050/PCIe/SSE2' Launched Version: 1.12.2 LWJGL: 2.9.4 OpenGL: GeForce GTX 1050/PCIe/SSE2 GL version 4.6.0 NVIDIA 445.75, NVIDIA Corporation GL Caps: Using GL 1.3 multitexturing. Using GL 1.3 texture combiners. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Shaders are available because OpenGL 2.1 is supported. VBOs are available because OpenGL 1.5 is supported. Using VBOs: Yes Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: Current Language: English (US) Profiler Position: N/A (disabled) CPU: 16x AMD Ryzen 7 1700 Eight-Core Processor
-
il faut que tu donne une valeur de base à amountType
-
C’est le cas et on ne peut pas avoir de NPE sur un int de toute façon.
C’est fontRender qui est null.
à mon avis au moment où ta classe est utilisé,this.mc.fontRenderer
vaut encore null.Fais comme ça :
drawCenteredString(this.mc.fontRenderer, this.amountTiles + "%", 0,100, 11);
-
@robin4002 merci !
Juste une question : Comment je peux faire pour afficher un item sur l’écran (moi un coffre) dans mon gui ?
Je crois y’a un truc genre ItemRenderer.Merci
-
@robin4002 par contre quand je fais le code pour que le gui s’affiche uniquement lorsque je tiens l’item, plus rien n’est affiché.
if(event.getType() == RenderGameOverlayEvent.ElementType.EXPERIENCE && mc.player.getHeldItem(EnumHand.MAIN_HAND) == new ItemStack(ItemInit.radar)/*&& ItemRadar.isUsed == 1*/) { //code }
-
Parcequ’il ne faut pas comparer des itemstack avec ==
L’opérateur==
vérifies uniquement le contenu dans le stack (je parle l’espace mémoire, pas de l’itemstack).
Donc ça fonctionne très bien pour les types primitifs (int, boolean, float, double, short, long, char) mais sur les objets, cela compare uniquement s’il s’agit de la même référence.
En conséquenceun objet == new Quelquechose
sera toujours false, car ce sont forcément deux références différentes.
== ne renvoie que vrai avec des objets s’il s’agit de la même référence. Typiquement dans Minecraft les blocs ou items sont des singletons, donc on peut les comparer avec un ==.Pour comparer le contenu des objets, il existe souvent une méthode .equals.
Par exemplestack.equals(new ItemStack(ItemInit.radar))
. Mais cette méthode compare de façon profonde le contenu, ce qui nécessite plus de perf et surtout va aussi vérifier la quantité de l’itemstack, le tag NBT, etc. Donc par exemple ici, si stack est enchanté ou si on a 2 item en main au lieu d’un, ça ne fonctionne plus.Pour ce cas (et la majorité des comparaisons d’item / bloc dans le jeu), il faut comparer l’item qui se trouve dans l’itemstack :
mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ItemInit.radar
-
En gros faut oublier
==
et mettre que des.equals()
? -
Je pense que tu n’as pas bien lu mon message.
J’ai dit que cela dépend de ce qu’on veut faire. -
@robin4002 a dit dans Uncmlaim finder en 1.12.2 :
Pour ce cas (et la majorité d
Merci ! Ca marche !
Dernier soucis : je veux ajouter une durabilité mais il se casse instantanément…package com.avonia.mod.init.objects; import com.avonia.mod.Main; import com.avonia.mod.init.ItemInit; import com.avonia.mod.util.IHasModel; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ItemRadar extends Item implements IHasModel { private static EntityPlayer player; public static int durabilité = 90*20*60*60; public ItemRadar(String name) { setUnlocalizedName(name); setRegistryName(name); setCreativeTab(CreativeTabs.COMBAT); setMaxDamage(durabilité); setMaxStackSize(1); ItemInit.ITEMS.add(this); } @Override public void registerModels() { Main.proxy.registerItemRederer(this, 0); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { player = (EntityPlayer)entityIn; if(player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemRadar) { for(int dura = 90*20*60*60; dura >= 0; dura--) { stack.damageItem(1, player); } } super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); } }
Encore merci et désolé du dérangement.
-
Retires la double for à la ligne 47, elle n’a rien à faire là.
Si tu bocule sur toute la durabilité c’est normal de tomber à 0. -
@robin4002 merci je vais tester. En plus c’est bête car onUpdate fais deja une update par tick
-
pas le temps de répondre, trop rapide @robin4002 …
-
@robin4002 désolé de te déranger encore mais j’ai un dernier soucis :
je veux créer une durabilité (ce qui est fait ) et l’afficher sous formath:m:s
mais je ne sais pas exactement comment. -
-
@robin4002 merci. Mais juste, je sais pas si c’est moi qui suis bête mais je n’arrive pas à récupérer la durabilité…
Mon code:
package com.avonia.mod.util.handlers; import java.time.Duration; import java.time.LocalTime; import org.jline.utils.PumpReader; import org.lwjgl.opengl.GL11; import com.avonia.mod.init.ItemInit; import com.avonia.mod.init.objects.ItemRadar; import com.avonia.mod.util.Reference; import net.minecraft.block.BlockDoublePlant.EnumPlantType; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.block.model.ModelManager; import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.IResourceManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class RadarHandler extends Gui { private static Minecraft mc; public static int amountTiles = 0; public static int damage = ItemRadar.maxD - (ItemRadar.maxD - ItemRadar.itemD); ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer(); FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() == RenderGameOverlayEvent.ElementType.HELMET && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ItemInit.radar /*&& ItemRadar.isUsed == 1*/) { mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); amountTiles = mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 0).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ - 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX - 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); drawCenteredString(this.mc.fontRenderer, this.amountTiles + "%", 23, 50, -1); drawCenteredString(this.mc.fontRenderer, this.formatDuration(), 23, 58, -1); event.setCanceled(true); } } public static String formatDuration() { Duration duration = Duration.ofSeconds(damage / 20); long seconds = duration.getSeconds(); long absSeconds = Math.abs(seconds); String positive = String.format( "%d:%02d:%02d", absSeconds / 3600, (absSeconds % 3600) / 60, absSeconds % 60); return seconds < 0 ? "-" + positive : positive; } }
package com.avonia.mod.init.objects; import com.avonia.mod.Main; import com.avonia.mod.init.ItemInit; import com.avonia.mod.util.IHasModel; import net.minecraft.client.Minecraft; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import scala.deprecated; public class ItemRadar extends Item implements IHasModel { private static EntityPlayer player; public static int durabilité = 90*20*60; public static int maxD = 0; public static int itemD = 0; public ItemRadar(String name) { setUnlocalizedName(name); setRegistryName(name); setCreativeTab(CreativeTabs.COMBAT); setMaxDamage(durabilité); setMaxStackSize(1); ItemInit.ITEMS.add(this); } @Override public void registerModels() { Main.proxy.registerItemRederer(this, 0); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { player = (EntityPlayer)entityIn; stack = player.getHeldItem(EnumHand.MAIN_HAND); if(player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemRadar) { if(durabilité >= 0) { durabilité --; stack.damageItem(1, player); itemD = stack.getItemDamage(); maxD = stack.getMaxDamage(); } } super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); } }
-
en utilisant la fonction getItemDamage() de ton itemstack.
-
Quand je fais ca :
package com.avonia.mod.util.handlers; import java.time.Duration; import java.time.LocalTime; import org.jline.utils.PumpReader; import org.lwjgl.opengl.GL11; import com.avonia.mod.init.ItemInit; import com.avonia.mod.init.objects.ItemRadar; import com.avonia.mod.util.Reference; import net.minecraft.block.BlockDoublePlant.EnumPlantType; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.RenderItem; import net.minecraft.client.renderer.block.model.ModelManager; import net.minecraft.client.renderer.color.ItemColors; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.IResourceManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class RadarHandler extends Gui { private static Minecraft mc; public static int amountTiles = 0; public static ItemStack stack = mc.player.getHeldItem(EnumHand.MAIN_HAND); public static int maxD = stack.getMaxDamage(), itemD = stack.getItemDamage(); public static int damage = maxD - (maxD - itemD); ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer(); FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() == RenderGameOverlayEvent.ElementType.HELMET && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ItemInit.radar /*&& ItemRadar.isUsed == 1*/) { mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); amountTiles = mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 0).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ - 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX - 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); drawCenteredString(this.mc.fontRenderer, this.amountTiles + "%", 23, 50, -1); drawCenteredString(this.mc.fontRenderer, this.formatDuration(), 23, 58, -1); event.setCanceled(true); } } public static String formatDuration() { Duration duration = Duration.ofSeconds(damage / 20); long seconds = duration.getSeconds(); long absSeconds = Math.abs(seconds); String positive = String.format( "%d:%02d:%02d", absSeconds / 3600, (absSeconds % 3600) / 60, absSeconds % 60); return seconds < 0 ? "-" + positive : positive; } }
Ca crash…
-
Bon, après de lonnnngues recherches voici le code de l’unclaim finder en 1.12.2 avec 1h30 de durabilité :
Classe de l’item :public class ItemRadar extends Item implements IHasModel { private static EntityPlayer player; public static int durabilité = 90*20*60; public ItemRadar(String name) { setUnlocalizedName(name); setRegistryName(name); setCreativeTab(CreativeTabs.COMBAT); setMaxDamage(durabilité); setMaxStackSize(1); ItemInit.ITEMS.add(this); } @Override public void registerModels() { Main.proxy.registerItemRederer(this, 0); } @Override public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) { player = (EntityPlayer)entityIn; stack = player.getHeldItem(EnumHand.MAIN_HAND); if(player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ItemRadar) { if(durabilité >= 0) { durabilité --; stack.damageItem(1, player); } } super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected); } }
Classe du GUI :
public class RadarHandler extends Gui { private static Minecraft mc; public static int amountTiles = 0; ItemRenderer itemRenderer = Minecraft.getMinecraft().getItemRenderer(); FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() == RenderGameOverlayEvent.ElementType.HELMET && mc.player.getHeldItem(EnumHand.MAIN_HAND).getItem() == ItemInit.radar /*&& ItemRadar.isUsed == 1*/) { mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); amountTiles = mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 0).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ + 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 0, mc.player.chunkCoordZ - 1).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX + 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); amountTiles = amountTiles + mc.world.getChunkFromChunkCoords(mc.player.chunkCoordX - 1, mc.player.chunkCoordZ).getTileEntityMap().values().size(); drawCenteredString(this.mc.fontRenderer, this.amountTiles + "%", 23, 39, -1); drawCenteredString(this.mc.fontRenderer, this.formatDuration(), 23, 48, -1); event.setCanceled(true); } } public static String formatDuration() { ItemStack stack = mc.player.getHeldItem(EnumHand.MAIN_HAND); int maxD = stack.getMaxDamage(); int itemD = stack.getItemDamage(); int damage = maxD - itemD; Duration duration = Duration.ofSeconds(damage / 20); long seconds = duration.getSeconds(); long absSeconds = Math.abs(seconds); String positive = String.format( "%d:%02d:%02d", absSeconds / 3600, (absSeconds % 3600) / 60, absSeconds % 60); return seconds < 0 ? "-" + positive : positive; } }
Client proxy :
public class ClientProxy extends CommonProxy { @Override public void registerItemRederer(Item item, int meta) { ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), "inventory")); MinecraftForge.EVENT_BUS.register(new RadarHandler()); } }
Bonne journée et merci à @DailyCraft et @robin4002 pour leur aide !
-
A tu fait un mod que je peux telecharger avec ? car j’en aurai besoin pour 1 PvP fac