L'event drop
-
Salut,
Est-ce qu’il est possible que le drop soit un nombre aléatoire entre 0 et 3 par exemple?
J’ai vu cette méthode dans le cochon :
protected void dropFewItems(boolean par1, int par2) { int j = this.rand.nextInt(3) + 1 + this.rand.nextInt(1 + par2); for (int k = 0; k < j; ++k) { if (this.isBurning()) { this.dropItem(Item.porkCooked.itemID, 1); } else { this.dropItem(Item.porkRaw.itemID, 1); } } if (this.getSaddled()) { this.dropItem(Item.saddle.itemID, 1); } }Mais je ne sais pas comment l’utiliser avec forge :s
Merci d’avance

-
C’est possible, tout simplement, les lignes où il y a “dropItem”, au bout tu as le chiffre 1, tu le remplace par : rand.nextInt(3) et puis voilà (bien sur, faut virer la boucle for
) -
J’ai essayé mais ça me dit que " void is an invalid type for the variable dropFewItems " et rand me dit comme erreur " rand cannot be resolved or is not a field ".
Voici ma classe sans le drop aléatoire :
package nyvelia.common; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntityWolf; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingDropsEvent; public class LivingEvent { @ForgeSubscribe public void onLivingDrops(LivingDropsEvent event) { if(event.entity instanceof EntityWolf) { EntityItem newdrop = new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, new ItemStack(Nyvelia.Tissu, 1)); event.drops.add(newdrop); } } }Je sais pas trop où l’ajouter en faite :s
-
“new ItemStack(Nyvelia.Tissu, 1));” remplace le 1 par rand.nextInt(3) alors

-
" rand cannot be resolved " T_T
-
Mh… envoie ta class !
-
Je l’ai envoyé juste au-dessus ^^ j’ai juste changé " new ItemStack(Nyvelia.Tissu, 1)); " en " new ItemStack(Nyvelia.Tissu, rand.nextInt(3))); ".
-
package nyvelia.common; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntityWolf; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.entity.living.LivingDropsEvent; public class LivingEvent { public final Random rand = new Random(); @ForgeSubscribe public void onLivingDrops(LivingDropsEvent event) { if(event.entity instanceof EntityWolf) { EntityItem newdrop = new EntityItem(event.entity.worldObj, event.entity.posX, event.entity.posY, event.entity.posZ, new ItemStack(Nyvelia.Tissu, rand.nextInt(3))); event.drops.add(newdrop); } } }Voili voilou

-
Merci ça marche impec

-
Salut petit probleme mon eclipse me propose de créer l’anotation forgesubscribe je doit le faire?
merci de votre réponse
-
Remplace par @SubscribeEvent
-
@‘Portuar’:
Remplace par @SubscribeEvent
merci bien cela marche mais pourquoi je doit utiliser SubscribeEvent?
-
Car ForgeSubscribe a été remplacé par SubscribeEvent en 1.7