package org.egordorichev.lasttry.item;

import org.egordorichev.lasttry.LastTry;
import org.egordorichev.lasttry.item.blocks.BlockGround;
import org.egordorichev.lasttry.util.Assets;
import org.egordorichev.lasttry.world.tile.TileData;
import org.newdawn.slick.Image;

public class Block extends Item {
	public static final int DIRT_ID = 1;
	public static final int GRASS_ID = 3;
	public static final Block dirt = new BlockGround(Block.DIRT_ID, "Dirt block", true, Assets.dirtTileTexture);
	public static final Block grass = new BlockGround(Block.GRASS_ID, "Grass block", true, Assets.grassTileTexture);
	public static final int TEX_SIZE = 16;

	protected boolean solid;
	

	public Block(int id, String name, boolean solid, Image tiles) {
		super(id, name, Item.Type.BLOCK);

		this.texture = tiles;
		this.solid = solid;
	}

	public void renderBlock(TileData data, int x, int y) {
		boolean t = LastTry.world.getBlockId(x, y - 1) == this.id;
		boolean r = LastTry.world.getBlockId(x + 1, y) == this.id;
		boolean b = LastTry.world.getBlockId(x, y + 1) == this.id;
		boolean l = LastTry.world.getBlockId(x - 1, y) == this.id;

		this.texture.getSubImage(this.calculateBinary(t, r, b, l) * Block.TEX_SIZE, data.variant * Block.TEX_SIZE, Block.TEX_SIZE, Block.TEX_SIZE).draw(x * Block.TEX_SIZE, y * Block.TEX_SIZE);
	}

	protected int calculateBinary(boolean top, boolean right, boolean bottom, boolean left) {
		int result = 0;

		if(top == true) {
			result += 1;
		}

		if(right == true) {
			result += 2;
		}

		if(bottom == true) {
			result += 4;
		}

		if(left == true) {
			result += 8;
		}

		return result;
	}

	public boolean isSolid() {
		return this.solid;
	}
	
	public static void preload() { }

}

@@ -300,85 +300,8 @@
 m %7B%0A
-%09public static final int DIRT_ID = 1;%0A%09public static final int GRASS_ID = 3;%0A
 %09pub
@@ -350,21 +350,24 @@
 und(
-Block.DIRT_ID
+ItemID.dirtBlock
 , %22D
@@ -464,22 +464,25 @@
 und(
-Block.GRASS_ID
+ItemID.grassBlock
 , %22G
@@ -518,32 +518,34 @@
 ssTileTexture);%0A
+%09%0A
 %09public static f
@@ -568,17 +568,16 @@
 E = 16;%0A
-%0A
 %09protect
@@ -593,18 +593,16 @@
 n solid;
-%0A%09
 %0A%0A%09publi

Update Block.java