package com.hea3ven.buildingbricks.core.client.gui;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import com.hea3ven.buildingbricks.core.ModBuildingBricks;
import com.hea3ven.buildingbricks.core.materials.Material;
import com.hea3ven.buildingbricks.core.materials.MaterialStack;

public class GuiTrowel extends GuiContainer {

	private static final ResourceLocation BG_RESOURCE =
			new ResourceLocation("buildingbricks:textures/gui/container/trowel.png");

	private EntityPlayer player;

	public GuiTrowel(EntityPlayer player, ItemStack trowel) {
		super(ModBuildingBricks.trowel.getContainer(player, trowel));

		this.player = player;
	}

	@Override
	protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
		GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
		mc.getTextureManager().bindTexture(BG_RESOURCE);

		int k = (this.width - this.xSize) / 2;
		int l = (this.height - this.ySize) / 2;
		this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

		ItemStack stack = player.getCurrentEquippedItem();
		Material mat = MaterialStack.get(stack);
		int i = mat.getBlockRotation().getIndex(ModBuildingBricks.trowel.getCurrentBlockType(stack));
		int xCol = i % 4;
		int yCol = i / 4;
		this.drawTexturedModalRect(k + 95 + 18 * xCol, l + 6 + 18 * yCol, 176, 0, 22, 22);
	}
}

@@ -1280,16 +1280,38 @@
 stack);%0A
+%09%09if (mat != null) %7B%0A%09
 %09%09int i 
@@ -1396,24 +1396,25 @@
 (stack));%0A%09%09
+%09
 int xCol = i
@@ -1419,16 +1419,17 @@
  i %25 4;%0A
+%09
 %09%09int yC
@@ -1440,16 +1440,17 @@
  i / 4;%0A
+%09
 %09%09this.d
@@ -1526,13 +1526,17 @@
 2, 22);%0A
+%09%09%7D%0A
 %09%7D%0A%7D%0A

Fix crash when opening the gui for an unbinded trowel