Advertisement
Cypher121

Slot

Oct 9th, 2015
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. package com.cout970.magneticraft.container;
  2.  
  3. import com.cout970.magneticraft.Magneticraft;
  4. import com.cout970.magneticraft.util.Log;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.inventory.Slot;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.util.ResourceLocation;
  9.  
  10. public class SlotShelvingUnit extends Slot implements ISlotToggleable, ISlotLockable {
  11.     public static final int HIDE_OFFSET = 1 << 20;
  12.     public int baseX, baseY, invNum;
  13.     public boolean hidden, locked;
  14.     private static ResourceLocation BG_LOCKED = new ResourceLocation(Magneticraft.NAME.toLowerCase() + ":textures/gui/slot_locked.png");
  15.  
  16.     public SlotShelvingUnit(IInventory inv, int index, int dx, int dy, int number) {
  17.         super(inv, index, dx, dy);
  18.         hidden = locked = false;
  19.         baseX = dx;
  20.         baseY = dy;
  21.         invNum = number;
  22.     }
  23.  
  24.     @Override
  25.     public ItemStack getStack() {
  26.         Log.debug(invNum + " " + String.valueOf(inventory));
  27.         return super.getStack();
  28.     }
  29.  
  30.     @Override
  31.     public void hide() {
  32.         if (!hidden) {
  33.             hidden = true;
  34.             xDisplayPosition += HIDE_OFFSET;
  35.             yDisplayPosition += HIDE_OFFSET;
  36.         }
  37.     }
  38.  
  39.     @Override
  40.     public void show() {
  41.         if (hidden) {
  42.             hidden = false;
  43.             xDisplayPosition -= HIDE_OFFSET;
  44.             yDisplayPosition -= HIDE_OFFSET;
  45.         }
  46.     }
  47.  
  48.     @Override
  49.     public boolean isHidden() {
  50.         return hidden;
  51.     }
  52.  
  53.     @Override
  54.     public void lock() {
  55.         locked = true;
  56.         setBackgroundIconTexture(BG_LOCKED);
  57.     }
  58.  
  59.     @Override
  60.     public void unlock() {
  61.         locked = false;
  62.         setBackgroundIconTexture(null);
  63.     }
  64.  
  65.     @Override
  66.     public boolean isItemValid(ItemStack is) {
  67.         return !locked;
  68.     }
  69.  
  70.     @Override
  71.     public int getSlotStackLimit() {
  72.         return (locked) ? 0 : super.getSlotStackLimit();
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement