Advertisement
AwesomeSpider8

ContainerTileEntityPurifier *Changed Energy*

Feb 12th, 2017
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class ContainerTileEntityPurifier extends Container {
  2.     private TileEntityPurifier te;
  3.  
  4.     private int progress;
  5.     private int currentProgress;
  6.     private int storedPower;
  7.  
  8.     public ContainerTileEntityPurifier(IInventory playerInv, TileEntityPurifier te) {
  9.         this.te = te;
  10.  
  11.         // Tile Entity, Slot 1, Slot ID 1
  12.         this.addSlotToContainer(new SlotPurifierSand(te.getInventory(), 0, 58, 40));
  13.         this.addSlotToContainer(new SlotPurifierOutput(te.getInventory(), 1, 102, 40));
  14.  
  15.         // Player Inventory, Slot 9-35, Slot IDs 9-35
  16.         for (int y = 0; y < 3; ++y) {
  17.             for (int x = 0; x < 9; ++x) {
  18.                 this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
  19.             }
  20.         }
  21.  
  22.         // Player Inventory, Slot 0-8, Slot IDs 36-44
  23.         for (int x = 0; x < 9; ++x) {
  24.             this.addSlotToContainer(new Slot(playerInv, x, 8 + x * 18, 142));
  25.         }
  26.     }
  27.  
  28.     /**
  29.      * Looks for changes made in the container, sends them to every listener.
  30.      */
  31.     @Override
  32.     public void detectAndSendChanges() {
  33.         super.detectAndSendChanges();
  34.  
  35.         for(IContainerListener listener : listeners) {
  36.             if (progress != te.getField(0)) {
  37.                 if (listener instanceof EntityPlayerMP) {
  38.                     ModPacketHandler.INSTANCE.sendTo(new PurifierMessage(progress, currentProgress, storedPower, this.windowId), (EntityPlayerMP) listener);
  39.                 }
  40.             }
  41.  
  42.             if (currentProgress != te.getField(1)) {
  43.                 if (listener instanceof EntityPlayerMP) {
  44.                     ModPacketHandler.INSTANCE.sendTo(new PurifierMessage(progress, currentProgress, storedPower, this.windowId), (EntityPlayerMP) listener);
  45.                 }
  46.             }
  47.  
  48.             if (storedPower != te.getField(2)) {
  49.                 if (listener instanceof EntityPlayerMP) {
  50.                     int change = te.getField(2) - storedPower;
  51.  
  52.                     ModPacketHandler.INSTANCE.sendTo(new PurifierMessage(progress, currentProgress, change, this.windowId), (EntityPlayerMP) listener);
  53.                 }
  54.             }
  55.         }
  56.  
  57.         this.progress = this.te.getField(0);
  58.         this.currentProgress = this.te.getField(1);
  59.         this.storedPower = this.te.getField(2);
  60.     }
  61.  
  62.     @SideOnly(Side.CLIENT)
  63.     @Override
  64.     public void updateProgressBar(int id, int data) {
  65.         this.te.setField(id, data);
  66.     }
  67.  
  68.     @Override
  69.     public boolean canInteractWith(EntityPlayer playerIn) {
  70.         return true;
  71.     }
  72. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement