Advertisement
Cypher121

Tile

Oct 9th, 2015
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.91 KB | None | 0 0
  1. package com.cout970.magneticraft.tileentity.shelf;
  2.  
  3. import com.cout970.magneticraft.api.util.MgDirection;
  4. import com.cout970.magneticraft.api.util.VecInt;
  5. import com.cout970.magneticraft.api.util.VecIntUtil;
  6. import com.cout970.magneticraft.tileentity.TileBase;
  7. import com.cout970.magneticraft.util.ITileShelf;
  8. import com.cout970.magneticraft.util.InventoryComponent;
  9. import com.cout970.magneticraft.util.InventoryResizable;
  10. import net.minecraft.nbt.NBTTagCompound;
  11. import net.minecraft.util.AxisAlignedBB;
  12.  
  13. public class TileShelvingUnit extends TileBase implements ITileShelf {
  14.     private int crates;
  15.     public static final int MAX_CRATES = 24;
  16.     public static final int MAX_SHELVES = 3;
  17.     public static final int CRATE_SIZE = 27;
  18.     public static final int SHELF_CRATES = MAX_CRATES / MAX_SHELVES;
  19.  
  20.     private InventoryResizable[] rowInv = new InventoryResizable[MAX_SHELVES];
  21.  
  22.     public TileShelvingUnit() {
  23.         crates = 0;
  24.         for (int i = 0; i < MAX_SHELVES; i++) {
  25.             rowInv[i] = new InventoryResizable(this, CRATE_SIZE * SHELF_CRATES, "Shelf " + i);
  26.             rowInv[i].lock();
  27.         }
  28.     }
  29.  
  30.     public InventoryComponent getInv(int i) {
  31.         return rowInv[i];
  32.     }
  33.  
  34.     @Override
  35.     public TileShelvingUnit getMainTile() {
  36.         return this;
  37.     }
  38.  
  39.     public boolean addCrate() {
  40.         if (crates < MAX_CRATES) {
  41.             if (rowInv[crates / SHELF_CRATES].resize(CRATE_SIZE)) {
  42.                 crates++;
  43.                 return true;
  44.             }
  45.         }
  46.         return false;
  47.     }
  48.  
  49.     public boolean removeCrate() {
  50.         if (crates > 0) {
  51.             if (rowInv[(crates - 1) / SHELF_CRATES].resize(-CRATE_SIZE)) {
  52.                 crates--;
  53.                 return true;
  54.             }
  55.         }
  56.         return false;
  57.     }
  58.  
  59.     public int getCrateCount() {
  60.         return crates;
  61.     }
  62.  
  63.     public MgDirection getDirection() {
  64.         return MgDirection.getDirection(getBlockMetadata());
  65.     }
  66.  
  67.     @Override
  68.     public AxisAlignedBB getRenderBoundingBox() {
  69.         VecInt v1 = VecIntUtil.getRotatedOffset(MgDirection.getDirection(getBlockMetadata()), -2, 0, 0);
  70.         VecInt v2 = VecIntUtil.getRotatedOffset(MgDirection.getDirection(getBlockMetadata()), 2, 3, 1);
  71.         VecInt block = new VecInt(xCoord, yCoord, zCoord);
  72.  
  73.         return VecIntUtil.getAABBFromVectors(v1.add(block), v2.add(block));
  74.     }
  75.  
  76.     @Override
  77.     public void readFromNBT(NBTTagCompound nbt) {
  78.         super.readFromNBT(nbt);
  79.         crates = nbt.getInteger("crates");
  80.         for (int i = 0; i < MAX_SHELVES; i++) {
  81.             rowInv[i].readFromNBT(nbt, rowInv[i].name);
  82.         }
  83.     }
  84.  
  85.     @Override
  86.     public void writeToNBT(NBTTagCompound nbt) {
  87.         super.writeToNBT(nbt);
  88.         nbt.setInteger("crates", crates);
  89.         for (int i = 0; i < MAX_SHELVES; i++) {
  90.             rowInv[i].writeToNBT(nbt, rowInv[i].name);
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement