Guest User

Untitled

a guest
Sep 22nd, 2016
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.21 KB | None | 0 0
  1. package melonslise.runicinscription.common.container;
  2.  
  3. import java.util.Arrays;
  4.  
  5. import melonslise.runicinscription.RunicInscription;
  6. import melonslise.runicinscription.common.inventory.InventoryRuneInscription;
  7. import melonslise.runicinscription.common.inventory.SlotRuneInscription;
  8. import net.minecraft.entity.player.EntityPlayer;
  9. import net.minecraft.entity.player.InventoryPlayer;
  10. import net.minecraft.init.Items;
  11. import net.minecraft.inventory.Container;
  12. import net.minecraft.inventory.Slot;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.world.World;
  15.  
  16. public class ContainerRuneInscription extends Container
  17. {
  18.     public boolean grid[][] = new boolean[5][7];
  19.     public InventoryRuneInscription inventoryInscription = new InventoryRuneInscription(this);
  20.     private World worldobj;
  21.     private int posX;
  22.     private int posY;
  23.     private int posZ;
  24.     private static final int Input = 0;
  25.     private static final int Output = 1;
  26.    
  27.     public ContainerRuneInscription(InventoryPlayer inventoryPlayer, World world, int x, int y, int z)
  28.     {
  29.         this.worldobj = world;
  30.         this.posX = x;
  31.         this.posY = y;
  32.         this.posZ = z;
  33.        
  34.         this.addSlotToContainer(new SlotRuneInscription(inventoryInscription, this, Input, 8, 47));
  35.         this.addSlotToContainer(new SlotRuneInscription(inventoryInscription, this, Output, 152, 47));
  36.        
  37.         for (int i = 0; i < 3; ++i)
  38.         {
  39.             for (int k = 0; k < 9; ++k)
  40.             {
  41.                 this.addSlotToContainer(new Slot(inventoryPlayer, k + i * 9 + 9, 8 + k * 18, 124 + i * 18));
  42.             }
  43.         }
  44.        
  45.         for (int i = 0; i < 9; ++i)
  46.         {
  47.             this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 182));
  48.         }
  49.     }
  50.    
  51.     @Override
  52.     public ItemStack transferStackInSlot(EntityPlayer player, int fromSlot)
  53.     {
  54.         ItemStack itemStack = null;
  55.         Slot slot = (Slot)this.inventorySlots.get(fromSlot);
  56.  
  57.         if (slot != null && slot.getHasStack())
  58.         {
  59.             ItemStack itemStack1 = slot.getStack();
  60.             itemStack = itemStack1.copy();
  61.            
  62.             if(fromSlot <= this.Output)
  63.             {
  64.                 if (!this.mergeItemStack(itemStack1, this.Output + 1, this.Output + 36 + 1, true))
  65.                 {
  66.                     return null;
  67.                 }
  68.             }
  69.             else if(fromSlot > this.Output)
  70.             {
  71.                 if(itemStack1.getItem() == Items.dye)
  72.                 {
  73.                     if(!this.mergeItemStack(itemStack1, this.Input, this.Input + 1, true))
  74.                     {
  75.                         return null;
  76.                     }
  77.                 }
  78.             }
  79.             else if (fromSlot >= this.Output + 1 && fromSlot < this.Output + 28)
  80.             {
  81.                 if (!this.mergeItemStack(itemStack1, this.Output + 28, this.Output + 37, false))
  82.                 {
  83.                     return null;
  84.                 }
  85.             }
  86.             else if (fromSlot >= this.Output + 28 && fromSlot < this.Output + 37)
  87.             {
  88.                 if(!this.mergeItemStack(itemStack1, this.Output + 1, this.Output + 28, false))
  89.                 {
  90.                     return null;
  91.                 }
  92.             }
  93.  
  94.             if (itemStack1.stackSize == 0)
  95.             {
  96.                 slot.putStack((ItemStack)null);
  97.             }
  98.             else
  99.             {
  100.                 slot.onSlotChanged();
  101.             }
  102.  
  103.             if (itemStack1.stackSize == itemStack.stackSize)
  104.             {
  105.                 return null;
  106.             }
  107.  
  108.             slot.onPickupFromSlot(player, itemStack1);
  109.         }
  110.  
  111.         return itemStack;
  112.     }
  113.    
  114.     public void onContainerClosed(EntityPlayer player)
  115.     {
  116.         super.onContainerClosed(player);
  117.        
  118.         for(int x = 0; x < 5; ++x)
  119.         {
  120.             for(int y = 0; y < 7; ++y)
  121.             {
  122.                 grid[x][y] = false;
  123.             }
  124.         }
  125.        
  126.         if(!this.worldobj.isRemote)
  127.         {
  128.             ItemStack itemStack = this.inventoryInscription.getStackInSlotOnClosing(0);
  129.            
  130.             if (itemStack != null)
  131.             {
  132.                 player.dropPlayerItemWithRandomChoice(itemStack, false);
  133.             }
  134.         }
  135.     }
  136.    
  137.     @Override
  138.     public boolean canInteractWith(EntityPlayer player)
  139.     {
  140.         return true;
  141.     }
  142.    
  143.    
  144.    
  145.     ////
  146.     //// RECIPES
  147.     ////
  148.    
  149.    
  150.    
  151.     public void updateGrid(boolean grid, int posX, int posY)
  152.     {
  153.         this.grid[posX][posY] = grid;
  154.         this.checkRecipes();
  155.     }
  156.    
  157.     public void checkRecipes()
  158.     {
  159.         // Add dye
  160.        
  161.         boolean Firebolt[][] = new boolean[5][7];
  162.         Firebolt[0][0] = false; Firebolt[1][0] = false; Firebolt[2][0] = true; Firebolt[3][0] = false; Firebolt[4][0] = true;
  163.         Firebolt[0][1] = false; Firebolt[1][1] = false; Firebolt[2][1] = true; Firebolt[3][1] = true; Firebolt[4][1] = false;
  164.         Firebolt[0][2] = false; Firebolt[1][2] = false; Firebolt[2][2] = true; Firebolt[3][2] = false; Firebolt[4][2] = false;
  165.         Firebolt[0][3] = false; Firebolt[1][3] = false; Firebolt[2][3] = true; Firebolt[3][3] = false; Firebolt[4][3] = false;
  166.         Firebolt[0][4] = false; Firebolt[1][4] = false; Firebolt[2][4] = true; Firebolt[3][4] = false; Firebolt[4][4] = false;
  167.         Firebolt[0][5] = false; Firebolt[1][5] = true; Firebolt[2][5] = true; Firebolt[3][5] = false; Firebolt[4][5] = false;
  168.         Firebolt[0][6] = true; Firebolt[1][6] = false; Firebolt[2][6] = true; Firebolt[3][6] = false; Firebolt[4][6] = false;
  169.        
  170.         boolean Icebolt[][] = new boolean[5][7];
  171.         Icebolt[0][0] = false; Icebolt[1][0] = false; Icebolt[2][0] = true; Icebolt[3][0] = false; Icebolt[4][0] = false;
  172.         Icebolt[0][1] = false; Icebolt[1][1] = false; Icebolt[2][1] = true; Icebolt[3][1] = false; Icebolt[4][1] = false;
  173.         Icebolt[0][2] = false; Icebolt[1][2] = false; Icebolt[2][2] = true; Icebolt[3][2] = false; Icebolt[4][2] = false;
  174.         Icebolt[0][3] = false; Icebolt[1][3] = false; Icebolt[2][3] = true; Icebolt[3][3] = false; Icebolt[4][3] = false;
  175.         Icebolt[0][4] = false; Icebolt[1][4] = false; Icebolt[2][4] = true; Icebolt[3][4] = false; Icebolt[4][4] = false;
  176.         Icebolt[0][5] = false; Icebolt[1][5] = false; Icebolt[2][5] = true; Icebolt[3][5] = false; Icebolt[4][5] = false;
  177.         Icebolt[0][6] = false; Icebolt[1][6] = false; Icebolt[2][6] = true; Icebolt[3][6] = false; Icebolt[4][6] = false;
  178.        
  179.         boolean Lightningbolt[][] = new boolean[5][7];
  180.         Lightningbolt[0][0] = false; Lightningbolt[1][0] = true; Lightningbolt[2][0] = true; Lightningbolt[3][0] = false; Lightningbolt[4][0] = false;
  181.         Lightningbolt[0][1] = false; Lightningbolt[1][1] = true; Lightningbolt[2][1] = false; Lightningbolt[3][1] = true; Lightningbolt[4][1] = false;
  182.         Lightningbolt[0][2] = false; Lightningbolt[1][2] = true; Lightningbolt[2][2] = true; Lightningbolt[3][2] = false; Lightningbolt[4][2] = false;
  183.         Lightningbolt[0][3] = false; Lightningbolt[1][3] = true; Lightningbolt[2][3] = false; Lightningbolt[3][3] = true; Lightningbolt[4][3] = false;
  184.         Lightningbolt[0][4] = false; Lightningbolt[1][4] = true; Lightningbolt[2][4] = false; Lightningbolt[3][4] = false; Lightningbolt[4][4] = false;
  185.         Lightningbolt[0][5] = false; Lightningbolt[1][5] = true; Lightningbolt[2][5] = false; Lightningbolt[3][5] = false; Lightningbolt[4][5] = false;
  186.         Lightningbolt[0][6] = false; Lightningbolt[1][6] = true; Lightningbolt[2][6] = false; Lightningbolt[3][6] = false; Lightningbolt[4][6] = false;
  187.        
  188.         boolean Heal[][] = new boolean[5][7];
  189.         Heal[0][0] = true; Heal[1][0] = false; Heal[2][0] = false; Heal[3][0] = false; Heal[4][0] = true;
  190.         Heal[0][1] = true; Heal[1][1] = true; Heal[2][1] = false; Heal[3][1] = true; Heal[4][1] = true;
  191.         Heal[0][2] = true; Heal[1][2] = false; Heal[2][2] = true; Heal[3][2] = false; Heal[4][2] = true;
  192.         Heal[0][3] = true; Heal[1][3] = true; Heal[2][3] = false; Heal[3][3] = true; Heal[4][3] = true;
  193.         Heal[0][4] = true; Heal[1][4] = false; Heal[2][4] = false; Heal[3][4] = false; Heal[4][4] = true;
  194.         Heal[0][5] = true; Heal[1][5] = false; Heal[2][5] = false; Heal[3][5] = false; Heal[4][5] = true;
  195.         Heal[0][6] = true; Heal[1][6] = false; Heal[2][6] = false; Heal[3][6] = false; Heal[4][6] = true;
  196.        
  197.         boolean Dispel[][] = new boolean[5][7];
  198.         Dispel[0][0] = false; Dispel[1][0] = false; Dispel[2][0] = true; Dispel[3][0] = false; Dispel[4][0] = false;
  199.         Dispel[0][1] = true; Dispel[1][1] = false; Dispel[2][1] = true; Dispel[3][1] = false; Dispel[4][1] = false;
  200.         Dispel[0][2] = false; Dispel[1][2] = true; Dispel[2][2] = true; Dispel[3][2] = false; Dispel[4][2] = false;
  201.         Dispel[0][3] = false; Dispel[1][3] = false; Dispel[2][3] = true; Dispel[3][3] = true; Dispel[4][3] = false;
  202.         Dispel[0][4] = false; Dispel[1][4] = false; Dispel[2][4] = true; Dispel[3][4] = false; Dispel[4][4] = true;
  203.         Dispel[0][5] = false; Dispel[1][5] = false; Dispel[2][5] = true; Dispel[3][5] = false; Dispel[4][5] = false;
  204.         Dispel[0][6] = false; Dispel[1][6] = false; Dispel[2][6] = true; Dispel[3][6] = false; Dispel[4][6] = false;
  205.        
  206.         boolean Firerain[][] = new boolean[5][7];
  207.         Firerain[0][0] = false; Firerain[1][0] = false; Firerain[2][0] = false; Firerain[3][0] = false; Firerain[4][0] = false;
  208.         Firerain[0][1] = true; Firerain[1][1] = false; Firerain[2][1] = false; Firerain[3][1] = false; Firerain[4][1] = false;
  209.         Firerain[0][2] = true; Firerain[1][2] = false; Firerain[2][2] = false; Firerain[3][2] = true; Firerain[4][2] = false;
  210.         Firerain[0][3] = true; Firerain[1][3] = false; Firerain[2][3] = true; Firerain[3][3] = false; Firerain[4][3] = true;
  211.         Firerain[0][4] = false; Firerain[1][4] = true; Firerain[2][4] = false; Firerain[3][4] = false; Firerain[4][4] = true;
  212.         Firerain[0][5] = false; Firerain[1][5] = false; Firerain[2][5] = false; Firerain[3][5] = false; Firerain[4][5] = true;
  213.         Firerain[0][6] = false; Firerain[1][6] = false; Firerain[2][6] = false; Firerain[3][6] = false; Firerain[4][6] = false;
  214.        
  215.         boolean Chainlightning[][] = new boolean[5][7];
  216.         Chainlightning[0][0] = false; Chainlightning[1][0] = false; Chainlightning[2][0] = false; Chainlightning[3][0] = false; Chainlightning[4][0] = false;
  217.         Chainlightning[0][1] = true; Chainlightning[1][1] = false; Chainlightning[2][1] = false; Chainlightning[3][1] = true; Chainlightning[4][1] = false;
  218.         Chainlightning[0][2] = true; Chainlightning[1][2] = true; Chainlightning[2][2] = false; Chainlightning[3][2] = true; Chainlightning[4][2] = false;
  219.         Chainlightning[0][3] = true; Chainlightning[1][3] = false; Chainlightning[2][3] = true; Chainlightning[3][3] = true; Chainlightning[4][3] = false;
  220.         Chainlightning[0][4] = true; Chainlightning[1][4] = false; Chainlightning[2][4] = false; Chainlightning[3][4] = true; Chainlightning[4][4] = false;
  221.         Chainlightning[0][5] = true; Chainlightning[1][5] = false; Chainlightning[2][5] = false; Chainlightning[3][5] = true; Chainlightning[4][5] = false;
  222.         Chainlightning[0][6] = false; Chainlightning[1][6] = false; Chainlightning[2][6] = false; Chainlightning[3][6] = false; Chainlightning[4][6] = false;
  223.        
  224.         if(inventoryInscription.getStackInSlot(0) != null)
  225.         {
  226.             if((this.compare2DArray(this.grid, Firebolt) ==  true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 1)))
  227.             {
  228.                 inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneFirebolt, 1));
  229.             }
  230.             else if((this.compare2DArray(this.grid, Icebolt) ==  true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 12)))
  231.             {
  232.                 inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneIcebolt, 1));
  233.             }
  234.             else if((this.compare2DArray(this.grid, Lightningbolt) ==  true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 11)))
  235.             {
  236.                 inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneLightningbolt, 1));
  237.             }
  238.             else if((this.compare2DArray(this.grid, Heal) ==  true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 10)))
  239.             {
  240.                 inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneHeal, 1));
  241.             }
  242.             else if((this.compare2DArray(this.grid, Dispel) ==  true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 10)))
  243.             {
  244.                 inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneDispel, 1));
  245.             }
  246.             else if((this.compare2DArray(this.grid, Firerain) ==  true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 1)))
  247.             {
  248.                 inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneFirerain, 1));
  249.             }
  250.             else if((this.compare2DArray(this.grid, Chainlightning) ==  true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 11)))
  251.             {
  252.                 inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneChainlightning, 1));
  253.             }
  254.             else
  255.             {
  256.                 inventoryInscription.setInventorySlotContents(1, null);
  257.             }
  258.         }
  259.         else
  260.         {
  261.             inventoryInscription.setInventorySlotContents(1, null);
  262.         }
  263.     }
  264.    
  265.     public static boolean compare2DArray(boolean[][] grid2, boolean[][] firebolt)
  266.     {
  267.         for (int index = 0; index < grid2.length; index ++)
  268.         {
  269.             if (!Arrays.equals(grid2[index], firebolt[index]))
  270.             {
  271.                 return false;
  272.             }
  273.         }
  274.  
  275.         return true;
  276.     }
  277. }
Add Comment
Please, Sign In to add comment