Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. package com.mod.drakania.Event;
  2.  
  3. import com.mod.drakania.init.ItemMod;
  4. import com.mod.drakania.items.ItemBackPack;
  5. import com.mod.drakania.ring.smallring;
  6.  
  7. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  8. import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.util.ChatComponentText;
  11. import net.minecraft.util.ChatStyle;
  12. import net.minecraft.util.EnumChatFormatting;
  13.  
  14. public class EventRing
  15. {
  16. @SubscribeEvent
  17. public void tickEvent(PlayerTickEvent event)
  18. {
  19. EntityPlayer player = event.player; // Tu récupères le player par l'event
  20. int count = 0;
  21. for(int i = 0; i < player.inventory.getSizeInventory(); i++) // Boucle ou l'on crée une variable i qui représente les slots de l'inventaire du joueur
  22. {
  23. if(player.inventory.getStackInSlot(i) != null) // Si le slot n'est pas null alors on passe au prochain
  24. {
  25. if(player.inventory.getStackInSlot(i).getItem() instanceof smallring) // Si l'item dans le slot est l'instance de ton item alors tu exécutes quelque chose
  26. {
  27. count++;
  28. if(count >= 2 && !player.worldObj.isRemote)
  29. {
  30. player.inventory.setInventorySlotContents(i, null);
  31. player.dropItem(ItemMod.ring, 1);
  32. player.addChatComponentMessage(new ChatComponentText("il est interdit d'avoir 2 Rings dans le même inventaire !").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_RED)));
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement