Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package melonslise.runicinscription.common.container;
- import java.util.Arrays;
- import melonslise.runicinscription.RunicInscription;
- import melonslise.runicinscription.common.inventory.InventoryRuneInscription;
- import melonslise.runicinscription.common.inventory.SlotRuneInscription;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.init.Items;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraft.world.World;
- public class ContainerRuneInscription extends Container
- {
- public boolean grid[][] = new boolean[5][7];
- public InventoryRuneInscription inventoryInscription = new InventoryRuneInscription(this);
- private World worldobj;
- private int posX;
- private int posY;
- private int posZ;
- private static final int Input = 0;
- private static final int Output = 1;
- public ContainerRuneInscription(InventoryPlayer inventoryPlayer, World world, int x, int y, int z)
- {
- this.worldobj = world;
- this.posX = x;
- this.posY = y;
- this.posZ = z;
- this.addSlotToContainer(new SlotRuneInscription(inventoryInscription, this, Input, 8, 47));
- this.addSlotToContainer(new SlotRuneInscription(inventoryInscription, this, Output, 152, 47));
- for (int i = 0; i < 3; ++i)
- {
- for (int k = 0; k < 9; ++k)
- {
- this.addSlotToContainer(new Slot(inventoryPlayer, k + i * 9 + 9, 8 + k * 18, 124 + i * 18));
- }
- }
- for (int i = 0; i < 9; ++i)
- {
- this.addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 182));
- }
- }
- @Override
- public ItemStack transferStackInSlot(EntityPlayer player, int fromSlot)
- {
- ItemStack itemStack = null;
- Slot slot = (Slot)this.inventorySlots.get(fromSlot);
- if (slot != null && slot.getHasStack())
- {
- ItemStack itemStack1 = slot.getStack();
- itemStack = itemStack1.copy();
- if(fromSlot <= this.Output)
- {
- if (!this.mergeItemStack(itemStack1, this.Output + 1, this.Output + 36 + 1, true))
- {
- return null;
- }
- }
- else if(fromSlot > this.Output)
- {
- if(itemStack1.getItem() == Items.dye)
- {
- if(!this.mergeItemStack(itemStack1, this.Input, this.Input + 1, true))
- {
- return null;
- }
- }
- }
- else if (fromSlot >= this.Output + 1 && fromSlot < this.Output + 28)
- {
- if (!this.mergeItemStack(itemStack1, this.Output + 28, this.Output + 37, false))
- {
- return null;
- }
- }
- else if (fromSlot >= this.Output + 28 && fromSlot < this.Output + 37)
- {
- if(!this.mergeItemStack(itemStack1, this.Output + 1, this.Output + 28, false))
- {
- return null;
- }
- }
- if (itemStack1.stackSize == 0)
- {
- slot.putStack((ItemStack)null);
- }
- else
- {
- slot.onSlotChanged();
- }
- if (itemStack1.stackSize == itemStack.stackSize)
- {
- return null;
- }
- slot.onPickupFromSlot(player, itemStack1);
- }
- return itemStack;
- }
- public void onContainerClosed(EntityPlayer player)
- {
- super.onContainerClosed(player);
- for(int x = 0; x < 5; ++x)
- {
- for(int y = 0; y < 7; ++y)
- {
- grid[x][y] = false;
- }
- }
- if(!this.worldobj.isRemote)
- {
- ItemStack itemStack = this.inventoryInscription.getStackInSlotOnClosing(0);
- if (itemStack != null)
- {
- player.dropPlayerItemWithRandomChoice(itemStack, false);
- }
- }
- }
- @Override
- public boolean canInteractWith(EntityPlayer player)
- {
- return true;
- }
- ////
- //// RECIPES
- ////
- public void updateGrid(boolean grid, int posX, int posY)
- {
- this.grid[posX][posY] = grid;
- this.checkRecipes();
- }
- public void checkRecipes()
- {
- // Add dye
- boolean Firebolt[][] = new boolean[5][7];
- Firebolt[0][0] = false; Firebolt[1][0] = false; Firebolt[2][0] = true; Firebolt[3][0] = false; Firebolt[4][0] = true;
- Firebolt[0][1] = false; Firebolt[1][1] = false; Firebolt[2][1] = true; Firebolt[3][1] = true; Firebolt[4][1] = false;
- Firebolt[0][2] = false; Firebolt[1][2] = false; Firebolt[2][2] = true; Firebolt[3][2] = false; Firebolt[4][2] = false;
- Firebolt[0][3] = false; Firebolt[1][3] = false; Firebolt[2][3] = true; Firebolt[3][3] = false; Firebolt[4][3] = false;
- Firebolt[0][4] = false; Firebolt[1][4] = false; Firebolt[2][4] = true; Firebolt[3][4] = false; Firebolt[4][4] = false;
- Firebolt[0][5] = false; Firebolt[1][5] = true; Firebolt[2][5] = true; Firebolt[3][5] = false; Firebolt[4][5] = false;
- Firebolt[0][6] = true; Firebolt[1][6] = false; Firebolt[2][6] = true; Firebolt[3][6] = false; Firebolt[4][6] = false;
- boolean Icebolt[][] = new boolean[5][7];
- Icebolt[0][0] = false; Icebolt[1][0] = false; Icebolt[2][0] = true; Icebolt[3][0] = false; Icebolt[4][0] = false;
- Icebolt[0][1] = false; Icebolt[1][1] = false; Icebolt[2][1] = true; Icebolt[3][1] = false; Icebolt[4][1] = false;
- Icebolt[0][2] = false; Icebolt[1][2] = false; Icebolt[2][2] = true; Icebolt[3][2] = false; Icebolt[4][2] = false;
- Icebolt[0][3] = false; Icebolt[1][3] = false; Icebolt[2][3] = true; Icebolt[3][3] = false; Icebolt[4][3] = false;
- Icebolt[0][4] = false; Icebolt[1][4] = false; Icebolt[2][4] = true; Icebolt[3][4] = false; Icebolt[4][4] = false;
- Icebolt[0][5] = false; Icebolt[1][5] = false; Icebolt[2][5] = true; Icebolt[3][5] = false; Icebolt[4][5] = false;
- Icebolt[0][6] = false; Icebolt[1][6] = false; Icebolt[2][6] = true; Icebolt[3][6] = false; Icebolt[4][6] = false;
- boolean Lightningbolt[][] = new boolean[5][7];
- Lightningbolt[0][0] = false; Lightningbolt[1][0] = true; Lightningbolt[2][0] = true; Lightningbolt[3][0] = false; Lightningbolt[4][0] = false;
- Lightningbolt[0][1] = false; Lightningbolt[1][1] = true; Lightningbolt[2][1] = false; Lightningbolt[3][1] = true; Lightningbolt[4][1] = false;
- Lightningbolt[0][2] = false; Lightningbolt[1][2] = true; Lightningbolt[2][2] = true; Lightningbolt[3][2] = false; Lightningbolt[4][2] = false;
- Lightningbolt[0][3] = false; Lightningbolt[1][3] = true; Lightningbolt[2][3] = false; Lightningbolt[3][3] = true; Lightningbolt[4][3] = false;
- Lightningbolt[0][4] = false; Lightningbolt[1][4] = true; Lightningbolt[2][4] = false; Lightningbolt[3][4] = false; Lightningbolt[4][4] = false;
- Lightningbolt[0][5] = false; Lightningbolt[1][5] = true; Lightningbolt[2][5] = false; Lightningbolt[3][5] = false; Lightningbolt[4][5] = false;
- Lightningbolt[0][6] = false; Lightningbolt[1][6] = true; Lightningbolt[2][6] = false; Lightningbolt[3][6] = false; Lightningbolt[4][6] = false;
- boolean Heal[][] = new boolean[5][7];
- Heal[0][0] = true; Heal[1][0] = false; Heal[2][0] = false; Heal[3][0] = false; Heal[4][0] = true;
- Heal[0][1] = true; Heal[1][1] = true; Heal[2][1] = false; Heal[3][1] = true; Heal[4][1] = true;
- Heal[0][2] = true; Heal[1][2] = false; Heal[2][2] = true; Heal[3][2] = false; Heal[4][2] = true;
- Heal[0][3] = true; Heal[1][3] = true; Heal[2][3] = false; Heal[3][3] = true; Heal[4][3] = true;
- Heal[0][4] = true; Heal[1][4] = false; Heal[2][4] = false; Heal[3][4] = false; Heal[4][4] = true;
- Heal[0][5] = true; Heal[1][5] = false; Heal[2][5] = false; Heal[3][5] = false; Heal[4][5] = true;
- Heal[0][6] = true; Heal[1][6] = false; Heal[2][6] = false; Heal[3][6] = false; Heal[4][6] = true;
- boolean Dispel[][] = new boolean[5][7];
- Dispel[0][0] = false; Dispel[1][0] = false; Dispel[2][0] = true; Dispel[3][0] = false; Dispel[4][0] = false;
- Dispel[0][1] = true; Dispel[1][1] = false; Dispel[2][1] = true; Dispel[3][1] = false; Dispel[4][1] = false;
- Dispel[0][2] = false; Dispel[1][2] = true; Dispel[2][2] = true; Dispel[3][2] = false; Dispel[4][2] = false;
- Dispel[0][3] = false; Dispel[1][3] = false; Dispel[2][3] = true; Dispel[3][3] = true; Dispel[4][3] = false;
- Dispel[0][4] = false; Dispel[1][4] = false; Dispel[2][4] = true; Dispel[3][4] = false; Dispel[4][4] = true;
- Dispel[0][5] = false; Dispel[1][5] = false; Dispel[2][5] = true; Dispel[3][5] = false; Dispel[4][5] = false;
- Dispel[0][6] = false; Dispel[1][6] = false; Dispel[2][6] = true; Dispel[3][6] = false; Dispel[4][6] = false;
- boolean Firerain[][] = new boolean[5][7];
- Firerain[0][0] = false; Firerain[1][0] = false; Firerain[2][0] = false; Firerain[3][0] = false; Firerain[4][0] = false;
- Firerain[0][1] = true; Firerain[1][1] = false; Firerain[2][1] = false; Firerain[3][1] = false; Firerain[4][1] = false;
- Firerain[0][2] = true; Firerain[1][2] = false; Firerain[2][2] = false; Firerain[3][2] = true; Firerain[4][2] = false;
- Firerain[0][3] = true; Firerain[1][3] = false; Firerain[2][3] = true; Firerain[3][3] = false; Firerain[4][3] = true;
- Firerain[0][4] = false; Firerain[1][4] = true; Firerain[2][4] = false; Firerain[3][4] = false; Firerain[4][4] = true;
- Firerain[0][5] = false; Firerain[1][5] = false; Firerain[2][5] = false; Firerain[3][5] = false; Firerain[4][5] = true;
- Firerain[0][6] = false; Firerain[1][6] = false; Firerain[2][6] = false; Firerain[3][6] = false; Firerain[4][6] = false;
- boolean Chainlightning[][] = new boolean[5][7];
- Chainlightning[0][0] = false; Chainlightning[1][0] = false; Chainlightning[2][0] = false; Chainlightning[3][0] = false; Chainlightning[4][0] = false;
- Chainlightning[0][1] = true; Chainlightning[1][1] = false; Chainlightning[2][1] = false; Chainlightning[3][1] = true; Chainlightning[4][1] = false;
- Chainlightning[0][2] = true; Chainlightning[1][2] = true; Chainlightning[2][2] = false; Chainlightning[3][2] = true; Chainlightning[4][2] = false;
- Chainlightning[0][3] = true; Chainlightning[1][3] = false; Chainlightning[2][3] = true; Chainlightning[3][3] = true; Chainlightning[4][3] = false;
- Chainlightning[0][4] = true; Chainlightning[1][4] = false; Chainlightning[2][4] = false; Chainlightning[3][4] = true; Chainlightning[4][4] = false;
- Chainlightning[0][5] = true; Chainlightning[1][5] = false; Chainlightning[2][5] = false; Chainlightning[3][5] = true; Chainlightning[4][5] = false;
- Chainlightning[0][6] = false; Chainlightning[1][6] = false; Chainlightning[2][6] = false; Chainlightning[3][6] = false; Chainlightning[4][6] = false;
- if(inventoryInscription.getStackInSlot(0) != null)
- {
- if((this.compare2DArray(this.grid, Firebolt) == true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 1)))
- {
- inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneFirebolt, 1));
- }
- else if((this.compare2DArray(this.grid, Icebolt) == true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 12)))
- {
- inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneIcebolt, 1));
- }
- else if((this.compare2DArray(this.grid, Lightningbolt) == true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 11)))
- {
- inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneLightningbolt, 1));
- }
- else if((this.compare2DArray(this.grid, Heal) == true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 10)))
- {
- inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneHeal, 1));
- }
- else if((this.compare2DArray(this.grid, Dispel) == true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 10)))
- {
- inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneDispel, 1));
- }
- else if((this.compare2DArray(this.grid, Firerain) == true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 1)))
- {
- inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneFirerain, 1));
- }
- else if((this.compare2DArray(this.grid, Chainlightning) == true) && ((inventoryInscription.getStackInSlot(0).getItem() == Items.dye) && (inventoryInscription.getStackInSlot(0).getItemDamage() == 11)))
- {
- inventoryInscription.setInventorySlotContents(1, new ItemStack(RunicInscription.itemRuneChainlightning, 1));
- }
- else
- {
- inventoryInscription.setInventorySlotContents(1, null);
- }
- }
- else
- {
- inventoryInscription.setInventorySlotContents(1, null);
- }
- }
- public static boolean compare2DArray(boolean[][] grid2, boolean[][] firebolt)
- {
- for (int index = 0; index < grid2.length; index ++)
- {
- if (!Arrays.equals(grid2[index], firebolt[index]))
- {
- return false;
- }
- }
- return true;
- }
- }
Add Comment
Please, Sign In to add comment