Item qui a un cooldown
-
Petit crash =/ :
– Head -- Stacktrace: at fr.Mosca421.mods.Items.strengthstick.onItemRightClick(strengthstick.java:43) at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:164) at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:430) at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1557) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['Player487'/245, l='MpServer', x=-748,61, y=5,62, z=602,93]] Chunk stats: MultiplayerChunkCache: 625, 625 Level seed: 0 Level generator: ID 01 - flat, ver 0\. Features enabled: false Level generator options: Level spawn location: World: (-741,4,260), Chunk: (at 11,0,4 in -47,16; contains blocks -752,0,256 to -737,255,271), Region: (-2,0; contains chunks -64,0 to -33,31, blocks -1024,0,0 to -513,255,511) Level time: 462682 game time, 106716 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; [EntityClientPlayerMP['Player487'/245, l='MpServer', x=-748,61, y=5,62, z=602,93]] 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)A propos du code j’ai environs le meme que bodri j’ai juste modifier le haseffect
-
Ta fonction onUpdate ne sera jamais appelé car tu n’as pas les bons arguments (ni le bon type).
public void onUpdate(ItemStack stack, World world, Entity entity, int slotIndex, boolean inHand) {}Donc ça serait plutôt comme ça :
public void onUpdate(ItemStack stack, World world, Entity entity, int slotIndex, boolean inHand) { if(!stack.hasTagCompound() && stack.getTagCompound().getInteger("timer") > 0) stack.getTagCompound().setInteger("timer", stack.getTagCompound().getInteger("timer") - 1); }Et pour onItemRightClick :
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if(!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } item.getTagCompound().setInteger("timer", 20); item.damageItem(1, player); player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 50, 2)); return stack; } -
Et puis ton code n’est pas adapté, tu veux mettre un effet de potion si ton timer est fini. Genre un effet de potion possible toutes les 20 secondes par-exemple ?
-
Non quand le mec clique dessus sa fait l’effet après il ne peut pas l’effectuer pendant 10 seconde ansi de suite
-
Ouep c’est ce que je dis …
Je t’envois le code
-
Tu es un coeur Merci =p
-
Voilà, je t’ai même ajouté quelque commentaires =D
package fr.mrplaigon.testmod.common.item; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.world.World; public class StrengthStick extends Item { public StrengthStick() { this.setMaxDamage(16); this.setMaxStackSize(1); } @Override public void onUpdate(ItemStack item, World world, Entity player, int slotIndex, boolean inHand) { if(item.hasTagCompound())//Si ton item n'a pas de tag alors on ne fait rien { if(item.stackTagCompound.getInteger("timer") > 0)//si ton timer est supérieur à 0 (après un clic droit logiquement) { item.stackTagCompound.setInteger("timer", (int) (item.stackTagCompound.getInteger("timer") + 1));//On l'incrémente de 1 à chaque tick } if(item.stackTagCompound.getInteger("timer") >= (int) (6*20))//Remplace 6 par le nombre de secondes du timer souhaité { item.stackTagCompound.setInteger("timer", 0);//On remet à 0 si le timer est arrivé à la limite souhaitée } } super.onUpdate(item, world, player, slotIndex, inHand); } public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) { if(!item.hasTagCompound())//Même condition, si ton item n'a pas de tag on lui en ajoute avec l'int timer en + { item.setTagCompound(new NBTTagCompound()); item.stackTagCompound.setInteger("timer", 0); } if(item.stackTagCompound.getInteger("timer") == 0) { player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 120, 2)); item.stackTagCompound.setInteger("timer", 1);//On le met à 1 pour pouvoir rentrer dans la condition de onUpdate() } else { if(world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("Tu dois attendre que le baton se recharge !"));//On indique au joueur via ce message si le timer n'est pas encore arrivé à la limite souhaitée } return item; } @SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack item) { return true; } }N’oublie pas le petit + stp
-
Si tu me dis ou il est je veux bien =p
Edit : Juste j’ai essayer de mon coter de faire que l’item ne soit pas enchanter si l’item est inutilisable et enchanter quand il l’es sauf que je crash a chaque fois =/
-
Juste j’ai essayer de mon coter de faire que l’item ne soit pas enchanter si l’item est inutilisable et enchanter quand il l’es sauf que je crash a chaque fois =/
-
Ok voici le code =D
@SideOnly(Side.CLIENT) public boolean hasEffect(ItemStack item) { return item.hasTagCompound() ? (item.stackTagCompound.getInteger("timer") == 0 ? true : false) : false;//On vérifie déjà si l'ItemStack a set un NBTTagCompound si oui, on vérifie si Timer en fait partie et si il est égal à 0, si oui, on return true à la méthode } -
Merci =p
-
N’oublie pas la balise résolue

-
Merci! Grâce à toi, Deleted, j’ai enfin réussie à développer mon item! Merci beaucoup!