Advertisement
Guest User

Untitled

a guest
Aug 6th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. /**
  2.  * @author Intektor
  3.  */
  4. public abstract class AbstractContainer<T extends IInventory> extends Container {
  5.  
  6.     protected final T inventory;
  7.  
  8.     protected final EntityPlayer player;
  9.  
  10.     public AbstractContainer(T inventory, EntityPlayer player) {
  11.         this.inventory = inventory;
  12.         this.player = player;
  13.         addSlots();
  14.         if (inventory instanceof AbstractInventory) {
  15.             ((AbstractInventory) inventory).setContainer(this);
  16.         }
  17.     }
  18.  
  19.     public T inventory() {
  20.         return inventory;
  21.     }
  22.  
  23.     protected abstract void addSlots();
  24.  
  25.     @Override
  26.     public boolean canInteractWith(EntityPlayer player) {
  27.         return inventory.isUseableByPlayer(player);
  28.     }
  29.  
  30.     @Override
  31.     public void onContainerClosed(EntityPlayer player) {
  32.         inventory.closeInventory(player);
  33.     }
  34. }
  35.  
  36. public ContainerMagazineTable(MagazineTableInventory inventory, EntityPlayer player, BlockPos pos) {
  37.         super(inventory, player);
  38.         this.pos = pos;
  39.     }
  40.  
  41.     @Override
  42.     protected void addSlots() {
  43.         addSlotToContainer(new Slot(inventory, 0, 24, 35) {
  44.             @Override
  45.             public boolean isItemValid(ItemStack stack) {
  46.                 if (stack != null) {
  47.                     Item item = stack.getItem();
  48.                     return item instanceof ItemGun || item instanceof ItemMagazine;
  49.                 }
  50.                 return false;
  51.             }
  52.         });
  53.  
  54.         addSlotToContainer(new SimpleSlot(inventory, 1, 52, 35));
  55.         addSlotToContainer(new SimpleSlot(inventory, 2, 52 + 18, 35));
  56.         addSlotToContainer(new SimpleSlot(inventory, 3, 52 + 36, 35));
  57.  
  58.         addSlotToContainer(new Slots.SlotNoInput(inventory, 4, 145, 35));
  59.  
  60.         for (int i = 0; i < 3; ++i) {
  61.             for (int j = 0; j < 9; ++j) {
  62.                 this.addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
  63.             }
  64.         }
  65.  
  66.         for (int k = 0; k < 9; ++k) {
  67.             this.addSlotToContainer(new Slot(player.inventory, k, 8 + k * 18, 142));
  68.         }
  69.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement