Résolu Uncmlaim finder en 1.12.2
-
Bonjour.
J’ai déjà fait un unclaim finder sur minecraft 1.7.10 mais j’ignore comment faire en 1.12.2.
je n’ai vu aucun topic à ce sujet donc je vous demande de bien vouloir m’aider.CDLT, DrasticLp
-
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 !
-
En fait tu fais le mod “Le mod qui recopie pala” ?
Mais sinon Il faut que tu créer un gui puis tu récupère le nombre de tile entity que tu affiche dans le gui
-
@DailyCraft je veux bien mais je ne sais pas comment trouver : le rayon d’action, les nombre de TE.
Merci. -
up ?
-
C’mon y’en a des dizaines de sujets comme celui ci sur le forum et avec du code en +
-
@Plaigon je sais mais y’en a pas en 1.12.2 qui marche.
-
@Plaigon voici mon code : quand je lance ca crash (je crois a cause du EnumHand hand)
package com.avonia.mod.util.handlers; 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; private String show; private EnumHand hand; FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.show = "0%"; this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() == RenderGameOverlayEvent.ElementType.EXPERIENCE) { if(isHoldingRadar(hand)) { mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); int amountTiles = this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ + 0).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ + 1).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ - 1).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 1, this.mc.player.chunkCoordZ).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX - 1, this.mc.player.chunkCoordZ).getTileEntityMap().values().size(); } event.setCanceled(true); } } public void drawString(FontRenderer par1FontRenderer, String par2Str, int par3, int par4, int par5) { par1FontRenderer.drawStringWithShadow(par2Str, par3, par4, par5); } private static boolean isHoldingRadar(EnumHand hand) { return Minecraft.getMinecraft().player.getHeldItem(hand) == new ItemStack(ItemInit.radar); } }
-
Ta variable RadarHandler#hand est null. SI tu veux vérifier la présence de l’item radar dans la main droite alors c’est EnumHand.MAIN_HAND, sinon pour la main gauche c’est EnumHand.OFF_HAND
-
Ce message a été supprimé ! -
@Plaigon … Ca ne crash plus mais ca ne s’affiche pas.
public class RadarHandler extends Gui { private Minecraft mc; private String show; FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.show = "0%"; this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() == RenderGameOverlayEvent.ElementType.EXPERIENCE) { if(ItemRadar.isUsed && mc.world.isRemote && mc.player.getHeldItem(EnumHand.MAIN_HAND) == new ItemStack(ItemInit.radar)) { mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); int amountTiles = this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ + 0).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ + 1).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ - 1).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 1, this.mc.player.chunkCoordZ).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX - 1, this.mc.player.chunkCoordZ).getTileEntityMap().values().size(); } event.setCanceled(true); } } public void drawString(FontRenderer par1FontRenderer, String par2Str, int par3, int par4, int par5) { par1FontRenderer.drawStringWithShadow(par2Str, par3, par4, par5); } }
-
Si tu veux afficher un overlay il faut vérifier le type rendu à l’écran lors de l’event, de mémoire ça devrait être HELMET.
Regarde comment la citrouille affiche son overlay, t’auras juste à copy paste pour ton cas à toi. -
@Plaigon avec EXPERIENCE ca allait mais c’est uniquement quand je rajoute la condition avec l’item dans la main que ca ne s’affiche plus. (jai testé avant avec HELMET
-
Surement ItemRadar.isUsed qui coince alors. Tu peux debug et voir l’état de tes variables, tu gagneras en efficacité.
D’ailleurs pour éviter tout problème de valeur commune, n’utilise pas de variables static dans les classes du type Item, Block, Entity, etc… mais plutôt les NBTTag -
@Plaigon le isUsed pose problème mais même sans ca ne vas pas
-
Si tu ne veux pas debug, pose des println et t’auras la réponse.
-
@Plaigon bah j’ai fait ca :
package com.avonia.mod.util.handlers; 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; private String show; FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.show = "0%"; this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() == RenderGameOverlayEvent.ElementType.HELMET) { if(mc.world.isRemote && mc.player.getHeldItem(EnumHand.MAIN_HAND) == new ItemStack(ItemInit.radar)) { mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); int amountTiles = this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ + 0).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ + 1).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 0, this.mc.player.chunkCoordZ - 1).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX + 1, this.mc.player.chunkCoordZ).getTileEntityMap().values().size(); amountTiles = amountTiles + this.mc.world.getChunkFromChunkCoords(this.mc.player.chunkCoordX - 1, this.mc.player.chunkCoordZ).getTileEntityMap().values().size(); System.out.println("affiché"); } event.setCanceled(true); } } }
Mais j’ai tjrs rien dans la console.
-
En général quand je draw un overlay, j’utilise des attributs OpenGL avant et après, comme le fait l’overlay de la citrouille. De + si ta texture a une résolution de 32*32 tu peux simplement utiliser Gui#drawTexturedModalRect je pense.
-
@Plaigon a dit dans Uncmlaim finder en 1.12.2 :
utiliser
J’ai juste modif pour la taille parce que sinon ca dupliquait la texture.
-
@Plaigon mais j’ai un autre prblm : quand j’essaie de dessinner un string, ca crash/
public class RadarHandler extends Gui { private Minecraft mc; private String show; FontRenderer fontRender; final ResourceLocation bg = new ResourceLocation(Reference.MODID + ":textures/items/radar.png"); public RadarHandler() { this.mc = Minecraft.getMinecraft(); this.show = "0%"; this.fontRender = this.mc.fontRenderer; } @SideOnly(Side.CLIENT) @SubscribeEvent public void onRenderPre(RenderGameOverlayEvent.Pre event) { if(event.getType() == RenderGameOverlayEvent.ElementType.HELMET) { /*if(mc.world.isRemote && mc.player.getHeldItem(EnumHand.MAIN_HAND) == new ItemStack(ItemInit.radar)) {*/ mc.getTextureManager().bindTexture(this.bg); drawModalRectWithCustomSizedTexture(5,5,0,0,32,32,32,32); int 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, amountTiles + "%", 0,100, 11); System.out.println("affiché"); //} event.setCanceled(true); } } }
Crash report :
---- Minecraft Crash Report ---- // Who set us up the TNT? Time: 4/13/20 4:10 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:66) 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.renderHelmet(GuiIngameForge.java:271) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:135) 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:66) 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.renderHelmet(GuiIngameForge.java:271) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:135) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityPlayerSP['Player996'/584, 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['Player996'/584, 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: 667795368 bytes (636 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 ```
-