Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bbw2.moneyMod.client.gui;
- import com.bbw2.moneyMod.blocks.TEShop;
- import com.bbw2.moneyMod.init.ModItems;
- import com.bbw2.moneyMod.reference.Ref;
- import com.bbw2.moneyMod.utility.ConfigValues;
- import net.minecraft.client.gui.GuiButton;
- import net.minecraft.client.gui.inventory.GuiContainer;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.util.StatCollector;
- import org.lwjgl.opengl.GL11;
- /**
- * Created on 10/6/2015.
- */
- public class GuiStoreOwner extends GuiContainer {
- private static final ResourceLocation gui = new ResourceLocation(Ref.MOD_ID.toLowerCase()+":textures/gui/store.png");
- private InventoryPlayer playerInv;
- private TEShop storeInv;
- //int inventoryRows;
- public GuiStoreOwner(EntityPlayer player, TEShop storeInv) {
- super(new StoreContainer(player, storeInv));
- this.playerInv = player.inventory;
- this.storeInv = storeInv;
- this.ySize = 221;
- int k = (this.width - this.xSize) / 2;
- int l = (this.height - this.ySize) / 2;
- buttonList.add(new GuiButton(1,10,52,20,20,"X"));
- }
- @Override
- public void onGuiClosed() {
- storeInv.closeInventory();
- }
- @Override
- protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
- GL11.glColor4f(1f, 1f, 1f, 1f);
- this.mc.getTextureManager().bindTexture(gui);
- int k = (this.width - this.xSize) / 2;
- int l = (this.height - this.ySize) / 2;
- this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
- for (int i = 0; i < storeInv.getShopSlots(); i++) {
- this.drawTexturedModalRect(k + 29, l + 17 + (i * 22), 176, (storeInv.getStackInSlot(i+1) == null ? 18 : 0), 18, 18);
- }
- for (int i = 0; i < storeInv.getShopSlots(); i++) {
- for (int j = 0; j < storeInv.getExtraStorage(); j++) {
- this.drawTexturedModalRect(k + 29 + ((j + 1) * 22), l + 17 + (i * 22), 176, (storeInv.getStackInSlot(i+1) == null ? 18 : 0), 18, 18);
- }
- }
- }
- @Override
- protected void drawGuiContainerForegroundLayer(int param1, int param2) {
- //draw text and stuff here
- //the parameters for drawString are: string, x, y, color
- fontRendererObj.drawString(storeInv.getInventoryName() + " Owner Config", 8, 6, 4210752);
- //draws "Inventory" or your regional equivalent
- fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2 , 4210752);
- for (int i = 0; i < storeInv.getShopSlots(); i++) {
- //fontRendererObj.drawString("100.000", 29 + 20, 17 + 6 + (i * 22), 4210752);
- }
- }
- public static class StoreContainer extends Container {
- private InventoryPlayer playerInv;
- private TEShop storeInv;
- public StoreContainer(EntityPlayer player, final TEShop storeInv){
- super();
- this.playerInv = player.inventory;
- this.storeInv = storeInv;
- storeInv.openInventory();
- int i = (6 - 4) * 18 + 1;
- int j;
- int k;
- this.addSlotToContainer(new Slot(storeInv, 0, 8, 18){
- @Override
- public boolean isItemValid(ItemStack stack) {
- return stack.getItem() == ModItems.creditCard;
- }
- });
- for (j = 0; j < storeInv.getShopSlots(); j++) {
- this.addSlotToContainer(new Slot(storeInv, j + 1, 8 + 22, 18 + (22 * (j))){
- @Override
- public boolean canTakeStack(EntityPlayer player) {
- return storeInv.isOwner(player) || storeInv.getCardCredit() >= 64f;
- }
- @Override
- public boolean isItemValid(ItemStack stack) {
- return storeInv.isOwner(player);
- }
- @Override
- public ItemStack decrStackSize(int amt) {
- if (ConfigValues.doStoresHaveFiniteStock||
- storeInv.isOwner(player)) return super.decrStackSize(amt);
- else return getStack().copy();
- }
- });
- }
- for (j = 0; j < storeInv.getShopSlots(); j++) {
- for (k = 0; k < storeInv.getExtraStorage(); k++) {
- this.addSlotToContainer(new Slot(storeInv, k + j * storeInv.getExtraStorage() + 5, 8 + (22 * (k + 2)), 18 + (22 * (j))));
- }
- }
- for (j = 0; j < 3; ++j) {
- for (k = 0; k < 9; ++k) {
- this.addSlotToContainer(new Slot(playerInv, k + j * 9 + 9, 8 + k * 18, 103 + j * 18 + i));
- }
- }
- for (j = 0; j < 9; ++j) {
- this.addSlotToContainer(new Slot(playerInv, j, 8 + j * 18, 161 + i));
- }
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
- ItemStack stack = null;
- Slot slotObject = (Slot) inventorySlots.get(slot);
- //null checks and checks if the item can be stacked (maxStackSize > 1)
- if (slotObject != null && slotObject.getHasStack()) {
- ItemStack stackInSlot = slotObject.getStack();
- stack = stackInSlot.copy();
- //merges the item into player inventory since its in the tileEntity
- if (slot < storeInv.getSizeInventory()) {
- if (!this.mergeItemStack(stackInSlot, storeInv.getSizeInventory(), 36+ storeInv.getSizeInventory(), true)) {
- return null;
- }
- }
- //places it into the tileEntity is possible since its in the player inventory
- else if (!this.mergeItemStack(stackInSlot, 0, storeInv.getSizeInventory(), false)) {
- return null;
- }
- if (stackInSlot.stackSize == 0) {
- slotObject.putStack(null);
- } else {
- slotObject.onSlotChanged();
- }
- if (stackInSlot.stackSize == stack.stackSize) {
- return null;
- }
- slotObject.onPickupFromSlot(player, stackInSlot);
- }
- return stack;
- }
- @Override public boolean canInteractWith(EntityPlayer player) {return true;}
- @Override
- public boolean isPlayerNotUsingContainer(EntityPlayer player) {
- return super.isPlayerNotUsingContainer(player);
- }
- @Override
- public void onContainerClosed(EntityPlayer player) {
- storeInv.closeInventory();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement