Résolu Problème avec les events.
-
Bonjour,
J’ai suivi un tutoriel sur youtube expliquent comment créer un système de mana.
Le problème est que la vidéos date de mai 2013 donc de la 1.5 voir de la 1.4, du coup même si aucune erreur n’est affiché sur éclipse le jeu ne traite pas l’information.J’ai essayé de modifié le code en le recoupant avec des infos plus récentes mais la le jeux crash complètement.
Class Du joueur:
package noob.common; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class CustomPlayer extends Entity implements IExtendedEntityProperties { private int mana; public CustomPlayer(World par1World) { super(par1World); } @Override public void saveNBTData(NBTTagCompound compound) { compound.setInteger("Mana level", this.mana); } @Override public void loadNBTData(NBTTagCompound compound) { this.mana = compound.getInteger("Mana level"); } @Override public void init(Entity entity, World world) { this.mana = 0; } @Override protected void entityInit() { // TODO Auto-generated method stub } @Override protected void readEntityFromNBT(NBTTagCompound nbttagcompound) { // TODO Auto-generated method stub } @Override protected void writeEntityToNBT(NBTTagCompound nbttagcompound) { // TODO Auto-generated method stub } public int getMana() { return this.mana; } public void setMana(int lvl) { this.mana = lvl; } }
Class de l’event:
package noob.common; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.IExtendedEntityProperties; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.event.entity.living.LivingDeathEvent; public class AddCustomPlayerProperties { @ForgeSubscribe public void init(EntityConstructing event) { if (event.entity instanceof EntityPlayer) { event.entity.registerExtendedProperties("Custom Player", new CustomPlayer(event.entity.worldObj)); } } @ForgeSubscribe public void death(LivingDeathEvent event) { Entity source = event.source.getSourceOfDamage(); if (source != null) { if (event.entity instanceof EntityPlayer) { IExtendedEntityProperties prop = event.entity.getExtendedProperties("Custom Player"); int mana = ((CustomPlayer)prop).getMana()+1; System.out.println("Mana de "+source.getEntityName()+"= "+mana); ((CustomPlayer)prop).setMana(mana); } } } }
Sachant que j’ai bien mis cette ligne là: ```java
MinecraftForge.EVENT_BUS.register(new AddCustomPlayerProperties());Merci d'avance.
-
Mauvaise section
-
Gugu42 à raison, de plus j’ai suivi le même tutoriel, et il est parfaitement fonctionnel en 1.6
-
C’est encore fonctionnel en 1.6, je pense que c’est un problème avec le tag nbt, enlève l’espace.
Même chose pour le registerExtendedProperties évite les espaces dans les string. -
J’ai enlevé les espaces mais sa ne change rien.
-
Envoie le crash report.
-
Il n’y a pas de crash justement c’est ça que je trouve bizarre.
Rien de particulier ne s’affiche dans la console.2014-01-02 19:39:02 [Infos] [Minecraft-Server] Preparing start region for level 0 2014-01-02 19:39:04 [Infos] [Minecraft-Server] Preparing spawn area: 25% 2014-01-02 19:39:07 [Infos] [Minecraft-Server] Preparing spawn area: 72% 2014-01-02 19:39:08 [Infos] [STDOUT] loading single player 2014-01-02 19:39:08 [Infos] [Minecraft-Server] Player505[/127.0.0.1:0] logged in with entity id 25 at (-732.1298898366373, 4.0, 650.2893601972046) 2014-01-02 19:39:08 [Infos] [Minecraft-Server] Player505 joined the game 2014-01-02 19:39:09 [Infos] [STDOUT] Setting up custom skins 2014-01-02 19:39:16 [Infos] [Minecraft-Server] Saving and pausing game… 2014-01-02 19:39:16 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/Overworld 2014-01-02 19:39:17 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/Nether 2014-01-02 19:39:17 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/The End 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving and pausing game… 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/Overworld 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/Nether 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/The End 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Stopping server 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving players 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Player505 left the game 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving worlds 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/Overworld 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/Nether 2014-01-02 19:39:49 [Infos] [Minecraft-Server] Saving chunks for level 'Mod terracraft'/The End 2014-01-02 19:39:50 [Infos] [ForgeModLoader] Unloading dimension 0 2014-01-02 19:39:50 [Infos] [ForgeModLoader] Unloading dimension -1 2014-01-02 19:39:50 [Infos] [ForgeModLoader] Unloading dimension 1 2014-01-02 19:39:52 [Infos] [Minecraft-Client] Stopping! 2014-01-02 19:39:52 [Infos] [STDOUT] 2014-01-02 19:39:52 [Infos] [STDOUT] SoundSystem shutting down… 2014-01-02 19:39:53 [Infos] [STDOUT] Author: Paul Lamb, www.paulscode.com 2014-01-02 19:39:53 [Infos] [STDOUT]
J’ai tué un mouton entre les 2 pauses de jeu.
-
Ton event death est foireux.
@ForgeSubscribe public void death(LivingDeathEvent event) { Entity source = event.source.getEntity(); if (source != null && source instanceof EntityPlayer) { IExtendedEntityProperties prop = event.entity.getExtendedProperties("Custom Player"); int mana = ((CustomPlayer)prop).getMana()+1; System.out.println("Mana de "+source.getEntityName()+"= "+mana); ((CustomPlayer)prop).setMana(mana); } }
-
Maintenant le jeu crash:
–-- Minecraft Crash Report ---- // Why is it breaking :( Time: 02/01/14 20:52 Description: Ticking memory connection java.lang.NullPointerException at noob.common.AddCustomPlayerProperties.death(AddCustomPlayerProperties.java:29) at net.minecraftforge.event.ASMEventHandler_4_AddCustomPlayerProperties_death_LivingDeathEvent.invoke(.dynamic) at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39) at net.minecraftforge.event.EventBus.post(EventBus.java:108) at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:342) at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:988) at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:951) at net.minecraft.entity.passive.EntityAnimal.attackEntityFrom(EntityAnimal.java:206) at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1367) at net.minecraft.network.NetServerHandler.handleUseEntity(NetServerHandler.java:854) at net.minecraft.network.packet.Packet7UseEntity.processPacket(Packet7UseEntity.java:57) at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141) at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at noob.common.AddCustomPlayerProperties.death(AddCustomPlayerProperties.java:29) at net.minecraftforge.event.ASMEventHandler_4_AddCustomPlayerProperties_death_LivingDeathEvent.invoke(.dynamic) at net.minecraftforge.event.ASMEventHandler.invoke(ASMEventHandler.java:39) at net.minecraftforge.event.EventBus.post(EventBus.java:108) at net.minecraftforge.common.ForgeHooks.onLivingDeath(ForgeHooks.java:342) at net.minecraft.entity.EntityLivingBase.onDeath(EntityLivingBase.java:988) at net.minecraft.entity.EntityLivingBase.attackEntityFrom(EntityLivingBase.java:951) at net.minecraft.entity.passive.EntityAnimal.attackEntityFrom(EntityAnimal.java:206) at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1367) at net.minecraft.network.NetServerHandler.handleUseEntity(NetServerHandler.java:854) at net.minecraft.network.packet.Packet7UseEntity.processPacket(Packet7UseEntity.java:57) at net.minecraft.network.MemoryConnection.processReadPackets(MemoryConnection.java:89) at net.minecraft.network.NetServerHandler.networkTick(NetServerHandler.java:141) -- Ticking connection -- Details: Connection: net.minecraft.network.NetServerHandler@160f199 Stacktrace: at net.minecraft.network.NetworkListenThread.networkTick(NetworkListenThread.java:54) at net.minecraft.server.integrated.IntegratedServerListenThread.networkTick(IntegratedServerListenThread.java:109) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:691) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:587) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:129) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:484) at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) -- System Details -- Details: Minecraft Version: 1.6.4 Operating System: Linux (i386) version 3.8.0-34-generic Java Version: 1.7.0_45, Oracle Corporation Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation Memory: 856063448 bytes (816 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 726 (40656 bytes; 0 MB) allocated, 408 (22848 bytes; 0 MB) used Suspicious classes: FML and Forge are installed IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 FML: MCP v8.11 FML v6.4.20.916 Minecraft Forge 9.11.1.916 5 mods loaded, 5 mods active mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{6.4.20.916} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{9.11.1.916} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available noob{INDEV} [Horizon 2.0] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available terracraft{0.3.0} [Terraria on Minecraft] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 72 (4032 bytes; 0 MB) allocated, 53 (2968 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player969'/25, l='Mod terracraft', x=-730,41, y=4,00, z=654,26]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
-
Je travaille sur les propriété d’entité actuellement.
IExtendedEntityProperties prop = event.entity.getExtendedProperties("Custom Player");
Essaie
CustomPlayer prop = new CustomPlayer(source.getEntityWorld());
-
Il me met une erreur à getEntityWorld()
désolé j’ai rien dit. En faisant cast sur le getEntityWorld() tout marche correctement ou presque cela affiche bien: “Mana de Player961= 1” mais il le ré-affiche a chaque fois et ne mais pas a jour la valeur de mana.
-
Non gugu, avec ça tu créer a chaque fois une nouvelle instance, le premier code était bon.
Tu as quoi à la ligne 29 de AddCustomPlayerProperties.java ? -
Voila ce que j’ai à la ligne 29 :
int mana = ((CustomPlayer)prop).getMana()+1;
-
Si tu a suivi le tutoriel sur MinecraftForums.net, je l’ai suivi aussi, et il marche a la perfection.
-
Je n’est pas suivit celui là. Je vais regarder ce tutoriel la.
-
Renvoie tout tes codes, il y a un npe sur la ligne que tu a envoyé, donc je pense que le custom player prop est null. Il me faut tout tes codes actuels pour savoir pourquoi.
-
Voila le code de AddCustomPlayerProperties:
package noob.common; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.common.IExtendedEntityProperties; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.event.entity.living.LivingDeathEvent; public class AddCustomPlayerProperties { @ForgeSubscribe public void init(EntityConstructing event) { if (event.entity instanceof EntityPlayer) { event.entity.registerExtendedProperties("Player", new CustomPlayer(event.entity.worldObj)); } } @ForgeSubscribe public void death(LivingDeathEvent event) { Entity source = event.source.getEntity(); if (source != null && source instanceof EntityPlayer) { IExtendedEntityProperties prop = event.entity.getExtendedProperties("Custom Player"); int mana = ((CustomPlayer)prop).getMana()+1; System.out.println("Mana de "+source.getEntityName()+"= "+mana); ((CustomPlayer)prop).setMana(mana); } } }
-
Je te conseille le tutoriel ici :
Car celui que tu utilise est fait de manière bizarre, il utilise l’interface pour appeler ton Custom Player.
-
Ok merci je vais regarder.
Merci beaucoup sa marche!
Je pense que je vais pouvoir avancé maintenant. -
Juste pour information, le NPE d’avant été causé car tu n’avais pas le bon nom :
IExtendedEntityProperties prop = event.entity.getExtendedProperties("Custom Player");
La où tu l’as utilisé et :
event.entity.registerExtendedProperties("Player", new CustomPlayer(event.entity.worldObj));
La où tu l’as enregistré, si les noms sont pas les mêmes, normal que ça fonctionne pas x).