Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mod.drakania.Event;
- import com.mod.drakania.init.ItemMod;
- import com.mod.drakania.items.ItemBackPack;
- import cpw.mods.fml.common.eventhandler.SubscribeEvent;
- import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.util.ChatComponentText;
- import net.minecraft.util.ChatStyle;
- import net.minecraft.util.EnumChatFormatting;
- public class EnderChest
- {
- @SubscribeEvent
- public void tickEvent(PlayerTickEvent event)
- {
- EntityPlayer player = event.player; // Tu récupères le player par l'event
- int count = 0;
- 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
- {
- if(player.inventory.getStackInSlotOnClosing(i) != null) // Si le slot n'est pas null alors on passe au prochain
- {
- 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
- {
- count++;
- if(count >= 2 && !player.worldObj.isRemote)
- {
- player.inventory.setInventorySlotContents(i, null);
- player.dropItem(ItemMod.backpack, 1);
- player.addChatComponentMessage(new ChatComponentText("il est interdit d'avoir 2 Backpacks dans le même inventaire !").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.DARK_RED)));
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement