package net.geforcemods.securitycraft.blocks;

import net.geforcemods.securitycraft.tileentity.BlockPocketManagerTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer.Builder;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Direction;
import net.minecraft.util.Hand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.World;
import net.minecraftforge.fml.network.NetworkHooks;

public class BlockPocketManagerBlock extends OwnableBlock
{
	public static final DirectionProperty FACING = DirectionProperty.create("facing", Direction.Plane.HORIZONTAL);

	public BlockPocketManagerBlock(Block.Properties properties)
	{
		super(properties);
	}

	@Override
	public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit)
	{
		if(!world.isRemote)
		{
			TileEntity te = world.getTileEntity(pos);

			if(te instanceof INamedContainerProvider)
				NetworkHooks.openGui((ServerPlayerEntity)player, (INamedContainerProvider)te, pos);
		}

		return ActionResultType.SUCCESS;
	}

	@Override
	public BlockState getStateForPlacement(BlockItemUseContext context)
	{
		return getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
	}

	@Override
	protected void fillStateContainer(Builder<Block, BlockState> builder)
	{
		builder.add(FACING);
	}

	@Override
	public TileEntity createTileEntity(BlockState state, IBlockReader world)
	{
		return new BlockPocketManagerTileEntity();
	}

	@Override
	public BlockState rotate(BlockState state, Rotation rot)
	{
		return state.with(FACING, rot.rotate(state.get(FACING)));
	}

	@Override
	public BlockState mirror(BlockState state, Mirror mirror)
	{
		return state.rotate(mirror.toRotation(state.get(FACING)));
	}
}

@@ -294,32 +294,81 @@
 rPlayerEntity;%0D%0A
+import net.minecraft.inventory.InventoryHelper;%0D%0A
 import net.minec
@@ -1709,32 +1709,720 @@
 SUCCESS;%0D%0A%09%7D%0D%0A%0D%0A
+%09@Override%0D%0A%09public void onReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean isMoving)%0D%0A%09%7B%0D%0A%09%09if(world.isRemote %7C%7C state.getBlock() == newState.getBlock())%0D%0A%09%09%09return;%0D%0A%0D%0A%09%09TileEntity tile = world.getTileEntity(pos);%0D%0A%0D%0A%09%09if(tile instanceof BlockPocketManagerTileEntity)%0D%0A%09%09%7B%0D%0A%09%09%09BlockPocketManagerTileEntity te = (BlockPocketManagerTileEntity)tile;%0D%0A%0D%0A%09%09%09te.getStorageHandler().ifPresent(handler -%3E %7B%0D%0A%09%09%09%09for(int i = 0; i %3C handler.getSlots(); i++)%0D%0A%09%09%09%09%7B%0D%0A%09%09%09%09%09InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), handler.getStackInSlot(i));%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D);%0D%0A%09%09%7D%0D%0A%0D%0A%09%09super.onReplaced(state, world, pos, newState, isMoving);%0D%0A%09%7D%0D%0A%0D%0A
 %09@Override%0D%0A%09pub

fix block pocket manager's contents not dropping when broken