Non résolu Erreur lors de l'annulation d'une touche
-
Bonjour,
Je cherche pour l’exemple ici à empêcher le joueur d’avancer si jamais il appuie sur la touche correspondante. Cependant quand la condition est réunie et que j’appuie sur le touche en question le jeu crash.Comment cela se fait-il ?
:::
@SideOnly(Side.CLIENT) @SubscribeEvent public void onKeyEvent(InputEvent.KeyInputEvent event) { if (Minecraft.getMinecraft().gameSettings.keyBindForward.isPressed()) { if(PacketThirdPerson.Toggle == true) { event.setCanceled(true); } } }
:::
Merci d’avance
-
Salut, tu crash tout simplement car tu tentes de cancel un event qui n’est pas cancelable, comme t’auras pu le voir sur cette liste:
https://www.minecraftforgefrance.fr/forge-events.phpLa solution ici sera de set ses motions à 0 (client side), ou alors de coder ça uniquement server side avec un attribute movementSpeed mis à 0D.
-
@‘Plaigon’:
Salut, tu crash tout simplement car tu tentes de cancel un event qui n’est pas cancelable, comme t’auras pu le voir sur cette liste:
https://www.minecraftforgefrance.fr/forge-events.phpLa solution ici sera de set ses motions à 0 (client side), ou alors de coder ça uniquement server side avec un attribute movementSpeed mis à 0D.
D’accord merci. Comment set les motions à 0 ? Parce que j’y ai pensé en voyant l’erreur comme quoi c’était pas cancellable dans les logs mais justement je sais pas comment faire…
EDIT : J’ai fait cela :
@SideOnly(Side.CLIENT) @SubscribeEvent public void onKeyEvent(InputEvent.KeyInputEvent event) { if (Minecraft.getMinecraft().gameSettings.keyBindForward.isPressed()) { if(PacketThirdPerson.Toggle == true) { mc.thePlayer.motionZ = 0; mc.thePlayer.motionY = 0; mc.thePlayer.motionX = 0; } } }
J’ai cette erreur dans les logs : “Unexpected error”
-
Les motions (ou mouvements, en français), sont représentés par 3 variables pour chaque axe, inscrits dans la classe net.minecraft.entity.Entity. Donc si tu as une instance de ton joueur, tu pourras faire ceci:
player.motionX = 0D; player.motionY = 0D; player.motionZ = 0D;
-
@‘Plaigon’:
Les motions (ou mouvements, en français), sont représentés par 3 variables pour chaque axe, inscrits dans la classe net.minecraft.entity.Entity. Donc si tu as une instance de ton joueur, tu pourras faire ceci:
player.motionX = 0D; player.motionY = 0D; player.motionZ = 0D;
Ok donc j’ai fais ça comme ça :
private Minecraft mc; @SideOnly(Side.CLIENT) @SubscribeEvent public void onKeyEvent(InputEvent.KeyInputEvent event) { if (Minecraft.getMinecraft().gameSettings.keyBindForward.isPressed()) { if(PacketThirdPerson.Toggle == true) { mc.thePlayer.motionX = 0D; mc.thePlayer.motionY = 0D; mc.thePlayer.motionZ = 0D; } } }
Et toujours la même erreur quand je presse la touche : “Unexpected error”
-
C’est quoi ça: PacketThirdPerson.Toggle ? On peut en savoir + ?
File le crash, ça aide toujours -
@‘Plaigon’:
C’est quoi ça: PacketThirdPerson.Toggle ? On peut en savoir + ?
File le crash, ça aide toujours:::
–-- Minecraft Crash Report ---- // Don't be sad, have a hug! <3 Time: 13/02/18 18:39 Description: Unexpected error java.lang.NullPointerException: Unexpected error at fr.gtalife.overlay.HUDRender.onKeyEvent(HUDRender.java:70) at cpw.mods.fml.common.eventhandler.ASMEventHandler_17_HUDRender_onKeyEvent_KeyInputEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1964) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) at net.minecraft.client.Minecraft.run(Minecraft.java:962) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at fr.gtalife.overlay.HUDRender.onKeyEvent(HUDRender.java:70) at cpw.mods.fml.common.eventhandler.ASMEventHandler_17_HUDRender_onKeyEvent_KeyInputEvent.invoke(.dynamic) at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54) at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140) at cpw.mods.fml.common.FMLCommonHandler.fireKeyInput(FMLCommonHandler.java:540) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['Player736'/220, l='MpServer', x=220,87, y=102,62, z=179,40]] Chunk stats: MultiplayerChunkCache: 520, 520 Level seed: 0 Level generator: ID 00 - default, ver 1\. Features enabled: false Level generator options: Level spawn location: World: (240,64,208), Chunk: (at 0,4,0 in 15,13; contains blocks 240,0,208 to 255,255,223), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Level time: 85793 game time, 12181 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: survival (ID 0). Hardcore: false. Cheats: false Forced entities: 53 total; [EntityChicken['Poule'/128, l='MpServer', x=287,47, y=70,00, z=166,31], EntityChicken['Poule'/129, l='MpServer', x=276,47, y=83,00, z=184,31], EntityChicken['Poule'/132, l='MpServer', x=299,47, y=84,00, z=251,94], EntityChicken['Poule'/32, l='MpServer', x=143,44, y=87,00, z=123,53], EntityChicken['Poule'/35, l='MpServer', x=152,47, y=88,00, z=157,63], EntityChicken['Poule'/36, l='MpServer', x=155,56, y=80,00, z=210,47], EntityChicken['Poule'/37, l='MpServer', x=152,69, y=76,00, z=226,47], EntityBat['Chauve-souris'/38, l='MpServer', x=157,51, y=37,91, z=237,02], EntityBat['Chauve-souris'/39, l='MpServer', x=156,86, y=38,24, z=242,46], EntityChicken['Poule'/40, l='MpServer', x=147,53, y=77,00, z=257,47], EntityChicken['Poule'/45, l='MpServer', x=163,28, y=83,00, z=186,28], EntityChicken['Poule'/46, l='MpServer', x=152,56, y=80,00, z=198,56], EntityBat['Chauve-souris'/47, l='MpServer', x=162,75, y=41,10, z=225,72], EntityBat['Chauve-souris'/48, l='MpServer', x=162,25, y=40,10, z=240,25], EntityBat['Chauve-souris'/49, l='MpServer', x=177,86, y=35,26, z=243,35], EntityChicken['Poule'/50, l='MpServer', x=165,12, y=77,00, z=241,27], EntityChicken['Poule'/51, l='MpServer', x=167,53, y=78,00, z=244,38], EntityChicken['Poule'/59, l='MpServer', x=179,47, y=79,00, z=222,53], EntityBat['Chauve-souris'/60, l='MpServer', x=194,50, y=34,00, z=249,82], EntityChicken['Poule'/61, l='MpServer', x=188,06, y=85,00, z=256,75], EntityBat['Chauve-souris'/64, l='MpServer', x=194,51, y=12,09, z=166,51], EntityCow['Vache'/75, l='MpServer', x=220,38, y=78,00, z=120,59], EntityChicken['Poule'/87, l='MpServer', x=231,19, y=75,00, z=159,34], EntityChicken['Poule'/88, l='MpServer', x=239,38, y=72,00, z=204,66], EntityBat['Chauve-souris'/89, l='MpServer', x=234,25, y=13,10, z=250,91], EntityBat['Chauve-souris'/90, l='MpServer', x=233,25, y=13,10, z=250,75], EntityBat['Chauve-souris'/91, l='MpServer', x=223,37, y=12,00, z=259,41], EntitySheep['Mouton'/98, l='MpServer', x=249,19, y=69,00, z=108,13], EntityChicken['Poule'/99, l='MpServer', x=250,47, y=69,00, z=106,59], EntitySheep['Mouton'/100, l='MpServer', x=249,76, y=69,00, z=121,59], EntityBat['Chauve-souris'/101, l='MpServer', x=246,38, y=29,10, z=134,75], EntityChicken['Poule'/102, l='MpServer', x=247,53, y=64,00, z=136,44], EntityChicken['Poule'/103, l='MpServer', x=249,47, y=68,00, z=165,53], EntityChicken['Poule'/104, l='MpServer', x=250,47, y=73,00, z=218,53], EntityChicken['Poule'/105, l='MpServer', x=244,78, y=88,00, z=223,34], EntitySheep['Mouton'/108, l='MpServer', x=256,75, y=68,00, z=125,56], EntitySheep['Mouton'/109, l='MpServer', x=255,69, y=69,00, z=118,02], EntityChicken['Poule'/110, l='MpServer', x=266,66, y=57,00, z=138,56], EntitySheep['Mouton'/111, l='MpServer', x=265,03, y=68,00, z=127,09], EntityChicken['Poule'/112, l='MpServer', x=276,13, y=67,45, z=131,79], EntitySheep['Mouton'/113, l='MpServer', x=259,19, y=69,00, z=158,84], EntityChicken['Poule'/114, l='MpServer', x=255,41, y=69,00, z=169,79], EntityChicken['Poule'/115, l='MpServer', x=261,44, y=69,00, z=183,38], EntityBat['Chauve-souris'/116, l='MpServer', x=259,16, y=42,10, z=226,91], EntitySheep['Mouton'/120, l='MpServer', x=286,03, y=67,00, z=100,06], EntityChicken['Poule'/121, l='MpServer', x=276,53, y=67,00, z=108,53], EntitySheep['Mouton'/122, l='MpServer', x=274,03, y=67,00, z=111,94], EntitySheep['Mouton'/123, l='MpServer', x=279,16, y=68,00, z=140,22], EntityClientPlayerMP['Player736'/220, l='MpServer', x=220,87, y=102,62, z=179,40], EntityChicken['Poule'/124, l='MpServer', x=284,53, y=70,00, z=130,63], EntityChicken['Poule'/125, l='MpServer', x=272,47, y=68,00, z=148,59], EntityChicken['Poule'/126, l='MpServer', x=282,38, y=68,00, z=150,41], EntityBat['Chauve-souris'/127, l='MpServer', x=271,29, y=27,94, z=170,65]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:415) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2566) at net.minecraft.client.Minecraft.run(Minecraft.java:991) at net.minecraft.client.main.Main.main(Main.java:164) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source) – System Details -- Details: Minecraft Version: 1.7.10 Operating System: Windows 10 (amd64) version 10.0 Java Version: 1.8.0_151, Oracle Corporation Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 733115816 bytes (699 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94 FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1558 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 UCHIJAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) UCHIJAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) UCHIJAAAA Forge{10.13.4.1558} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1558-1.7.10.jar) UCHIJAAAA gtalifemod{1.0} [gtalifemod] (bin) UCHIJAAAA iCraft{@VERSION@} [iCraft] (bin) GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 388.71' Renderer: 'GeForce GTX 1070/PCIe/SSE2' Launched Version: 1.7.10 LWJGL: 2.9.1 OpenGL: GeForce GTX 1070/PCIe/SSE2 GL version 4.6.0 NVIDIA 388.71, NVIDIA Corporation GL Caps: Using GL 1.3 multitexturing. Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported. Anisotropic filtering is supported and maximum anisotropy is 16. Shaders are available because OpenGL 2.1 is supported. Is Modded: Definitely; Client brand changed to 'fml,forge' Type: Client (map_client.txt) Resource Packs: [GTALife Texture Pack v1.0.zip] Current Language: Français (France) Profiler Position: N/A (disabled) Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used Anisotropic Filtering: Off (1)
:::
Pour le PacketThirdPerson.Toggle c’est une condition que j’ai ajoutée quand le mode 3ème personne est activé chez le joueur.
Cependant, ça n’a pas d’incidence car même si j’enlève cette ligne j’ai la même erreur. -
Possible d’avoir ta classe HUDRender ? Et pour check ceci, nullement besoin de ton boolean, minecraft a déjà une variable pour: Minecraft.getMinecraft().gameSettings.thirdPersonView
-
@‘Plaigon’:
Possible d’avoir ta classe HUDRender ? Et pour check ceci, nullement besoin de ton boolean, minecraft a déjà une variable pour: Minecraft.getMinecraft().gameSettings.thirdPersonView
Oui je remplacerai ma variable par Minecraft.getMinecraft().gameSettings.thirdPersonView.
En ce qui concerne ma classe il n’y a rien d’autre à l’intérieur à part le code que j’ai envoyé pour le moment
-
Le crash indique cette ligne-là:
fr.gtalife.overlay.HUDRender.onKeyEvent(HUDRender.java:70)Donc il serait intéressant soit de nous la remonter, soit de nous filer l’entièreté de ta classe.
-
@‘Plaigon’:
Le crash indique cette ligne-là:
fr.gtalife.overlay.HUDRender.onKeyEvent(HUDRender.java:70)Donc il serait intéressant soit de nous la remonter, soit de nous filer l’entièreté de ta classe.
Ah oui pardon.
J’ai enlevé la variable c’est déjà ça, et la ligne 70 correspond à “mc.thePlayer.motionX = 0D;”@SideOnly(Side.CLIENT) @SubscribeEvent public void onKeyEvent(InputEvent.KeyInputEvent event) { if (Minecraft.getMinecraft().gameSettings.keyBindForward.isPressed()) { if(Minecraft.getMinecraft().gameSettings.thirdPersonView == 2) { mc.thePlayer.motionX = 0D; mc.thePlayer.motionY = 0D; mc.thePlayer.motionZ = 0D; } } }
-
Sûrement car ta variable mc est null, utilise plutôt Minecraft.getMinecraft().thePlayer
-
@‘Plaigon’:
Sûrement car ta variable mc est null, utilise plutôt Minecraft.getMinecraft().thePlayer
J’ai déjà essayé, même problème
-
Bon, file ta classe entière + ton crash report le + récent, je vais tester de mon côté
-
@‘Plaigon’:
Bon, file ta classe entière + ton crash report le + récent, je vais tester de mon côté
C’est fait en MP
-
Je n’aurai pas le temps de look ce soir, tu pourrais l’envoyer ici, + de membres t’aideront ainsi