Advertisement
Arctic_Wolfy

Shop Owner GUI

Oct 6th, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.08 KB | None | 0 0
  1. package com.bbw2.moneyMod.client.gui;
  2.  
  3. import com.bbw2.moneyMod.blocks.TEShop;
  4. import com.bbw2.moneyMod.init.ModItems;
  5. import com.bbw2.moneyMod.reference.Ref;
  6. import com.bbw2.moneyMod.utility.ConfigValues;
  7. import net.minecraft.client.gui.GuiButton;
  8. import net.minecraft.client.gui.inventory.GuiContainer;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.entity.player.InventoryPlayer;
  11. import net.minecraft.inventory.Container;
  12. import net.minecraft.inventory.Slot;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.util.ResourceLocation;
  15. import net.minecraft.util.StatCollector;
  16. import org.lwjgl.opengl.GL11;
  17.  
  18. /**
  19.  * Created on 10/6/2015.
  20.  */
  21. public class GuiStoreOwner extends GuiContainer {
  22.     private static final ResourceLocation gui = new ResourceLocation(Ref.MOD_ID.toLowerCase()+":textures/gui/store.png");
  23.     private InventoryPlayer playerInv;
  24.     private TEShop storeInv;
  25.     //int inventoryRows;
  26.  
  27.     public GuiStoreOwner(EntityPlayer player, TEShop storeInv) {
  28.         super(new StoreContainer(player, storeInv));
  29.         this.playerInv = player.inventory;
  30.         this.storeInv = storeInv;
  31.         this.ySize = 221;
  32.  
  33.         int k = (this.width - this.xSize) / 2;
  34.         int l = (this.height - this.ySize) / 2;
  35.  
  36.         buttonList.add(new GuiButton(1,10,52,20,20,"X"));
  37.     }
  38.  
  39.     @Override
  40.     public void onGuiClosed() {
  41.         storeInv.closeInventory();
  42.     }
  43.  
  44.     @Override
  45.     protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
  46.         GL11.glColor4f(1f, 1f, 1f, 1f);
  47.         this.mc.getTextureManager().bindTexture(gui);
  48.         int k = (this.width - this.xSize) / 2;
  49.         int l = (this.height - this.ySize) / 2;
  50.         this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
  51.  
  52.         for (int i = 0; i < storeInv.getShopSlots(); i++) {
  53.             this.drawTexturedModalRect(k + 29, l + 17 + (i * 22), 176, (storeInv.getStackInSlot(i+1) == null ? 18 : 0), 18, 18);
  54.         }
  55.  
  56.         for (int i = 0; i < storeInv.getShopSlots(); i++) {
  57.             for (int j = 0; j < storeInv.getExtraStorage(); j++) {
  58.                 this.drawTexturedModalRect(k + 29 + ((j + 1) * 22), l + 17 + (i * 22), 176, (storeInv.getStackInSlot(i+1) == null ? 18 : 0), 18, 18);
  59.             }
  60.         }
  61.  
  62.     }
  63.  
  64.     @Override
  65.     protected void drawGuiContainerForegroundLayer(int param1, int param2) {
  66.         //draw text and stuff here
  67.         //the parameters for drawString are: string, x, y, color
  68.         fontRendererObj.drawString(storeInv.getInventoryName() + " Owner Config", 8, 6, 4210752);
  69.         //draws "Inventory" or your regional equivalent
  70.         fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2 , 4210752);
  71.  
  72.         for (int i = 0; i < storeInv.getShopSlots(); i++) {
  73.             //fontRendererObj.drawString("100.000", 29 + 20, 17 + 6 + (i * 22), 4210752);
  74.         }
  75.  
  76.     }
  77.  
  78.     public static class StoreContainer extends Container {
  79.         private InventoryPlayer playerInv;
  80.         private TEShop storeInv;
  81.  
  82.         public StoreContainer(EntityPlayer player, final TEShop storeInv){
  83.             super();
  84.             this.playerInv = player.inventory;
  85.             this.storeInv = storeInv;
  86.  
  87.             storeInv.openInventory();
  88.  
  89.             int i = (6 - 4) * 18 + 1;
  90.             int j;
  91.             int k;
  92.  
  93.             this.addSlotToContainer(new Slot(storeInv, 0, 8, 18){
  94.                 @Override
  95.                 public boolean isItemValid(ItemStack stack) {
  96.                     return stack.getItem() == ModItems.creditCard;
  97.                 }
  98.             });
  99.             for (j = 0; j < storeInv.getShopSlots(); j++) {
  100.                 this.addSlotToContainer(new Slot(storeInv, j + 1, 8 + 22, 18 + (22 * (j))){
  101.                     @Override
  102.                     public boolean canTakeStack(EntityPlayer player) {
  103.                         return storeInv.isOwner(player) ||  storeInv.getCardCredit() >= 64f;
  104.                     }
  105.                     @Override
  106.                     public boolean isItemValid(ItemStack stack) {
  107.                         return storeInv.isOwner(player);
  108.                     }
  109.  
  110.                     @Override
  111.                     public ItemStack decrStackSize(int amt) {
  112.                         if (ConfigValues.doStoresHaveFiniteStock||
  113.                                 storeInv.isOwner(player)) return super.decrStackSize(amt);
  114.                         else return getStack().copy();
  115.                     }
  116.                 });
  117.             }
  118.  
  119.             for (j = 0; j < storeInv.getShopSlots(); j++) {
  120.                 for (k = 0; k < storeInv.getExtraStorage(); k++) {
  121.                     this.addSlotToContainer(new Slot(storeInv, k + j * storeInv.getExtraStorage() + 5, 8 + (22 * (k + 2)), 18 + (22 * (j))));
  122.                 }
  123.             }
  124.  
  125.  
  126.             for (j = 0; j < 3; ++j) {
  127.                 for (k = 0; k < 9; ++k) {
  128.                     this.addSlotToContainer(new Slot(playerInv, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
  129.                 }
  130.             }
  131.  
  132.             for (j = 0; j < 9; ++j) {
  133.                 this.addSlotToContainer(new Slot(playerInv, j, 8 + j * 18, 161 + i));
  134.             }
  135.         }
  136.  
  137.         @Override
  138.         public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
  139.             ItemStack stack = null;
  140.             Slot slotObject = (Slot) inventorySlots.get(slot);
  141.  
  142.             //null checks and checks if the item can be stacked (maxStackSize > 1)
  143.             if (slotObject != null && slotObject.getHasStack()) {
  144.                 ItemStack stackInSlot = slotObject.getStack();
  145.                 stack = stackInSlot.copy();
  146.  
  147.                 //merges the item into player inventory since its in the tileEntity
  148.                 if (slot < storeInv.getSizeInventory()) {
  149.                     if (!this.mergeItemStack(stackInSlot, storeInv.getSizeInventory(), 36+ storeInv.getSizeInventory(), true)) {
  150.                         return null;
  151.                     }
  152.                 }
  153.                 //places it into the tileEntity is possible since its in the player inventory
  154.                 else if (!this.mergeItemStack(stackInSlot, 0, storeInv.getSizeInventory(), false)) {
  155.                     return null;
  156.                 }
  157.  
  158.                 if (stackInSlot.stackSize == 0) {
  159.                     slotObject.putStack(null);
  160.                 } else {
  161.                     slotObject.onSlotChanged();
  162.                 }
  163.  
  164.                 if (stackInSlot.stackSize == stack.stackSize) {
  165.                     return null;
  166.                 }
  167.                 slotObject.onPickupFromSlot(player, stackInSlot);
  168.             }
  169.             return stack;
  170.         }
  171.  
  172.         @Override public boolean canInteractWith(EntityPlayer player) {return true;}
  173.  
  174.         @Override
  175.         public boolean isPlayerNotUsingContainer(EntityPlayer player) {
  176.             return super.isPlayerNotUsingContainer(player);
  177.         }
  178.  
  179.         @Override
  180.         public void onContainerClosed(EntityPlayer player) {
  181.             storeInv.closeInventory();
  182.         }
  183.     }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement