Advertisement
Guest User

Untitled

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