Code Cooldown, besoin d'avis
-
Le tuto de BrokenSwing par-exemple.
-
Yep j’ai vu je me penche dessus

J’ai encore un soucis… J’ai fait cela mais en jeu cela n’a pas d’effet…
public class ItemDes extends Item { ItemStack itemdes = new ItemStack (Heimnor.itemdes); public ItemStack onItemRightClick(ItemStack itemdes, World world, EntityPlayer player) { if (!itemdes.hasTagCompound()) { itemdes.setTagCompound(new NBTTagCompound()); itemdes.stackTagCompound.setInteger("timer", 0); } if (itemdes.stackTagCompound.getInteger("timer") == 0){ } if(!world.isRemote) { MinecraftServer server = MinecraftServer.getServer(); ICommandManager command = server.getCommandManager(); command.executeCommand(player, "/dndroll 2d6"); itemdes.stackTagCompound.setInteger("timer", 1); } return itemdes; } public void onUpdate(ItemStack itemdes, World world, EntityPlayer player, int var1, boolean var2) { super.onUpdate(itemdes, world, player, var1, var2); if (itemdes.hasTagCompound()) { if (itemdes.stackTagCompound.getInteger("timer") > 0) { itemdes.stackTagCompound.setInteger("timer", (int) (itemdes.stackTagCompound.getInteger("timer") + 1)); } if (itemdes.stackTagCompound.getInteger("timer") >= (int) (200)) { itemdes.stackTagCompound.setInteger("timer", 0); } } } }Je ne vois toujours pas ce qui ne va pas en fait.
-
Essaie de débug pour voir où le code s’arrête
-
@‘Dylem’:
3 - La fonction onUpdate prend les arguments :
public void onUpdate(ItemStack p_77663_1_, World p_77663_2_, Entity p_77663_3_, int p_77663_4_, boolean p_77663_5_) {}…
-
Il semblerait que la fonction OnUpdate ne marche pas d’après la console …
-
Qu’est-ce qui ne “marche pas” ? Faut savoir détailler ses soucis quand on débute. La commande est-elle exécutée, oui ou non ? Ou est-ce seulement le counter qui ne va pas ??
-
Je ne crois pas que tu comprennes bien le problème que je soulève…
Le paramètre est Entity, pas EntityPlayer…
public void onUpdate(ItemStack itemdes, World world, Entity entity, int var1, boolean var2) { super.onUpdate(itemdes, world, entity, var1, var2); if(entity != null && entity instanceof EntityPlayer) { if (itemdes.hasTagCompound()) { if (itemdes.stackTagCompound.getInteger("timer") > 0) itemdes.stackTagCompound.setInteger("timer",itemdes.stackTagCompound.getInteger("timer") + 1); if (itemdes.stackTagCompound.getInteger("timer") >= 200) itemdes.stackTagCompound.setInteger("timer", 0); } } } -
Excusez moi je vais détailler plus, en fait la commande se lance, tout ce qui est dans la fonction onItemRightClick fonctionne parfaitement, en revanche, (en plaçant des System.out.println(“Etape x”)) tout ce qui se trouve dans la fonction onUpdate ne semble pas s’executer.
Etape 1 et 2 se lance sans soucis mais pas de signe de vie de l’Etape 3. Ce qui fait que je peux lancer la commande mais il n’y a pas de cooldown sur cette dernière.
EDIT : L’execution se passe bien jusqu’a cette ligne de code qui pose probleme :
if (itemdes.stackTagCompound.getInteger("timer") >= (200))public class ItemDes extends Item { ItemStack itemdes = new ItemStack (Heimnor.itemdes); public ItemStack onItemRightClick(ItemStack itemdes, World world, EntityPlayer player) { if (!itemdes.hasTagCompound()) { itemdes.setTagCompound(new NBTTagCompound()); itemdes.stackTagCompound.setInteger("timer", 0); } if (itemdes.stackTagCompound.getInteger("timer") == 0){ } if(!world.isRemote) { System.out.println("Etape 1"); MinecraftServer server = MinecraftServer.getServer(); ICommandManager command = server.getCommandManager(); command.executeCommand(player, "/dndroll 2d6"); itemdes.stackTagCompound.setInteger("timer", 1); } return itemdes; } public void onUpdate(ItemStack itemdes, World world, net.minecraft.entity.Entity entity, int var1, boolean var2) { super.onUpdate(itemdes, world, entity, var1, var2); if(entity != null && entity instanceof EntityPlayer) { if (itemdes.hasTagCompound()) { if (itemdes.stackTagCompound.getInteger("timer") > 0) {System.out.println("Etape 2"); itemdes.stackTagCompound.setInteger("timer", (int) (itemdes.stackTagCompound.getInteger("timer") + 1)); } if (itemdes.stackTagCompound.getInteger("timer") >= (200)) { itemdes.stackTagCompound.setInteger("timer", 0); System.out.println("Etape 3"); } } } } } -
Alors encore une fois, plusieurs remarques

1 - Enlève ça au début de ton programme, je ne sais pas ce que tu voulais faire avec mais ça pourrait causer des problèmes (plusieurs variables ayant le même nom)
ItemStack itemdes = new ItemStack (Heimnor.itemdes);2 - Il n’y a rien dans cette condition :
if (itemdes.stackTagCompound.getInteger("timer") == 0){ }Rajoute-là plutôt avec celle-ci :
if(!world.isRemote && itemdes.stackTagCompound.getInteger("timer") == 0)3- C’est quoi ces casts d’int en int ? Enlève les (int), ils ne servent à rien ici :
(int) (itemdes.stackTagCompound.getInteger("timer")(int) (200)4 - Juste pour vérifier, print ça dans onItemRightClick :
System.out.println(!itemdes.isStackable() ? "tout va bien" : "probleme"); -
Ah ! Ca fonctionne, merci de votre aide
Ca a refait ma journée ducoup ! Je pense que le vrai problème venait de cette fameuse condition vide … Et ducoup le print m’a mis tout va bien .public class ItemDes extends Item { public ItemStack onItemRightClick(ItemStack itemdes, World world, EntityPlayer player) { if (!itemdes.hasTagCompound()) { itemdes.setTagCompound(new NBTTagCompound()); itemdes.stackTagCompound.setInteger("timer", 0); } if(!world.isRemote && itemdes.stackTagCompound.getInteger("timer") == 0) { MinecraftServer server = MinecraftServer.getServer(); ICommandManager command = server.getCommandManager(); command.executeCommand(player, "/dndroll 2d6"); itemdes.stackTagCompound.setInteger("timer", 1); System.out.println(itemdes.isStackable() ? "tout va bien" : "probleme"); } return itemdes; } public void onUpdate(ItemStack itemdes, World world, net.minecraft.entity.Entity entity, int var1, boolean var2) { super.onUpdate(itemdes, world, entity, var1, var2); if(entity != null && entity instanceof EntityPlayer) { if (itemdes.hasTagCompound()) { if (itemdes.stackTagCompound.getInteger("timer") > 0) { itemdes.stackTagCompound.setInteger("timer", (itemdes.stackTagCompound.getInteger("timer") + 1)); } if (itemdes.stackTagCompound.getInteger("timer") >= (20)) {System.out.println("Etape 2"); itemdes.stackTagCompound.setInteger("timer", 0); System.out.println("Etape 3"); } } } } } -
Pense juste à sélectionner la meilleure réponse du topic.