Advertisement
Guest User

ContainerAlloyFurnace.java

a guest
Jan 6th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.02 KB | None | 0 0
  1. package mokonaDesu.undercraft.tileentities;
  2.  
  3. import java.util.List;
  4.  
  5. import cpw.mods.fml.relauncher.Side;
  6. import cpw.mods.fml.relauncher.SideOnly;
  7.  
  8. import net.minecraft.client.Minecraft;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.entity.player.InventoryPlayer;
  11. import net.minecraft.inventory.Container;
  12. import net.minecraft.inventory.ICrafting;
  13. import net.minecraft.inventory.Slot;
  14. import net.minecraft.inventory.SlotFurnace;
  15. import net.minecraft.item.ItemStack;
  16.  
  17. public class ContainerAlloyFurnace extends Container
  18. {
  19.     private TileEntityAlloyFurnace furnace;
  20.     private int lastFuelLevel[] = {0, 0, 0, 0};
  21.     private int lastMaxFuelLevel[] = {0, 0, 0, 0};
  22.     private int[] lastItemHeat = {0, 0, 0};
  23.     private int[] lastItemHeatRequired = {0, 0, 0};
  24.     private int lastTemperature = 0;
  25.  
  26.     public ContainerAlloyFurnace(InventoryPlayer par1InventoryPlayer, TileEntityAlloyFurnace par2TileEntityFurnace)
  27.     {
  28.         furnace = par2TileEntityFurnace;
  29.                 //fuel
  30.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 0, 53, 73));
  31.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 1, 72, 73));
  32.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 2, 92, 73));
  33.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 3, 111, 73));
  34.                
  35.                 //smelting
  36.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 4, 43, 32));
  37.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 5, 82, -7));
  38.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 6, 121, 32));
  39.        
  40.                 //molds
  41.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 7, 149, -10));
  42.        
  43.                 //result
  44.         this.addSlotToContainer(new Slot(par2TileEntityFurnace, 8, 82, 32));
  45.        
  46.         for (int i = 0; i < 3; i++)
  47.         {
  48.             for (int k = 0; k < 9; k++)
  49.             {
  50.                  this.addSlotToContainer(new Slot(par1InventoryPlayer, k + i * 9 + 9, 8 + k * 18, 105 + (i * 18)));
  51.             }
  52.         }
  53.  
  54.         for (int j = 0; j < 9; j++)
  55.         {
  56.              this.addSlotToContainer(new Slot(par1InventoryPlayer, j, 8 + j * 18, 163));
  57.         }
  58.     }
  59.  
  60.  
  61.     @Override
  62.     public boolean canInteractWith(EntityPlayer par1EntityPlayer)
  63.     {
  64.         return furnace.isUseableByPlayer(par1EntityPlayer);
  65.     }
  66.    
  67.     public void addCraftingToCrafters(ICrafting par1ICrafting)
  68.     {
  69.         super.addCraftingToCrafters(par1ICrafting);
  70.        
  71. for (int i = 0; i < 4; i++)
  72.         par1ICrafting.sendProgressBarUpdate(this, i, this.furnace.fuelLevel[i]);
  73.  
  74. for (int i = 0; i < 4; i++)
  75.     par1ICrafting.sendProgressBarUpdate(this, i + 4, this.furnace.maxFuelLevel[i]);
  76.  
  77. for (int i = 0; i < 3; i++)
  78.     par1ICrafting.sendProgressBarUpdate(this, i + 8, this.furnace.itemHeat[i]);
  79.  
  80. for (int i = 0; i < 3; i++)
  81.     par1ICrafting.sendProgressBarUpdate(this, i + 11, this.furnace.itemHeatRequired[i]);
  82.  
  83.     par1ICrafting.sendProgressBarUpdate(this, 14, this.furnace.temperature);
  84.  
  85.     }
  86.    
  87.     public void detectAndSendChanges()
  88.     {
  89.         super.detectAndSendChanges();
  90.  
  91.         for (int i = 0; i < this.crafters.size(); i++)
  92.         {
  93.             ICrafting crafting = (ICrafting)this.crafters.get(i);
  94.  
  95.             for (int j = 0; j < 4; j++)
  96.             if (this.lastFuelLevel[j] != this.furnace.fuelLevel[j])
  97.             {
  98.                 crafting.sendProgressBarUpdate(this, j, this.furnace.fuelLevel[j]);
  99.                 this.lastFuelLevel[j] = this.furnace.fuelLevel[j];
  100.             }
  101.            
  102.             for (int j = 0; j < 4; j++)
  103.                 if (this.lastMaxFuelLevel[j] != this.furnace.maxFuelLevel[j])
  104.                 {
  105.                     crafting.sendProgressBarUpdate(this, j + 4, this.furnace.maxFuelLevel[j]);
  106.                     this.lastMaxFuelLevel[j] = this.furnace.maxFuelLevel[j];
  107.                 }
  108.            
  109.             for (int j = 0; j < 3; j++)
  110.                 if (this.lastItemHeat[j] != this.furnace.itemHeat[j])
  111.                 {
  112.                     crafting.sendProgressBarUpdate(this, j + 8, this.furnace.itemHeat[j]);
  113.                     this.lastItemHeat[j] = this.furnace.itemHeat[j];
  114.                 }
  115.            
  116.             for (int j = 0; j < 3; j++)
  117.                 if (this.lastItemHeatRequired[j] != this.furnace.itemHeatRequired[j])
  118.                 {
  119.                     crafting.sendProgressBarUpdate(this, j + 11, this.furnace.itemHeatRequired[j]);
  120.                     this.lastItemHeatRequired[j] = this.furnace.itemHeatRequired[j];
  121.                 }
  122.            
  123.                 if (this.lastTemperature != this.furnace.temperature)
  124.                 {
  125.                 crafting.sendProgressBarUpdate(this, 14, this.furnace.temperature);
  126.                 this.lastTemperature = this.furnace.temperature;
  127.                 }
  128.            
  129.         }
  130.  
  131.     }
  132.    
  133.     @SideOnly(Side.CLIENT)
  134.     public void updateProgressBar(int index, int value)
  135.     {
  136.             if (index >= 0 && index <= 3) {     //fuelLevel update
  137.                     this.furnace.fuelLevel[index] = value;
  138.                     return;
  139.                 }
  140.  
  141.             if (index >= 4 && index <= 7) {     //maxFuelLevel update
  142.                     this.furnace.maxFuelLevel[index - 4] = value;
  143.                     return;
  144.             }
  145.            
  146.             if (index >= 8 && index <= 10) {    //itemHeat update
  147.                     this.furnace.itemHeat[index - 8] = value;
  148.                     return;
  149.             }
  150.            
  151.             if (index >= 11 && index <= 13) {   //itemHeatRequired update
  152.                     this.furnace.itemHeatRequired[index - 11] = value;
  153.                     return;
  154.             }
  155.            
  156.             if (index == 14) this.furnace.temperature = value;
  157.  
  158.     }
  159.  
  160.    
  161.     @Override
  162.     public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
  163.             ItemStack stack = null;
  164.             Slot slotObject = (Slot) inventorySlots.get(slot);
  165.  
  166.             //null checks and checks if the item can be stacked (maxStackSize > 1)
  167.             if (slotObject != null && slotObject.getHasStack()) {
  168.                     ItemStack stackInSlot = slotObject.getStack();
  169.                     stack = stackInSlot.copy();
  170.  
  171.                     //merges the item into player inventory since its in the tileEntity
  172.                     if (slot < 9) {
  173.                             if (!this.mergeItemStack(stackInSlot, 9, 45, true)) {
  174.                                     return null;
  175.                             }
  176.                     }
  177.                     //places it into the tileEntity is possible since its in the player inventory
  178.                     else if (!this.mergeItemStack(stackInSlot, 0, 9, false)) {
  179.                             return null;
  180.                     }
  181.  
  182.                     if (stackInSlot.stackSize == 0) {
  183.                             slotObject.putStack(null);
  184.                     } else {
  185.                             slotObject.onSlotChanged();
  186.                     }
  187.  
  188.                     if (stackInSlot.stackSize == stack.stackSize) {
  189.                             return null;
  190.                     }
  191.                     slotObject.onPickupFromSlot(player, stackInSlot);
  192.             }
  193.             return stack;
  194.     }
  195.    
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement