package com.five35.minecraft.deathbox;

import com.mojang.authlib.GameProfile;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class DeathBoxBlock extends Block implements ITileEntityProvider {
	DeathBoxBlock() {
		super(DeathBoxMaterial.getInstance());

		this.disableStats();
		this.setHardness(-1); // == unbreakable
	}

	@Override
	public boolean canEntityDestroy(final IBlockAccess world, final int x, final int y, final int z, final Entity entity) {
		return false;
	}

	@Override
	public boolean canHarvestBlock(final EntityPlayer player, final int meta) {
		return false;
	}

	@Override
	public boolean canPlaceBlockAt(final World world, final int x, final int y, final int z) {
		return false;
	}

	@Override
	public TileEntity createNewTileEntity(final World world, final int metadata) {
		return new DeathBoxTileEntity();
	}

	@Override
	public AxisAlignedBB getCollisionBoundingBoxFromPool(final World world, final int x, final int y, final int z) {
		return null;
	}

	@Override
	public ItemStack getPickBlock(final MovingObjectPosition target, final World world, final int x, final int y, final int z) {
		return null;
	}

	@Override
	public int getRenderType() {
		return -1;
	}

	@Override
	public boolean isOpaqueCube() {
		return false;
	}

	@Override
	public boolean onBlockActivated(final World world, final int x, final int y, final int z, final EntityPlayer player, final int side, final float xOffset, final float yOffset, final float zOffset) {
		if (world.isRemote) {
			return false;
		}

		final TileEntity tileEntity = world.getTileEntity(x, y, z);

		if (tileEntity instanceof DeathBoxTileEntity) {
			final DeathBoxTileEntity deathBox = (DeathBoxTileEntity) tileEntity;
			final GameProfile owner = deathBox.getOwner();

			if (DeathBox.getProxy().getConfig().canRecover(owner, player)) {
				final String message = String.format("%s is recovering a death box left by %s.", owner.getName(), player.getCommandSenderName());
				DeathBox.getProxy().getLogger().info(message);

				deathBox.recover(player);

				return true;
			}

			final String message = String.format("%s does not have permission to recover a death box left by %s.", owner.getName(), player.getCommandSenderName());
			DeathBox.getProxy().getLogger().info(message);
		}

		return false;
	}

	@Override
	public void onBlockClicked(final World world, final int x, final int y, final int z, final EntityPlayer player) {
		if (world.isRemote) {
			return;
		}

		final TileEntity tileEntity = world.getTileEntity(x, y, z);

		if (tileEntity instanceof DeathBoxTileEntity) {
			final DeathBoxTileEntity deathBox = (DeathBoxTileEntity) tileEntity;
			final GameProfile owner = deathBox.getOwner();

			if (DeathBox.getProxy().getConfig().canPop(owner, player)) {
				final String message = String.format("%s is popping a death box left by %s.", owner.getName(), player.getCommandSenderName());
				DeathBox.getProxy().getLogger().info(message);

				deathBox.pop();
			} else {
				final String message = String.format("%s does not have permission to pop a death box left by %s.", owner.getName(), player.getCommandSenderName());
				DeathBox.getProxy().getLogger().info(message);
			}
		}
	}

	@Override
	public void onBlockExploded(final World world, final int x, final int y, final int z, final Explosion explosion) {
		// DeathBox is unexplodable!
	}

	@Override
	public boolean removedByPlayer(final World world, final EntityPlayer player, final int x, final int y, final int z) {
		return false;
	}

	@Override
	public boolean renderAsNormalBlock() {
		return false;
	}
}

@@ -150,24 +150,70 @@
 tyProvider;%0A
+import net.minecraft.block.state.IBlockState;%0A
 import net.m
@@ -407,16 +407,90 @@
 gnedBB;%0A
+import net.minecraft.util.BlockPos;%0Aimport net.minecraft.util.EnumFacing;%0A
 import n
@@ -927,39 +927,25 @@
 nal 
-int x, final int y, final int z
+BlockPos position
 , fi
@@ -1030,24 +1030,75 @@
 Block(final 
+IBlockAccess world, final BlockPos position, final 
 EntityPlayer
@@ -1104,32 +1104,16 @@
 r player
-, final int meta
 ) %7B%0A%09%09re
@@ -1200,39 +1200,25 @@
 nal 
-int x, final int y, final int z
+BlockPos position
 ) %7B%0A
@@ -1427,16 +1427,8 @@
 gBox
-FromPool
 (fin
@@ -1453,39 +1453,50 @@
 nal 
-int x, final int y, final int z
+BlockPos position, final IBlockState state
 ) %7B%0A
@@ -1620,39 +1620,25 @@
 nal 
-int x, final int y, final int z
+BlockPos position
 ) %7B%0A
@@ -1851,39 +1851,50 @@
 nal 
-int x, final int y, final int z
+BlockPos position, final IBlockState state
 , fi
@@ -1924,19 +1924,26 @@
 , final 
+EnumFac
 in
-t
+g
  side, f
@@ -2096,39 +2096,40 @@
 d.getTileEntity(
-x, y, z
+position
 );%0A%0A%09%09if (tileEn
@@ -2474,32 +2474,44 @@
 getCommandSender
+Entity().get
 Name());%0A%09%09%09%09Dea
@@ -2747,32 +2747,44 @@
 getCommandSender
+Entity().get
 Name());%0A%09%09%09Deat
@@ -2919,39 +2919,25 @@
 nal 
-int x, final int y, final int z
+BlockPos position
 , fi
@@ -3059,15 +3059,16 @@
 ity(
-x, y, z
+position
 );%0A%0A
@@ -3418,36 +3418,38 @@
 getCommandSender
-Name
+Entity
 ());%0A%09%09%09%09DeathBo
@@ -3664,20 +3664,22 @@
 ndSender
-Name
+Entity
 ());%0A%09%09%09
@@ -3808,39 +3808,25 @@
 nal 
-int x, final int y, final int z
+BlockPos position
 , fi
@@ -3959,48 +3959,33 @@
 nal 
-EntityPlayer player, final int x
+BlockPos position
 , final 
 int 
@@ -3984,97 +3984,54 @@
 nal 
-int y, final int z) %7B%0A%09%09return false;%0A%09%7D%0A%0A%09@Override%0A%09public boolean renderAsNormalBlock(
+EntityPlayer player, final boolean willHarvest
 ) %7B%0A

update block for 1.8