Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. package com.lycoon.lemnoslife.gui;
  2.  
  3. import com.lycoon.lemnoslife.ExtendedEntityPropTuto;
  4. import com.lycoon.lemnoslife.Main;
  5. import com.lycoon.lemnoslife.assets.ItemCoca;
  6.  
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.entity.player.InventoryPlayer;
  9. import net.minecraft.inventory.Container;
  10. import net.minecraft.inventory.IInventory;
  11. import net.minecraft.inventory.Slot;
  12. import net.minecraft.item.Item;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.util.ChatComponentText;
  15. import net.minecraft.util.ChatStyle;
  16. import net.minecraft.util.EnumChatFormatting;
  17.  
  18. public class ContainerShop extends Container {
  19.  
  20.     public static ChatStyle rouge = new ChatStyle().setColor(EnumChatFormatting.RED);
  21.     public static ChatStyle vert = new ChatStyle().setColor(EnumChatFormatting.GREEN);
  22.    
  23.     public ContainerShop(IInventory playerInv) {
  24.         for (int x = 0; x < 9; x++) {
  25.             this.addSlotToContainer(new Slot(playerInv, x, 145 + 21 * x + 5, 8));
  26.         }
  27.         this.putStackInSlot(0, new ItemStack(Main.itemPhone));
  28.         this.putStackInSlot(1, new ItemStack(Main.itemGPS));
  29.     }
  30.  
  31.     @Override
  32.     public boolean canInteractWith(EntityPlayer player) {
  33.         return true;
  34.     }
  35.  
  36.     /*
  37.      * Clic gauche: key = 0
  38.      * Clic droit: key = 1
  39.      * Clic molette: key = 2
  40.      */
  41.     public ItemStack slotClick(int slotID, int key, int par3, EntityPlayer player)
  42.     {
  43.         ItemStack itemstack = null;
  44.         ExtendedEntityPropTuto extProp = ExtendedEntityPropTuto.get(player);
  45.         InventoryPlayer inventoryplayer = player.inventory;
  46.        
  47.         if(slotID == 0){
  48.             if(extProp.getSoldeLiquide() >= 500){
  49.                 extProp.setSoldeLiquide(extProp.getSoldeLiquide() - 500); //Retrait du montant depuis l'arg
  50.                 inventoryplayer.addItemStackToInventory(new ItemStack(Main.itemPhone)); //Ajout de l'item dans l'inventaire
  51.                 player.addChatMessage(new ChatComponentText("[Magasin] Vous avez acheté un portable pour 500€.").setChatStyle(vert));
  52.             }
  53.             else{
  54.                 player.addChatMessage(new ChatComponentText("[Magasin] Vous n'avez pas assez d'argent.").setChatStyle(rouge));
  55.             }
  56.         }
  57.         else if(slotID == 1){
  58.             if(extProp.getSoldeLiquide() >= 2000){
  59.                 extProp.setSoldeLiquide(extProp.getSoldeLiquide() - 2000);
  60.                 inventoryplayer.addItemStackToInventory(new ItemStack(Main.itemGPS));
  61.                 player.addChatMessage(new ChatComponentText("[Magasin] Vous avez acheté un GPS pour 2000€.").setChatStyle(vert));
  62.             }
  63.             else{
  64.                 player.addChatMessage(new ChatComponentText("[Magasin] Vous n'avez pas assez d'argent.").setChatStyle(rouge));
  65.             }
  66.         }
  67.        
  68.         return itemstack;
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement