Advertisement
smbarbour

Decompiled result

Oct 24th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.04 KB | None | 0 0
  1. package org.mcupdater.autopackager;
  2.  
  3. import cofh.api.energy.EnergyStorage;
  4. import cofh.api.energy.TileEnergyHandler;
  5. import cofh.lib.util.helpers.InventoryHelper;
  6. import cpw.mods.fml.common.Optional.Interface;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. import java.util.Map.Entry;
  10. import java.util.SortedSet;
  11. import java.util.TreeSet;
  12. import net.minecraft.entity.player.EntityPlayer;
  13. import net.minecraft.inventory.Container;
  14. import net.minecraft.inventory.IInventory;
  15. import net.minecraft.inventory.ISidedInventory;
  16. import net.minecraft.inventory.InventoryCrafting;
  17. import net.minecraft.item.ItemStack;
  18. import net.minecraft.item.crafting.CraftingManager;
  19. import net.minecraft.nbt.NBTTagCompound;
  20. import net.minecraft.tileentity.TileEntity;
  21. import net.minecraft.util.ChatComponentText;
  22. import net.minecraft.util.ChatComponentTranslation;
  23. import net.minecraft.world.World;
  24. import net.minecraftforge.common.util.ForgeDirection;
  25. import org.mcupdater.shared.Position;
  26.  
  27. @Optional.Interface(iface="com.dynious.refinedrelocation.api.tileentity.ISortingMember", modid="RefinedRelocation")
  28. public class TilePackager extends TileEnergyHandler
  29. {
  30.   private Object sortingHandler;
  31.   private ForgeDirection orientation;
  32.   private int tickCounter = 0;
  33.   private int tickDelay = AutoPackager.delayCycleNormal;
  34.   private TilePackager.Mode mode;
  35.  
  36.   public TilePackager()
  37.   {
  38.     this.mode = TilePackager.Mode.HYBRID;
  39.   }
  40.  
  41.   public void func_145845_h()
  42.   {
  43.     super.func_145845_h();
  44.     if (++this.tickCounter >= this.tickDelay) {
  45.       this.tickCounter = 0;
  46.       if (this.storage.getEnergyStored() > AutoPackager.energyPerCycle)
  47.         if (tryCraft()) {
  48.           this.storage.extractEnergy(AutoPackager.energyPerCycle, false);
  49.           this.tickDelay = AutoPackager.delayCycleNormal;
  50.         } else {
  51.           this.tickDelay = AutoPackager.delayCycleIdle;
  52.         }
  53.     }
  54.   }
  55.  
  56.   private boolean tryCraft()
  57.   {
  58.     if (this.orientation == null) {
  59.       return false;
  60.     }
  61.     Position inputPos = new Position(this.field_145851_c, this.field_145848_d, this.field_145849_e, this.orientation);
  62.     Position outputPos = new Position(this.field_145851_c, this.field_145848_d, this.field_145849_e, this.orientation);
  63.     inputPos.moveLeft(1.0D);
  64.     outputPos.moveRight(1.0D);
  65.     TileEntity tileInput = this.field_145850_b.func_147438_o((int)inputPos.x, (int)inputPos.y, (int)inputPos.z);
  66.     TileEntity tileOutput = this.field_145850_b.func_147438_o((int)outputPos.x, (int)outputPos.y, (int)outputPos.z);
  67.     Map slotMap = new HashMap();
  68.     IInventory invInput;
  69.     if (((tileInput instanceof IInventory)) && ((tileOutput instanceof IInventory))) {
  70.       invInput = (IInventory)tileInput;
  71.       IInventory invOutput = (IInventory)tileOutput;
  72.       for (int slot = 0; slot < invInput.func_70302_i_(); slot++) {
  73.         if ((invInput.func_70301_a(slot) != null) && (
  74.           (!(invInput instanceof ISidedInventory)) || (((ISidedInventory)invInput).func_102008_b(slot, null, ForgeDirection.DOWN.ordinal()))))
  75.         {
  76.           if (slotMap.containsKey(invInput.func_70301_a(slot).func_77977_a() + ":" + invInput.func_70301_a(slot).func_77960_j())) {
  77.             ((SortedSet)slotMap.get(invInput.func_70301_a(slot).func_77977_a() + ":" + invInput.func_70301_a(slot).func_77960_j())).add(Integer.valueOf(slot));
  78.           } else {
  79.             SortedSet slotList = new TreeSet();
  80.             slotList.add(Integer.valueOf(slot));
  81.             slotMap.put(invInput.func_70301_a(slot).func_77977_a() + ":" + invInput.func_70301_a(slot).func_77960_j(), slotList);
  82.           }
  83.           if (((this.mode == TilePackager.Mode.HYBRID) || (this.mode == TilePackager.Mode.SMALL)) && (invInput.func_70301_a(slot).field_77994_a >= 4)) {
  84.             ItemStack testStack = invInput.func_70301_a(slot).func_77946_l();
  85.             testStack.field_77994_a = 1;
  86.             InventoryCrafting smallCraft = new InventoryCrafting(new Container()
  87.             {
  88.               public boolean func_75145_c(EntityPlayer entityPlayer) {
  89.                 return false;
  90.               }
  91.             }
  92.             , 2, 2);
  93.  
  94.             for (int craftSlot = 0; craftSlot < 4; craftSlot++) {
  95.               smallCraft.func_70299_a(craftSlot, testStack);
  96.             }
  97.             ItemStack result = CraftingManager.func_77594_a().func_82787_a(smallCraft, this.field_145850_b);
  98.             if (result != null) {
  99.               testStack = InventoryHelper.simulateInsertItemStackIntoInventory(invOutput, result, 1);
  100.               if (testStack == null) {
  101.                 invInput.func_70298_a(slot, 4);
  102.                 InventoryHelper.insertItemStackIntoInventory(invOutput, result, 1);
  103.                 return true;
  104.               }
  105.             }
  106.           }
  107.           if (((this.mode == TilePackager.Mode.HYBRID) || (this.mode == TilePackager.Mode.LARGE)) && (invInput.func_70301_a(slot).field_77994_a >= 9)) {
  108.             ItemStack testStack = invInput.func_70301_a(slot).func_77946_l();
  109.             testStack.field_77994_a = 1;
  110.             InventoryCrafting largeCraft = new InventoryCrafting(new Container()
  111.             {
  112.               public boolean func_75145_c(EntityPlayer entityPlayer) {
  113.                 return false;
  114.               }
  115.             }
  116.             , 3, 3);
  117.  
  118.             for (int craftSlot = 0; craftSlot < 9; craftSlot++) {
  119.               largeCraft.func_70299_a(craftSlot, testStack);
  120.             }
  121.             ItemStack result = CraftingManager.func_77594_a().func_82787_a(largeCraft, this.field_145850_b);
  122.             if (result != null) {
  123.               testStack = InventoryHelper.simulateInsertItemStackIntoInventory(invOutput, result, 1);
  124.               if (testStack == null) {
  125.                 invInput.func_70298_a(slot, 9);
  126.                 InventoryHelper.insertItemStackIntoInventory(invOutput, result, 1);
  127.                 return true;
  128.               }
  129.             }
  130.           }
  131.         }
  132.       }
  133.       for (Map.Entry entry : slotMap.entrySet()) {
  134.         if (((SortedSet)entry.getValue()).size() > 1) {
  135.           SortedSet slots = (SortedSet)entry.getValue();
  136.           while (slots.size() > 1) {
  137.             if ((invInput.func_70301_a(((Integer)slots.first()).intValue()) == null) || (!(invInput.func_70301_a(((Integer)slots.first()).intValue()).func_77977_a() + ":" + invInput.func_70301_a(((Integer)slots.first()).intValue()).func_77960_j()).equals(entry.getKey())) || (invInput.func_70301_a(((Integer)slots.first()).intValue()).field_77994_a >= invInput.func_70301_a(((Integer)slots.first()).intValue()).func_77976_d())) {
  138.               slots.remove(slots.first());
  139.             }
  140.             else if ((invInput.func_70301_a(((Integer)slots.last()).intValue()) == null) || (!invInput.func_70301_a(((Integer)slots.last()).intValue()).func_77969_a(invInput.func_70301_a(((Integer)slots.first()).intValue()))) || (!ItemStack.func_77970_a(invInput.func_70301_a(((Integer)slots.first()).intValue()), invInput.func_70301_a(((Integer)slots.last()).intValue())))) {
  141.               slots.remove(slots.last());
  142.             }
  143.             else if (invInput.func_70301_a(((Integer)slots.first()).intValue()).field_77994_a + invInput.func_70301_a(((Integer)slots.last()).intValue()).field_77994_a <= invInput.func_70301_a(((Integer)slots.first()).intValue()).func_77976_d()) {
  144.               invInput.func_70301_a(((Integer)slots.first()).intValue()).field_77994_a += invInput.func_70301_a(((Integer)slots.last()).intValue()).field_77994_a;
  145.               invInput.func_70299_a(((Integer)slots.last()).intValue(), null);
  146.             } else {
  147.               int spaceRemain = invInput.func_70301_a(((Integer)slots.first()).intValue()).func_77976_d() - invInput.func_70301_a(((Integer)slots.first()).intValue()).field_77994_a;
  148.               invInput.func_70301_a(((Integer)slots.first()).intValue()).field_77994_a += spaceRemain;
  149.               invInput.func_70298_a(((Integer)slots.last()).intValue(), spaceRemain);
  150.             }
  151.           }
  152.         }
  153.       }
  154.     }
  155.     return false;
  156.   }
  157.  
  158.   public void func_145841_b(NBTTagCompound tagCompound)
  159.   {
  160.     super.func_145841_b(tagCompound);
  161.     tagCompound.func_74768_a("orientation", this.orientation.ordinal());
  162.     tagCompound.func_74768_a("mode", this.mode.ordinal());
  163.   }
  164.  
  165.   public void func_145839_a(NBTTagCompound tagCompound)
  166.   {
  167.     super.func_145839_a(tagCompound);
  168.     this.orientation = ForgeDirection.getOrientation(tagCompound.func_74762_e("orientation"));
  169.     this.mode = TilePackager.Mode.values()[tagCompound.func_74762_e("mode")];
  170.   }
  171.  
  172.   public void setOrientation(ForgeDirection orientation) {
  173.     this.orientation = orientation;
  174.   }
  175.  
  176.   public void cycleMode(EntityPlayer player) {
  177.     this.mode = TilePackager.Mode.values()[((this.mode.ordinal() + 1) % TilePackager.Mode.values().length)];
  178.     if (!this.field_145850_b.field_72995_K)
  179.       player.func_145747_a(new ChatComponentText("Current mode: " + this.mode.getMessage()));
  180.   }
  181.  
  182.   public void checkMode(EntityPlayer player)
  183.   {
  184.     if (!this.field_145850_b.field_72995_K)
  185.       player.func_145747_a(new ChatComponentTranslation("Current mode: " + this.mode.getMessage(), new Object[0]));
  186.   }
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement